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 "tethering_private.h"
34 #define ALLOWED_LIST "/etc/hostapd.accept"
35 #define BLOCKED_LIST "/etc/hostapd.deny"
36 #define TEMP_LIST "/etc/hostapd_tmp"
37 #define MAC_ADDR_LEN 18
38 #define MAX_BUF_SIZE 80
40 static GSList *allowed_list = NULL;
41 static GSList *blocked_list = NULL;
43 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
44 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
45 GVariant *parameters, gpointer user_data);
47 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
48 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
49 GVariant *parameters, gpointer user_data);
51 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
52 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
53 GVariant *parameters, gpointer user_data);
55 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
56 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
57 GVariant *parameters, gpointer user_data);
59 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
60 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
61 GVariant *parameters, gpointer user_data);
63 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
64 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
65 GVariant *parameters, gpointer user_data);
67 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
68 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
69 GVariant *parameters, gpointer user_data);
71 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
72 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
73 GVariant *parameters, gpointer user_data);
75 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
76 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
77 GVariant *parameters, gpointer user_data);
79 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
80 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
81 GVariant *parameters, gpointer user_data);
83 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
84 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
85 GVariant *parameters, gpointer user_data);
87 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
88 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
89 GVariant *parameters, gpointer user_data);
91 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
92 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
93 GVariant *parameters, gpointer user_data);
95 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
96 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
97 GVariant *parameters, gpointer user_data);
99 static __tethering_sig_t sigs[] = {
100 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
101 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
102 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
103 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
104 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
105 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
106 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
107 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
108 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
109 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
110 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
111 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
112 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
113 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
116 static int retry = 0;
118 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
120 if (conn == NULL || signal_name == NULL)
121 return; //LCOV_EXCL_LINE
123 GVariant *message = NULL;
124 GError *error = NULL;
127 message = g_variant_new("(s)", arg);
129 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
130 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
132 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
133 g_error_free(error); //LCOV_EXCL_LINE
135 g_variant_unref(message);
138 static bool __any_tethering_is_enabled(tethering_h tethering)
140 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
141 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
142 tethering_is_enabled(tethering, TETHERING_TYPE_BT))
148 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
150 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
151 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
152 ERR("Invalid param\n");
153 return TETHERING_ERROR_INVALID_PARAMETER;
156 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
157 ERR("vconf_set_int is failed\n");
158 return TETHERING_ERROR_OPERATION_FAILED;
161 return TETHERING_ERROR_NONE;
164 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
166 if (security_type == NULL) {
167 ERR("Invalid param\n");
168 return TETHERING_ERROR_INVALID_PARAMETER;
171 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
172 (int *)security_type) < 0) {
173 ERR("vconf_get_int is failed\n");
174 return TETHERING_ERROR_OPERATION_FAILED;
177 return TETHERING_ERROR_NONE;
180 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
182 if (path == NULL || ssid == NULL || size == 0)
186 char *ptr_tmp = NULL;
188 ptr = vconf_get_str(path);
192 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
195 g_strlcpy(ssid, ptr, size);
201 static tethering_error_e __set_visible(const bool visible)
203 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
204 ERR("vconf_set_int is failed\n");
205 return TETHERING_ERROR_OPERATION_FAILED;
208 return TETHERING_ERROR_NONE;
211 static tethering_error_e __get_visible(bool *visible)
213 if (visible == NULL) {
214 ERR("Invalid param\n");
215 return TETHERING_ERROR_INVALID_PARAMETER;
220 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
221 ERR("vconf_get_int is failed\n");
222 return TETHERING_ERROR_OPERATION_FAILED;
229 return TETHERING_ERROR_NONE;
232 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
234 if (passphrase == NULL ||
235 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
238 guint32 rand_int = 0;
241 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
242 rand_int = g_random_int_range('a', 'z');
243 passphrase[index] = rand_int;
245 passphrase[index] = '\0';
250 static tethering_error_e __get_error(int agent_error)
252 tethering_error_e err = TETHERING_ERROR_NONE;
254 switch (agent_error) {
255 case MOBILE_AP_ERROR_NONE:
256 err = TETHERING_ERROR_NONE;
260 case MOBILE_AP_ERROR_RESOURCE:
261 err = TETHERING_ERROR_OUT_OF_MEMORY;
265 case MOBILE_AP_ERROR_INTERNAL:
266 err = TETHERING_ERROR_OPERATION_FAILED;
269 case MOBILE_AP_ERROR_INVALID_PARAM:
270 err = TETHERING_ERROR_INVALID_PARAMETER;
273 case MOBILE_AP_ERROR_ALREADY_ENABLED:
274 err = TETHERING_ERROR_OPERATION_FAILED;
277 case MOBILE_AP_ERROR_NOT_ENABLED:
278 err = TETHERING_ERROR_NOT_ENABLED;
281 case MOBILE_AP_ERROR_NET_OPEN:
282 err = TETHERING_ERROR_OPERATION_FAILED;
285 case MOBILE_AP_ERROR_NET_CLOSE:
286 err = TETHERING_ERROR_OPERATION_FAILED;
289 case MOBILE_AP_ERROR_DHCP:
290 err = TETHERING_ERROR_OPERATION_FAILED;
293 case MOBILE_AP_ERROR_IN_PROGRESS:
294 err = TETHERING_ERROR_OPERATION_FAILED;
298 case MOBILE_AP_ERROR_NOT_PERMITTED:
299 err = TETHERING_ERROR_NOT_PERMITTED;
302 case MOBILE_AP_ERROR_PERMISSION_DENIED:
303 err = TETHERING_ERROR_PERMISSION_DENIED;
307 ERR("Not defined error : %d\n", agent_error);
308 err = TETHERING_ERROR_OPERATION_FAILED;
316 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
317 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
318 GVariant *parameters, gpointer user_data)
322 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
324 __tethering_h *th = (__tethering_h *)user_data;
326 tethering_type_e type = 0;
327 mobile_ap_type_e ap_type = 0;
328 tethering_connection_state_changed_cb ccb = NULL;
329 __tethering_client_h client;
337 memset(&client, 0, sizeof(__tethering_client_h));
338 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
340 if (!g_strcmp0(buf, "DhcpConnected")) {
342 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
345 ERR("Unknown event [%s]\n", buf);
349 if (ap_type == MOBILE_AP_TYPE_USB)
350 type = TETHERING_TYPE_USB;
351 else if (ap_type == MOBILE_AP_TYPE_WIFI)
352 type = TETHERING_TYPE_WIFI;
353 else if (ap_type == MOBILE_AP_TYPE_BT)
354 type = TETHERING_TYPE_BT;
356 ERR("Not supported tethering type [%d]\n", ap_type);
360 ccb = th->changed_cb[type];
363 data = th->changed_user_data[type];
365 client.interface = type;
366 g_strlcpy(client.ip, ip, sizeof(client.ip));
367 g_strlcpy(client.mac, mac, sizeof(client.mac));
369 client.hostname = g_strdup(name);
370 client.tm = (time_t)timestamp;
372 ccb((tethering_client_h)&client, opened, data);
373 g_free(client.hostname);
384 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
385 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
386 GVariant *parameters, gpointer user_data)
390 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
392 __tethering_h *th = (__tethering_h *)user_data;
393 tethering_type_e type = 0;
394 tethering_disabled_cb dcb = NULL;
396 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
398 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
399 dcb = th->disabled_cb[type];
402 data = th->disabled_user_data[type];
404 dcb(TETHERING_ERROR_NONE, type, code, data);
411 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
412 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
413 GVariant *parameters, gpointer user_data)
417 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
419 __tethering_h *th = (__tethering_h *)user_data;
420 tethering_type_e type = TETHERING_TYPE_WIFI;
421 bool is_requested = false;
422 tethering_enabled_cb ecb = NULL;
425 ecb = th->enabled_cb[type];
428 data = th->enabled_user_data[type];
430 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
434 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
435 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
436 GVariant *parameters, gpointer user_data)
440 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
442 __tethering_h *th = (__tethering_h *)user_data;
443 tethering_type_e type = TETHERING_TYPE_WIFI;
444 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
445 tethering_disabled_cb dcb = NULL;
449 dcb = th->disabled_cb[type];
452 data = th->disabled_user_data[type];
453 g_variant_get(parameters, "(s)", &buf);
454 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
455 code = TETHERING_DISABLED_BY_WIFI_ON;
456 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
457 code = TETHERING_DISABLED_BY_TIMEOUT;
460 dcb(TETHERING_ERROR_NONE, type, code, data);
466 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
467 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
468 GVariant *parameters, gpointer user_data)
472 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
474 __tethering_h *th = (__tethering_h *)user_data;
475 tethering_type_e type = TETHERING_TYPE_USB;
476 bool is_requested = false;
477 tethering_enabled_cb ecb = NULL;
480 ecb = th->enabled_cb[type];
483 data = th->enabled_user_data[type];
485 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
489 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
490 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
491 GVariant *parameters, gpointer user_data)
495 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
497 __tethering_h *th = (__tethering_h *)user_data;
498 tethering_type_e type = TETHERING_TYPE_USB;
499 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
500 tethering_disabled_cb dcb = NULL;
504 dcb = th->disabled_cb[type];
507 data = th->disabled_user_data[type];
509 g_variant_get(parameters, "(s)", &buf);
510 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
511 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
513 dcb(TETHERING_ERROR_NONE, type, code, data);
519 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
520 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
521 GVariant *parameters, gpointer user_data)
525 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
527 __tethering_h *th = (__tethering_h *)user_data;
528 tethering_type_e type = TETHERING_TYPE_BT;
529 bool is_requested = false;
530 tethering_enabled_cb ecb = NULL;
533 ecb = th->enabled_cb[type];
536 data = th->enabled_user_data[type];
538 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
542 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
543 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
544 GVariant *parameters, gpointer user_data)
548 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
550 __tethering_h *th = (__tethering_h *)user_data;
551 tethering_type_e type = TETHERING_TYPE_BT;
552 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
553 tethering_disabled_cb dcb = NULL;
557 dcb = th->disabled_cb[type];
560 data = th->disabled_user_data[type];
561 g_variant_get(parameters, "(s)", &buf);
562 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
563 code = TETHERING_DISABLED_BY_BT_OFF;
564 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
565 code = TETHERING_DISABLED_BY_TIMEOUT;
567 dcb(TETHERING_ERROR_NONE, type, code, data);
574 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
575 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
576 GVariant *parameters, gpointer user_data)
580 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
582 __tethering_h *th = (__tethering_h *)user_data;
583 tethering_type_e type = 0;
584 tethering_disabled_cb dcb = NULL;
586 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
588 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
589 dcb = th->disabled_cb[type];
592 data = th->disabled_user_data[type];
594 dcb(TETHERING_ERROR_NONE, type, code, data);
599 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
600 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
601 GVariant *parameters, gpointer user_data)
605 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
607 __tethering_h *th = (__tethering_h *)user_data;
608 tethering_type_e type = 0;
609 tethering_disabled_cb dcb = NULL;
611 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
613 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
614 dcb = th->disabled_cb[type];
617 data = th->disabled_user_data[type];
619 dcb(TETHERING_ERROR_NONE, type, code, data);
624 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
625 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
626 GVariant *parameters, gpointer user_data)
630 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
632 __tethering_h *th = (__tethering_h *)user_data;
633 tethering_type_e type = 0;
634 tethering_disabled_cb dcb = NULL;
636 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
638 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
639 dcb = th->disabled_cb[type];
642 data = th->disabled_user_data[type];
644 dcb(TETHERING_ERROR_NONE, type, code, data);
650 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
651 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
652 GVariant *parameters, gpointer user_data)
657 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
658 __tethering_h *th = (__tethering_h *)user_data;
660 tethering_wifi_security_type_changed_cb scb = NULL;
662 tethering_wifi_security_type_e security_type;
665 scb = th->security_type_changed_cb;
669 g_variant_get(parameters, "(s)", &buf);
670 data = th->security_type_user_data;
671 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
672 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
673 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
674 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
676 SERR("Unknown type : %s\n", buf);
681 scb(security_type, data);
686 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
687 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
688 GVariant *parameters, gpointer user_data)
692 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
693 __tethering_h *th = (__tethering_h *)user_data;
695 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
697 bool visible = false;
700 scb = th->ssid_visibility_changed_cb;
705 g_variant_get(parameters, "(s)", &buf);
706 data = th->ssid_visibility_user_data;
707 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
715 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
716 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
717 GVariant *parameters, gpointer user_data)
721 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
722 __tethering_h *th = (__tethering_h *)user_data;
724 tethering_wifi_passphrase_changed_cb pcb = NULL;
727 pcb = th->passphrase_changed_cb;
731 data = th->passphrase_user_data;
737 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
742 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
743 GError *g_error = NULL;
746 tethering_error_e error;
747 __tethering_h *th = (__tethering_h *)user_data;
748 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
749 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
751 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
754 ERR("DBus error [%s]\n", g_error->message);
755 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
756 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
757 g_error_free(g_error);
758 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
760 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
761 error = TETHERING_ERROR_PERMISSION_DENIED;
763 error = TETHERING_ERROR_OPERATION_FAILED;
764 g_error_free(g_error);
767 g_variant_get(g_var, "(u)", &info);
768 error = __get_error(info);
772 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
773 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
774 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
775 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
781 ecb(error, TETHERING_TYPE_WIFI, true, data);
782 g_variant_unref(g_var);
786 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
790 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
791 GError *g_error = NULL;
794 tethering_error_e error;
796 __tethering_h *th = (__tethering_h *)user_data;
797 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
798 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
800 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
803 ERR("DBus error [%s]\n", g_error->message);
804 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
805 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
806 g_error_free(g_error);
807 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
811 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
812 error = TETHERING_ERROR_PERMISSION_DENIED;
814 error = TETHERING_ERROR_OPERATION_FAILED;
815 g_error_free(g_error);
818 g_variant_get(g_var, "(u)", &info);
819 g_variant_unref(g_var);
820 error = __get_error(info);
824 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
825 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
826 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
827 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
834 ecb(error, TETHERING_TYPE_BT, true, data);
839 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
844 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
845 __tethering_h *th = (__tethering_h *)user_data;
846 GError *g_error = NULL;
849 tethering_error_e error;
850 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
851 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
853 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
855 ERR("DBus error [%s]\n", g_error->message);
856 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
857 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
858 g_error_free(g_error);
859 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
863 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
864 error = TETHERING_ERROR_PERMISSION_DENIED;
866 error = TETHERING_ERROR_OPERATION_FAILED;
867 g_error_free(g_error);
869 g_variant_get(g_var, "(u)", &info);
870 g_variant_unref(g_var);
871 error = __get_error(info);
875 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
876 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
877 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
878 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
885 ecb(error, TETHERING_TYPE_USB, true, data);
890 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
895 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
896 GError *g_error = NULL;
898 guint info, event_type;
899 tethering_error_e error;
900 tethering_type_e type;
901 tethering_h tethering = (tethering_h)user_data;
902 __tethering_h *th = (__tethering_h *)tethering;
903 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
904 tethering_disabled_cb dcb = NULL;
907 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
910 ERR("DBus error [%s]\n", g_error->message);
911 g_error_free(g_error);
915 g_variant_get(g_var, "(uu)", &event_type, &info);
916 DBG("cfm event : %d info : %d\n", event_type, info);
917 g_variant_unref(g_var);
918 error = __get_error(info);
919 DBG("cfm event : %d info : %d\n", event_type, error);
920 switch (event_type) {
921 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
922 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
923 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
924 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
925 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
927 type = TETHERING_TYPE_WIFI;
928 dcb = th->disabled_cb[type];
929 data = th->disabled_user_data[type];
931 dcb(error, type, code, data);
934 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
935 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
936 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
937 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
938 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
940 type = TETHERING_TYPE_BT;
941 dcb = th->disabled_cb[type];
942 data = th->disabled_user_data[type];
944 dcb(error, type, code, data);
948 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
949 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
950 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
951 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
952 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
954 type = TETHERING_TYPE_USB;
955 dcb = th->disabled_cb[type];
956 data = th->disabled_user_data[type];
958 dcb(error, type, code, data);
962 case MOBILE_AP_DISABLE_CFM:
964 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
965 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
966 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
967 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
968 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
969 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
970 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
971 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
972 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
973 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
974 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
975 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
977 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
978 dcb = th->disabled_cb[type];
981 data = th->disabled_user_data[type];
983 dcb(error, type, code, data);
988 ERR("Invalid event\n");
994 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
999 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1001 GError *g_error = NULL;
1004 guint64 tx_bytes, rx_bytes;
1005 __tethering_h *th = (__tethering_h *)user_data;
1006 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1009 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1012 ERR("DBus fail [%s]\n", g_error->message);
1013 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1014 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1016 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1021 if (th->data_usage_cb == NULL) {
1022 ERR("There is no data_usage_cb\n");
1026 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1028 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1029 th->data_usage_cb(TETHERING_ERROR_NONE,
1030 rx_bytes, tx_bytes, th->data_usage_user_data);
1031 g_variant_unref(g_var);
1033 th->data_usage_cb = NULL;
1034 th->data_usage_user_data = NULL;
1039 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1044 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1045 GError *g_error = NULL;
1048 __tethering_h *th = (__tethering_h *)user_data;
1049 tethering_error_e tethering_error;
1051 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1053 ERR("DBus fail [%s]\n", g_error->message);
1054 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1055 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1057 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1058 g_error_free(g_error);
1060 if (th->settings_reloaded_cb == NULL) {
1061 DBG("There is no settings_reloaded_cb\n-\n");
1064 g_variant_get(g_var, "(u)", &info);
1065 tethering_error = __get_error(info);
1066 g_variant_unref(g_var);
1068 th->settings_reloaded_cb(tethering_error,
1069 th->settings_reloaded_user_data);
1071 th->settings_reloaded_cb = NULL;
1072 th->settings_reloaded_user_data = NULL;
1076 static void __connect_signals(tethering_h tethering)
1079 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1081 __tethering_h *th = (__tethering_h *)tethering;
1082 GDBusConnection *connection = th->client_bus;
1085 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1086 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1087 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1088 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1089 sigs[i].cb, tethering, NULL);
1094 static void __disconnect_signals(tethering_h tethering)
1098 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1100 __tethering_h *th = (__tethering_h *)tethering;
1101 GDBusConnection *connection = th->client_bus;
1105 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1106 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1112 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1114 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1118 case TETHERING_TYPE_USB:
1119 g_strlcpy(buf, TETHERING_USB_IF, len);
1122 case TETHERING_TYPE_WIFI:
1123 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1126 case TETHERING_TYPE_BT:
1127 g_strlcpy(buf, TETHERING_BT_IF, len);
1131 ERR("Not supported type : %d\n", type);
1137 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1139 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1142 case TETHERING_TYPE_USB:
1143 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1146 case TETHERING_TYPE_WIFI:
1147 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1150 case TETHERING_TYPE_BT:
1151 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1155 ERR("Not supported type : %d\n", type);
1161 static int __get_common_ssid(char *ssid, unsigned int size)
1164 ERR("ssid is null\n"); //LCOV_EXCL_LINE
1165 return TETHERING_ERROR_INVALID_PARAMETER;
1169 char *ptr_tmp = NULL;
1171 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1173 ERR("vconf_get_str is failed and set default ssid");
1174 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1176 g_strlcpy(ssid, ptr, size);
1180 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1183 return TETHERING_ERROR_NONE;
1186 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1188 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1191 case TETHERING_WIFI_MODE_TYPE_B:
1192 *buf = g_strdup("b");
1194 case TETHERING_WIFI_MODE_TYPE_G:
1195 *buf = g_strdup("g");
1197 case TETHERING_WIFI_MODE_TYPE_A:
1198 *buf = g_strdup("a");
1200 case TETHERING_WIFI_MODE_TYPE_AD:
1201 *buf = g_strdup("ad");
1204 ERR("Not supported type : %d\n", type);
1210 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1214 __tethering_h *th = (__tethering_h *)tethering;
1215 tethering_error_e ret = TETHERING_ERROR_NONE;
1218 if (th == NULL || set == NULL) {
1219 ERR("null parameter\n-\n");
1220 return TETHERING_ERROR_INVALID_PARAMETER;
1223 if (th->ssid == NULL)
1224 __get_common_ssid(set->ssid, sizeof(set->ssid));
1226 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1228 ret = __get_security_type(&set->sec_type);
1229 if (ret != TETHERING_ERROR_NONE)
1230 set->sec_type = th->sec_type;
1232 ret = __get_visible(&set->visibility);
1233 if (ret != TETHERING_ERROR_NONE)
1234 set->visibility = th->visibility;
1236 set->mac_filter = th->mac_filter;
1237 set->channel = th->channel;
1239 __get_wifi_mode_type(th->mode_type, &ptr);
1241 g_strlcpy(set->mode, "", sizeof(set->mode));
1243 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1247 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1248 g_strlcpy(set->key, "", sizeof(set->key));
1250 GDBusProxy *proxy = th->client_bus_proxy;
1251 GVariant *parameters;
1252 GError *error = NULL;
1253 char *passphrase = NULL;
1254 unsigned int len = 0;
1256 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1257 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1261 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1263 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1264 ret = TETHERING_ERROR_PERMISSION_DENIED;
1266 ret = TETHERING_ERROR_OPERATION_FAILED;
1268 g_error_free(error);
1273 if (parameters != NULL) {
1274 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1275 g_variant_unref(parameters);
1278 g_strlcpy(set->key, passphrase, sizeof(set->key));
1281 return TETHERING_ERROR_NONE;
1284 static bool __check_precondition(tethering_type_e type)
1287 int cellular_state = 0;
1290 /* data network through cellular */
1291 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1292 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1293 ERR("Data Network can be connected later");
1297 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1298 if (dnet_state > VCONFKEY_DNET_OFF) {
1299 ERR("Data Network is connected");
1303 /* data network through wifi */
1304 if (type != TETHERING_TYPE_WIFI) {
1305 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1306 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1307 ERR("Wi-Fi is connected!");
1312 ERR("Network is not available!");
1318 * @brief Creates the handle of tethering.
1320 * @privlevel platform
1321 * @privilege http://tizen.org/privilege/tethering.admin
1322 * @remarks The @a tethering must be released tethering_destroy() by you.
1323 * @param[out] tethering A handle of a new mobile ap handle on success
1324 * @return 0 on success, otherwise a negative error value.
1325 * @retval #TETHERING_ERROR_NONE Successful
1326 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1327 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1328 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1329 * @see tethering_destroy()
1331 API int tethering_create(tethering_h *tethering)
1333 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1334 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1335 "parameter(tethering) is NULL\n");
1338 __tethering_h *th = NULL;
1339 GError *error = NULL;
1340 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1342 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1344 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1345 "malloc is failed\n");
1346 memset(th, 0x00, sizeof(__tethering_h));
1347 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1348 th->visibility = true;
1349 th->mac_filter = false;
1351 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1353 if (__generate_initial_passphrase(th->passphrase,
1354 sizeof(th->passphrase)) == 0) {
1355 ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
1357 return TETHERING_ERROR_OPERATION_FAILED;
1360 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1361 ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
1363 return TETHERING_ERROR_OPERATION_FAILED;
1366 #if !GLIB_CHECK_VERSION(2, 36, 0)
1369 GCancellable *cancellable = g_cancellable_new();
1370 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1373 ERR("Couldn't connect to the System bus[%s]", error->message);
1374 g_error_free(error);
1375 g_cancellable_cancel(cancellable);
1376 g_object_unref(cancellable);
1378 return TETHERING_ERROR_OPERATION_FAILED;
1381 th->cancellable = cancellable;
1383 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1384 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1385 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1386 if (!th->client_bus_proxy) {
1389 ERR("Couldn't create the proxy object because of %s\n", error->message);
1390 g_cancellable_cancel(th->cancellable);
1391 g_object_unref(th->cancellable);
1392 g_object_unref(th->client_bus);
1394 return TETHERING_ERROR_OPERATION_FAILED;
1398 __connect_signals((tethering_h)th);
1400 *tethering = (tethering_h)th;
1401 DBG("Tethering Handle : 0x%X\n", th);
1403 return TETHERING_ERROR_NONE;
1408 * @brief Destroys the handle of tethering.
1410 * @privlevel platform
1411 * @privilege http://tizen.org/privilege/tethering.admin
1412 * @param[in] tethering The handle of tethering
1413 * @return 0 on success, otherwise a negative error value.
1414 * @retval #TETHERING_ERROR_NONE Successful
1415 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1416 * @see tethering_create()
1418 API int tethering_destroy(tethering_h tethering)
1421 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1422 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1423 "parameter(tethering) is NULL\n");
1425 __tethering_h *th = (__tethering_h *)tethering;
1427 DBG("Tethering Handle : 0x%X\n", th);
1428 __disconnect_signals(tethering);
1433 g_object_unref(th->cancellable);
1434 g_object_unref(th->client_bus_proxy);
1435 g_object_unref(th->client_bus);
1436 memset(th, 0x00, sizeof(__tethering_h));
1440 return TETHERING_ERROR_NONE;
1445 * @brief Enables the tethering, asynchronously.
1447 * @privlevel platform
1448 * @privilege http://tizen.org/privilege/tethering.admin
1449 * @param[in] tethering The handle of tethering
1450 * @param[in] type The type of tethering
1451 * @return 0 on success, otherwise negative error value.
1452 * @retval #TETHERING_ERROR_NONE Successful
1453 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1454 * @post tethering_enabled_cb() will be invoked.
1455 * @see tethering_is_enabled()
1456 * @see tethering_disable()
1458 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1460 DBG("+ type : %d\n", type);
1461 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1462 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1463 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1464 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1466 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1467 "parameter(tethering) is NULL\n");
1469 tethering_error_e ret = TETHERING_ERROR_NONE;
1470 __tethering_h *th = (__tethering_h *)tethering;
1471 GDBusProxy *proxy = th->client_bus_proxy;
1472 GDBusConnection *connection = th->client_bus;
1474 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1476 if (__check_precondition(type) == FALSE) {
1479 return TETHERING_ERROR_OPERATION_FAILED;
1485 case TETHERING_TYPE_USB:
1486 g_dbus_connection_signal_unsubscribe(connection,
1487 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1489 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1490 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1491 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1495 case TETHERING_TYPE_WIFI: {
1496 _softap_settings_t set = {"", "", "", 0, false};
1498 ret = __prepare_wifi_settings(tethering, &set);
1499 if (ret != TETHERING_ERROR_NONE) {
1500 ERR("softap settings initialization failed\n");
1502 return TETHERING_ERROR_OPERATION_FAILED;
1504 g_dbus_connection_signal_unsubscribe(connection,
1505 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1507 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1508 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
1509 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1510 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1514 case TETHERING_TYPE_BT:
1515 g_dbus_connection_signal_unsubscribe(connection,
1516 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1518 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1519 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1520 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1525 case TETHERING_TYPE_ALL: {
1526 _softap_settings_t set = {"", "", "", 0, false};
1528 ret = __prepare_wifi_settings(tethering, &set);
1529 if (ret != TETHERING_ERROR_NONE) {
1530 ERR("softap settings initialization failed\n");
1531 return TETHERING_ERROR_OPERATION_FAILED;
1534 /* TETHERING_TYPE_USB */
1535 g_dbus_connection_signal_unsubscribe(connection,
1536 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1538 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1539 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1540 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1542 /* TETHERING_TYPE_WIFI */
1543 g_dbus_connection_signal_unsubscribe(connection,
1544 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1546 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1547 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1548 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1549 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1551 /* TETHERING_TYPE_BT */
1552 g_dbus_connection_signal_unsubscribe(connection,
1553 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1555 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1556 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1557 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1562 ERR("Unknown type : %d\n", type);
1564 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1567 return TETHERING_ERROR_INVALID_PARAMETER;
1570 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1572 return TETHERING_ERROR_NONE;
1577 * @brief Disables the tethering, asynchronously.
1579 * @privlevel platform
1580 * @privilege http://tizen.org/privilege/tethering.admin
1581 * @param[in] tethering The handle of tethering
1582 * @param[in] type The type of tethering
1583 * @return 0 on success, otherwise negative error value.
1584 * @retval #TETHERING_ERROR_NONE Successful
1585 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1586 * @post tethering_disabled_cb() will be invoked.
1587 * @see tethering_is_enabled()
1588 * @see tethering_enable()
1590 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1592 DBG("+ type : %d\n", type);
1593 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1594 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1595 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1597 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1598 "parameter(tethering) is NULL\n");
1600 __tethering_h *th = (__tethering_h *)tethering;
1601 GDBusProxy *proxy = th->client_bus_proxy;
1602 GDBusConnection *connection = th->client_bus;
1605 case TETHERING_TYPE_USB:
1606 g_dbus_connection_signal_unsubscribe(connection,
1607 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1609 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1610 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1611 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1615 case TETHERING_TYPE_WIFI:
1617 g_dbus_connection_signal_unsubscribe(connection,
1618 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1620 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1621 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1622 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1625 case TETHERING_TYPE_BT:
1627 g_dbus_connection_signal_unsubscribe(connection,
1628 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1630 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1631 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1632 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1635 case TETHERING_TYPE_ALL:
1636 g_dbus_connection_signal_unsubscribe(connection,
1637 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1639 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1640 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1641 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1643 g_dbus_connection_signal_unsubscribe(connection,
1644 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1646 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1647 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1648 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1650 g_dbus_connection_signal_unsubscribe(connection,
1651 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1653 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1654 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1655 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1659 ERR("Not supported tethering type [%d]\n", type);
1661 return TETHERING_ERROR_INVALID_PARAMETER;
1664 return TETHERING_ERROR_NONE;
1669 * @brief Checks whetehr the tethering is enabled or not.
1671 * @privlevel platform
1672 * @privilege http://tizen.org/privilege/tethering.admin
1673 * @param[in] tethering The handle of tethering
1674 * @param[in] type The type of tethering
1675 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1677 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1680 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1682 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1684 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1688 case TETHERING_TYPE_USB:
1689 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1692 case TETHERING_TYPE_WIFI:
1693 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1696 case TETHERING_TYPE_BT:
1697 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1701 ERR("Not supported type : %d\n", type);
1704 return is_on & vconf_type ? true : false;
1709 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1711 * @privlevel platform
1712 * @privilege http://tizen.org/privilege/tethering.admin
1713 * @remarks @a mac_address must be released with free() by you.
1714 * @param[in] tethering The handle of tethering
1715 * @param[in] type The type of tethering
1716 * @param[out] mac_address The MAC address
1717 * @return 0 on success, otherwise a negative error value.
1718 * @retval #TETHERING_ERROR_NONE Successful
1719 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1720 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1721 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1722 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1723 * @pre tethering must be enabled.
1724 * @see tethering_is_enabled()
1725 * @see tethering_enable()
1727 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1729 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1730 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1731 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1733 _retvm_if(tethering_is_enabled(tethering, type) == false,
1734 TETHERING_ERROR_NOT_ENABLED,
1735 "tethering type[%d] is not enabled\n", type);
1736 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1737 "parameter(tethering) is NULL\n");
1738 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1739 "parameter(mac_address) is NULL\n");
1743 char *macbuf = NULL;
1745 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1746 TETHERING_ERROR_OPERATION_FAILED,
1747 "getting interface name is failed\n");
1749 s = socket(AF_INET, SOCK_DGRAM, 0);
1750 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1751 "getting socket is failed\n");
1752 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1753 ERR("getting mac is failed\n");
1755 return TETHERING_ERROR_OPERATION_FAILED;
1759 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1760 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1761 "Not enough memory\n");
1762 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1763 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1764 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1765 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1766 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1767 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1768 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1770 *mac_address = macbuf;
1772 return TETHERING_ERROR_NONE;
1777 * @brief Gets the name of network interface. For example, usb0.
1779 * @privlevel platform
1780 * @privilege http://tizen.org/privilege/tethering.admin
1781 * @remarks @a interface_name must be released with free() by you.
1782 * @param[in] tethering The handle of tethering
1783 * @param[in] type The type of tethering
1784 * @param[out] interface_name The name of network interface
1785 * @return 0 on success, otherwise negative error value.
1786 * @retval #TETHERING_ERROR_NONE Successful
1787 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1788 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1789 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1790 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1791 * @pre tethering must be enabled.
1792 * @see tethering_is_enabled()
1793 * @see tethering_enable()
1795 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1797 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1798 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1799 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1801 _retvm_if(tethering_is_enabled(tethering, type) == false,
1802 TETHERING_ERROR_NOT_ENABLED,
1803 "tethering type[%d] is not enabled\n", type);
1804 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1805 "parameter(tethering) is NULL\n");
1806 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1807 "parameter(interface_name) is NULL\n");
1809 char intf[TETHERING_STR_INFO_LEN] = {0, };
1811 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1812 TETHERING_ERROR_OPERATION_FAILED,
1813 "getting interface name is failed\n");
1814 *interface_name = strdup(intf);
1815 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1816 "Not enough memory\n");
1818 return TETHERING_ERROR_NONE;
1823 * @brief Gets the local IP address.
1825 * @privlevel platform
1826 * @privilege http://tizen.org/privilege/tethering.admin
1827 * @remarks @a ip_address must be released with free() by you.
1828 * @param[in] tethering The handle of tethering
1829 * @param[in] type The type of tethering
1830 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1831 * @param[out] ip_address The local IP address
1832 * @return 0 on success, otherwise negative error value.
1833 * @retval #TETHERING_ERROR_NONE Successful
1834 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1835 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1836 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1837 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1838 * @pre tethering must be enabled.
1839 * @see tethering_is_enabled()
1840 * @see tethering_enable()
1842 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1845 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1846 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1847 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1849 _retvm_if(tethering_is_enabled(tethering, type) == false,
1850 TETHERING_ERROR_NOT_ENABLED,
1851 "tethering type[%d] is not enabled\n", type);
1852 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1853 "parameter(tethering) is NULL\n");
1854 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1855 "parameter(ip_address) is NULL\n");
1861 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1862 TETHERING_ERROR_OPERATION_FAILED,
1863 "getting interface name is failed\n");
1865 s = socket(AF_INET, SOCK_DGRAM, 0);
1866 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1867 "getting socket is failed\n");
1868 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1869 ERR("ioctl is failed\n");
1871 return TETHERING_ERROR_OPERATION_FAILED;
1875 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1876 *ip_address = strdup(ipbuf);
1877 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1878 "Not enough memory\n");
1880 return TETHERING_ERROR_NONE;
1885 * @brief Gets the Gateway address.
1887 * @privlevel platform
1888 * @privilege http://tizen.org/privilege/tethering.admin
1889 * @remarks @a gateway_address must be released with free() by you.
1890 * @param[in] tethering The handle of tethering
1891 * @param[in] type The type of tethering
1892 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1893 * @param[out] gateway_address The local IP address
1894 * @return 0 on success, otherwise negative error value.
1895 * @retval #TETHERING_ERROR_NONE Successful
1896 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1897 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1898 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1899 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1900 * @pre tethering must be enabled.
1901 * @see tethering_is_enabled()
1902 * @see tethering_enable()
1904 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1907 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1908 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1909 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1911 _retvm_if(tethering_is_enabled(tethering, type) == false,
1912 TETHERING_ERROR_NOT_ENABLED,
1913 "tethering type[%d] is not enabled\n", type);
1914 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1915 "parameter(tethering) is NULL\n");
1916 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1917 "parameter(gateway_address) is NULL\n");
1919 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1921 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1922 TETHERING_ERROR_OPERATION_FAILED,
1923 "getting gateway address is failed\n");
1925 *gateway_address = strdup(gateway_buf);
1927 return TETHERING_ERROR_NONE;
1932 * @brief Gets the Subnet Mask.
1934 * @privlevel platform
1935 * @privilege http://tizen.org/privilege/tethering.admin
1936 * @remarks @a subnet_mask must be released with free() by you.
1937 * @param[in] tethering The handle of tethering
1938 * @param[in] type The type of tethering
1939 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1940 * @param[out] subnet_mask The local IP address
1941 * @return 0 on success, otherwise negative error value.
1942 * @retval #TETHERING_ERROR_NONE Successful
1943 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1944 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1945 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1946 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1947 * @pre tethering must be enabled.
1948 * @see tethering_is_enabled()
1949 * @see tethering_enable()
1951 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1953 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1954 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1955 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1957 _retvm_if(tethering_is_enabled(tethering, type) == false,
1958 TETHERING_ERROR_NOT_ENABLED,
1959 "tethering is not enabled\n");
1960 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1961 "parameter(tethering) is NULL\n");
1962 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1963 "parameter(subnet_mask) is NULL\n");
1965 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
1966 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1967 "Not enough memory\n");
1969 return TETHERING_ERROR_NONE;
1974 * @brief Gets the data usage.
1976 * @privlevel platform
1977 * @privilege http://tizen.org/privilege/tethering.admin
1978 * @param[in] tethering The handle of tethering
1979 * @param[out] usage The data usage
1980 * @return 0 on success, otherwise negative error value.
1981 * @retval #TETHERING_ERROR_NONE Successful
1982 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1983 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1984 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1985 * @pre tethering must be enabled.
1986 * @see tethering_is_enabled()
1987 * @see tethering_enable()
1989 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
1991 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1993 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1994 "parameter(tethering) is NULL\n");
1995 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1996 "parameter(callback) is NULL\n");
1997 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1998 TETHERING_ERROR_NOT_ENABLED,
1999 "tethering is not enabled\n");
2001 __tethering_h *th = (__tethering_h *)tethering;
2002 GDBusProxy *proxy = th->client_bus_proxy;
2004 th->data_usage_cb = callback;
2005 th->data_usage_user_data = user_data;
2007 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2008 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2009 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2011 return TETHERING_ERROR_NONE;
2016 * @brief Gets the client which is connected by tethering "type".
2018 * @privlevel platform
2019 * @privilege http://tizen.org/privilege/tethering.admin
2020 * @param[in] tethering The handle of tethering
2021 * @param[in] type The type of tethering
2022 * @param[in] callback The callback function to invoke
2023 * @param[in] user_data The user data to be passed to the callback function
2024 * @retval #TETHERING_ERROR_NONE Successful
2025 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2026 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2027 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2028 * @pre tethering must be enabled.
2029 * @see tethering_is_enabled()
2030 * @see tethering_enable()
2032 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2035 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2036 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2037 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2039 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2040 "parameter(tethering) is NULL\n");
2041 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2042 "parameter(callback) is NULL\n");
2043 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2044 TETHERING_ERROR_NOT_ENABLED,
2045 "tethering is not enabled\n");
2047 mobile_ap_type_e interface;
2048 __tethering_h *th = (__tethering_h *)tethering;
2049 __tethering_client_h client = {0, };
2052 gchar *hostname = NULL;
2053 guint timestamp = 0;
2054 GError *error = NULL;
2055 GVariant *result = NULL;
2056 GVariantIter *outer_iter = NULL;
2057 GVariantIter *inner_iter = NULL;
2058 GVariant *station = NULL;
2059 GVariant *value = NULL;
2062 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2063 NULL, G_DBUS_CALL_FLAGS_NONE,
2064 -1, th->cancellable, &error);
2066 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2067 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2068 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2069 g_variant_get(station, "a{sv}", &inner_iter);
2070 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2071 if (g_strcmp0(key, "Type") == 0) {
2072 interface = g_variant_get_int32(value);
2073 if (interface == MOBILE_AP_TYPE_USB)
2074 client.interface = TETHERING_TYPE_USB;
2075 else if (interface == MOBILE_AP_TYPE_WIFI)
2076 client.interface = TETHERING_TYPE_WIFI;
2077 else if (interface == MOBILE_AP_TYPE_BT)
2078 client.interface = TETHERING_TYPE_BT;
2080 ERR("Invalid interface\n");
2082 g_variant_unref(value);
2085 DBG("interface is %d\n", client.interface);
2086 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2088 g_variant_unref(value);
2091 } else if (g_strcmp0(key, "IP") == 0) {
2092 g_variant_get(value, "s", &ip);
2093 SDBG("ip is %s\n", ip);
2094 g_strlcpy(client.ip, ip, sizeof(client.ip));
2095 } else if (g_strcmp0(key, "MAC") == 0) {
2096 g_variant_get(value, "s", &mac);
2097 SDBG("mac is %s\n", mac);
2098 g_strlcpy(client.mac, mac, sizeof(client.mac));
2099 } else if (g_strcmp0(key, "Name") == 0) {
2100 g_variant_get(value, "s", &hostname);
2101 SDBG("hsotname is %s\n", hostname);
2103 client.hostname = g_strdup(hostname);
2104 } else if (g_strcmp0(key, "Time") == 0) {
2105 timestamp = g_variant_get_int32(value);
2106 DBG("timestamp is %d\n", timestamp);
2107 client.tm = (time_t)timestamp;
2109 ERR("Key %s not required\n", key);
2115 g_variant_iter_free(inner_iter);
2116 if (callback((tethering_client_h)&client, user_data) == false) {
2117 DBG("iteration is stopped\n");
2118 g_free(client.hostname);
2119 g_variant_iter_free(outer_iter);
2120 g_variant_unref(station);
2121 g_variant_unref(result);
2123 return TETHERING_ERROR_OPERATION_FAILED;
2125 g_free(client.hostname);
2127 g_variant_iter_free(outer_iter);
2128 g_variant_unref(station);
2129 g_variant_unref(result);
2131 return TETHERING_ERROR_NONE;
2136 * @brief Registers the callback function called when tethering is enabled.
2138 * @privlevel platform
2139 * @privilege http://tizen.org/privilege/tethering.admin
2140 * @param[in] tethering The handle of tethering
2141 * @param[in] type The type of tethering
2142 * @param[in] callback The callback function to invoke
2143 * @param[in] user_data The user data to be passed to the callback function
2144 * @retval #TETHERING_ERROR_NONE Successful
2145 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2146 * @see tethering_unset_enabled_cb()
2148 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2150 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2151 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2152 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2154 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2155 "parameter(tethering) is NULL\n");
2156 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2157 "parameter(callback) is NULL\n");
2159 __tethering_h *th = (__tethering_h *)tethering;
2160 tethering_type_e ti;
2162 if (type != TETHERING_TYPE_ALL) {
2163 th->enabled_cb[type] = callback;
2164 th->enabled_user_data[type] = user_data;
2166 return TETHERING_ERROR_NONE;
2169 /* TETHERING_TYPE_ALL */
2170 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2171 th->enabled_cb[ti] = callback;
2172 th->enabled_user_data[ti] = user_data;
2175 return TETHERING_ERROR_NONE;
2180 * @brief Unregisters the callback function called when tethering is disabled.
2182 * @privlevel platform
2183 * @privilege http://tizen.org/privilege/tethering.admin
2184 * @param[in] tethering The handle of tethering
2185 * @param[in] type The type of tethering
2186 * @retval #TETHERING_ERROR_NONE Successful
2187 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2188 * @see tethering_set_enabled_cb()
2190 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2192 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2193 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2194 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2196 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2197 "parameter(tethering) is NULL\n");
2199 __tethering_h *th = (__tethering_h *)tethering;
2200 tethering_type_e ti;
2202 if (type != TETHERING_TYPE_ALL) {
2203 th->enabled_cb[type] = NULL;
2204 th->enabled_user_data[type] = NULL;
2206 return TETHERING_ERROR_NONE;
2209 /* TETHERING_TYPE_ALL */
2210 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2211 th->enabled_cb[ti] = NULL;
2212 th->enabled_user_data[ti] = NULL;
2215 return TETHERING_ERROR_NONE;
2220 * @brief Registers the callback function called when tethering is disabled.
2222 * @privlevel platform
2223 * @privilege http://tizen.org/privilege/tethering.admin
2224 * @param[in] tethering The handle of tethering
2225 * @param[in] type The type of tethering
2226 * @param[in] callback The callback function to invoke
2227 * @param[in] user_data The user data to be passed to the callback function
2228 * @retval #TETHERING_ERROR_NONE Successful
2229 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2230 * @see tethering_unset_disabled_cb()
2232 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2234 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2235 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2236 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2238 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2239 "parameter(tethering) is NULL\n");
2240 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2241 "parameter(callback) is NULL\n");
2243 __tethering_h *th = (__tethering_h *)tethering;
2244 tethering_type_e ti;
2246 if (type != TETHERING_TYPE_ALL) {
2247 th->disabled_cb[type] = callback;
2248 th->disabled_user_data[type] = user_data;
2250 return TETHERING_ERROR_NONE;
2253 /* TETHERING_TYPE_ALL */
2254 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2255 th->disabled_cb[ti] = callback;
2256 th->disabled_user_data[ti] = user_data;
2259 return TETHERING_ERROR_NONE;
2264 * @brief Unregisters 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 * @retval #TETHERING_ERROR_NONE Successful
2271 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2272 * @see tethering_set_disabled_cb()
2274 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2276 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2277 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2278 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2280 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2281 "parameter(tethering) is NULL\n");
2283 __tethering_h *th = (__tethering_h *)tethering;
2284 tethering_type_e ti;
2286 if (type != TETHERING_TYPE_ALL) {
2287 th->disabled_cb[type] = NULL;
2288 th->disabled_user_data[type] = NULL;
2290 return TETHERING_ERROR_NONE;
2293 /* TETHERING_TYPE_ALL */
2294 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2295 th->disabled_cb[ti] = NULL;
2296 th->disabled_user_data[ti] = NULL;
2299 return TETHERING_ERROR_NONE;
2304 * @brief Registers the callback function called when the state of connection is changed.
2306 * @privlevel platform
2307 * @privilege http://tizen.org/privilege/tethering.admin
2308 * @param[in] tethering The handle of tethering
2309 * @param[in] type The type of tethering
2310 * @param[in] callback The callback function to invoke
2311 * @param[in] user_data The user data to be passed to the callback function
2312 * @retval #TETHERING_ERROR_NONE Successful
2313 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2314 * @see tethering_unset_connection_state_changed_cb_cb()
2316 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2318 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2319 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2320 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2322 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2323 "parameter(tethering) is NULL\n");
2324 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2325 "parameter(callback) is NULL\n");
2327 __tethering_h *th = (__tethering_h *)tethering;
2328 tethering_type_e ti;
2330 if (type != TETHERING_TYPE_ALL) {
2331 th->changed_cb[type] = callback;
2332 th->changed_user_data[type] = user_data;
2334 return TETHERING_ERROR_NONE;
2337 /* TETHERING_TYPE_ALL */
2338 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2339 th->changed_cb[ti] = callback;
2340 th->changed_user_data[ti] = user_data;
2343 return TETHERING_ERROR_NONE;
2348 * @brief Unregisters the callback function called when the state of connection is changed.
2350 * @privlevel platform
2351 * @privilege http://tizen.org/privilege/tethering.admin
2352 * @param[in] tethering The handle of tethering
2353 * @param[in] type The type of tethering
2354 * @retval #TETHERING_ERROR_NONE Successful
2355 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2356 * @see tethering_set_connection_state_changed_cb()
2358 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2360 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2361 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2362 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2364 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2365 "parameter(tethering) is NULL\n");
2367 __tethering_h *th = (__tethering_h *)tethering;
2368 tethering_type_e ti;
2370 if (type != TETHERING_TYPE_ALL) {
2371 th->changed_cb[type] = NULL;
2372 th->changed_user_data[type] = NULL;
2374 return TETHERING_ERROR_NONE;
2377 /* TETHERING_TYPE_ALL */
2378 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2379 th->changed_cb[ti] = NULL;
2380 th->changed_user_data[ti] = NULL;
2383 return TETHERING_ERROR_NONE;
2388 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2390 * @privlevel platform
2391 * @privilege http://tizen.org/privilege/tethering.admin
2392 * @param[in] tethering The handle of tethering
2393 * @param[in] callback The callback function to invoke
2394 * @param[in] user_data The user data to be passed to the callback function
2395 * @retval #TETHERING_ERROR_NONE Successful
2396 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2397 * @see tethering_wifi_unset_security_type_changed_cb()
2399 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2401 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2403 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2404 "parameter(tethering) is NULL\n");
2405 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2406 "parameter(callback) is NULL\n");
2408 __tethering_h *th = (__tethering_h *)tethering;
2410 th->security_type_changed_cb = callback;
2411 th->security_type_user_data = user_data;
2413 return TETHERING_ERROR_NONE;
2419 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2421 * @privlevel platform
2422 * @privilege http://tizen.org/privilege/tethering.admin
2423 * @param[in] tethering The handle of tethering
2424 * @param[in] type The type of tethering
2425 * @retval #TETHERING_ERROR_NONE Successful
2426 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2427 * @see tethering_wifi_set_security_type_changed_cb()
2429 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2431 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2433 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2434 "parameter(tethering) is NULL\n");
2436 __tethering_h *th = (__tethering_h *)tethering;
2438 th->security_type_changed_cb = NULL;
2439 th->security_type_user_data = NULL;
2441 return TETHERING_ERROR_NONE;
2446 * @brief Registers the callback function called when the visibility of SSID is changed.
2448 * @privlevel platform
2449 * @privilege http://tizen.org/privilege/tethering.admin
2450 * @param[in] tethering The handle of tethering
2451 * @param[in] callback The callback function to invoke
2452 * @param[in] user_data The user data to be passed to the callback function
2453 * @retval #TETHERING_ERROR_NONE Successful
2454 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2455 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2457 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2459 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2461 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2462 "parameter(tethering) is NULL\n");
2463 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2464 "parameter(callback) is NULL\n");
2466 __tethering_h *th = (__tethering_h *)tethering;
2468 th->ssid_visibility_changed_cb = callback;
2469 th->ssid_visibility_user_data = user_data;
2471 return TETHERING_ERROR_NONE;
2476 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2478 * @privlevel platform
2479 * @privilege http://tizen.org/privilege/tethering.admin
2480 * @param[in] tethering The handle of tethering
2481 * @retval #TETHERING_ERROR_NONE Successful
2482 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2483 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2485 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2487 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2489 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2490 "parameter(tethering) is NULL\n");
2492 __tethering_h *th = (__tethering_h *)tethering;
2494 th->ssid_visibility_changed_cb = NULL;
2495 th->ssid_visibility_user_data = NULL;
2497 return TETHERING_ERROR_NONE;
2502 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2504 * @privlevel platform
2505 * @privilege http://tizen.org/privilege/tethering.admin
2506 * @param[in] tethering The handle of tethering
2507 * @param[in] callback The callback function to invoke
2508 * @param[in] user_data The user data to be passed to the callback function
2509 * @retval #TETHERING_ERROR_NONE Successful
2510 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2511 * @see tethering_wifi_unset_passphrase_changed_cb()
2513 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2515 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2517 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2518 "parameter(tethering) is NULL\n");
2519 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2520 "parameter(callback) is NULL\n");
2522 __tethering_h *th = (__tethering_h *)tethering;
2524 th->passphrase_changed_cb = callback;
2525 th->passphrase_user_data = user_data;
2527 return TETHERING_ERROR_NONE;
2532 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2534 * @privlevel platform
2535 * @privilege http://tizen.org/privilege/tethering.admin
2536 * @param[in] tethering The handle of tethering
2537 * @retval #TETHERING_ERROR_NONE Successful
2538 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2539 * @see tethering_wifi_set_passphrase_changed_cb()
2541 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2543 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2545 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2546 "parameter(tethering) is NULL\n");
2548 __tethering_h *th = (__tethering_h *)tethering;
2550 th->passphrase_changed_cb = NULL;
2551 th->passphrase_user_data = NULL;
2553 return TETHERING_ERROR_NONE;
2558 * @brief Sets the security type of Wi-Fi tethering.
2560 * @privlevel platform
2561 * @privilege http://tizen.org/privilege/tethering.admin
2562 * @remarks This change is applied next time Wi-Fi tethering is enabled
2563 * @param[in] tethering The handle of tethering
2564 * @param[in] type The security type
2565 * @return 0 on success, otherwise negative error value.
2566 * @retval #TETHERING_ERROR_NONE Successful
2567 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2568 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2569 * @see tethering_wifi_get_security_type()
2571 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2573 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2575 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2576 "parameter(tethering) is NULL\n");
2578 __tethering_h *th = (__tethering_h *)tethering;
2579 tethering_error_e ret = TETHERING_ERROR_NONE;
2581 ret = __set_security_type(type);
2582 if (ret == TETHERING_ERROR_NONE) {
2584 __send_dbus_signal(th->client_bus,
2585 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2586 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2587 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2588 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2595 * @brief Gets the security type of Wi-Fi tethering.
2597 * @privlevel platform
2598 * @privilege http://tizen.org/privilege/tethering.admin
2599 * @param[in] tethering The handle of tethering
2600 * @param[out] type The security type
2601 * @return 0 on success, otherwise negative error value.
2602 * @retval #TETHERING_ERROR_NONE Successful
2603 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2604 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2605 * @see tethering_wifi_set_security_type()
2607 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2609 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2611 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2612 "parameter(type) is NULL\n");
2614 return __get_security_type(type);
2619 * @brief Sets the SSID (service set identifier).
2621 * @privlevel platform
2622 * @privilege http://tizen.org/privilege/tethering.admin
2623 * @details If SSID is not set, Device name is used as SSID
2624 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2625 * @param[in] tethering The handle of tethering
2626 * @param[out] ssid The SSID
2627 * @return 0 on success, otherwise negative error value.
2628 * @retval #TETHERING_ERROR_NONE Successful
2629 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2630 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2632 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2634 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2636 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2637 "parameter(tethering) is NULL\n");
2638 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2639 "parameter(ssid) is NULL\n");
2641 __tethering_h *th = (__tethering_h *)tethering;
2642 char *p_ssid = NULL;
2645 ssid_len = strlen(ssid);
2646 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2647 ERR("parameter(ssid) is too long");
2648 return TETHERING_ERROR_INVALID_PARAMETER;
2651 p_ssid = strdup(ssid);
2652 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2653 "strdup is failed\n");
2659 return TETHERING_ERROR_NONE;
2664 * @brief Gets the SSID (service set identifier).
2666 * @privlevel platform
2667 * @privilege http://tizen.org/privilege/tethering.admin
2668 * @remarks @a ssid must be released with free() by you.
2669 * @param[in] tethering The handle of tethering
2670 * @param[out] ssid The SSID
2671 * @return 0 on success, otherwise negative error value.
2672 * @retval #TETHERING_ERROR_NONE Successful
2673 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2674 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2675 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2677 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2679 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2681 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2682 "parameter(tethering) is NULL\n");
2683 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2684 "parameter(ssid) is NULL\n");
2687 __tethering_h *th = (__tethering_h *)tethering;
2688 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2690 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2691 if (th->ssid != NULL) {
2692 DBG("Private SSID is set\n");
2693 *ssid = strdup(th->ssid);
2695 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2696 val, sizeof(val)) == false) {
2697 return TETHERING_ERROR_OPERATION_FAILED;
2699 *ssid = strdup(val);
2702 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2703 val, sizeof(val)) == false) {
2704 return TETHERING_ERROR_OPERATION_FAILED;
2706 *ssid = strdup(val);
2709 if (*ssid == NULL) {
2710 ERR("strdup is failed\n");
2711 return TETHERING_ERROR_OUT_OF_MEMORY;
2714 return TETHERING_ERROR_NONE;
2719 * @brief Sets the visibility of SSID(service set identifier).
2721 * @privlevel platform
2722 * @privilege http://tizen.org/privilege/tethering.admin
2723 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2724 * @remarks This change is applied next time Wi-Fi tethering is enabled
2725 * @param[in] tethering The handle of tethering
2726 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2727 * @return 0 on success, otherwise negative error value.
2728 * @retval #TETHERING_ERROR_NONE Successful
2729 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2730 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2731 * @see tethering_wifi_get_ssid_visibility()
2733 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2735 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2737 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2738 "parameter(tethering) is NULL\n");
2740 __tethering_h *th = (__tethering_h *)tethering;
2741 tethering_error_e ret = TETHERING_ERROR_NONE;
2743 ret = __set_visible(visible);
2744 if (ret == TETHERING_ERROR_NONE) {
2746 __send_dbus_signal(th->client_bus,
2747 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2748 visible ? SIGNAL_MSG_SSID_VISIBLE :
2749 SIGNAL_MSG_SSID_HIDE);
2756 * @brief Gets the visibility of SSID(service set identifier).
2758 * @privlevel platform
2759 * @privilege http://tizen.org/privilege/tethering.admin
2760 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2761 * @param[in] tethering The handle of tethering
2762 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2763 * @return 0 on success, otherwise negative error value.
2764 * @retval #TETHERING_ERROR_NONE Successful
2765 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2766 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2767 * @see tethering_wifi_set_ssid_visibility()
2769 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2771 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2773 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2774 "parameter(visible) is NULL\n");
2776 return __get_visible(visible);
2781 * @brief Sets the passphrase.
2783 * @privlevel platform
2784 * @privilege http://tizen.org/privilege/tethering.admin
2785 * @remarks This change is applied next time Wi-Fi tethering is enabled
2786 * @param[in] tethering The handle of tethering
2787 * @param[in] passphrase The passphrase
2788 * @return 0 on success, otherwise negative error value.
2789 * @retval #TETHERING_ERROR_NONE Successful
2790 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2791 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2792 * @see tethering_wifi_get_passphrase()
2794 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2796 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2798 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2799 "parameter(tethering) is NULL\n");
2800 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2801 "parameter(passphrase) is NULL\n");
2803 __tethering_h *th = (__tethering_h *)tethering;
2804 GDBusProxy *proxy = th->client_bus_proxy;
2805 GVariant *parameters;
2806 GError *error = NULL;
2807 int passphrase_len = 0;
2811 passphrase_len = strlen(passphrase);
2812 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
2813 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
2814 ERR("parameter(passphrase) is too short or long\n");
2815 return TETHERING_ERROR_INVALID_PARAMETER;
2818 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
2819 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2823 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2825 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2826 ret = TETHERING_ERROR_PERMISSION_DENIED;
2828 ret = TETHERING_ERROR_OPERATION_FAILED;
2830 g_error_free(error);
2835 g_variant_get(parameters, "(u)", &ret);
2836 g_variant_unref(parameters);
2838 if (ret == TETHERING_ERROR_NONE) {
2839 __send_dbus_signal(th->client_bus,
2840 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
2849 * @brief Gets the passphrase.
2851 * @privlevel platform
2852 * @privilege http://tizen.org/privilege/tethering.admin
2853 * @remarks @a passphrase must be released with free() by you.
2854 * @param[in] tethering The handle of tethering
2855 * @param[out] passphrase The passphrase
2856 * @return 0 on success, otherwise negative error value.
2857 * @retval #TETHERING_ERROR_NONE Successful
2858 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2859 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2860 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2861 * @see tethering_wifi_set_passphrase()
2863 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2865 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2867 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2868 "parameter(tethering) is NULL\n");
2869 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2870 "parameter(passphrase) is NULL\n");
2872 __tethering_h *th = (__tethering_h *)tethering;
2873 GDBusProxy *proxy = th->client_bus_proxy;
2874 GVariant *parameters;
2875 GError *error = NULL;
2876 unsigned int len = 0;
2877 tethering_error_e ret = TETHERING_ERROR_NONE;
2879 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
2880 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2884 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2886 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2887 ret = TETHERING_ERROR_PERMISSION_DENIED;
2889 ret = TETHERING_ERROR_OPERATION_FAILED;
2891 g_error_free(error);
2896 if (parameters != NULL) {
2897 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
2898 g_variant_unref(parameters);
2901 return TETHERING_ERROR_NONE;
2904 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
2906 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2907 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2908 "parameter(tethering) is NULL\n");
2910 __tethering_h *th = (__tethering_h *)tethering;
2911 th->channel = channel;
2913 return TETHERING_ERROR_NONE;
2916 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
2918 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2919 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2920 "parameter(tethering) is NULL\n");
2922 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2923 "parameter(channel) is NULL\n");
2925 __tethering_h *th = (__tethering_h *)tethering;
2926 *channel = th->channel;
2928 return TETHERING_ERROR_NONE;
2931 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
2933 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2934 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2935 "parameter(tethering) is NULL\n");
2937 __tethering_h *th = (__tethering_h *)tethering;
2939 th->mode_type = type;
2941 return TETHERING_ERROR_NONE;
2944 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
2946 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2947 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2948 "parameter(tethering) is NULL\n");
2949 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2950 "parameter(type) is NULL\n");
2952 __tethering_h *th = (__tethering_h *)tethering;
2953 *type = th->mode_type;
2955 return TETHERING_ERROR_NONE;
2961 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
2963 * @privlevel platform
2964 * @privilege http://tizen.org/privilege/tethering.admin
2965 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
2966 * @param[in] tethering The handle of tethering
2967 * @param[in] callback The callback function to invoke
2968 * @param[in] user_data The user data to be passed to the callback function
2969 * @return 0 on success, otherwise negative error value.
2970 * @retval #TETHERING_ERROR_NONE Successful
2971 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2972 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2974 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
2977 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2979 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2980 "parameter(tethering) is NULL\n");
2981 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2982 "parameter(callback) is NULL\n");
2984 __tethering_h *th = (__tethering_h *)tethering;
2985 _softap_settings_t set = {"", "", "", 0, false};
2986 GDBusProxy *proxy = th->client_bus_proxy;
2991 if (th->settings_reloaded_cb) {
2992 ERR("Operation in progress\n");
2993 return TETHERING_ERROR_OPERATION_FAILED;
2996 ret = __prepare_wifi_settings(tethering, &set);
2997 if (ret != TETHERING_ERROR_NONE) {
2998 ERR("softap settings initialization failed\n");
2999 return TETHERING_ERROR_OPERATION_FAILED;
3002 th->settings_reloaded_cb = callback;
3003 th->settings_reloaded_user_data = user_data;
3005 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3006 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
3007 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3008 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3010 return TETHERING_ERROR_NONE;
3013 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3015 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3017 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3018 "parameter(tethering) is NULL\n");
3020 __tethering_h *th = (__tethering_h *)tethering;
3021 th->mac_filter = mac_filter;
3023 return TETHERING_ERROR_NONE;
3026 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3028 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3030 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3031 "parameter(mac_filter) is NULL\n");
3032 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3033 "parameter(mac_filter) is NULL\n");
3035 __tethering_h *th = (__tethering_h *)tethering;
3036 *mac_filter = th->mac_filter;
3038 return TETHERING_ERROR_NONE;
3041 static int __add_mac_to_file(const char *filepath, const char *mac)
3044 char line[MAX_BUF_SIZE] = "\0";
3045 bool mac_exist = false;
3048 p_mac = strdup(mac);
3049 if (p_mac == NULL) {
3050 ERR("strdup failed\n");
3051 return TETHERING_ERROR_OUT_OF_MEMORY;
3054 fp = fopen(filepath, "a+");
3056 ERR("fopen is failed\n");
3057 return TETHERING_ERROR_OPERATION_FAILED;
3060 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3061 if (strncmp(mac, line, 17) == 0) {
3062 DBG("MAC %s already exist in the list\n", mac);
3069 fprintf(fp, "%s\n", mac);
3071 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3072 allowed_list = g_slist_append(allowed_list, p_mac);
3073 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3074 blocked_list = g_slist_append(blocked_list, p_mac);
3079 return TETHERING_ERROR_NONE;
3082 static int __remove_mac_from_file(const char *filepath, const char *mac)
3086 char line[MAX_BUF_SIZE] = "\0";
3088 fp = fopen(filepath, "r");
3090 ERR("fopen is failed\n");
3091 return TETHERING_ERROR_OPERATION_FAILED;
3094 fp1 = fopen(TEMP_LIST, "w+");
3097 ERR("fopen is failed\n");
3098 return TETHERING_ERROR_OPERATION_FAILED;
3101 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3102 if (strncmp(mac, line, 17) == 0) {
3103 DBG("MAC %s found in the list\n", mac);
3105 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3106 GSList *list = NULL;
3107 for (list = allowed_list; list != NULL; list = list->next) {
3108 char *p_mac = (char *)list->data;
3109 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3110 allowed_list = g_slist_remove(allowed_list, p_mac);
3112 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3113 GSList *list = NULL;
3114 for (list = blocked_list; list != NULL; list = list->next) {
3115 char *p_mac = (char *)list->data;
3116 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3117 blocked_list = g_slist_remove(blocked_list, p_mac);
3121 fprintf(fp1, "%s", line);
3128 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3129 rename(TEMP_LIST, ALLOWED_LIST);
3130 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3131 rename(TEMP_LIST, BLOCKED_LIST);
3133 return TETHERING_ERROR_NONE;
3136 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3138 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3140 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3141 "parameter(tethering) is NULL\n");
3142 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3143 "parameter(mac) is NULL\n");
3145 return __add_mac_to_file(ALLOWED_LIST, mac);
3148 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3150 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3151 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3152 "parameter(tethering) is NULL\n");
3153 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3154 "parameter(mac) is NULL\n");
3156 return __remove_mac_from_file(ALLOWED_LIST, mac);
3159 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3161 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3162 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3163 "parameter(tethering) is NULL\n");
3164 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3165 "parameter(allowed_mac_list) is NULL\n");
3167 *allowed_mac_list = g_slist_copy(allowed_list);
3168 return TETHERING_ERROR_NONE;
3171 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3173 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3174 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3175 "parameter(tethering) is NULL\n");
3176 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3177 "parameter(mac) is NULL\n");
3179 return __add_mac_to_file(BLOCKED_LIST, mac);
3182 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3184 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3185 "parameter(tethering) is NULL\n");
3186 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3187 "parameter(mac) is NULL\n");
3189 return __remove_mac_from_file(BLOCKED_LIST, mac);
3192 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3194 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3196 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3197 "parameter(tethering) is NULL\n");
3198 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3199 "parameter(blocked_mac_list) is NULL\n");
3201 *blocked_mac_list = g_slist_copy(blocked_list);
3202 return TETHERING_ERROR_NONE;
3205 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3207 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3209 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3210 "parameter(tethering) is NULL\n");
3212 GVariant *parameters;
3213 GError *error = NULL;
3216 __tethering_h *th = (__tethering_h *)tethering;
3218 GDBusProxy *proxy = th->client_bus_proxy;
3220 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3221 g_variant_new("(b)", enable),
3222 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3225 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3226 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3227 result = TETHERING_ERROR_PERMISSION_DENIED;
3229 result = TETHERING_ERROR_OPERATION_FAILED;
3231 g_error_free(error);
3232 th->dhcp_enabled = false;
3237 g_variant_get(parameters, "(u)", &result);
3238 g_variant_unref(parameters);
3241 th->dhcp_enabled = true;
3243 th->dhcp_enabled = false;
3245 return TETHERING_ERROR_NONE;
3248 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3250 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3252 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3253 "parameter(tethering) is NULL\n");
3254 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3255 "parameter(rangestart) is NULL\n");
3256 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3257 "parameter(rangestop) is NULL\n");
3259 GVariant *parameters;
3260 GError *error = NULL;
3263 __tethering_h *th = (__tethering_h *)tethering;
3265 GDBusProxy *proxy = th->client_bus_proxy;
3267 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3268 g_variant_new("(ss)", rangestart, rangestop),
3269 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3271 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3273 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3274 result = TETHERING_ERROR_PERMISSION_DENIED;
3276 result = TETHERING_ERROR_OPERATION_FAILED;
3278 g_error_free(error);
3279 th->dhcp_enabled = false;
3284 g_variant_get(parameters, "(u)", &result);
3285 g_variant_unref(parameters);
3287 th->dhcp_enabled = true;
3289 return TETHERING_ERROR_NONE;
3292 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3294 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3295 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3296 "parameter(tethering) is NULL\n");
3297 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3298 "parameter(dhcp_enabled) is NULL\n");
3300 __tethering_h *th = (__tethering_h *)tethering;
3301 *dhcp_enabled = th->dhcp_enabled;
3303 return TETHERING_ERROR_NONE;