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 void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
41 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
42 GVariant *parameters, gpointer user_data);
44 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
45 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
46 GVariant *parameters, gpointer user_data);
48 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
49 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
50 GVariant *parameters, gpointer user_data);
52 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
53 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
54 GVariant *parameters, gpointer user_data);
56 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
57 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
58 GVariant *parameters, gpointer user_data);
60 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
61 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
62 GVariant *parameters, gpointer user_data);
64 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
65 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
66 GVariant *parameters, gpointer user_data);
68 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
69 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
70 GVariant *parameters, gpointer user_data);
72 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
73 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
74 GVariant *parameters, gpointer user_data);
76 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
77 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
78 GVariant *parameters, gpointer user_data);
80 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
81 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
82 GVariant *parameters, gpointer user_data);
84 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
85 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
86 GVariant *parameters, gpointer user_data);
88 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
89 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
90 GVariant *parameters, gpointer user_data);
92 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
93 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
94 GVariant *parameters, gpointer user_data);
96 static __tethering_sig_t sigs[] = {
97 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
98 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
99 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
100 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
101 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
102 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
103 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
104 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
105 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
106 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
107 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
108 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
109 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
110 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
113 static int retry = 0;
115 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
117 if (conn == NULL || signal_name == NULL)
118 return; //LCOV_EXCL_LINE
120 GVariant *message = NULL;
121 GError *error = NULL;
124 message = g_variant_new("(s)", arg);
126 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
127 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
129 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
130 g_error_free(error); //LCOV_EXCL_LINE
132 g_variant_unref(message);
135 static bool __any_tethering_is_enabled(tethering_h tethering)
137 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
138 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
139 tethering_is_enabled(tethering, TETHERING_TYPE_BT))
145 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
147 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
148 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
149 ERR("Invalid param\n");
150 return TETHERING_ERROR_INVALID_PARAMETER;
153 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
154 ERR("vconf_set_int is failed\n");
155 return TETHERING_ERROR_OPERATION_FAILED;
158 return TETHERING_ERROR_NONE;
161 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
163 if (security_type == NULL) {
164 ERR("Invalid param\n");
165 return TETHERING_ERROR_INVALID_PARAMETER;
168 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
169 (int *)security_type) < 0) {
170 ERR("vconf_get_int is failed\n");
171 return TETHERING_ERROR_OPERATION_FAILED;
174 return TETHERING_ERROR_NONE;
177 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
179 if (path == NULL || ssid == NULL || size == 0)
183 char *ptr_tmp = NULL;
185 ptr = vconf_get_str(path);
189 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
192 g_strlcpy(ssid, ptr, size);
198 static tethering_error_e __set_visible(const bool visible)
200 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
201 ERR("vconf_set_int is failed\n");
202 return TETHERING_ERROR_OPERATION_FAILED;
205 return TETHERING_ERROR_NONE;
208 static tethering_error_e __get_visible(bool *visible)
210 if (visible == NULL) {
211 ERR("Invalid param\n");
212 return TETHERING_ERROR_INVALID_PARAMETER;
217 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
218 ERR("vconf_get_int is failed\n");
219 return TETHERING_ERROR_OPERATION_FAILED;
226 return TETHERING_ERROR_NONE;
229 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
231 if (passphrase == NULL ||
232 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
235 guint32 rand_int = 0;
238 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
239 rand_int = g_random_int_range('a', 'z');
240 passphrase[index] = rand_int;
242 passphrase[index] = '\0';
247 static tethering_error_e __get_error(int agent_error)
249 tethering_error_e err = TETHERING_ERROR_NONE;
251 switch (agent_error) {
252 case MOBILE_AP_ERROR_NONE:
253 err = TETHERING_ERROR_NONE;
257 case MOBILE_AP_ERROR_RESOURCE:
258 err = TETHERING_ERROR_OUT_OF_MEMORY;
262 case MOBILE_AP_ERROR_INTERNAL:
263 err = TETHERING_ERROR_OPERATION_FAILED;
266 case MOBILE_AP_ERROR_INVALID_PARAM:
267 err = TETHERING_ERROR_INVALID_PARAMETER;
270 case MOBILE_AP_ERROR_ALREADY_ENABLED:
271 err = TETHERING_ERROR_OPERATION_FAILED;
274 case MOBILE_AP_ERROR_NOT_ENABLED:
275 err = TETHERING_ERROR_NOT_ENABLED;
278 case MOBILE_AP_ERROR_NET_OPEN:
279 err = TETHERING_ERROR_OPERATION_FAILED;
282 case MOBILE_AP_ERROR_NET_CLOSE:
283 err = TETHERING_ERROR_OPERATION_FAILED;
286 case MOBILE_AP_ERROR_DHCP:
287 err = TETHERING_ERROR_OPERATION_FAILED;
290 case MOBILE_AP_ERROR_IN_PROGRESS:
291 err = TETHERING_ERROR_OPERATION_FAILED;
295 case MOBILE_AP_ERROR_NOT_PERMITTED:
296 err = TETHERING_ERROR_NOT_PERMITTED;
299 case MOBILE_AP_ERROR_PERMISSION_DENIED:
300 err = TETHERING_ERROR_PERMISSION_DENIED;
304 ERR("Not defined error : %d\n", agent_error);
305 err = TETHERING_ERROR_OPERATION_FAILED;
313 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
314 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
315 GVariant *parameters, gpointer user_data)
319 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
321 __tethering_h *th = (__tethering_h *)user_data;
323 tethering_type_e type = 0;
324 mobile_ap_type_e ap_type = 0;
325 tethering_connection_state_changed_cb ccb = NULL;
326 __tethering_client_h client;
334 memset(&client, 0, sizeof(__tethering_client_h));
335 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
337 if (!g_strcmp0(buf, "DhcpConnected")) {
339 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
342 ERR("Unknown event [%s]\n", buf);
346 if (ap_type == MOBILE_AP_TYPE_USB)
347 type = TETHERING_TYPE_USB;
348 else if (ap_type == MOBILE_AP_TYPE_WIFI)
349 type = TETHERING_TYPE_WIFI;
350 else if (ap_type == MOBILE_AP_TYPE_BT)
351 type = TETHERING_TYPE_BT;
353 ERR("Not supported tethering type [%d]\n", ap_type);
357 ccb = th->changed_cb[type];
360 data = th->changed_user_data[type];
362 client.interface = type;
363 g_strlcpy(client.ip, ip, sizeof(client.ip));
364 g_strlcpy(client.mac, mac, sizeof(client.mac));
366 client.hostname = g_strdup(name);
367 client.tm = (time_t)timestamp;
369 ccb((tethering_client_h)&client, opened, data);
370 g_free(client.hostname);
381 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
382 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
383 GVariant *parameters, gpointer user_data)
387 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
389 __tethering_h *th = (__tethering_h *)user_data;
390 tethering_type_e type = 0;
391 tethering_disabled_cb dcb = NULL;
393 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
395 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
396 dcb = th->disabled_cb[type];
399 data = th->disabled_user_data[type];
401 dcb(TETHERING_ERROR_NONE, type, code, data);
408 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
409 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
410 GVariant *parameters, gpointer user_data)
414 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
416 __tethering_h *th = (__tethering_h *)user_data;
417 tethering_type_e type = TETHERING_TYPE_WIFI;
418 bool is_requested = false;
419 tethering_enabled_cb ecb = NULL;
422 ecb = th->enabled_cb[type];
425 data = th->enabled_user_data[type];
427 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
431 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
432 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
433 GVariant *parameters, gpointer user_data)
437 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
439 __tethering_h *th = (__tethering_h *)user_data;
440 tethering_type_e type = TETHERING_TYPE_WIFI;
441 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
442 tethering_disabled_cb dcb = NULL;
446 dcb = th->disabled_cb[type];
449 data = th->disabled_user_data[type];
450 g_variant_get(parameters, "(s)", &buf);
451 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
452 code = TETHERING_DISABLED_BY_WIFI_ON;
453 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
454 code = TETHERING_DISABLED_BY_TIMEOUT;
457 dcb(TETHERING_ERROR_NONE, type, code, data);
463 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
464 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
465 GVariant *parameters, gpointer user_data)
469 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
471 __tethering_h *th = (__tethering_h *)user_data;
472 tethering_type_e type = TETHERING_TYPE_USB;
473 bool is_requested = false;
474 tethering_enabled_cb ecb = NULL;
477 ecb = th->enabled_cb[type];
480 data = th->enabled_user_data[type];
482 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
486 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
487 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
488 GVariant *parameters, gpointer user_data)
492 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
494 __tethering_h *th = (__tethering_h *)user_data;
495 tethering_type_e type = TETHERING_TYPE_USB;
496 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
497 tethering_disabled_cb dcb = NULL;
501 dcb = th->disabled_cb[type];
504 data = th->disabled_user_data[type];
506 g_variant_get(parameters, "(s)", &buf);
507 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
508 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
510 dcb(TETHERING_ERROR_NONE, type, code, data);
516 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
517 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
518 GVariant *parameters, gpointer user_data)
522 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
524 __tethering_h *th = (__tethering_h *)user_data;
525 tethering_type_e type = TETHERING_TYPE_BT;
526 bool is_requested = false;
527 tethering_enabled_cb ecb = NULL;
530 ecb = th->enabled_cb[type];
533 data = th->enabled_user_data[type];
535 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
539 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
540 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
541 GVariant *parameters, gpointer user_data)
545 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
547 __tethering_h *th = (__tethering_h *)user_data;
548 tethering_type_e type = TETHERING_TYPE_BT;
549 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
550 tethering_disabled_cb dcb = NULL;
554 dcb = th->disabled_cb[type];
557 data = th->disabled_user_data[type];
558 g_variant_get(parameters, "(s)", &buf);
559 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
560 code = TETHERING_DISABLED_BY_BT_OFF;
561 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
562 code = TETHERING_DISABLED_BY_TIMEOUT;
564 dcb(TETHERING_ERROR_NONE, type, code, data);
571 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
572 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
573 GVariant *parameters, gpointer user_data)
577 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
579 __tethering_h *th = (__tethering_h *)user_data;
580 tethering_type_e type = 0;
581 tethering_disabled_cb dcb = NULL;
583 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
585 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
586 dcb = th->disabled_cb[type];
589 data = th->disabled_user_data[type];
591 dcb(TETHERING_ERROR_NONE, type, code, data);
596 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
597 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
598 GVariant *parameters, gpointer user_data)
602 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
604 __tethering_h *th = (__tethering_h *)user_data;
605 tethering_type_e type = 0;
606 tethering_disabled_cb dcb = NULL;
608 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
610 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
611 dcb = th->disabled_cb[type];
614 data = th->disabled_user_data[type];
616 dcb(TETHERING_ERROR_NONE, type, code, data);
621 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
622 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
623 GVariant *parameters, gpointer user_data)
627 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
629 __tethering_h *th = (__tethering_h *)user_data;
630 tethering_type_e type = 0;
631 tethering_disabled_cb dcb = NULL;
633 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
635 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
636 dcb = th->disabled_cb[type];
639 data = th->disabled_user_data[type];
641 dcb(TETHERING_ERROR_NONE, type, code, data);
647 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
648 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
649 GVariant *parameters, gpointer user_data)
654 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
655 __tethering_h *th = (__tethering_h *)user_data;
657 tethering_wifi_security_type_changed_cb scb = NULL;
659 tethering_wifi_security_type_e security_type;
662 scb = th->security_type_changed_cb;
666 g_variant_get(parameters, "(s)", &buf);
667 data = th->security_type_user_data;
668 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
669 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
670 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
671 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
673 SERR("Unknown type : %s\n", buf);
678 scb(security_type, data);
683 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
684 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
685 GVariant *parameters, gpointer user_data)
689 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
690 __tethering_h *th = (__tethering_h *)user_data;
692 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
694 bool visible = false;
697 scb = th->ssid_visibility_changed_cb;
702 g_variant_get(parameters, "(s)", &buf);
703 data = th->ssid_visibility_user_data;
704 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
712 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
713 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
714 GVariant *parameters, gpointer user_data)
718 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
719 __tethering_h *th = (__tethering_h *)user_data;
721 tethering_wifi_passphrase_changed_cb pcb = NULL;
724 pcb = th->passphrase_changed_cb;
728 data = th->passphrase_user_data;
734 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
739 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
740 GError *g_error = NULL;
743 tethering_error_e error;
744 __tethering_h *th = (__tethering_h *)user_data;
745 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
746 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
748 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
751 ERR("DBus error [%s]\n", g_error->message);
752 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
753 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
754 g_error_free(g_error);
755 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
757 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
758 error = TETHERING_ERROR_PERMISSION_DENIED;
760 error = TETHERING_ERROR_OPERATION_FAILED;
761 g_error_free(g_error);
764 g_variant_get(g_var, "(u)", &info);
765 error = __get_error(info);
769 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
770 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
771 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
772 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
778 ecb(error, TETHERING_TYPE_WIFI, true, data);
779 g_variant_unref(g_var);
783 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
787 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
788 GError *g_error = NULL;
791 tethering_error_e error;
793 __tethering_h *th = (__tethering_h *)user_data;
794 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
795 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
797 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
800 ERR("DBus error [%s]\n", g_error->message);
801 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
802 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
803 g_error_free(g_error);
804 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
808 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
809 error = TETHERING_ERROR_PERMISSION_DENIED;
811 error = TETHERING_ERROR_OPERATION_FAILED;
812 g_error_free(g_error);
815 g_variant_get(g_var, "(u)", &info);
816 g_variant_unref(g_var);
817 error = __get_error(info);
821 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
822 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
823 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
824 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
831 ecb(error, TETHERING_TYPE_BT, true, data);
836 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
841 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
842 __tethering_h *th = (__tethering_h *)user_data;
843 GError *g_error = NULL;
846 tethering_error_e error;
847 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
848 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
850 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
852 ERR("DBus error [%s]\n", g_error->message);
853 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
854 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
855 g_error_free(g_error);
856 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
860 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
861 error = TETHERING_ERROR_PERMISSION_DENIED;
863 error = TETHERING_ERROR_OPERATION_FAILED;
864 g_error_free(g_error);
866 g_variant_get(g_var, "(u)", &info);
867 g_variant_unref(g_var);
868 error = __get_error(info);
872 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
873 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
874 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
875 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
882 ecb(error, TETHERING_TYPE_USB, true, data);
887 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
892 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
893 GError *g_error = NULL;
895 guint info, event_type;
896 tethering_error_e error;
897 tethering_type_e type;
898 tethering_h tethering = (tethering_h)user_data;
899 __tethering_h *th = (__tethering_h *)tethering;
900 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
901 tethering_disabled_cb dcb = NULL;
904 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
907 ERR("DBus error [%s]\n", g_error->message);
908 g_error_free(g_error);
912 g_variant_get(g_var, "(uu)", &event_type, &info);
913 DBG("cfm event : %d info : %d\n", event_type, info);
914 g_variant_unref(g_var);
915 error = __get_error(info);
916 DBG("cfm event : %d info : %d\n", event_type, error);
917 switch (event_type) {
918 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
919 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
920 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
921 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
922 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
924 type = TETHERING_TYPE_WIFI;
925 dcb = th->disabled_cb[type];
926 data = th->disabled_user_data[type];
928 dcb(error, type, code, data);
931 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
932 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
933 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
934 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
935 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
937 type = TETHERING_TYPE_BT;
938 dcb = th->disabled_cb[type];
939 data = th->disabled_user_data[type];
941 dcb(error, type, code, data);
945 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
946 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
947 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
948 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
949 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
951 type = TETHERING_TYPE_USB;
952 dcb = th->disabled_cb[type];
953 data = th->disabled_user_data[type];
955 dcb(error, type, code, data);
959 case MOBILE_AP_DISABLE_CFM:
961 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
962 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
963 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
964 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
965 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
966 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
967 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
968 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
969 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
970 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
971 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
972 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
974 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
975 dcb = th->disabled_cb[type];
978 data = th->disabled_user_data[type];
980 dcb(error, type, code, data);
985 ERR("Invalid event\n");
991 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
996 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
998 GError *g_error = NULL;
1001 guint64 tx_bytes, rx_bytes;
1002 __tethering_h *th = (__tethering_h *)user_data;
1003 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1006 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1009 ERR("DBus fail [%s]\n", g_error->message);
1010 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1011 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1013 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1018 if (th->data_usage_cb == NULL) {
1019 ERR("There is no data_usage_cb\n");
1023 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1025 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1026 th->data_usage_cb(TETHERING_ERROR_NONE,
1027 rx_bytes, tx_bytes, th->data_usage_user_data);
1028 g_variant_unref(g_var);
1030 th->data_usage_cb = NULL;
1031 th->data_usage_user_data = NULL;
1036 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1041 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1042 GError *g_error = NULL;
1045 __tethering_h *th = (__tethering_h *)user_data;
1046 tethering_error_e tethering_error;
1048 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1050 ERR("DBus fail [%s]\n", g_error->message);
1051 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1052 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1054 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1055 g_error_free(g_error);
1057 if (th->settings_reloaded_cb == NULL) {
1058 DBG("There is no settings_reloaded_cb\n-\n");
1061 g_variant_get(g_var, "(u)", &info);
1062 tethering_error = __get_error(info);
1063 g_variant_unref(g_var);
1065 th->settings_reloaded_cb(tethering_error,
1066 th->settings_reloaded_user_data);
1068 th->settings_reloaded_cb = NULL;
1069 th->settings_reloaded_user_data = NULL;
1073 static void __connect_signals(tethering_h tethering)
1076 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1078 __tethering_h *th = (__tethering_h *)tethering;
1079 GDBusConnection *connection = th->client_bus;
1082 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1083 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1084 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1085 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1086 sigs[i].cb, tethering, NULL);
1091 static void __disconnect_signals(tethering_h tethering)
1095 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1097 __tethering_h *th = (__tethering_h *)tethering;
1098 GDBusConnection *connection = th->client_bus;
1102 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1103 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1109 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1111 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1115 case TETHERING_TYPE_USB:
1116 g_strlcpy(buf, TETHERING_USB_IF, len);
1119 case TETHERING_TYPE_WIFI:
1120 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1123 case TETHERING_TYPE_BT:
1124 g_strlcpy(buf, TETHERING_BT_IF, len);
1128 ERR("Not supported type : %d\n", type);
1134 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1136 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1139 case TETHERING_TYPE_USB:
1140 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1143 case TETHERING_TYPE_WIFI:
1144 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1147 case TETHERING_TYPE_BT:
1148 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1152 ERR("Not supported type : %d\n", type);
1158 static int __get_common_ssid(char *ssid, unsigned int size)
1161 ERR("ssid is null\n"); //LCOV_EXCL_LINE
1162 return TETHERING_ERROR_INVALID_PARAMETER;
1166 char *ptr_tmp = NULL;
1168 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1170 ERR("vconf_get_str is failed and set default ssid");
1171 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1173 g_strlcpy(ssid, ptr, size);
1177 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1180 return TETHERING_ERROR_NONE;
1183 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1185 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1188 case TETHERING_WIFI_MODE_TYPE_B:
1189 *buf = g_strdup("b");
1191 case TETHERING_WIFI_MODE_TYPE_G:
1192 *buf = g_strdup("g");
1194 case TETHERING_WIFI_MODE_TYPE_A:
1195 *buf = g_strdup("a");
1197 case TETHERING_WIFI_MODE_TYPE_AD:
1198 *buf = g_strdup("ad");
1201 ERR("Not supported type : %d\n", type);
1207 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1211 __tethering_h *th = (__tethering_h *)tethering;
1212 tethering_error_e ret = TETHERING_ERROR_NONE;
1215 if (th == NULL || set == NULL) {
1216 ERR("null parameter\n-\n");
1217 return TETHERING_ERROR_INVALID_PARAMETER;
1220 if (th->ssid == NULL)
1221 __get_common_ssid(set->ssid, sizeof(set->ssid));
1223 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1225 ret = __get_security_type(&set->sec_type);
1226 if (ret != TETHERING_ERROR_NONE)
1227 set->sec_type = th->sec_type;
1229 ret = __get_visible(&set->visibility);
1230 if (ret != TETHERING_ERROR_NONE)
1231 set->visibility = th->visibility;
1233 set->mac_filter = th->mac_filter;
1234 set->channel = th->channel;
1236 __get_wifi_mode_type(th->mode_type, &ptr);
1238 g_strlcpy(set->mode, "", sizeof(set->mode));
1240 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1244 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1245 g_strlcpy(set->key, "", sizeof(set->key));
1247 GDBusProxy *proxy = th->client_bus_proxy;
1248 GVariant *parameters;
1249 GError *error = NULL;
1250 char *passphrase = NULL;
1251 unsigned int len = 0;
1253 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1254 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1258 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1260 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1261 ret = TETHERING_ERROR_PERMISSION_DENIED;
1263 ret = TETHERING_ERROR_OPERATION_FAILED;
1265 g_error_free(error);
1270 if (parameters != NULL) {
1271 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1272 g_variant_unref(parameters);
1275 g_strlcpy(set->key, passphrase, sizeof(set->key));
1278 return TETHERING_ERROR_NONE;
1281 static bool __check_precondition(tethering_type_e type)
1284 int cellular_state = 0;
1287 /* data network through cellular */
1288 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1289 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1290 ERR("Data Network can be connected later");
1294 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1295 if (dnet_state > VCONFKEY_DNET_OFF) {
1296 ERR("Data Network is connected");
1300 /* data network through wifi */
1301 if (type != TETHERING_TYPE_WIFI) {
1302 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1303 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1304 ERR("Wi-Fi is connected!");
1309 ERR("Network is not available!");
1315 * @brief Creates the handle of tethering.
1317 * @privlevel platform
1318 * @privilege http://tizen.org/privilege/tethering.admin
1319 * @remarks The @a tethering must be released tethering_destroy() by you.
1320 * @param[out] tethering A handle of a new mobile ap handle on success
1321 * @return 0 on success, otherwise a negative error value.
1322 * @retval #TETHERING_ERROR_NONE Successful
1323 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1324 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1325 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1326 * @see tethering_destroy()
1328 API int tethering_create(tethering_h *tethering)
1330 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1331 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1332 "parameter(tethering) is NULL\n");
1335 __tethering_h *th = NULL;
1336 GError *error = NULL;
1337 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1339 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1341 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1342 "malloc is failed\n");
1343 memset(th, 0x00, sizeof(__tethering_h));
1344 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1345 th->visibility = true;
1346 th->mac_filter = false;
1348 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1350 if (__generate_initial_passphrase(th->passphrase,
1351 sizeof(th->passphrase)) == 0) {
1352 ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
1354 return TETHERING_ERROR_OPERATION_FAILED;
1357 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1358 ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
1360 return TETHERING_ERROR_OPERATION_FAILED;
1363 #if !GLIB_CHECK_VERSION(2, 36, 0)
1366 GCancellable *cancellable = g_cancellable_new();
1367 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1370 ERR("Couldn't connect to the System bus[%s]", error->message);
1371 g_error_free(error);
1372 g_cancellable_cancel(cancellable);
1373 g_object_unref(cancellable);
1375 return TETHERING_ERROR_OPERATION_FAILED;
1378 th->cancellable = cancellable;
1380 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1381 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1382 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1383 if (!th->client_bus_proxy) {
1386 ERR("Couldn't create the proxy object because of %s\n", error->message);
1387 g_cancellable_cancel(th->cancellable);
1388 g_object_unref(th->cancellable);
1389 g_object_unref(th->client_bus);
1391 return TETHERING_ERROR_OPERATION_FAILED;
1395 __connect_signals((tethering_h)th);
1397 *tethering = (tethering_h)th;
1398 DBG("Tethering Handle : 0x%X\n", th);
1400 return TETHERING_ERROR_NONE;
1405 * @brief Destroys the handle of tethering.
1407 * @privlevel platform
1408 * @privilege http://tizen.org/privilege/tethering.admin
1409 * @param[in] tethering The handle of tethering
1410 * @return 0 on success, otherwise a negative error value.
1411 * @retval #TETHERING_ERROR_NONE Successful
1412 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1413 * @see tethering_create()
1415 API int tethering_destroy(tethering_h tethering)
1418 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1419 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1420 "parameter(tethering) is NULL\n");
1422 __tethering_h *th = (__tethering_h *)tethering;
1424 DBG("Tethering Handle : 0x%X\n", th);
1425 __disconnect_signals(tethering);
1430 g_object_unref(th->cancellable);
1431 g_object_unref(th->client_bus_proxy);
1432 g_object_unref(th->client_bus);
1433 memset(th, 0x00, sizeof(__tethering_h));
1437 return TETHERING_ERROR_NONE;
1442 * @brief Enables the tethering, asynchronously.
1444 * @privlevel platform
1445 * @privilege http://tizen.org/privilege/tethering.admin
1446 * @param[in] tethering The handle of tethering
1447 * @param[in] type The type of tethering
1448 * @return 0 on success, otherwise negative error value.
1449 * @retval #TETHERING_ERROR_NONE Successful
1450 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1451 * @post tethering_enabled_cb() will be invoked.
1452 * @see tethering_is_enabled()
1453 * @see tethering_disable()
1455 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1457 DBG("+ type : %d\n", type);
1458 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1459 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1460 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1461 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1463 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1464 "parameter(tethering) is NULL\n");
1466 tethering_error_e ret = TETHERING_ERROR_NONE;
1467 __tethering_h *th = (__tethering_h *)tethering;
1468 GDBusProxy *proxy = th->client_bus_proxy;
1469 GDBusConnection *connection = th->client_bus;
1471 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1473 if (__check_precondition(type) == FALSE) {
1476 return TETHERING_ERROR_OPERATION_FAILED;
1482 case TETHERING_TYPE_USB:
1483 g_dbus_connection_signal_unsubscribe(connection,
1484 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1486 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1487 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1488 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1492 case TETHERING_TYPE_WIFI: {
1493 _softap_settings_t set = {"", "", "", 0, false};
1495 ret = __prepare_wifi_settings(tethering, &set);
1496 if (ret != TETHERING_ERROR_NONE) {
1497 ERR("softap settings initialization failed\n");
1499 return TETHERING_ERROR_OPERATION_FAILED;
1501 g_dbus_connection_signal_unsubscribe(connection,
1502 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1504 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1505 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
1506 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1507 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1511 case TETHERING_TYPE_BT:
1512 g_dbus_connection_signal_unsubscribe(connection,
1513 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1515 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1516 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1517 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1522 case TETHERING_TYPE_ALL: {
1523 _softap_settings_t set = {"", "", "", 0, false};
1525 ret = __prepare_wifi_settings(tethering, &set);
1526 if (ret != TETHERING_ERROR_NONE) {
1527 ERR("softap settings initialization failed\n");
1528 return TETHERING_ERROR_OPERATION_FAILED;
1531 /* TETHERING_TYPE_USB */
1532 g_dbus_connection_signal_unsubscribe(connection,
1533 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1535 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1536 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1537 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1539 /* TETHERING_TYPE_WIFI */
1540 g_dbus_connection_signal_unsubscribe(connection,
1541 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1543 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1544 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1545 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1546 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1548 /* TETHERING_TYPE_BT */
1549 g_dbus_connection_signal_unsubscribe(connection,
1550 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1552 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1553 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1554 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1559 ERR("Unknown type : %d\n", type);
1561 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1564 return TETHERING_ERROR_INVALID_PARAMETER;
1567 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1569 return TETHERING_ERROR_NONE;
1574 * @brief Disables the tethering, asynchronously.
1576 * @privlevel platform
1577 * @privilege http://tizen.org/privilege/tethering.admin
1578 * @param[in] tethering The handle of tethering
1579 * @param[in] type The type of tethering
1580 * @return 0 on success, otherwise negative error value.
1581 * @retval #TETHERING_ERROR_NONE Successful
1582 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1583 * @post tethering_disabled_cb() will be invoked.
1584 * @see tethering_is_enabled()
1585 * @see tethering_enable()
1587 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1589 DBG("+ type : %d\n", type);
1590 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1591 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1592 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1594 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1595 "parameter(tethering) is NULL\n");
1597 __tethering_h *th = (__tethering_h *)tethering;
1598 GDBusProxy *proxy = th->client_bus_proxy;
1599 GDBusConnection *connection = th->client_bus;
1602 case TETHERING_TYPE_USB:
1603 g_dbus_connection_signal_unsubscribe(connection,
1604 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1606 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1607 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1608 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1612 case TETHERING_TYPE_WIFI:
1614 g_dbus_connection_signal_unsubscribe(connection,
1615 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1617 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1618 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1619 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1622 case TETHERING_TYPE_BT:
1624 g_dbus_connection_signal_unsubscribe(connection,
1625 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1627 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1628 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1629 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1632 case TETHERING_TYPE_ALL:
1633 g_dbus_connection_signal_unsubscribe(connection,
1634 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1636 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1637 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1638 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1640 g_dbus_connection_signal_unsubscribe(connection,
1641 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1643 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1644 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1645 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1647 g_dbus_connection_signal_unsubscribe(connection,
1648 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1650 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1651 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1652 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1656 ERR("Not supported tethering type [%d]\n", type);
1658 return TETHERING_ERROR_INVALID_PARAMETER;
1661 return TETHERING_ERROR_NONE;
1666 * @brief Checks whetehr the tethering is enabled or not.
1668 * @privlevel platform
1669 * @privilege http://tizen.org/privilege/tethering.admin
1670 * @param[in] tethering The handle of tethering
1671 * @param[in] type The type of tethering
1672 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1674 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1677 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1679 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1681 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1685 case TETHERING_TYPE_USB:
1686 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1689 case TETHERING_TYPE_WIFI:
1690 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1693 case TETHERING_TYPE_BT:
1694 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1698 ERR("Not supported type : %d\n", type);
1701 return is_on & vconf_type ? true : false;
1706 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1708 * @privlevel platform
1709 * @privilege http://tizen.org/privilege/tethering.admin
1710 * @remarks @a mac_address must be released with free() by you.
1711 * @param[in] tethering The handle of tethering
1712 * @param[in] type The type of tethering
1713 * @param[out] mac_address The MAC address
1714 * @return 0 on success, otherwise a negative error value.
1715 * @retval #TETHERING_ERROR_NONE Successful
1716 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1717 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1718 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1719 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1720 * @pre tethering must be enabled.
1721 * @see tethering_is_enabled()
1722 * @see tethering_enable()
1724 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1726 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1727 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1728 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1730 _retvm_if(tethering_is_enabled(tethering, type) == false,
1731 TETHERING_ERROR_NOT_ENABLED,
1732 "tethering type[%d] is not enabled\n", type);
1733 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1734 "parameter(tethering) is NULL\n");
1735 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1736 "parameter(mac_address) is NULL\n");
1740 char *macbuf = NULL;
1742 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1743 TETHERING_ERROR_OPERATION_FAILED,
1744 "getting interface name is failed\n");
1746 s = socket(AF_INET, SOCK_DGRAM, 0);
1747 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1748 "getting socket is failed\n");
1749 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1750 ERR("getting mac is failed\n");
1752 return TETHERING_ERROR_OPERATION_FAILED;
1756 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1757 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1758 "Not enough memory\n");
1759 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1760 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1761 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1762 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1763 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1764 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1765 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1767 *mac_address = macbuf;
1769 return TETHERING_ERROR_NONE;
1774 * @brief Gets the name of network interface. For example, usb0.
1776 * @privlevel platform
1777 * @privilege http://tizen.org/privilege/tethering.admin
1778 * @remarks @a interface_name must be released with free() by you.
1779 * @param[in] tethering The handle of tethering
1780 * @param[in] type The type of tethering
1781 * @param[out] interface_name The name of network interface
1782 * @return 0 on success, otherwise negative error value.
1783 * @retval #TETHERING_ERROR_NONE Successful
1784 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1785 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1786 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1787 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1788 * @pre tethering must be enabled.
1789 * @see tethering_is_enabled()
1790 * @see tethering_enable()
1792 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1794 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1795 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1796 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1798 _retvm_if(tethering_is_enabled(tethering, type) == false,
1799 TETHERING_ERROR_NOT_ENABLED,
1800 "tethering type[%d] is not enabled\n", type);
1801 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1802 "parameter(tethering) is NULL\n");
1803 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1804 "parameter(interface_name) is NULL\n");
1806 char intf[TETHERING_STR_INFO_LEN] = {0, };
1808 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1809 TETHERING_ERROR_OPERATION_FAILED,
1810 "getting interface name is failed\n");
1811 *interface_name = strdup(intf);
1812 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1813 "Not enough memory\n");
1815 return TETHERING_ERROR_NONE;
1820 * @brief Gets the local IP address.
1822 * @privlevel platform
1823 * @privilege http://tizen.org/privilege/tethering.admin
1824 * @remarks @a ip_address must be released with free() by you.
1825 * @param[in] tethering The handle of tethering
1826 * @param[in] type The type of tethering
1827 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1828 * @param[out] ip_address The local IP address
1829 * @return 0 on success, otherwise negative error value.
1830 * @retval #TETHERING_ERROR_NONE Successful
1831 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1832 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1833 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1834 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1835 * @pre tethering must be enabled.
1836 * @see tethering_is_enabled()
1837 * @see tethering_enable()
1839 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1842 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1843 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1844 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1846 _retvm_if(tethering_is_enabled(tethering, type) == false,
1847 TETHERING_ERROR_NOT_ENABLED,
1848 "tethering type[%d] is not enabled\n", type);
1849 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1850 "parameter(tethering) is NULL\n");
1851 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1852 "parameter(ip_address) is NULL\n");
1858 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1859 TETHERING_ERROR_OPERATION_FAILED,
1860 "getting interface name is failed\n");
1862 s = socket(AF_INET, SOCK_DGRAM, 0);
1863 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1864 "getting socket is failed\n");
1865 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1866 ERR("ioctl is failed\n");
1868 return TETHERING_ERROR_OPERATION_FAILED;
1872 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1873 *ip_address = strdup(ipbuf);
1874 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1875 "Not enough memory\n");
1877 return TETHERING_ERROR_NONE;
1882 * @brief Gets the Gateway address.
1884 * @privlevel platform
1885 * @privilege http://tizen.org/privilege/tethering.admin
1886 * @remarks @a gateway_address must be released with free() by you.
1887 * @param[in] tethering The handle of tethering
1888 * @param[in] type The type of tethering
1889 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1890 * @param[out] gateway_address The local IP address
1891 * @return 0 on success, otherwise negative error value.
1892 * @retval #TETHERING_ERROR_NONE Successful
1893 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1894 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1895 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1896 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1897 * @pre tethering must be enabled.
1898 * @see tethering_is_enabled()
1899 * @see tethering_enable()
1901 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1904 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1905 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1906 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1908 _retvm_if(tethering_is_enabled(tethering, type) == false,
1909 TETHERING_ERROR_NOT_ENABLED,
1910 "tethering type[%d] is not enabled\n", type);
1911 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1912 "parameter(tethering) is NULL\n");
1913 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1914 "parameter(gateway_address) is NULL\n");
1916 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1918 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1919 TETHERING_ERROR_OPERATION_FAILED,
1920 "getting gateway address is failed\n");
1922 *gateway_address = strdup(gateway_buf);
1924 return TETHERING_ERROR_NONE;
1929 * @brief Gets the Subnet Mask.
1931 * @privlevel platform
1932 * @privilege http://tizen.org/privilege/tethering.admin
1933 * @remarks @a subnet_mask must be released with free() by you.
1934 * @param[in] tethering The handle of tethering
1935 * @param[in] type The type of tethering
1936 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1937 * @param[out] subnet_mask The local IP address
1938 * @return 0 on success, otherwise negative error value.
1939 * @retval #TETHERING_ERROR_NONE Successful
1940 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1941 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1942 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1943 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1944 * @pre tethering must be enabled.
1945 * @see tethering_is_enabled()
1946 * @see tethering_enable()
1948 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1950 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1951 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1952 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1954 _retvm_if(tethering_is_enabled(tethering, type) == false,
1955 TETHERING_ERROR_NOT_ENABLED,
1956 "tethering is not enabled\n");
1957 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1958 "parameter(tethering) is NULL\n");
1959 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1960 "parameter(subnet_mask) is NULL\n");
1962 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
1963 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1964 "Not enough memory\n");
1966 return TETHERING_ERROR_NONE;
1971 * @brief Gets the data usage.
1973 * @privlevel platform
1974 * @privilege http://tizen.org/privilege/tethering.admin
1975 * @param[in] tethering The handle of tethering
1976 * @param[out] usage The data usage
1977 * @return 0 on success, otherwise negative error value.
1978 * @retval #TETHERING_ERROR_NONE Successful
1979 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1980 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1981 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1982 * @pre tethering must be enabled.
1983 * @see tethering_is_enabled()
1984 * @see tethering_enable()
1986 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
1988 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1990 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1991 "parameter(tethering) is NULL\n");
1992 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1993 "parameter(callback) is NULL\n");
1994 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1995 TETHERING_ERROR_NOT_ENABLED,
1996 "tethering is not enabled\n");
1998 __tethering_h *th = (__tethering_h *)tethering;
1999 GDBusProxy *proxy = th->client_bus_proxy;
2001 th->data_usage_cb = callback;
2002 th->data_usage_user_data = user_data;
2004 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2005 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2006 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2008 return TETHERING_ERROR_NONE;
2013 * @brief Gets the client which is connected by tethering "type".
2015 * @privlevel platform
2016 * @privilege http://tizen.org/privilege/tethering.admin
2017 * @param[in] tethering The handle of tethering
2018 * @param[in] type The type of tethering
2019 * @param[in] callback The callback function to invoke
2020 * @param[in] user_data The user data to be passed to the callback function
2021 * @retval #TETHERING_ERROR_NONE Successful
2022 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2023 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2024 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2025 * @pre tethering must be enabled.
2026 * @see tethering_is_enabled()
2027 * @see tethering_enable()
2029 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2032 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2033 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2034 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2036 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2037 "parameter(tethering) is NULL\n");
2038 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2039 "parameter(callback) is NULL\n");
2040 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2041 TETHERING_ERROR_NOT_ENABLED,
2042 "tethering is not enabled\n");
2044 mobile_ap_type_e interface;
2045 __tethering_h *th = (__tethering_h *)tethering;
2046 __tethering_client_h client = {0, };
2049 gchar *hostname = NULL;
2050 guint timestamp = 0;
2051 GError *error = NULL;
2052 GVariant *result = NULL;
2053 GVariantIter *outer_iter = NULL;
2054 GVariantIter *inner_iter = NULL;
2055 GVariant *station = NULL;
2056 GVariant *value = NULL;
2059 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2060 NULL, G_DBUS_CALL_FLAGS_NONE,
2061 -1, th->cancellable, &error);
2063 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2064 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2065 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2066 g_variant_get(station, "a{sv}", &inner_iter);
2067 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2068 if (g_strcmp0(key, "Type") == 0) {
2069 interface = g_variant_get_int32(value);
2070 if (interface == MOBILE_AP_TYPE_USB)
2071 client.interface = TETHERING_TYPE_USB;
2072 else if (interface == MOBILE_AP_TYPE_WIFI)
2073 client.interface = TETHERING_TYPE_WIFI;
2074 else if (interface == MOBILE_AP_TYPE_BT)
2075 client.interface = TETHERING_TYPE_BT;
2077 ERR("Invalid interface\n");
2079 g_variant_unref(value);
2082 DBG("interface is %d\n", client.interface);
2083 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2085 g_variant_unref(value);
2088 } else if (g_strcmp0(key, "IP") == 0) {
2089 g_variant_get(value, "s", &ip);
2090 SDBG("ip is %s\n", ip);
2091 g_strlcpy(client.ip, ip, sizeof(client.ip));
2092 } else if (g_strcmp0(key, "MAC") == 0) {
2093 g_variant_get(value, "s", &mac);
2094 SDBG("mac is %s\n", mac);
2095 g_strlcpy(client.mac, mac, sizeof(client.mac));
2096 } else if (g_strcmp0(key, "Name") == 0) {
2097 g_variant_get(value, "s", &hostname);
2098 SDBG("hsotname is %s\n", hostname);
2100 client.hostname = g_strdup(hostname);
2101 } else if (g_strcmp0(key, "Time") == 0) {
2102 timestamp = g_variant_get_int32(value);
2103 DBG("timestamp is %d\n", timestamp);
2104 client.tm = (time_t)timestamp;
2106 ERR("Key %s not required\n", key);
2112 g_variant_iter_free(inner_iter);
2113 if (callback((tethering_client_h)&client, user_data) == false) {
2114 DBG("iteration is stopped\n");
2115 g_free(client.hostname);
2116 g_variant_iter_free(outer_iter);
2117 g_variant_unref(station);
2118 g_variant_unref(result);
2120 return TETHERING_ERROR_OPERATION_FAILED;
2122 g_free(client.hostname);
2124 g_variant_iter_free(outer_iter);
2125 g_variant_unref(station);
2126 g_variant_unref(result);
2128 return TETHERING_ERROR_NONE;
2133 * @brief Registers the callback function called when tethering is enabled.
2135 * @privlevel platform
2136 * @privilege http://tizen.org/privilege/tethering.admin
2137 * @param[in] tethering The handle of tethering
2138 * @param[in] type The type of tethering
2139 * @param[in] callback The callback function to invoke
2140 * @param[in] user_data The user data to be passed to the callback function
2141 * @retval #TETHERING_ERROR_NONE Successful
2142 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2143 * @see tethering_unset_enabled_cb()
2145 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2147 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2148 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2149 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2151 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2152 "parameter(tethering) is NULL\n");
2153 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2154 "parameter(callback) is NULL\n");
2156 __tethering_h *th = (__tethering_h *)tethering;
2157 tethering_type_e ti;
2159 if (type != TETHERING_TYPE_ALL) {
2160 th->enabled_cb[type] = callback;
2161 th->enabled_user_data[type] = user_data;
2163 return TETHERING_ERROR_NONE;
2166 /* TETHERING_TYPE_ALL */
2167 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2168 th->enabled_cb[ti] = callback;
2169 th->enabled_user_data[ti] = user_data;
2172 return TETHERING_ERROR_NONE;
2177 * @brief Unregisters the callback function called when tethering is disabled.
2179 * @privlevel platform
2180 * @privilege http://tizen.org/privilege/tethering.admin
2181 * @param[in] tethering The handle of tethering
2182 * @param[in] type The type of tethering
2183 * @retval #TETHERING_ERROR_NONE Successful
2184 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2185 * @see tethering_set_enabled_cb()
2187 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2189 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2190 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2191 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2193 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2194 "parameter(tethering) is NULL\n");
2196 __tethering_h *th = (__tethering_h *)tethering;
2197 tethering_type_e ti;
2199 if (type != TETHERING_TYPE_ALL) {
2200 th->enabled_cb[type] = NULL;
2201 th->enabled_user_data[type] = NULL;
2203 return TETHERING_ERROR_NONE;
2206 /* TETHERING_TYPE_ALL */
2207 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2208 th->enabled_cb[ti] = NULL;
2209 th->enabled_user_data[ti] = NULL;
2212 return TETHERING_ERROR_NONE;
2217 * @brief Registers the callback function called when tethering is disabled.
2219 * @privlevel platform
2220 * @privilege http://tizen.org/privilege/tethering.admin
2221 * @param[in] tethering The handle of tethering
2222 * @param[in] type The type of tethering
2223 * @param[in] callback The callback function to invoke
2224 * @param[in] user_data The user data to be passed to the callback function
2225 * @retval #TETHERING_ERROR_NONE Successful
2226 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2227 * @see tethering_unset_disabled_cb()
2229 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2231 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2232 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2233 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2235 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2236 "parameter(tethering) is NULL\n");
2237 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2238 "parameter(callback) is NULL\n");
2240 __tethering_h *th = (__tethering_h *)tethering;
2241 tethering_type_e ti;
2243 if (type != TETHERING_TYPE_ALL) {
2244 th->disabled_cb[type] = callback;
2245 th->disabled_user_data[type] = user_data;
2247 return TETHERING_ERROR_NONE;
2250 /* TETHERING_TYPE_ALL */
2251 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2252 th->disabled_cb[ti] = callback;
2253 th->disabled_user_data[ti] = user_data;
2256 return TETHERING_ERROR_NONE;
2261 * @brief Unregisters the callback function called when tethering is disabled.
2263 * @privlevel platform
2264 * @privilege http://tizen.org/privilege/tethering.admin
2265 * @param[in] tethering The handle of tethering
2266 * @param[in] type The type of tethering
2267 * @retval #TETHERING_ERROR_NONE Successful
2268 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2269 * @see tethering_set_disabled_cb()
2271 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2273 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2274 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2275 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2277 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2278 "parameter(tethering) is NULL\n");
2280 __tethering_h *th = (__tethering_h *)tethering;
2281 tethering_type_e ti;
2283 if (type != TETHERING_TYPE_ALL) {
2284 th->disabled_cb[type] = NULL;
2285 th->disabled_user_data[type] = NULL;
2287 return TETHERING_ERROR_NONE;
2290 /* TETHERING_TYPE_ALL */
2291 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2292 th->disabled_cb[ti] = NULL;
2293 th->disabled_user_data[ti] = NULL;
2296 return TETHERING_ERROR_NONE;
2301 * @brief Registers the callback function called when the state of connection is changed.
2303 * @privlevel platform
2304 * @privilege http://tizen.org/privilege/tethering.admin
2305 * @param[in] tethering The handle of tethering
2306 * @param[in] type The type of tethering
2307 * @param[in] callback The callback function to invoke
2308 * @param[in] user_data The user data to be passed to the callback function
2309 * @retval #TETHERING_ERROR_NONE Successful
2310 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2311 * @see tethering_unset_connection_state_changed_cb_cb()
2313 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2315 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2316 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2317 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2319 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2320 "parameter(tethering) is NULL\n");
2321 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2322 "parameter(callback) is NULL\n");
2324 __tethering_h *th = (__tethering_h *)tethering;
2325 tethering_type_e ti;
2327 if (type != TETHERING_TYPE_ALL) {
2328 th->changed_cb[type] = callback;
2329 th->changed_user_data[type] = user_data;
2331 return TETHERING_ERROR_NONE;
2334 /* TETHERING_TYPE_ALL */
2335 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2336 th->changed_cb[ti] = callback;
2337 th->changed_user_data[ti] = user_data;
2340 return TETHERING_ERROR_NONE;
2345 * @brief Unregisters the callback function called when the state of connection is changed.
2347 * @privlevel platform
2348 * @privilege http://tizen.org/privilege/tethering.admin
2349 * @param[in] tethering The handle of tethering
2350 * @param[in] type The type of tethering
2351 * @retval #TETHERING_ERROR_NONE Successful
2352 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2353 * @see tethering_set_connection_state_changed_cb()
2355 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2357 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2358 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2359 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2361 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2362 "parameter(tethering) is NULL\n");
2364 __tethering_h *th = (__tethering_h *)tethering;
2365 tethering_type_e ti;
2367 if (type != TETHERING_TYPE_ALL) {
2368 th->changed_cb[type] = NULL;
2369 th->changed_user_data[type] = NULL;
2371 return TETHERING_ERROR_NONE;
2374 /* TETHERING_TYPE_ALL */
2375 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2376 th->changed_cb[ti] = NULL;
2377 th->changed_user_data[ti] = NULL;
2380 return TETHERING_ERROR_NONE;
2385 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2387 * @privlevel platform
2388 * @privilege http://tizen.org/privilege/tethering.admin
2389 * @param[in] tethering The handle of tethering
2390 * @param[in] callback The callback function to invoke
2391 * @param[in] user_data The user data to be passed to the callback function
2392 * @retval #TETHERING_ERROR_NONE Successful
2393 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2394 * @see tethering_wifi_unset_security_type_changed_cb()
2396 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2398 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2400 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2401 "parameter(tethering) is NULL\n");
2402 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2403 "parameter(callback) is NULL\n");
2405 __tethering_h *th = (__tethering_h *)tethering;
2407 th->security_type_changed_cb = callback;
2408 th->security_type_user_data = user_data;
2410 return TETHERING_ERROR_NONE;
2416 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2418 * @privlevel platform
2419 * @privilege http://tizen.org/privilege/tethering.admin
2420 * @param[in] tethering The handle of tethering
2421 * @param[in] type The type of tethering
2422 * @retval #TETHERING_ERROR_NONE Successful
2423 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2424 * @see tethering_wifi_set_security_type_changed_cb()
2426 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2428 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2430 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2431 "parameter(tethering) is NULL\n");
2433 __tethering_h *th = (__tethering_h *)tethering;
2435 th->security_type_changed_cb = NULL;
2436 th->security_type_user_data = NULL;
2438 return TETHERING_ERROR_NONE;
2443 * @brief Registers the callback function called when the visibility of SSID is changed.
2445 * @privlevel platform
2446 * @privilege http://tizen.org/privilege/tethering.admin
2447 * @param[in] tethering The handle of tethering
2448 * @param[in] callback The callback function to invoke
2449 * @param[in] user_data The user data to be passed to the callback function
2450 * @retval #TETHERING_ERROR_NONE Successful
2451 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2452 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2454 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2456 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2458 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2459 "parameter(tethering) is NULL\n");
2460 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2461 "parameter(callback) is NULL\n");
2463 __tethering_h *th = (__tethering_h *)tethering;
2465 th->ssid_visibility_changed_cb = callback;
2466 th->ssid_visibility_user_data = user_data;
2468 return TETHERING_ERROR_NONE;
2473 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2475 * @privlevel platform
2476 * @privilege http://tizen.org/privilege/tethering.admin
2477 * @param[in] tethering The handle of tethering
2478 * @retval #TETHERING_ERROR_NONE Successful
2479 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2480 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2482 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2484 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2486 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2487 "parameter(tethering) is NULL\n");
2489 __tethering_h *th = (__tethering_h *)tethering;
2491 th->ssid_visibility_changed_cb = NULL;
2492 th->ssid_visibility_user_data = NULL;
2494 return TETHERING_ERROR_NONE;
2499 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2501 * @privlevel platform
2502 * @privilege http://tizen.org/privilege/tethering.admin
2503 * @param[in] tethering The handle of tethering
2504 * @param[in] callback The callback function to invoke
2505 * @param[in] user_data The user data to be passed to the callback function
2506 * @retval #TETHERING_ERROR_NONE Successful
2507 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2508 * @see tethering_wifi_unset_passphrase_changed_cb()
2510 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2512 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2514 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2515 "parameter(tethering) is NULL\n");
2516 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2517 "parameter(callback) is NULL\n");
2519 __tethering_h *th = (__tethering_h *)tethering;
2521 th->passphrase_changed_cb = callback;
2522 th->passphrase_user_data = user_data;
2524 return TETHERING_ERROR_NONE;
2529 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2531 * @privlevel platform
2532 * @privilege http://tizen.org/privilege/tethering.admin
2533 * @param[in] tethering The handle of tethering
2534 * @retval #TETHERING_ERROR_NONE Successful
2535 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2536 * @see tethering_wifi_set_passphrase_changed_cb()
2538 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2540 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2542 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2543 "parameter(tethering) is NULL\n");
2545 __tethering_h *th = (__tethering_h *)tethering;
2547 th->passphrase_changed_cb = NULL;
2548 th->passphrase_user_data = NULL;
2550 return TETHERING_ERROR_NONE;
2555 * @brief Sets the security type of Wi-Fi tethering.
2557 * @privlevel platform
2558 * @privilege http://tizen.org/privilege/tethering.admin
2559 * @remarks This change is applied next time Wi-Fi tethering is enabled
2560 * @param[in] tethering The handle of tethering
2561 * @param[in] type The security type
2562 * @return 0 on success, otherwise negative error value.
2563 * @retval #TETHERING_ERROR_NONE Successful
2564 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2565 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2566 * @see tethering_wifi_get_security_type()
2568 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2570 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2572 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2573 "parameter(tethering) is NULL\n");
2575 __tethering_h *th = (__tethering_h *)tethering;
2576 tethering_error_e ret = TETHERING_ERROR_NONE;
2578 ret = __set_security_type(type);
2579 if (ret == TETHERING_ERROR_NONE) {
2581 __send_dbus_signal(th->client_bus,
2582 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2583 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2584 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2585 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2592 * @brief Gets the security type of Wi-Fi tethering.
2594 * @privlevel platform
2595 * @privilege http://tizen.org/privilege/tethering.admin
2596 * @param[in] tethering The handle of tethering
2597 * @param[out] type The security type
2598 * @return 0 on success, otherwise negative error value.
2599 * @retval #TETHERING_ERROR_NONE Successful
2600 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2601 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2602 * @see tethering_wifi_set_security_type()
2604 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2606 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2608 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2609 "parameter(type) is NULL\n");
2611 return __get_security_type(type);
2616 * @brief Sets the SSID (service set identifier).
2618 * @privlevel platform
2619 * @privilege http://tizen.org/privilege/tethering.admin
2620 * @details If SSID is not set, Device name is used as SSID
2621 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2622 * @param[in] tethering The handle of tethering
2623 * @param[out] ssid The SSID
2624 * @return 0 on success, otherwise negative error value.
2625 * @retval #TETHERING_ERROR_NONE Successful
2626 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2627 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2629 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2631 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2633 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2634 "parameter(tethering) is NULL\n");
2635 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2636 "parameter(ssid) is NULL\n");
2638 __tethering_h *th = (__tethering_h *)tethering;
2639 char *p_ssid = NULL;
2642 ssid_len = strlen(ssid);
2643 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2644 ERR("parameter(ssid) is too long");
2645 return TETHERING_ERROR_INVALID_PARAMETER;
2648 p_ssid = strdup(ssid);
2649 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2650 "strdup is failed\n");
2656 return TETHERING_ERROR_NONE;
2661 * @brief Gets the SSID (service set identifier).
2663 * @privlevel platform
2664 * @privilege http://tizen.org/privilege/tethering.admin
2665 * @remarks @a ssid must be released with free() by you.
2666 * @param[in] tethering The handle of tethering
2667 * @param[out] ssid The SSID
2668 * @return 0 on success, otherwise negative error value.
2669 * @retval #TETHERING_ERROR_NONE Successful
2670 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2671 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2672 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2674 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2676 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2678 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2679 "parameter(tethering) is NULL\n");
2680 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2681 "parameter(ssid) is NULL\n");
2684 __tethering_h *th = (__tethering_h *)tethering;
2685 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2687 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2688 if (th->ssid != NULL) {
2689 DBG("Private SSID is set\n");
2690 *ssid = strdup(th->ssid);
2692 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2693 val, sizeof(val)) == false) {
2694 return TETHERING_ERROR_OPERATION_FAILED;
2696 *ssid = strdup(val);
2699 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2700 val, sizeof(val)) == false) {
2701 return TETHERING_ERROR_OPERATION_FAILED;
2703 *ssid = strdup(val);
2706 if (*ssid == NULL) {
2707 ERR("strdup is failed\n");
2708 return TETHERING_ERROR_OUT_OF_MEMORY;
2711 return TETHERING_ERROR_NONE;
2716 * @brief Sets the visibility of SSID(service set identifier).
2718 * @privlevel platform
2719 * @privilege http://tizen.org/privilege/tethering.admin
2720 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2721 * @remarks This change is applied next time Wi-Fi tethering is enabled
2722 * @param[in] tethering The handle of tethering
2723 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2724 * @return 0 on success, otherwise negative error value.
2725 * @retval #TETHERING_ERROR_NONE Successful
2726 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2727 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2728 * @see tethering_wifi_get_ssid_visibility()
2730 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2732 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2734 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2735 "parameter(tethering) is NULL\n");
2737 __tethering_h *th = (__tethering_h *)tethering;
2738 tethering_error_e ret = TETHERING_ERROR_NONE;
2740 ret = __set_visible(visible);
2741 if (ret == TETHERING_ERROR_NONE) {
2743 __send_dbus_signal(th->client_bus,
2744 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2745 visible ? SIGNAL_MSG_SSID_VISIBLE :
2746 SIGNAL_MSG_SSID_HIDE);
2753 * @brief Gets the visibility of SSID(service set identifier).
2755 * @privlevel platform
2756 * @privilege http://tizen.org/privilege/tethering.admin
2757 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2758 * @param[in] tethering The handle of tethering
2759 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2760 * @return 0 on success, otherwise negative error value.
2761 * @retval #TETHERING_ERROR_NONE Successful
2762 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2763 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2764 * @see tethering_wifi_set_ssid_visibility()
2766 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2768 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2770 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2771 "parameter(visible) is NULL\n");
2773 return __get_visible(visible);
2778 * @brief Sets the passphrase.
2780 * @privlevel platform
2781 * @privilege http://tizen.org/privilege/tethering.admin
2782 * @remarks This change is applied next time Wi-Fi tethering is enabled
2783 * @param[in] tethering The handle of tethering
2784 * @param[in] passphrase The passphrase
2785 * @return 0 on success, otherwise negative error value.
2786 * @retval #TETHERING_ERROR_NONE Successful
2787 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2788 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2789 * @see tethering_wifi_get_passphrase()
2791 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2793 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2795 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2796 "parameter(tethering) is NULL\n");
2797 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2798 "parameter(passphrase) is NULL\n");
2800 __tethering_h *th = (__tethering_h *)tethering;
2801 GDBusProxy *proxy = th->client_bus_proxy;
2802 GVariant *parameters;
2803 GError *error = NULL;
2804 int passphrase_len = 0;
2808 passphrase_len = strlen(passphrase);
2809 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
2810 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
2811 ERR("parameter(passphrase) is too short or long\n");
2812 return TETHERING_ERROR_INVALID_PARAMETER;
2815 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
2816 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2820 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2822 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2823 ret = TETHERING_ERROR_PERMISSION_DENIED;
2825 ret = TETHERING_ERROR_OPERATION_FAILED;
2827 g_error_free(error);
2832 g_variant_get(parameters, "(u)", &ret);
2833 g_variant_unref(parameters);
2835 if (ret == TETHERING_ERROR_NONE) {
2836 __send_dbus_signal(th->client_bus,
2837 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
2846 * @brief Gets the passphrase.
2848 * @privlevel platform
2849 * @privilege http://tizen.org/privilege/tethering.admin
2850 * @remarks @a passphrase must be released with free() by you.
2851 * @param[in] tethering The handle of tethering
2852 * @param[out] passphrase The passphrase
2853 * @return 0 on success, otherwise negative error value.
2854 * @retval #TETHERING_ERROR_NONE Successful
2855 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2856 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2857 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2858 * @see tethering_wifi_set_passphrase()
2860 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2862 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2864 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2865 "parameter(tethering) is NULL\n");
2866 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2867 "parameter(passphrase) is NULL\n");
2869 __tethering_h *th = (__tethering_h *)tethering;
2870 GDBusProxy *proxy = th->client_bus_proxy;
2871 GVariant *parameters;
2872 GError *error = NULL;
2873 unsigned int len = 0;
2874 tethering_error_e ret = TETHERING_ERROR_NONE;
2876 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
2877 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2881 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2883 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2884 ret = TETHERING_ERROR_PERMISSION_DENIED;
2886 ret = TETHERING_ERROR_OPERATION_FAILED;
2888 g_error_free(error);
2893 if (parameters != NULL) {
2894 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
2895 g_variant_unref(parameters);
2898 return TETHERING_ERROR_NONE;
2901 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
2903 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2904 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2905 "parameter(tethering) is NULL\n");
2907 __tethering_h *th = (__tethering_h *)tethering;
2908 th->channel = channel;
2910 return TETHERING_ERROR_NONE;
2913 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
2915 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2916 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2917 "parameter(tethering) is NULL\n");
2919 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2920 "parameter(channel) is NULL\n");
2922 __tethering_h *th = (__tethering_h *)tethering;
2923 *channel = th->channel;
2925 return TETHERING_ERROR_NONE;
2928 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
2930 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2931 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2932 "parameter(tethering) is NULL\n");
2934 __tethering_h *th = (__tethering_h *)tethering;
2936 th->mode_type = type;
2938 return TETHERING_ERROR_NONE;
2941 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
2943 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2944 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2945 "parameter(tethering) is NULL\n");
2946 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2947 "parameter(type) is NULL\n");
2949 __tethering_h *th = (__tethering_h *)tethering;
2950 *type = th->mode_type;
2952 return TETHERING_ERROR_NONE;
2958 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
2960 * @privlevel platform
2961 * @privilege http://tizen.org/privilege/tethering.admin
2962 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
2963 * @param[in] tethering The handle of tethering
2964 * @param[in] callback The callback function to invoke
2965 * @param[in] user_data The user data to be passed to the callback function
2966 * @return 0 on success, otherwise negative error value.
2967 * @retval #TETHERING_ERROR_NONE Successful
2968 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2969 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2971 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
2974 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2976 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2977 "parameter(tethering) is NULL\n");
2978 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2979 "parameter(callback) is NULL\n");
2981 __tethering_h *th = (__tethering_h *)tethering;
2982 _softap_settings_t set = {"", "", "", 0, false};
2983 GDBusProxy *proxy = th->client_bus_proxy;
2988 if (th->settings_reloaded_cb) {
2989 ERR("Operation in progress\n");
2990 return TETHERING_ERROR_OPERATION_FAILED;
2993 ret = __prepare_wifi_settings(tethering, &set);
2994 if (ret != TETHERING_ERROR_NONE) {
2995 ERR("softap settings initialization failed\n");
2996 return TETHERING_ERROR_OPERATION_FAILED;
2999 th->settings_reloaded_cb = callback;
3000 th->settings_reloaded_user_data = user_data;
3002 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3003 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
3004 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3005 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3007 return TETHERING_ERROR_NONE;
3010 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3012 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3014 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3015 "parameter(tethering) is NULL\n");
3017 __tethering_h *th = (__tethering_h *)tethering;
3018 th->mac_filter = mac_filter;
3020 return TETHERING_ERROR_NONE;
3023 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3025 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3027 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3028 "parameter(mac_filter) is NULL\n");
3029 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3030 "parameter(mac_filter) is NULL\n");
3032 __tethering_h *th = (__tethering_h *)tethering;
3033 *mac_filter = th->mac_filter;
3035 return TETHERING_ERROR_NONE;
3038 static int __add_mac_to_file(const char *filepath, const char *mac)
3041 char line[MAX_BUF_SIZE] = "\0";
3042 bool mac_exist = false;
3044 fp = fopen(filepath, "a+");
3046 ERR("fopen is failed\n");
3047 return TETHERING_ERROR_OPERATION_FAILED;
3050 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3051 if (strncmp(mac, line, 17) == 0) {
3052 DBG("MAC %s already exist in the list\n", mac);
3059 fprintf(fp, "%s\n", mac);
3063 return TETHERING_ERROR_NONE;
3066 static int __remove_mac_from_file(const char *filepath, const char *mac)
3070 char line[MAX_BUF_SIZE] = "\0";
3072 fp = fopen(filepath, "r");
3074 ERR("fopen is failed\n");
3075 return TETHERING_ERROR_OPERATION_FAILED;
3078 fp1 = fopen(TEMP_LIST, "w+");
3081 ERR("fopen is failed\n");
3082 return TETHERING_ERROR_OPERATION_FAILED;
3085 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3086 if (strncmp(mac, line, 17) == 0)
3087 DBG("MAC %s found in the list\n", mac);
3089 fprintf(fp1, "%s", line);
3095 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3096 rename(TEMP_LIST, ALLOWED_LIST);
3097 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3098 rename(TEMP_LIST, BLOCKED_LIST);
3100 return TETHERING_ERROR_NONE;
3103 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3105 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3107 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3108 "parameter(tethering) is NULL\n");
3109 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3110 "parameter(mac) is NULL\n");
3112 return __add_mac_to_file(ALLOWED_LIST, mac);
3115 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3117 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3118 "parameter(tethering) is NULL\n");
3119 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3120 "parameter(mac) is NULL\n");
3122 return __remove_mac_from_file(ALLOWED_LIST, mac);
3125 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3127 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3128 "parameter(tethering) is NULL\n");
3129 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3130 "parameter(mac) is NULL\n");
3132 return __add_mac_to_file(BLOCKED_LIST, mac);
3135 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3137 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3138 "parameter(tethering) is NULL\n");
3139 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3140 "parameter(mac) is NULL\n");
3142 return __remove_mac_from_file(BLOCKED_LIST, mac);
3145 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3147 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3149 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3150 "parameter(tethering) is NULL\n");
3152 GVariant *parameters;
3153 GError *error = NULL;
3156 __tethering_h *th = (__tethering_h *)tethering;
3158 GDBusProxy *proxy = th->client_bus_proxy;
3160 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3161 g_variant_new("(b)", enable),
3162 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3165 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3166 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3167 result = TETHERING_ERROR_PERMISSION_DENIED;
3169 result = TETHERING_ERROR_OPERATION_FAILED;
3171 g_error_free(error);
3172 th->dhcp_enabled = false;
3177 g_variant_get(parameters, "(u)", &result);
3178 g_variant_unref(parameters);
3181 th->dhcp_enabled = true;
3183 th->dhcp_enabled = false;
3185 return TETHERING_ERROR_NONE;
3188 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3190 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3192 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3193 "parameter(tethering) is NULL\n");
3194 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3195 "parameter(rangestart) is NULL\n");
3196 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3197 "parameter(rangestop) is NULL\n");
3199 GVariant *parameters;
3200 GError *error = NULL;
3203 __tethering_h *th = (__tethering_h *)tethering;
3205 GDBusProxy *proxy = th->client_bus_proxy;
3207 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3208 g_variant_new("(ss)", rangestart, rangestop),
3209 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3211 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3213 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3214 result = TETHERING_ERROR_PERMISSION_DENIED;
3216 result = TETHERING_ERROR_OPERATION_FAILED;
3218 g_error_free(error);
3219 th->dhcp_enabled = false;
3224 g_variant_get(parameters, "(u)", &result);
3225 g_variant_unref(parameters);
3227 th->dhcp_enabled = true;
3229 return TETHERING_ERROR_NONE;
3232 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3234 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3235 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3236 "parameter(tethering) is NULL\n");
3237 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3238 "parameter(dhcp_enabled) is NULL\n");
3240 __tethering_h *th = (__tethering_h *)tethering;
3241 *dhcp_enabled = th->dhcp_enabled;
3243 return TETHERING_ERROR_NONE;