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},
131 static int retry = 0;
133 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
135 if (conn == NULL || signal_name == NULL)
136 return; //LCOV_EXCL_LINE
138 GVariant *message = NULL;
139 GError *error = NULL;
142 message = g_variant_new("(s)", arg);
144 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
145 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
147 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
148 g_error_free(error); //LCOV_EXCL_LINE
150 g_variant_unref(message);
153 static bool __any_tethering_is_enabled(tethering_h tethering)
155 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
156 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
157 tethering_is_enabled(tethering, TETHERING_TYPE_BT))
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");
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");
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");
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");
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");
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");
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");
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;
289 case MOBILE_AP_ERROR_ALREADY_ENABLED:
290 err = TETHERING_ERROR_OPERATION_FAILED;
293 case MOBILE_AP_ERROR_NOT_ENABLED:
294 err = TETHERING_ERROR_NOT_ENABLED;
297 case MOBILE_AP_ERROR_NET_OPEN:
298 err = TETHERING_ERROR_OPERATION_FAILED;
301 case MOBILE_AP_ERROR_NET_CLOSE:
302 err = TETHERING_ERROR_OPERATION_FAILED;
305 case MOBILE_AP_ERROR_DHCP:
306 err = TETHERING_ERROR_OPERATION_FAILED;
309 case MOBILE_AP_ERROR_IN_PROGRESS:
310 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;
372 ERR("Not supported tethering type [%d]\n", ap_type);
376 ccb = th->changed_cb[type];
379 data = th->changed_user_data[type];
381 client.interface = type;
382 g_strlcpy(client.ip, ip, sizeof(client.ip));
383 g_strlcpy(client.mac, mac, sizeof(client.mac));
385 client.hostname = g_strdup(name);
386 client.tm = (time_t)timestamp;
388 ccb((tethering_client_h)&client, opened, data);
389 g_free(client.hostname);
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);
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)
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;
723 g_variant_get(parameters, "(s)", &buf);
724 data = th->ssid_visibility_user_data;
725 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
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)
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;
755 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
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 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
772 ERR("DBus error [%s]\n", g_error->message);
773 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
774 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
775 g_error_free(g_error);
776 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
778 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
779 error = TETHERING_ERROR_PERMISSION_DENIED;
781 error = TETHERING_ERROR_OPERATION_FAILED;
782 g_error_free(g_error);
785 g_variant_get(g_var, "(u)", &info);
786 error = __get_error(info);
790 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
791 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
792 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
793 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
799 ecb(error, TETHERING_TYPE_WIFI, true, data);
800 g_variant_unref(g_var);
804 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
808 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
809 GError *g_error = NULL;
812 tethering_error_e error;
814 __tethering_h *th = (__tethering_h *)user_data;
815 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
816 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
818 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
821 ERR("DBus error [%s]\n", g_error->message);
822 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
823 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
824 g_error_free(g_error);
825 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
829 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
830 error = TETHERING_ERROR_PERMISSION_DENIED;
832 error = TETHERING_ERROR_OPERATION_FAILED;
833 g_error_free(g_error);
836 g_variant_get(g_var, "(u)", &info);
837 g_variant_unref(g_var);
838 error = __get_error(info);
842 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
843 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
844 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
845 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
852 ecb(error, TETHERING_TYPE_BT, true, data);
857 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
862 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
863 __tethering_h *th = (__tethering_h *)user_data;
864 GError *g_error = NULL;
867 tethering_error_e error;
868 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
869 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
871 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
873 ERR("DBus error [%s]\n", g_error->message);
874 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
875 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
876 g_error_free(g_error);
877 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
881 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
882 error = TETHERING_ERROR_PERMISSION_DENIED;
884 error = TETHERING_ERROR_OPERATION_FAILED;
885 g_error_free(g_error);
887 g_variant_get(g_var, "(u)", &info);
888 g_variant_unref(g_var);
889 error = __get_error(info);
893 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
894 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
895 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
896 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
903 ecb(error, TETHERING_TYPE_USB, true, data);
908 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
913 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
914 GError *g_error = NULL;
916 guint info, event_type;
917 tethering_error_e error;
918 tethering_type_e type;
919 tethering_h tethering = (tethering_h)user_data;
920 __tethering_h *th = (__tethering_h *)tethering;
921 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
922 tethering_disabled_cb dcb = NULL;
925 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
928 ERR("DBus error [%s]\n", g_error->message);
929 g_error_free(g_error);
933 g_variant_get(g_var, "(uu)", &event_type, &info);
934 DBG("cfm event : %d info : %d\n", event_type, info);
935 g_variant_unref(g_var);
936 error = __get_error(info);
937 DBG("cfm event : %d info : %d\n", event_type, error);
938 switch (event_type) {
939 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
940 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
941 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
942 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
943 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
945 type = TETHERING_TYPE_WIFI;
946 dcb = th->disabled_cb[type];
947 data = th->disabled_user_data[type];
949 dcb(error, type, code, data);
952 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
953 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
954 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
955 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
956 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
958 type = TETHERING_TYPE_BT;
959 dcb = th->disabled_cb[type];
960 data = th->disabled_user_data[type];
962 dcb(error, type, code, data);
966 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
967 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
968 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
969 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
970 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
972 type = TETHERING_TYPE_USB;
973 dcb = th->disabled_cb[type];
974 data = th->disabled_user_data[type];
976 dcb(error, type, code, data);
980 case MOBILE_AP_DISABLE_CFM:
982 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
983 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
984 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
985 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
986 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
987 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
988 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
989 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
990 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
991 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
992 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
993 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
995 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
996 dcb = th->disabled_cb[type];
999 data = th->disabled_user_data[type];
1001 dcb(error, type, code, data);
1006 ERR("Invalid event\n");
1012 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1017 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1019 GError *g_error = NULL;
1022 guint64 tx_bytes, rx_bytes;
1023 __tethering_h *th = (__tethering_h *)user_data;
1024 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1027 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1030 ERR("DBus fail [%s]\n", g_error->message);
1031 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1032 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1034 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1039 if (th->data_usage_cb == NULL) {
1040 ERR("There is no data_usage_cb\n");
1044 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1046 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1047 th->data_usage_cb(TETHERING_ERROR_NONE,
1048 rx_bytes, tx_bytes, th->data_usage_user_data);
1049 g_variant_unref(g_var);
1051 th->data_usage_cb = NULL;
1052 th->data_usage_user_data = NULL;
1057 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1062 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1063 GError *g_error = NULL;
1066 __tethering_h *th = (__tethering_h *)user_data;
1067 tethering_error_e tethering_error;
1069 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1071 ERR("DBus fail [%s]\n", g_error->message);
1072 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1073 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1075 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1076 g_error_free(g_error);
1078 if (th->settings_reloaded_cb == NULL) {
1079 DBG("There is no settings_reloaded_cb\n-\n");
1082 g_variant_get(g_var, "(u)", &info);
1083 tethering_error = __get_error(info);
1084 g_variant_unref(g_var);
1086 th->settings_reloaded_cb(tethering_error,
1087 th->settings_reloaded_user_data);
1089 th->settings_reloaded_cb = NULL;
1090 th->settings_reloaded_user_data = NULL;
1094 static void __connect_signals(tethering_h tethering)
1097 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1099 __tethering_h *th = (__tethering_h *)tethering;
1100 GDBusConnection *connection = th->client_bus;
1103 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1104 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1105 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1106 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1107 sigs[i].cb, tethering, NULL);
1112 static void __disconnect_signals(tethering_h tethering)
1116 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1118 __tethering_h *th = (__tethering_h *)tethering;
1119 GDBusConnection *connection = th->client_bus;
1123 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1124 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1130 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1132 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1136 case TETHERING_TYPE_USB:
1137 g_strlcpy(buf, TETHERING_USB_IF, len);
1140 case TETHERING_TYPE_WIFI:
1141 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1144 case TETHERING_TYPE_BT:
1145 g_strlcpy(buf, TETHERING_BT_IF, len);
1149 ERR("Not supported type : %d\n", type);
1155 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1157 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1160 case TETHERING_TYPE_USB:
1161 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1164 case TETHERING_TYPE_WIFI:
1165 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1168 case TETHERING_TYPE_BT:
1169 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1173 ERR("Not supported type : %d\n", type);
1179 static int __get_common_ssid(char *ssid, unsigned int size)
1182 ERR("ssid is null\n"); //LCOV_EXCL_LINE
1183 return TETHERING_ERROR_INVALID_PARAMETER;
1187 char *ptr_tmp = NULL;
1189 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1191 ERR("vconf_get_str is failed and set default ssid");
1192 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1194 g_strlcpy(ssid, ptr, size);
1198 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1201 return TETHERING_ERROR_NONE;
1204 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1206 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1209 case TETHERING_WIFI_MODE_TYPE_B:
1210 *buf = g_strdup("b");
1212 case TETHERING_WIFI_MODE_TYPE_G:
1213 *buf = g_strdup("g");
1215 case TETHERING_WIFI_MODE_TYPE_A:
1216 *buf = g_strdup("a");
1218 case TETHERING_WIFI_MODE_TYPE_AD:
1219 *buf = g_strdup("ad");
1222 ERR("Not supported type : %d\n", type);
1228 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1232 __tethering_h *th = (__tethering_h *)tethering;
1233 tethering_error_e ret = TETHERING_ERROR_NONE;
1236 if (th == NULL || set == NULL) {
1237 ERR("null parameter\n-\n");
1238 return TETHERING_ERROR_INVALID_PARAMETER;
1241 if (th->ssid == NULL)
1242 __get_common_ssid(set->ssid, sizeof(set->ssid));
1244 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1246 ret = __get_security_type(&set->sec_type);
1247 if (ret != TETHERING_ERROR_NONE)
1248 set->sec_type = th->sec_type;
1250 ret = __get_visible(&set->visibility);
1251 if (ret != TETHERING_ERROR_NONE)
1252 set->visibility = th->visibility;
1254 set->mac_filter = th->mac_filter;
1255 set->max_connected = th->wifi_max_connected;
1256 set->channel = th->channel;
1258 __get_wifi_mode_type(th->mode_type, &ptr);
1260 g_strlcpy(set->mode, "", sizeof(set->mode));
1262 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1266 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1267 g_strlcpy(set->key, "", sizeof(set->key));
1269 GDBusProxy *proxy = th->client_bus_proxy;
1270 GVariant *parameters;
1271 GError *error = NULL;
1272 char *passphrase = NULL;
1273 unsigned int len = 0;
1275 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1276 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1280 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1282 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1283 ret = TETHERING_ERROR_PERMISSION_DENIED;
1285 ret = TETHERING_ERROR_OPERATION_FAILED;
1287 g_error_free(error);
1292 if (parameters != NULL) {
1293 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1294 g_variant_unref(parameters);
1297 g_strlcpy(set->key, passphrase, sizeof(set->key));
1300 return TETHERING_ERROR_NONE;
1303 static bool __check_precondition(tethering_type_e type)
1306 int cellular_state = 0;
1309 /* data network through cellular */
1310 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1311 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1312 ERR("Data Network can be connected later");
1317 /* data network through ethernet */
1318 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_state);
1319 if (dnet_state == VCONFKEY_NETWORK_ETHERNET) {
1320 ERR("Data Network is connected");
1324 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1325 if (dnet_state > VCONFKEY_DNET_OFF) {
1326 ERR("Data Network is connected");
1329 #endif/*TIZEN_TV_EXT*/
1331 /* data network through wifi */
1332 if (type != TETHERING_TYPE_WIFI) {
1333 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1334 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1335 ERR("Wi-Fi is connected!");
1340 ERR("Network is not available!");
1346 * @brief Creates the handle of tethering.
1348 * @privlevel platform
1349 * @privilege http://tizen.org/privilege/tethering.admin
1350 * @remarks The @a tethering must be released tethering_destroy() by you.
1351 * @param[out] tethering A handle of a new mobile ap handle on success
1352 * @return 0 on success, otherwise a negative error value.
1353 * @retval #TETHERING_ERROR_NONE Successful
1354 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1355 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1356 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1357 * @see tethering_destroy()
1359 API int tethering_create(tethering_h *tethering)
1361 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1362 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1363 "parameter(tethering) is NULL\n");
1366 __tethering_h *th = NULL;
1367 GError *error = NULL;
1368 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1370 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1372 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1373 "malloc is failed\n");
1374 memset(th, 0x00, sizeof(__tethering_h));
1375 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1376 th->visibility = true;
1377 th->mac_filter = false;
1379 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1380 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1381 th->change_mac = false;
1383 if (__generate_initial_passphrase(th->passphrase,
1384 sizeof(th->passphrase)) == 0) {
1385 ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
1387 return TETHERING_ERROR_OPERATION_FAILED;
1390 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1391 ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
1393 return TETHERING_ERROR_OPERATION_FAILED;
1396 #if !GLIB_CHECK_VERSION(2, 36, 0)
1399 GCancellable *cancellable = g_cancellable_new();
1400 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1403 ERR("Couldn't connect to the System bus[%s]", error->message);
1404 g_error_free(error);
1405 g_cancellable_cancel(cancellable);
1406 g_object_unref(cancellable);
1408 return TETHERING_ERROR_OPERATION_FAILED;
1411 th->cancellable = cancellable;
1413 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1414 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1415 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1416 if (!th->client_bus_proxy) {
1419 ERR("Couldn't create the proxy object because of %s\n", error->message);
1420 g_cancellable_cancel(th->cancellable);
1421 g_object_unref(th->cancellable);
1422 g_object_unref(th->client_bus);
1424 return TETHERING_ERROR_OPERATION_FAILED;
1428 __connect_signals((tethering_h)th);
1430 *tethering = (tethering_h)th;
1431 DBG("Tethering Handle : 0x%X\n", th);
1433 return TETHERING_ERROR_NONE;
1438 * @brief Destroys the handle of tethering.
1440 * @privlevel platform
1441 * @privilege http://tizen.org/privilege/tethering.admin
1442 * @param[in] tethering The handle of tethering
1443 * @return 0 on success, otherwise a negative error value.
1444 * @retval #TETHERING_ERROR_NONE Successful
1445 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1446 * @see tethering_create()
1448 API int tethering_destroy(tethering_h tethering)
1451 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1452 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1453 "parameter(tethering) is NULL\n");
1455 GVariant *result = NULL;
1456 __tethering_h *th = (__tethering_h *)tethering;
1458 DBG("Tethering Handle : 0x%X\n", th);
1460 if (th->change_mac) {
1461 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "reset_mac", NULL,
1462 G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
1463 g_variant_unref(result);
1466 __disconnect_signals(tethering);
1471 g_object_unref(th->cancellable);
1472 g_object_unref(th->client_bus_proxy);
1473 g_object_unref(th->client_bus);
1474 memset(th, 0x00, sizeof(__tethering_h));
1478 return TETHERING_ERROR_NONE;
1483 * @brief Enables the tethering, asynchronously.
1485 * @privlevel platform
1486 * @privilege http://tizen.org/privilege/tethering.admin
1487 * @param[in] tethering The handle of tethering
1488 * @param[in] type The type of tethering
1489 * @return 0 on success, otherwise negative error value.
1490 * @retval #TETHERING_ERROR_NONE Successful
1491 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1492 * @post tethering_enabled_cb() will be invoked.
1493 * @see tethering_is_enabled()
1494 * @see tethering_disable()
1496 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1498 DBG("+ type : %d\n", type);
1499 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1500 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1501 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1502 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1504 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1505 "parameter(tethering) is NULL\n");
1507 tethering_error_e ret = TETHERING_ERROR_NONE;
1508 __tethering_h *th = (__tethering_h *)tethering;
1509 GDBusProxy *proxy = th->client_bus_proxy;
1510 GDBusConnection *connection = th->client_bus;
1512 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1514 if (__check_precondition(type) == FALSE) {
1517 return TETHERING_ERROR_OPERATION_FAILED;
1523 case TETHERING_TYPE_USB:
1524 g_dbus_connection_signal_unsubscribe(connection,
1525 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1527 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1528 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1529 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1533 case TETHERING_TYPE_WIFI: {
1534 _softap_settings_t set = {"", "", "", 0, false};
1536 ret = __prepare_wifi_settings(tethering, &set);
1537 if (ret != TETHERING_ERROR_NONE) {
1538 ERR("softap settings initialization failed\n");
1540 return TETHERING_ERROR_OPERATION_FAILED;
1542 g_dbus_connection_signal_unsubscribe(connection,
1543 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1545 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1546 g_variant_new("(sssiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type),
1547 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1548 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1552 case TETHERING_TYPE_BT:
1553 g_dbus_connection_signal_unsubscribe(connection,
1554 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1556 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1557 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1558 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1563 case TETHERING_TYPE_ALL: {
1564 _softap_settings_t set = {"", "", "", 0, false};
1566 ret = __prepare_wifi_settings(tethering, &set);
1567 if (ret != TETHERING_ERROR_NONE) {
1568 ERR("softap settings initialization failed\n");
1569 return TETHERING_ERROR_OPERATION_FAILED;
1572 /* TETHERING_TYPE_USB */
1573 g_dbus_connection_signal_unsubscribe(connection,
1574 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1576 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1577 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1578 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1580 /* TETHERING_TYPE_WIFI */
1581 g_dbus_connection_signal_unsubscribe(connection,
1582 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1584 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1585 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1586 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1587 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1589 /* TETHERING_TYPE_BT */
1590 g_dbus_connection_signal_unsubscribe(connection,
1591 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1593 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1594 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1595 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1600 ERR("Unknown type : %d\n", type);
1602 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1605 return TETHERING_ERROR_INVALID_PARAMETER;
1608 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1610 return TETHERING_ERROR_NONE;
1615 * @brief Disables the tethering, asynchronously.
1617 * @privlevel platform
1618 * @privilege http://tizen.org/privilege/tethering.admin
1619 * @param[in] tethering The handle of tethering
1620 * @param[in] type The type of tethering
1621 * @return 0 on success, otherwise negative error value.
1622 * @retval #TETHERING_ERROR_NONE Successful
1623 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1624 * @post tethering_disabled_cb() will be invoked.
1625 * @see tethering_is_enabled()
1626 * @see tethering_enable()
1628 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1630 DBG("+ type : %d\n", type);
1631 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1632 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1633 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1634 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1636 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1637 "parameter(tethering) is NULL\n");
1639 __tethering_h *th = (__tethering_h *)tethering;
1640 GDBusProxy *proxy = th->client_bus_proxy;
1641 GDBusConnection *connection = th->client_bus;
1644 case TETHERING_TYPE_USB:
1645 g_dbus_connection_signal_unsubscribe(connection,
1646 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1648 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1649 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1650 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1654 case TETHERING_TYPE_WIFI:
1656 g_dbus_connection_signal_unsubscribe(connection,
1657 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1659 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1660 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1661 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1664 case TETHERING_TYPE_BT:
1666 g_dbus_connection_signal_unsubscribe(connection,
1667 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1669 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1670 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1671 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1674 case TETHERING_TYPE_ALL:
1675 g_dbus_connection_signal_unsubscribe(connection,
1676 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1678 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1679 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1680 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1682 g_dbus_connection_signal_unsubscribe(connection,
1683 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1685 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1686 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1687 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1689 g_dbus_connection_signal_unsubscribe(connection,
1690 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1692 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1693 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1694 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1698 ERR("Not supported tethering type [%d]\n", type);
1700 return TETHERING_ERROR_INVALID_PARAMETER;
1703 return TETHERING_ERROR_NONE;
1708 * @brief Checks whetehr the tethering is enabled or not.
1710 * @privlevel platform
1711 * @privilege http://tizen.org/privilege/tethering.admin
1712 * @param[in] tethering The handle of tethering
1713 * @param[in] type The type of tethering
1714 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1716 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1719 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1721 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1723 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1727 case TETHERING_TYPE_USB:
1728 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1731 case TETHERING_TYPE_WIFI:
1732 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1735 case TETHERING_TYPE_BT:
1736 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1740 ERR("Not supported type : %d\n", type);
1743 return is_on & vconf_type ? true : false;
1748 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1750 * @privlevel platform
1751 * @privilege http://tizen.org/privilege/tethering.admin
1752 * @remarks @a mac_address must be released with free() by you.
1753 * @param[in] tethering The handle of tethering
1754 * @param[in] type The type of tethering
1755 * @param[out] mac_address The MAC address
1756 * @return 0 on success, otherwise a negative error value.
1757 * @retval #TETHERING_ERROR_NONE Successful
1758 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1759 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1760 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1761 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1762 * @pre tethering must be enabled.
1763 * @see tethering_is_enabled()
1764 * @see tethering_enable()
1766 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1768 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1769 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1770 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1771 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1773 _retvm_if(tethering_is_enabled(tethering, type) == false,
1774 TETHERING_ERROR_NOT_ENABLED,
1775 "tethering type[%d] is not enabled\n", type);
1776 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1777 "parameter(tethering) is NULL\n");
1778 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1779 "parameter(mac_address) is NULL\n");
1783 char *macbuf = NULL;
1785 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1786 TETHERING_ERROR_OPERATION_FAILED,
1787 "getting interface name is failed\n");
1789 s = socket(AF_INET, SOCK_DGRAM, 0);
1790 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1791 "getting socket is failed\n");
1792 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1793 ERR("getting mac is failed\n");
1795 return TETHERING_ERROR_OPERATION_FAILED;
1799 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1800 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1801 "Not enough memory\n");
1802 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1803 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1804 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1805 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1806 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1807 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1808 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1810 *mac_address = macbuf;
1812 return TETHERING_ERROR_NONE;
1817 * @brief Gets the name of network interface. For example, usb0.
1819 * @privlevel platform
1820 * @privilege http://tizen.org/privilege/tethering.admin
1821 * @remarks @a interface_name must be released with free() by you.
1822 * @param[in] tethering The handle of tethering
1823 * @param[in] type The type of tethering
1824 * @param[out] interface_name The name of network interface
1825 * @return 0 on success, otherwise negative error value.
1826 * @retval #TETHERING_ERROR_NONE Successful
1827 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1828 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1829 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1830 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1831 * @pre tethering must be enabled.
1832 * @see tethering_is_enabled()
1833 * @see tethering_enable()
1835 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1837 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1838 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1839 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1840 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1842 _retvm_if(tethering_is_enabled(tethering, type) == false,
1843 TETHERING_ERROR_NOT_ENABLED,
1844 "tethering type[%d] is not enabled\n", type);
1845 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1846 "parameter(tethering) is NULL\n");
1847 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1848 "parameter(interface_name) is NULL\n");
1850 char intf[TETHERING_STR_INFO_LEN] = {0, };
1852 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1853 TETHERING_ERROR_OPERATION_FAILED,
1854 "getting interface name is failed\n");
1855 *interface_name = strdup(intf);
1856 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1857 "Not enough memory\n");
1859 return TETHERING_ERROR_NONE;
1864 * @brief Gets the local IP address.
1866 * @privlevel platform
1867 * @privilege http://tizen.org/privilege/tethering.admin
1868 * @remarks @a ip_address must be released with free() by you.
1869 * @param[in] tethering The handle of tethering
1870 * @param[in] type The type of tethering
1871 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1872 * @param[out] ip_address The local IP address
1873 * @return 0 on success, otherwise negative error value.
1874 * @retval #TETHERING_ERROR_NONE Successful
1875 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1876 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1877 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1878 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1879 * @pre tethering must be enabled.
1880 * @see tethering_is_enabled()
1881 * @see tethering_enable()
1883 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1885 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1886 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1887 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1888 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1890 _retvm_if(tethering_is_enabled(tethering, type) == false,
1891 TETHERING_ERROR_NOT_ENABLED,
1892 "tethering type[%d] is not enabled\n", type);
1893 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1894 "parameter(tethering) is NULL\n");
1895 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1896 "parameter(ip_address) is NULL\n");
1902 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1903 TETHERING_ERROR_OPERATION_FAILED,
1904 "getting interface name is failed\n");
1906 s = socket(AF_INET, SOCK_DGRAM, 0);
1907 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1908 "getting socket is failed\n");
1909 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1910 ERR("ioctl is failed\n");
1912 return TETHERING_ERROR_OPERATION_FAILED;
1916 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1917 *ip_address = strdup(ipbuf);
1918 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1919 "Not enough memory\n");
1921 return TETHERING_ERROR_NONE;
1926 * @brief Gets the Gateway address.
1928 * @privlevel platform
1929 * @privilege http://tizen.org/privilege/tethering.admin
1930 * @remarks @a gateway_address must be released with free() by you.
1931 * @param[in] tethering The handle of tethering
1932 * @param[in] type The type of tethering
1933 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1934 * @param[out] gateway_address The local IP address
1935 * @return 0 on success, otherwise negative error value.
1936 * @retval #TETHERING_ERROR_NONE Successful
1937 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1938 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1939 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1940 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1941 * @pre tethering must be enabled.
1942 * @see tethering_is_enabled()
1943 * @see tethering_enable()
1945 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1947 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1948 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1949 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1950 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1952 _retvm_if(tethering_is_enabled(tethering, type) == false,
1953 TETHERING_ERROR_NOT_ENABLED,
1954 "tethering type[%d] is not enabled\n", type);
1955 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1956 "parameter(tethering) is NULL\n");
1957 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1958 "parameter(gateway_address) is NULL\n");
1960 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1962 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1963 TETHERING_ERROR_OPERATION_FAILED,
1964 "getting gateway address is failed\n");
1966 *gateway_address = strdup(gateway_buf);
1968 return TETHERING_ERROR_NONE;
1973 * @brief Gets the Subnet Mask.
1975 * @privlevel platform
1976 * @privilege http://tizen.org/privilege/tethering.admin
1977 * @remarks @a subnet_mask must be released with free() by you.
1978 * @param[in] tethering The handle of tethering
1979 * @param[in] type The type of tethering
1980 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1981 * @param[out] subnet_mask The local IP address
1982 * @return 0 on success, otherwise negative error value.
1983 * @retval #TETHERING_ERROR_NONE Successful
1984 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1985 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1986 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1987 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1988 * @pre tethering must be enabled.
1989 * @see tethering_is_enabled()
1990 * @see tethering_enable()
1992 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1994 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1995 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1996 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1997 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1999 _retvm_if(tethering_is_enabled(tethering, type) == false,
2000 TETHERING_ERROR_NOT_ENABLED,
2001 "tethering is not enabled\n");
2002 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2003 "parameter(tethering) is NULL\n");
2004 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2005 "parameter(subnet_mask) is NULL\n");
2007 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2008 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2009 "Not enough memory\n");
2011 return TETHERING_ERROR_NONE;
2016 * @brief Gets the data usage.
2018 * @privlevel platform
2019 * @privilege http://tizen.org/privilege/tethering.admin
2020 * @param[in] tethering The handle of tethering
2021 * @param[out] usage The data usage
2022 * @return 0 on success, otherwise negative error value.
2023 * @retval #TETHERING_ERROR_NONE Successful
2024 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2025 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2026 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2027 * @pre tethering must be enabled.
2028 * @see tethering_is_enabled()
2029 * @see tethering_enable()
2031 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2033 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2035 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2036 "parameter(tethering) is NULL\n");
2037 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2038 "parameter(callback) is NULL\n");
2039 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2040 TETHERING_ERROR_NOT_ENABLED,
2041 "tethering is not enabled\n");
2043 __tethering_h *th = (__tethering_h *)tethering;
2044 GDBusProxy *proxy = th->client_bus_proxy;
2046 th->data_usage_cb = callback;
2047 th->data_usage_user_data = user_data;
2049 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2050 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2051 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2053 return TETHERING_ERROR_NONE;
2058 * @brief Gets the client which is connected by tethering "type".
2060 * @privlevel platform
2061 * @privilege http://tizen.org/privilege/tethering.admin
2062 * @param[in] tethering The handle of tethering
2063 * @param[in] type The type of tethering
2064 * @param[in] callback The callback function to invoke
2065 * @param[in] user_data The user data to be passed to the callback function
2066 * @retval #TETHERING_ERROR_NONE Successful
2067 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2068 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2069 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2070 * @pre tethering must be enabled.
2071 * @see tethering_is_enabled()
2072 * @see tethering_enable()
2074 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2076 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2077 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2078 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2079 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2081 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2082 "parameter(tethering) is NULL\n");
2083 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2084 "parameter(callback) is NULL\n");
2085 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2086 TETHERING_ERROR_NOT_ENABLED,
2087 "tethering is not enabled\n");
2089 mobile_ap_type_e interface;
2090 __tethering_h *th = (__tethering_h *)tethering;
2091 __tethering_client_h client = {0, };
2094 gchar *hostname = NULL;
2095 guint timestamp = 0;
2096 GError *error = NULL;
2097 GVariant *result = NULL;
2098 GVariantIter *outer_iter = NULL;
2099 GVariantIter *inner_iter = NULL;
2100 GVariant *station = NULL;
2101 GVariant *value = NULL;
2104 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2105 NULL, G_DBUS_CALL_FLAGS_NONE,
2106 -1, th->cancellable, &error);
2108 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2109 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2110 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2111 g_variant_get(station, "a{sv}", &inner_iter);
2112 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2113 if (g_strcmp0(key, "Type") == 0) {
2114 interface = g_variant_get_int32(value);
2115 if (interface == MOBILE_AP_TYPE_USB)
2116 client.interface = TETHERING_TYPE_USB;
2117 else if (interface == MOBILE_AP_TYPE_WIFI)
2118 client.interface = TETHERING_TYPE_WIFI;
2119 else if (interface == MOBILE_AP_TYPE_BT)
2120 client.interface = TETHERING_TYPE_BT;
2122 ERR("Invalid interface\n");
2124 g_variant_unref(value);
2127 DBG("interface is %d\n", client.interface);
2128 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2130 g_variant_unref(value);
2133 } else if (g_strcmp0(key, "IP") == 0) {
2134 g_variant_get(value, "s", &ip);
2135 SDBG("ip is %s\n", ip);
2136 g_strlcpy(client.ip, ip, sizeof(client.ip));
2137 } else if (g_strcmp0(key, "MAC") == 0) {
2138 g_variant_get(value, "s", &mac);
2139 SDBG("mac is %s\n", mac);
2140 g_strlcpy(client.mac, mac, sizeof(client.mac));
2141 } else if (g_strcmp0(key, "Name") == 0) {
2142 g_variant_get(value, "s", &hostname);
2143 SDBG("hsotname is %s\n", hostname);
2145 client.hostname = g_strdup(hostname);
2146 } else if (g_strcmp0(key, "Time") == 0) {
2147 timestamp = g_variant_get_int32(value);
2148 DBG("timestamp is %d\n", timestamp);
2149 client.tm = (time_t)timestamp;
2151 ERR("Key %s not required\n", key);
2157 g_variant_iter_free(inner_iter);
2158 if (callback((tethering_client_h)&client, user_data) == false) {
2159 DBG("iteration is stopped\n");
2160 g_free(client.hostname);
2161 g_variant_iter_free(outer_iter);
2162 g_variant_unref(station);
2163 g_variant_unref(result);
2165 return TETHERING_ERROR_OPERATION_FAILED;
2167 g_free(client.hostname);
2169 g_variant_iter_free(outer_iter);
2170 g_variant_unref(station);
2171 g_variant_unref(result);
2173 return TETHERING_ERROR_NONE;
2178 * @brief Registers the callback function called when tethering is enabled.
2180 * @privlevel platform
2181 * @privilege http://tizen.org/privilege/tethering.admin
2182 * @param[in] tethering The handle of tethering
2183 * @param[in] type The type of tethering
2184 * @param[in] callback The callback function to invoke
2185 * @param[in] user_data The user data to be passed to the callback function
2186 * @retval #TETHERING_ERROR_NONE Successful
2187 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2188 * @see tethering_unset_enabled_cb()
2190 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2192 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2193 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2194 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2195 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2197 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2198 "parameter(tethering) is NULL\n");
2199 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2200 "parameter(callback) is NULL\n");
2202 __tethering_h *th = (__tethering_h *)tethering;
2203 tethering_type_e ti;
2205 if (type != TETHERING_TYPE_ALL) {
2206 th->enabled_cb[type] = callback;
2207 th->enabled_user_data[type] = user_data;
2209 return TETHERING_ERROR_NONE;
2212 /* TETHERING_TYPE_ALL */
2213 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2214 th->enabled_cb[ti] = callback;
2215 th->enabled_user_data[ti] = user_data;
2218 return TETHERING_ERROR_NONE;
2223 * @brief Unregisters the callback function called when tethering is disabled.
2225 * @privlevel platform
2226 * @privilege http://tizen.org/privilege/tethering.admin
2227 * @param[in] tethering The handle of tethering
2228 * @param[in] type The type of tethering
2229 * @retval #TETHERING_ERROR_NONE Successful
2230 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2231 * @see tethering_set_enabled_cb()
2233 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2235 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2236 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2237 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2238 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2240 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2241 "parameter(tethering) is NULL\n");
2243 __tethering_h *th = (__tethering_h *)tethering;
2244 tethering_type_e ti;
2246 if (type != TETHERING_TYPE_ALL) {
2247 th->enabled_cb[type] = NULL;
2248 th->enabled_user_data[type] = NULL;
2250 return TETHERING_ERROR_NONE;
2253 /* TETHERING_TYPE_ALL */
2254 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2255 th->enabled_cb[ti] = NULL;
2256 th->enabled_user_data[ti] = NULL;
2259 return TETHERING_ERROR_NONE;
2264 * @brief Registers the callback function called when tethering is disabled.
2266 * @privlevel platform
2267 * @privilege http://tizen.org/privilege/tethering.admin
2268 * @param[in] tethering The handle of tethering
2269 * @param[in] type The type of tethering
2270 * @param[in] callback The callback function to invoke
2271 * @param[in] user_data The user data to be passed to the callback function
2272 * @retval #TETHERING_ERROR_NONE Successful
2273 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2274 * @see tethering_unset_disabled_cb()
2276 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2278 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2279 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2280 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2281 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2283 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2284 "parameter(tethering) is NULL\n");
2285 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2286 "parameter(callback) is NULL\n");
2288 __tethering_h *th = (__tethering_h *)tethering;
2289 tethering_type_e ti;
2291 if (type != TETHERING_TYPE_ALL) {
2292 th->disabled_cb[type] = callback;
2293 th->disabled_user_data[type] = user_data;
2295 return TETHERING_ERROR_NONE;
2298 /* TETHERING_TYPE_ALL */
2299 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2300 th->disabled_cb[ti] = callback;
2301 th->disabled_user_data[ti] = user_data;
2304 return TETHERING_ERROR_NONE;
2309 * @brief Unregisters the callback function called when tethering is disabled.
2311 * @privlevel platform
2312 * @privilege http://tizen.org/privilege/tethering.admin
2313 * @param[in] tethering The handle of tethering
2314 * @param[in] type The type of tethering
2315 * @retval #TETHERING_ERROR_NONE Successful
2316 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2317 * @see tethering_set_disabled_cb()
2319 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2321 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2322 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2323 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2324 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2326 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2327 "parameter(tethering) is NULL\n");
2329 __tethering_h *th = (__tethering_h *)tethering;
2330 tethering_type_e ti;
2332 if (type != TETHERING_TYPE_ALL) {
2333 th->disabled_cb[type] = NULL;
2334 th->disabled_user_data[type] = NULL;
2336 return TETHERING_ERROR_NONE;
2339 /* TETHERING_TYPE_ALL */
2340 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2341 th->disabled_cb[ti] = NULL;
2342 th->disabled_user_data[ti] = NULL;
2345 return TETHERING_ERROR_NONE;
2350 * @brief Registers the callback function called when the state of connection is changed.
2352 * @privlevel platform
2353 * @privilege http://tizen.org/privilege/tethering.admin
2354 * @param[in] tethering The handle of tethering
2355 * @param[in] type The type of tethering
2356 * @param[in] callback The callback function to invoke
2357 * @param[in] user_data The user data to be passed to the callback function
2358 * @retval #TETHERING_ERROR_NONE Successful
2359 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2360 * @see tethering_unset_connection_state_changed_cb_cb()
2362 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2364 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2365 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2366 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2367 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2369 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2370 "parameter(tethering) is NULL\n");
2371 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2372 "parameter(callback) is NULL\n");
2374 __tethering_h *th = (__tethering_h *)tethering;
2375 tethering_type_e ti;
2377 if (type != TETHERING_TYPE_ALL) {
2378 th->changed_cb[type] = callback;
2379 th->changed_user_data[type] = user_data;
2381 return TETHERING_ERROR_NONE;
2384 /* TETHERING_TYPE_ALL */
2385 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2386 th->changed_cb[ti] = callback;
2387 th->changed_user_data[ti] = user_data;
2390 return TETHERING_ERROR_NONE;
2395 * @brief Unregisters the callback function called when the state of connection is changed.
2397 * @privlevel platform
2398 * @privilege http://tizen.org/privilege/tethering.admin
2399 * @param[in] tethering The handle of tethering
2400 * @param[in] type The type of tethering
2401 * @retval #TETHERING_ERROR_NONE Successful
2402 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2403 * @see tethering_set_connection_state_changed_cb()
2405 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2407 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2408 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2409 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2410 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2412 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2413 "parameter(tethering) is NULL\n");
2415 __tethering_h *th = (__tethering_h *)tethering;
2416 tethering_type_e ti;
2418 if (type != TETHERING_TYPE_ALL) {
2419 th->changed_cb[type] = NULL;
2420 th->changed_user_data[type] = NULL;
2422 return TETHERING_ERROR_NONE;
2425 /* TETHERING_TYPE_ALL */
2426 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2427 th->changed_cb[ti] = NULL;
2428 th->changed_user_data[ti] = NULL;
2431 return TETHERING_ERROR_NONE;
2436 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2438 * @privlevel platform
2439 * @privilege http://tizen.org/privilege/tethering.admin
2440 * @param[in] tethering The handle of tethering
2441 * @param[in] callback The callback function to invoke
2442 * @param[in] user_data The user data to be passed to the callback function
2443 * @retval #TETHERING_ERROR_NONE Successful
2444 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2445 * @see tethering_wifi_unset_security_type_changed_cb()
2447 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2449 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2450 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2452 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2453 "parameter(tethering) is NULL\n");
2454 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2455 "parameter(callback) is NULL\n");
2457 __tethering_h *th = (__tethering_h *)tethering;
2459 th->security_type_changed_cb = callback;
2460 th->security_type_user_data = user_data;
2462 return TETHERING_ERROR_NONE;
2468 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2470 * @privlevel platform
2471 * @privilege http://tizen.org/privilege/tethering.admin
2472 * @param[in] tethering The handle of tethering
2473 * @param[in] type The type of tethering
2474 * @retval #TETHERING_ERROR_NONE Successful
2475 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2476 * @see tethering_wifi_set_security_type_changed_cb()
2478 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2480 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2481 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2483 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2484 "parameter(tethering) is NULL\n");
2486 __tethering_h *th = (__tethering_h *)tethering;
2488 th->security_type_changed_cb = NULL;
2489 th->security_type_user_data = NULL;
2491 return TETHERING_ERROR_NONE;
2496 * @brief Registers the callback function called when the visibility of SSID is changed.
2498 * @privlevel platform
2499 * @privilege http://tizen.org/privilege/tethering.admin
2500 * @param[in] tethering The handle of tethering
2501 * @param[in] callback The callback function to invoke
2502 * @param[in] user_data The user data to be passed to the callback function
2503 * @retval #TETHERING_ERROR_NONE Successful
2504 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2505 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2507 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2509 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2510 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2512 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2513 "parameter(tethering) is NULL\n");
2514 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2515 "parameter(callback) is NULL\n");
2517 __tethering_h *th = (__tethering_h *)tethering;
2519 th->ssid_visibility_changed_cb = callback;
2520 th->ssid_visibility_user_data = user_data;
2522 return TETHERING_ERROR_NONE;
2527 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2529 * @privlevel platform
2530 * @privilege http://tizen.org/privilege/tethering.admin
2531 * @param[in] tethering The handle of tethering
2532 * @retval #TETHERING_ERROR_NONE Successful
2533 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2534 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2536 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2538 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2539 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2541 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2542 "parameter(tethering) is NULL\n");
2544 __tethering_h *th = (__tethering_h *)tethering;
2546 th->ssid_visibility_changed_cb = NULL;
2547 th->ssid_visibility_user_data = NULL;
2549 return TETHERING_ERROR_NONE;
2554 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2556 * @privlevel platform
2557 * @privilege http://tizen.org/privilege/tethering.admin
2558 * @param[in] tethering The handle of tethering
2559 * @param[in] callback The callback function to invoke
2560 * @param[in] user_data The user data to be passed to the callback function
2561 * @retval #TETHERING_ERROR_NONE Successful
2562 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2563 * @see tethering_wifi_unset_passphrase_changed_cb()
2565 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2567 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2568 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2570 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2571 "parameter(tethering) is NULL\n");
2572 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2573 "parameter(callback) is NULL\n");
2575 __tethering_h *th = (__tethering_h *)tethering;
2577 th->passphrase_changed_cb = callback;
2578 th->passphrase_user_data = user_data;
2580 return TETHERING_ERROR_NONE;
2585 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2587 * @privlevel platform
2588 * @privilege http://tizen.org/privilege/tethering.admin
2589 * @param[in] tethering The handle of tethering
2590 * @retval #TETHERING_ERROR_NONE Successful
2591 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2592 * @see tethering_wifi_set_passphrase_changed_cb()
2594 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2596 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2597 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2599 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2600 "parameter(tethering) is NULL\n");
2602 __tethering_h *th = (__tethering_h *)tethering;
2604 th->passphrase_changed_cb = NULL;
2605 th->passphrase_user_data = NULL;
2607 return TETHERING_ERROR_NONE;
2612 * @brief Sets the security type of Wi-Fi tethering.
2614 * @privlevel platform
2615 * @privilege http://tizen.org/privilege/tethering.admin
2616 * @remarks This change is applied next time Wi-Fi tethering is enabled
2617 * @param[in] tethering The handle of tethering
2618 * @param[in] type The security type
2619 * @return 0 on success, otherwise negative error value.
2620 * @retval #TETHERING_ERROR_NONE Successful
2621 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2622 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2623 * @see tethering_wifi_get_security_type()
2625 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2627 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2628 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2630 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2631 "parameter(tethering) is NULL\n");
2633 __tethering_h *th = (__tethering_h *)tethering;
2634 tethering_error_e ret = TETHERING_ERROR_NONE;
2635 char *sec_str = NULL;
2637 ret = __set_security_type(type);
2638 if (ret == TETHERING_ERROR_NONE) {
2641 case TETHERING_WIFI_SECURITY_TYPE_NONE:
2642 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
2644 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
2645 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
2647 case TETHERING_WIFI_SECURITY_TYPE_WPS:
2648 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
2652 __send_dbus_signal(th->client_bus,
2653 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
2660 * @brief Gets the security type of Wi-Fi tethering.
2662 * @privlevel platform
2663 * @privilege http://tizen.org/privilege/tethering.admin
2664 * @param[in] tethering The handle of tethering
2665 * @param[out] type The security type
2666 * @return 0 on success, otherwise negative error value.
2667 * @retval #TETHERING_ERROR_NONE Successful
2668 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2669 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2670 * @see tethering_wifi_set_security_type()
2672 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2674 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2675 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2677 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2678 "parameter(type) is NULL\n");
2680 return __get_security_type(type);
2685 * @brief Sets the SSID (service set identifier).
2687 * @privlevel platform
2688 * @privilege http://tizen.org/privilege/tethering.admin
2689 * @details If SSID is not set, Device name is used as SSID
2690 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2691 * @param[in] tethering The handle of tethering
2692 * @param[out] ssid The SSID
2693 * @return 0 on success, otherwise negative error value.
2694 * @retval #TETHERING_ERROR_NONE Successful
2695 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2696 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2698 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2700 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2701 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2703 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2704 "parameter(tethering) is NULL\n");
2705 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2706 "parameter(ssid) is NULL\n");
2708 __tethering_h *th = (__tethering_h *)tethering;
2709 char *p_ssid = NULL;
2712 ssid_len = strlen(ssid);
2713 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2714 ERR("parameter(ssid) is too long");
2715 return TETHERING_ERROR_INVALID_PARAMETER;
2718 p_ssid = strdup(ssid);
2719 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2720 "strdup is failed\n");
2726 return TETHERING_ERROR_NONE;
2731 * @brief Gets the SSID (service set identifier).
2733 * @privlevel platform
2734 * @privilege http://tizen.org/privilege/tethering.admin
2735 * @remarks @a ssid must be released with free() by you.
2736 * @param[in] tethering The handle of tethering
2737 * @param[out] ssid The SSID
2738 * @return 0 on success, otherwise negative error value.
2739 * @retval #TETHERING_ERROR_NONE Successful
2740 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2741 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2742 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2744 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2746 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2747 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2749 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2750 "parameter(tethering) is NULL\n");
2751 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2752 "parameter(ssid) is NULL\n");
2755 __tethering_h *th = (__tethering_h *)tethering;
2756 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2758 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2759 if (th->ssid != NULL) {
2760 DBG("Private SSID is set\n");
2761 *ssid = strdup(th->ssid);
2763 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2764 val, sizeof(val)) == false) {
2765 return TETHERING_ERROR_OPERATION_FAILED;
2767 *ssid = strdup(val);
2770 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2771 val, sizeof(val)) == false) {
2772 return TETHERING_ERROR_OPERATION_FAILED;
2774 *ssid = strdup(val);
2777 if (*ssid == NULL) {
2778 ERR("strdup is failed\n");
2779 return TETHERING_ERROR_OUT_OF_MEMORY;
2782 return TETHERING_ERROR_NONE;
2787 * @brief Sets the visibility of SSID(service set identifier).
2789 * @privlevel platform
2790 * @privilege http://tizen.org/privilege/tethering.admin
2791 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2792 * @remarks This change is applied next time Wi-Fi tethering is enabled
2793 * @param[in] tethering The handle of tethering
2794 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2795 * @return 0 on success, otherwise negative error value.
2796 * @retval #TETHERING_ERROR_NONE Successful
2797 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2798 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2799 * @see tethering_wifi_get_ssid_visibility()
2801 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2803 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2804 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2806 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2807 "parameter(tethering) is NULL\n");
2809 __tethering_h *th = (__tethering_h *)tethering;
2810 tethering_error_e ret = TETHERING_ERROR_NONE;
2812 ret = __set_visible(visible);
2813 if (ret == TETHERING_ERROR_NONE) {
2815 __send_dbus_signal(th->client_bus,
2816 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2817 visible ? SIGNAL_MSG_SSID_VISIBLE :
2818 SIGNAL_MSG_SSID_HIDE);
2825 * @brief Gets the visibility of SSID(service set identifier).
2827 * @privlevel platform
2828 * @privilege http://tizen.org/privilege/tethering.admin
2829 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2830 * @param[in] tethering The handle of tethering
2831 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2832 * @return 0 on success, otherwise negative error value.
2833 * @retval #TETHERING_ERROR_NONE Successful
2834 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2835 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2836 * @see tethering_wifi_set_ssid_visibility()
2838 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2840 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2841 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2843 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2844 "parameter(visible) is NULL\n");
2846 return __get_visible(visible);
2851 * @brief Sets the passphrase.
2853 * @privlevel platform
2854 * @privilege http://tizen.org/privilege/tethering.admin
2855 * @remarks This change is applied next time Wi-Fi tethering is enabled
2856 * @param[in] tethering The handle of tethering
2857 * @param[in] passphrase The passphrase
2858 * @return 0 on success, otherwise negative error value.
2859 * @retval #TETHERING_ERROR_NONE Successful
2860 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2861 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2862 * @see tethering_wifi_get_passphrase()
2864 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2866 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2867 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2869 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2870 "parameter(tethering) is NULL\n");
2871 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2872 "parameter(passphrase) is NULL\n");
2874 __tethering_h *th = (__tethering_h *)tethering;
2875 GDBusProxy *proxy = th->client_bus_proxy;
2876 GVariant *parameters;
2877 GError *error = NULL;
2878 int passphrase_len = 0;
2882 passphrase_len = strlen(passphrase);
2883 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
2884 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
2885 ERR("parameter(passphrase) is too short or long\n");
2886 return TETHERING_ERROR_INVALID_PARAMETER;
2889 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
2890 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2894 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2896 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2897 ret = TETHERING_ERROR_PERMISSION_DENIED;
2899 ret = TETHERING_ERROR_OPERATION_FAILED;
2901 g_error_free(error);
2906 g_variant_get(parameters, "(u)", &ret);
2907 g_variant_unref(parameters);
2909 if (ret == TETHERING_ERROR_NONE) {
2910 __send_dbus_signal(th->client_bus,
2911 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
2920 * @brief Gets the passphrase.
2922 * @privlevel platform
2923 * @privilege http://tizen.org/privilege/tethering.admin
2924 * @remarks @a passphrase must be released with free() by you.
2925 * @param[in] tethering The handle of tethering
2926 * @param[out] passphrase The passphrase
2927 * @return 0 on success, otherwise negative error value.
2928 * @retval #TETHERING_ERROR_NONE Successful
2929 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2930 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2931 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2932 * @see tethering_wifi_set_passphrase()
2934 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2936 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2937 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2939 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2940 "parameter(tethering) is NULL\n");
2941 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2942 "parameter(passphrase) is NULL\n");
2944 __tethering_h *th = (__tethering_h *)tethering;
2945 GDBusProxy *proxy = th->client_bus_proxy;
2946 GVariant *parameters;
2947 GError *error = NULL;
2948 unsigned int len = 0;
2949 tethering_error_e ret = TETHERING_ERROR_NONE;
2951 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
2952 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2956 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2958 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2959 ret = TETHERING_ERROR_PERMISSION_DENIED;
2961 ret = TETHERING_ERROR_OPERATION_FAILED;
2963 g_error_free(error);
2968 if (parameters != NULL) {
2969 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
2970 g_variant_unref(parameters);
2973 return TETHERING_ERROR_NONE;
2976 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
2978 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2979 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2981 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2982 "parameter(tethering) is NULL\n");
2984 __tethering_h *th = (__tethering_h *)tethering;
2985 th->channel = channel;
2987 return TETHERING_ERROR_NONE;
2990 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
2992 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2993 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2995 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2996 "parameter(tethering) is NULL\n");
2998 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2999 "parameter(channel) is NULL\n");
3001 __tethering_h *th = (__tethering_h *)tethering;
3002 *channel = th->channel;
3004 return TETHERING_ERROR_NONE;
3007 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3009 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3010 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3012 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3013 "parameter(tethering) is NULL\n");
3015 __tethering_h *th = (__tethering_h *)tethering;
3017 th->mode_type = type;
3019 return TETHERING_ERROR_NONE;
3022 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3024 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3025 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3027 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3028 "parameter(tethering) is NULL\n");
3029 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3030 "parameter(type) is NULL\n");
3032 __tethering_h *th = (__tethering_h *)tethering;
3033 *type = th->mode_type;
3035 return TETHERING_ERROR_NONE;
3041 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3043 * @privlevel platform
3044 * @privilege http://tizen.org/privilege/tethering.admin
3045 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3046 * @param[in] tethering The handle of tethering
3047 * @param[in] callback The callback function to invoke
3048 * @param[in] user_data The user data to be passed to the callback function
3049 * @return 0 on success, otherwise negative error value.
3050 * @retval #TETHERING_ERROR_NONE Successful
3051 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3052 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3054 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3057 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3058 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3060 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3061 "parameter(tethering) is NULL\n");
3062 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3063 "parameter(callback) is NULL\n");
3065 __tethering_h *th = (__tethering_h *)tethering;
3066 _softap_settings_t set = {"", "", "", 0, false};
3067 GDBusProxy *proxy = th->client_bus_proxy;
3072 if (th->settings_reloaded_cb) {
3073 ERR("Operation in progress\n");
3074 return TETHERING_ERROR_OPERATION_FAILED;
3077 ret = __prepare_wifi_settings(tethering, &set);
3078 if (ret != TETHERING_ERROR_NONE) {
3079 ERR("softap settings initialization failed\n");
3080 return TETHERING_ERROR_OPERATION_FAILED;
3083 th->settings_reloaded_cb = callback;
3084 th->settings_reloaded_user_data = user_data;
3086 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3087 g_variant_new("(sssiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type),
3088 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3089 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3091 return TETHERING_ERROR_NONE;
3094 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3096 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3097 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3099 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3100 "parameter(tethering) is NULL\n");
3102 __tethering_h *th = (__tethering_h *)tethering;
3103 th->mac_filter = mac_filter;
3105 return TETHERING_ERROR_NONE;
3108 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3110 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3111 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3113 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3114 "parameter(mac_filter) is NULL\n");
3115 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3116 "parameter(mac_filter) is NULL\n");
3118 __tethering_h *th = (__tethering_h *)tethering;
3119 *mac_filter = th->mac_filter;
3121 return TETHERING_ERROR_NONE;
3124 static int __add_mac_to_file(const char *filepath, const char *mac)
3127 char line[MAX_BUF_SIZE] = "\0";
3128 bool mac_exist = false;
3131 p_mac = strdup(mac);
3132 if (p_mac == NULL) {
3133 ERR("strdup failed\n");
3134 return TETHERING_ERROR_OUT_OF_MEMORY;
3137 fp = fopen(filepath, "a+");
3139 ERR("fopen is failed\n");
3140 return TETHERING_ERROR_OPERATION_FAILED;
3143 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3144 if (strncmp(mac, line, 17) == 0) {
3145 DBG("MAC %s already exist in the list\n", mac);
3152 fprintf(fp, "%s\n", mac);
3154 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3155 allowed_list = g_slist_append(allowed_list, p_mac);
3156 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3157 blocked_list = g_slist_append(blocked_list, p_mac);
3162 return TETHERING_ERROR_NONE;
3165 static int __remove_mac_from_file(const char *filepath, const char *mac)
3169 char line[MAX_BUF_SIZE] = "\0";
3171 fp = fopen(filepath, "r");
3173 ERR("fopen is failed\n");
3174 return TETHERING_ERROR_OPERATION_FAILED;
3177 fp1 = fopen(TEMP_LIST, "w+");
3180 ERR("fopen is failed\n");
3181 return TETHERING_ERROR_OPERATION_FAILED;
3184 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3185 if (strncmp(mac, line, 17) == 0) {
3186 DBG("MAC %s found in the list\n", mac);
3188 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3189 GSList *list = NULL;
3190 for (list = allowed_list; list != NULL; list = list->next) {
3191 char *p_mac = (char *)list->data;
3192 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3193 allowed_list = g_slist_remove(allowed_list, p_mac);
3195 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3196 GSList *list = NULL;
3197 for (list = blocked_list; list != NULL; list = list->next) {
3198 char *p_mac = (char *)list->data;
3199 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3200 blocked_list = g_slist_remove(blocked_list, p_mac);
3204 fprintf(fp1, "%s", line);
3211 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3212 rename(TEMP_LIST, ALLOWED_LIST);
3213 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3214 rename(TEMP_LIST, BLOCKED_LIST);
3216 return TETHERING_ERROR_NONE;
3219 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3221 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3222 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3224 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3225 "parameter(tethering) is NULL\n");
3226 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3227 "parameter(mac) is NULL\n");
3229 return __add_mac_to_file(ALLOWED_LIST, mac);
3232 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3234 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3235 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3237 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3238 "parameter(tethering) is NULL\n");
3239 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3240 "parameter(mac) is NULL\n");
3242 return __remove_mac_from_file(ALLOWED_LIST, mac);
3245 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3247 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3248 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3250 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3251 "parameter(tethering) is NULL\n");
3252 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3253 "parameter(allowed_mac_list) is NULL\n");
3255 *allowed_mac_list = g_slist_copy(allowed_list);
3256 return TETHERING_ERROR_NONE;
3259 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3261 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3262 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3264 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3265 "parameter(tethering) is NULL\n");
3266 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3267 "parameter(mac) is NULL\n");
3269 return __add_mac_to_file(BLOCKED_LIST, mac);
3272 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3274 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3275 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3277 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3278 "parameter(tethering) is NULL\n");
3279 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3280 "parameter(mac) is NULL\n");
3282 return __remove_mac_from_file(BLOCKED_LIST, mac);
3285 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3287 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3288 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3290 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3291 "parameter(tethering) is NULL\n");
3292 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3293 "parameter(blocked_mac_list) is NULL\n");
3295 *blocked_mac_list = g_slist_copy(blocked_list);
3296 return TETHERING_ERROR_NONE;
3299 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3301 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3302 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3304 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3305 "parameter(tethering) is NULL\n");
3307 GVariant *parameters;
3308 GError *error = NULL;
3311 __tethering_h *th = (__tethering_h *)tethering;
3313 GDBusProxy *proxy = th->client_bus_proxy;
3315 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3316 g_variant_new("(b)", enable),
3317 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3320 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3321 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3322 result = TETHERING_ERROR_PERMISSION_DENIED;
3324 result = TETHERING_ERROR_OPERATION_FAILED;
3326 g_error_free(error);
3327 th->dhcp_enabled = false;
3332 g_variant_get(parameters, "(u)", &result);
3333 g_variant_unref(parameters);
3336 th->dhcp_enabled = true;
3338 th->dhcp_enabled = false;
3340 return TETHERING_ERROR_NONE;
3343 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3345 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3346 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3348 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3349 "parameter(tethering) is NULL\n");
3350 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3351 "parameter(rangestart) is NULL\n");
3352 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3353 "parameter(rangestop) is NULL\n");
3355 GVariant *parameters;
3356 GError *error = NULL;
3359 __tethering_h *th = (__tethering_h *)tethering;
3361 GDBusProxy *proxy = th->client_bus_proxy;
3363 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3364 g_variant_new("(ss)", rangestart, rangestop),
3365 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3367 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3369 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3370 result = TETHERING_ERROR_PERMISSION_DENIED;
3372 result = TETHERING_ERROR_OPERATION_FAILED;
3374 g_error_free(error);
3375 th->dhcp_enabled = false;
3380 g_variant_get(parameters, "(u)", &result);
3381 g_variant_unref(parameters);
3383 th->dhcp_enabled = true;
3385 return TETHERING_ERROR_NONE;
3388 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3390 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3391 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3393 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3394 "parameter(tethering) is NULL\n");
3395 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3396 "parameter(dhcp_enabled) is NULL\n");
3398 __tethering_h *th = (__tethering_h *)tethering;
3399 *dhcp_enabled = th->dhcp_enabled;
3401 return TETHERING_ERROR_NONE;
3404 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3406 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3407 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3409 GError *error = NULL;
3411 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3412 "parameter(tethering) is NULL\n");
3413 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3414 TETHERING_ERROR_NOT_ENABLED,
3415 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3416 __tethering_h *th = (__tethering_h *)tethering;
3418 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3419 g_variant_new("(u)", txpower),
3420 G_DBUS_CALL_FLAGS_NONE,
3421 -1, th->cancellable, &error);
3423 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3424 g_clear_error(&error);
3425 return TETHERING_ERROR_OPERATION_FAILED;
3427 return TETHERING_ERROR_NONE;
3430 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3432 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3433 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3435 GError *error = NULL;
3436 GVariant *result = NULL;
3438 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3439 "parameter(tethering) is NULL\n");
3440 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3441 TETHERING_ERROR_NOT_ENABLED,
3442 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3444 __tethering_h *th = (__tethering_h *)tethering;
3446 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3448 G_DBUS_CALL_FLAGS_NONE,
3449 -1, th->cancellable, &error);
3451 if (result != NULL) {
3452 g_variant_get(result, "(u)", txpower);
3453 g_variant_unref(result);
3456 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3457 g_clear_error(&error);
3458 return TETHERING_ERROR_OPERATION_FAILED;
3460 g_clear_error(&error);
3461 return TETHERING_ERROR_NONE;
3464 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
3466 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3467 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3469 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3470 "parameter(tethering) is NULL\n");
3472 GVariant *parameters;
3473 GError *error = NULL;
3476 __tethering_h *th = (__tethering_h *)tethering;
3478 GDBusProxy *proxy = th->client_bus_proxy;
3480 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
3481 g_variant_new("(u)", mtu),
3482 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3484 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3486 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3487 result = TETHERING_ERROR_PERMISSION_DENIED;
3489 result = TETHERING_ERROR_OPERATION_FAILED;
3491 g_error_free(error);
3495 g_variant_get(parameters, "(u)", &result);
3497 g_variant_unref(parameters);
3499 return TETHERING_ERROR_NONE;
3502 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
3504 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3505 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3507 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3508 "parameter(tethering) is NULL\n");
3509 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3510 "parameter(mac) is NULL\n");
3512 GVariant *parameters;
3513 GError *error = NULL;
3516 __tethering_h *th = (__tethering_h *)tethering;
3518 GDBusProxy *proxy = th->client_bus_proxy;
3520 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
3521 g_variant_new("(s)", mac),
3522 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3524 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3526 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3527 result = TETHERING_ERROR_PERMISSION_DENIED;
3529 result = TETHERING_ERROR_OPERATION_FAILED;
3531 g_error_free(error);
3535 g_variant_get(parameters, "(u)", &result);
3537 g_variant_unref(parameters);
3539 th->change_mac = true;
3541 return TETHERING_ERROR_NONE;
3544 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
3546 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3547 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3549 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3550 "parameter(tethering) is NULL\n");
3552 __tethering_h *th = (__tethering_h *)tethering;
3554 th->wifi_max_connected = max_device;
3556 return TETHERING_ERROR_NONE;
3559 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
3561 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3562 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3564 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3565 "parameter(tethering) is NULL\n");
3566 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3567 "parameter(max_device) is NULL\n");
3569 __tethering_h *th = (__tethering_h *)tethering;
3571 *max_device = th->wifi_max_connected;
3572 return TETHERING_ERROR_NONE;
3575 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
3577 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3578 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3580 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3581 "parameter(tethering) is NULL\n");
3583 GVariant *parameters;
3584 GError *error = NULL;
3587 __tethering_h *th = (__tethering_h *)tethering;
3589 GDBusProxy *proxy = th->client_bus_proxy;
3591 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
3592 g_variant_new("(b)", enable),
3593 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3595 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3597 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3598 result = TETHERING_ERROR_PERMISSION_DENIED;
3600 result = TETHERING_ERROR_OPERATION_FAILED;
3602 g_error_free(error);
3606 g_variant_get(parameters, "(u)", &result);
3607 g_variant_unref(parameters);
3609 th->port_forwarding = true;
3611 return TETHERING_ERROR_NONE;
3614 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)
3616 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3617 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3619 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3620 "parameter(tethering) is NULL\n");
3621 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3622 "parameter(protocol) is NULL\n");
3624 GVariant *parameters;
3625 GError *error = NULL;
3627 char cmd[MAX_BUF_SIZE] = { 0, };
3630 __tethering_h *th = (__tethering_h *)tethering;
3632 GDBusProxy *proxy = th->client_bus_proxy;
3634 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
3635 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
3636 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3638 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3640 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3641 result = TETHERING_ERROR_PERMISSION_DENIED;
3643 result = TETHERING_ERROR_OPERATION_FAILED;
3645 g_error_free(error);
3649 g_variant_get(parameters, "(u)", &result);
3650 g_variant_unref(parameters);
3652 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);
3656 ERR("strdup failed\n");
3657 return TETHERING_ERROR_OUT_OF_MEMORY;
3660 port_forwarding = g_slist_append(port_forwarding, list);
3662 return TETHERING_ERROR_NONE;
3665 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
3667 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3668 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3670 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3671 "parameter(tethering) is NULL\n");
3673 GVariant *parameters;
3674 GError *error = NULL;
3677 __tethering_h *th = (__tethering_h *)tethering;
3679 GDBusProxy *proxy = th->client_bus_proxy;
3681 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
3682 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3684 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3686 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3687 result = TETHERING_ERROR_PERMISSION_DENIED;
3689 result = TETHERING_ERROR_OPERATION_FAILED;
3691 g_error_free(error);
3695 g_variant_get(parameters, "(u)", &result);
3697 g_variant_unref(parameters);
3699 return TETHERING_ERROR_NONE;
3702 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool* forwarding_enabled)
3704 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3705 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3707 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3708 "parameter(tethering) is NULL\n");
3709 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3710 "parameter(forwarding_enabled) is NULL\n");
3712 __tethering_h *th = (__tethering_h *)tethering;
3714 *forwarding_enabled = th->port_forwarding;
3716 return TETHERING_ERROR_NONE;
3719 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
3721 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3722 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3724 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3725 "parameter(tethering) is NULL\n");
3726 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3727 "parameter(port_forwarding_list) is NULL\n");
3729 *port_forwarding_list = g_slist_copy(port_forwarding);
3730 return TETHERING_ERROR_NONE;
3733 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
3735 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3736 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3738 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3739 "parameter(tethering) is NULL\n");
3741 GVariant *parameters;
3742 GError *error = NULL;
3745 __tethering_h *th = (__tethering_h *)tethering;
3747 GDBusProxy *proxy = th->client_bus_proxy;
3749 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
3750 g_variant_new("(b)", enable),
3751 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3753 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3755 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3756 result = TETHERING_ERROR_PERMISSION_DENIED;
3758 result = TETHERING_ERROR_OPERATION_FAILED;
3760 g_error_free(error);
3764 g_variant_get(parameters, "(u)", &result);
3765 g_variant_unref(parameters);
3767 th->port_filtering = true;
3769 return TETHERING_ERROR_NONE;
3772 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
3774 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3775 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3777 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3778 "parameter(tethering) is NULL\n");
3779 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3780 "parameter(protocol) is NULL\n");
3782 GVariant *parameters;
3783 GError *error = NULL;
3785 char cmd[MAX_BUF_SIZE] = { 0, };
3788 __tethering_h *th = (__tethering_h *)tethering;
3790 GDBusProxy *proxy = th->client_bus_proxy;
3792 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
3793 g_variant_new("(isb)", port, protocol, allow),
3794 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3796 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3798 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3799 result = TETHERING_ERROR_PERMISSION_DENIED;
3801 result = TETHERING_ERROR_OPERATION_FAILED;
3803 g_error_free(error);
3807 g_variant_get(parameters, "(u)", &result);
3808 g_variant_unref(parameters);
3811 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
3813 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
3819 ERR("strdup failed\n");
3820 return TETHERING_ERROR_OUT_OF_MEMORY;
3823 port_filtering = g_slist_append(port_filtering, list);
3825 return TETHERING_ERROR_NONE;
3828 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
3830 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3831 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3833 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3834 "parameter(tethering) is NULL\n");
3835 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3836 "parameter(protocol) is NULL\n");
3838 GVariant *parameters;
3839 GError *error = NULL;
3841 char cmd[MAX_BUF_SIZE] = { 0, };
3844 __tethering_h *th = (__tethering_h *)tethering;
3846 GDBusProxy *proxy = th->client_bus_proxy;
3848 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
3849 g_variant_new("(iisb)", port1, port2, protocol, allow),
3850 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3852 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3854 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3855 result = TETHERING_ERROR_PERMISSION_DENIED;
3857 result = TETHERING_ERROR_OPERATION_FAILED;
3859 g_error_free(error);
3863 g_variant_get(parameters, "(u)", &result);
3864 g_variant_unref(parameters);
3867 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
3869 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
3875 ERR("strdup failed\n");
3876 return TETHERING_ERROR_OUT_OF_MEMORY;
3879 custom_port_filtering = g_slist_append(custom_port_filtering, list);
3881 return TETHERING_ERROR_NONE;
3884 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
3886 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3887 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3889 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3890 "parameter(tethering) is NULL\n");
3891 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3892 "parameter(port_filtering_list) is NULL\n");
3894 *port_filtering_list = g_slist_copy(port_filtering);
3895 return TETHERING_ERROR_NONE;
3898 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
3900 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3901 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3903 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3904 "parameter(tethering) is NULL\n");
3905 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3906 "parameter(custom_port_filtering_list) is NULL\n");
3908 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
3909 return TETHERING_ERROR_NONE;
3912 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool* filtering_enabled)
3914 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3915 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3917 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3918 "parameter(tethering) is NULL\n");
3919 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3920 "parameter(filtering_enabled) is NULL\n");
3922 __tethering_h *th = (__tethering_h *)tethering;
3924 *filtering_enabled = th->port_filtering;
3926 return TETHERING_ERROR_NONE;
3929 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
3931 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3932 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3934 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3935 "parameter(tethering) is NULL\n");
3937 GVariant *parameters;
3938 GError *error = NULL;
3941 __tethering_h *th = (__tethering_h *)tethering;
3943 GDBusProxy *proxy = th->client_bus_proxy;
3945 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
3946 g_variant_new("(ib)", type, enable),
3947 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3949 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3951 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3952 result = TETHERING_ERROR_PERMISSION_DENIED;
3954 result = TETHERING_ERROR_OPERATION_FAILED;
3956 g_error_free(error);
3960 g_variant_get(parameters, "(u)", &result);
3962 g_variant_unref(parameters);
3964 return TETHERING_ERROR_NONE;
3967 API int tethering_wifi_push_wps_button(tethering_h tethering)
3969 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3970 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3972 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3973 "parameter(tethering) is NULL");
3974 __tethering_h *th = (__tethering_h *)tethering;
3975 GDBusProxy *proxy = th->client_bus_proxy;
3976 GVariant *parameters = NULL;
3978 GError *error = NULL;
3980 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
3981 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3984 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3986 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3987 ret = TETHERING_ERROR_PERMISSION_DENIED;
3989 ret = TETHERING_ERROR_OPERATION_FAILED;
3991 g_error_free(error);
3995 if (parameters != NULL) {
3996 g_variant_get(parameters, "(u)", &ret);
3997 g_variant_unref(parameters);
4000 return TETHERING_ERROR_NONE;
4003 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4005 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4006 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4008 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4009 "parameter(tethering) is NULL");
4010 __tethering_h *th = (__tethering_h *)tethering;
4011 GDBusProxy *proxy = th->client_bus_proxy;
4012 GVariant *parameters = NULL;
4014 GError *error = NULL;
4016 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4017 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4020 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4022 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4023 ret = TETHERING_ERROR_PERMISSION_DENIED;
4025 ret = TETHERING_ERROR_OPERATION_FAILED;
4027 g_error_free(error);
4031 if (parameters != NULL) {
4032 g_variant_get(parameters, "(u)", &ret);
4033 g_variant_unref(parameters);
4036 return TETHERING_ERROR_NONE;