2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
24 #include <arpa/inet.h>
26 #include <dbus/dbus.h>
29 #include <openssl/evp.h>
30 #include <openssl/sha.h>
31 #include <ckmc/ckmc-manager.h>
32 #include <tzplatform_config.h>
33 #include "tethering_private.h"
35 #define ALLOWED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.accept")
36 #define BLOCKED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.deny")
37 #define TEMP_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/.hostapd_tmp")
38 #define MAC_ADDR_LEN 18
39 #define MAX_BUF_SIZE 80
41 static GSList *allowed_list = NULL;
42 static GSList *blocked_list = NULL;
44 static void __handle_wifi_tether_on(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_wifi_tether_off(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_on(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_usb_tether_off(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_on(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_bt_tether_off(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_net_closed(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_no_data_timeout(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_low_battery_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_flight_mode(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_security_type_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_ssid_visibility_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_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
93 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
94 GVariant *parameters, gpointer user_data);
96 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
97 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
98 GVariant *parameters, gpointer user_data);
100 static __tethering_sig_t sigs[] = {
101 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
102 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
103 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
104 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
105 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
106 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
107 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
108 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
109 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
110 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
111 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
112 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
113 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
114 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
117 static int retry = 0;
119 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
121 if (conn == NULL || signal_name == NULL)
122 return; //LCOV_EXCL_LINE
124 GVariant *message = NULL;
125 GError *error = NULL;
128 message = g_variant_new("(s)", arg);
130 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
131 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
133 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
134 g_error_free(error); //LCOV_EXCL_LINE
136 g_variant_unref(message);
139 static bool __any_tethering_is_enabled(tethering_h tethering)
141 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
142 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
143 tethering_is_enabled(tethering, TETHERING_TYPE_BT))
149 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
151 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
152 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
153 ERR("Invalid param\n");
154 return TETHERING_ERROR_INVALID_PARAMETER;
157 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
158 ERR("vconf_set_int is failed\n");
159 return TETHERING_ERROR_OPERATION_FAILED;
162 return TETHERING_ERROR_NONE;
165 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
167 if (security_type == NULL) {
168 ERR("Invalid param\n");
169 return TETHERING_ERROR_INVALID_PARAMETER;
172 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
173 (int *)security_type) < 0) {
174 ERR("vconf_get_int is failed\n");
175 return TETHERING_ERROR_OPERATION_FAILED;
178 return TETHERING_ERROR_NONE;
181 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
183 if (path == NULL || ssid == NULL || size == 0)
187 char *ptr_tmp = NULL;
189 ptr = vconf_get_str(path);
193 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
196 g_strlcpy(ssid, ptr, size);
202 static tethering_error_e __set_visible(const bool visible)
204 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
205 ERR("vconf_set_int is failed\n");
206 return TETHERING_ERROR_OPERATION_FAILED;
209 return TETHERING_ERROR_NONE;
212 static tethering_error_e __get_visible(bool *visible)
214 if (visible == NULL) {
215 ERR("Invalid param\n");
216 return TETHERING_ERROR_INVALID_PARAMETER;
221 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
222 ERR("vconf_get_int is failed\n");
223 return TETHERING_ERROR_OPERATION_FAILED;
230 return TETHERING_ERROR_NONE;
233 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
235 if (passphrase == NULL ||
236 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
239 guint32 rand_int = 0;
242 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
243 rand_int = g_random_int_range('a', 'z');
244 passphrase[index] = rand_int;
246 passphrase[index] = '\0';
251 static tethering_error_e __get_error(int agent_error)
253 tethering_error_e err = TETHERING_ERROR_NONE;
255 switch (agent_error) {
256 case MOBILE_AP_ERROR_NONE:
257 err = TETHERING_ERROR_NONE;
261 case MOBILE_AP_ERROR_RESOURCE:
262 err = TETHERING_ERROR_OUT_OF_MEMORY;
266 case MOBILE_AP_ERROR_INTERNAL:
267 err = TETHERING_ERROR_OPERATION_FAILED;
270 case MOBILE_AP_ERROR_INVALID_PARAM:
271 err = TETHERING_ERROR_INVALID_PARAMETER;
274 case MOBILE_AP_ERROR_ALREADY_ENABLED:
275 err = TETHERING_ERROR_OPERATION_FAILED;
278 case MOBILE_AP_ERROR_NOT_ENABLED:
279 err = TETHERING_ERROR_NOT_ENABLED;
282 case MOBILE_AP_ERROR_NET_OPEN:
283 err = TETHERING_ERROR_OPERATION_FAILED;
286 case MOBILE_AP_ERROR_NET_CLOSE:
287 err = TETHERING_ERROR_OPERATION_FAILED;
290 case MOBILE_AP_ERROR_DHCP:
291 err = TETHERING_ERROR_OPERATION_FAILED;
294 case MOBILE_AP_ERROR_IN_PROGRESS:
295 err = TETHERING_ERROR_OPERATION_FAILED;
299 case MOBILE_AP_ERROR_NOT_PERMITTED:
300 err = TETHERING_ERROR_NOT_PERMITTED;
303 case MOBILE_AP_ERROR_PERMISSION_DENIED:
304 err = TETHERING_ERROR_PERMISSION_DENIED;
308 ERR("Not defined error : %d\n", agent_error);
309 err = TETHERING_ERROR_OPERATION_FAILED;
317 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
318 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
319 GVariant *parameters, gpointer user_data)
323 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
325 __tethering_h *th = (__tethering_h *)user_data;
327 tethering_type_e type = 0;
328 mobile_ap_type_e ap_type = 0;
329 tethering_connection_state_changed_cb ccb = NULL;
330 __tethering_client_h client;
338 memset(&client, 0, sizeof(__tethering_client_h));
339 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
341 if (!g_strcmp0(buf, "DhcpConnected")) {
343 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
346 ERR("Unknown event [%s]\n", buf);
350 if (ap_type == MOBILE_AP_TYPE_USB)
351 type = TETHERING_TYPE_USB;
352 else if (ap_type == MOBILE_AP_TYPE_WIFI)
353 type = TETHERING_TYPE_WIFI;
354 else if (ap_type == MOBILE_AP_TYPE_BT)
355 type = TETHERING_TYPE_BT;
357 ERR("Not supported tethering type [%d]\n", ap_type);
361 ccb = th->changed_cb[type];
364 data = th->changed_user_data[type];
366 client.interface = type;
367 g_strlcpy(client.ip, ip, sizeof(client.ip));
368 g_strlcpy(client.mac, mac, sizeof(client.mac));
370 client.hostname = g_strdup(name);
371 client.tm = (time_t)timestamp;
373 ccb((tethering_client_h)&client, opened, data);
374 g_free(client.hostname);
385 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
386 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
387 GVariant *parameters, gpointer user_data)
391 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
393 __tethering_h *th = (__tethering_h *)user_data;
394 tethering_type_e type = 0;
395 tethering_disabled_cb dcb = NULL;
397 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
399 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
400 dcb = th->disabled_cb[type];
403 data = th->disabled_user_data[type];
405 dcb(TETHERING_ERROR_NONE, type, code, data);
412 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
413 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
414 GVariant *parameters, gpointer user_data)
418 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
420 __tethering_h *th = (__tethering_h *)user_data;
421 tethering_type_e type = TETHERING_TYPE_WIFI;
422 bool is_requested = false;
423 tethering_enabled_cb ecb = NULL;
426 ecb = th->enabled_cb[type];
429 data = th->enabled_user_data[type];
431 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
435 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
436 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
437 GVariant *parameters, gpointer user_data)
441 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
443 __tethering_h *th = (__tethering_h *)user_data;
444 tethering_type_e type = TETHERING_TYPE_WIFI;
445 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
446 tethering_disabled_cb dcb = NULL;
450 dcb = th->disabled_cb[type];
453 data = th->disabled_user_data[type];
454 g_variant_get(parameters, "(s)", &buf);
455 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
456 code = TETHERING_DISABLED_BY_WIFI_ON;
457 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
458 code = TETHERING_DISABLED_BY_TIMEOUT;
461 dcb(TETHERING_ERROR_NONE, type, code, data);
467 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
468 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
469 GVariant *parameters, gpointer user_data)
473 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
475 __tethering_h *th = (__tethering_h *)user_data;
476 tethering_type_e type = TETHERING_TYPE_USB;
477 bool is_requested = false;
478 tethering_enabled_cb ecb = NULL;
481 ecb = th->enabled_cb[type];
484 data = th->enabled_user_data[type];
486 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
490 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
491 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
492 GVariant *parameters, gpointer user_data)
496 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
498 __tethering_h *th = (__tethering_h *)user_data;
499 tethering_type_e type = TETHERING_TYPE_USB;
500 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
501 tethering_disabled_cb dcb = NULL;
505 dcb = th->disabled_cb[type];
508 data = th->disabled_user_data[type];
510 g_variant_get(parameters, "(s)", &buf);
511 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
512 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
514 dcb(TETHERING_ERROR_NONE, type, code, data);
520 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
521 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
522 GVariant *parameters, gpointer user_data)
526 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
528 __tethering_h *th = (__tethering_h *)user_data;
529 tethering_type_e type = TETHERING_TYPE_BT;
530 bool is_requested = false;
531 tethering_enabled_cb ecb = NULL;
534 ecb = th->enabled_cb[type];
537 data = th->enabled_user_data[type];
539 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
543 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
544 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
545 GVariant *parameters, gpointer user_data)
549 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
551 __tethering_h *th = (__tethering_h *)user_data;
552 tethering_type_e type = TETHERING_TYPE_BT;
553 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
554 tethering_disabled_cb dcb = NULL;
558 dcb = th->disabled_cb[type];
561 data = th->disabled_user_data[type];
562 g_variant_get(parameters, "(s)", &buf);
563 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
564 code = TETHERING_DISABLED_BY_BT_OFF;
565 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
566 code = TETHERING_DISABLED_BY_TIMEOUT;
568 dcb(TETHERING_ERROR_NONE, type, code, data);
575 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
576 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
577 GVariant *parameters, gpointer user_data)
581 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
583 __tethering_h *th = (__tethering_h *)user_data;
584 tethering_type_e type = 0;
585 tethering_disabled_cb dcb = NULL;
587 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
589 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
590 dcb = th->disabled_cb[type];
593 data = th->disabled_user_data[type];
595 dcb(TETHERING_ERROR_NONE, type, code, data);
600 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
601 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
602 GVariant *parameters, gpointer user_data)
606 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
608 __tethering_h *th = (__tethering_h *)user_data;
609 tethering_type_e type = 0;
610 tethering_disabled_cb dcb = NULL;
612 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
614 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
615 dcb = th->disabled_cb[type];
618 data = th->disabled_user_data[type];
620 dcb(TETHERING_ERROR_NONE, type, code, data);
625 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
626 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
627 GVariant *parameters, gpointer user_data)
631 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
633 __tethering_h *th = (__tethering_h *)user_data;
634 tethering_type_e type = 0;
635 tethering_disabled_cb dcb = NULL;
637 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
639 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
640 dcb = th->disabled_cb[type];
643 data = th->disabled_user_data[type];
645 dcb(TETHERING_ERROR_NONE, type, code, data);
651 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
652 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
653 GVariant *parameters, gpointer user_data)
658 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
659 __tethering_h *th = (__tethering_h *)user_data;
661 tethering_wifi_security_type_changed_cb scb = NULL;
663 tethering_wifi_security_type_e security_type;
666 scb = th->security_type_changed_cb;
670 g_variant_get(parameters, "(s)", &buf);
671 data = th->security_type_user_data;
672 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
673 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
674 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
675 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
677 SERR("Unknown type : %s\n", buf);
682 scb(security_type, data);
687 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
688 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
689 GVariant *parameters, gpointer user_data)
693 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
694 __tethering_h *th = (__tethering_h *)user_data;
696 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
698 bool visible = false;
701 scb = th->ssid_visibility_changed_cb;
706 g_variant_get(parameters, "(s)", &buf);
707 data = th->ssid_visibility_user_data;
708 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
716 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
717 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
718 GVariant *parameters, gpointer user_data)
722 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
723 __tethering_h *th = (__tethering_h *)user_data;
725 tethering_wifi_passphrase_changed_cb pcb = NULL;
728 pcb = th->passphrase_changed_cb;
732 data = th->passphrase_user_data;
738 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
743 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
744 GError *g_error = NULL;
747 tethering_error_e error;
748 __tethering_h *th = (__tethering_h *)user_data;
749 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
750 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
752 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
755 ERR("DBus error [%s]\n", g_error->message);
756 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
757 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
758 g_error_free(g_error);
759 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
761 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
762 error = TETHERING_ERROR_PERMISSION_DENIED;
764 error = TETHERING_ERROR_OPERATION_FAILED;
765 g_error_free(g_error);
768 g_variant_get(g_var, "(u)", &info);
769 error = __get_error(info);
773 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
774 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
775 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
776 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
782 ecb(error, TETHERING_TYPE_WIFI, true, data);
783 g_variant_unref(g_var);
787 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
791 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
792 GError *g_error = NULL;
795 tethering_error_e error;
797 __tethering_h *th = (__tethering_h *)user_data;
798 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
799 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
801 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
804 ERR("DBus error [%s]\n", g_error->message);
805 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
806 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
807 g_error_free(g_error);
808 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
812 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
813 error = TETHERING_ERROR_PERMISSION_DENIED;
815 error = TETHERING_ERROR_OPERATION_FAILED;
816 g_error_free(g_error);
819 g_variant_get(g_var, "(u)", &info);
820 g_variant_unref(g_var);
821 error = __get_error(info);
825 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
826 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
827 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
828 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
835 ecb(error, TETHERING_TYPE_BT, true, data);
840 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
845 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
846 __tethering_h *th = (__tethering_h *)user_data;
847 GError *g_error = NULL;
850 tethering_error_e error;
851 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
852 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
854 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
856 ERR("DBus error [%s]\n", g_error->message);
857 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
858 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
859 g_error_free(g_error);
860 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
864 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
865 error = TETHERING_ERROR_PERMISSION_DENIED;
867 error = TETHERING_ERROR_OPERATION_FAILED;
868 g_error_free(g_error);
870 g_variant_get(g_var, "(u)", &info);
871 g_variant_unref(g_var);
872 error = __get_error(info);
876 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
877 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
878 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
879 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
886 ecb(error, TETHERING_TYPE_USB, true, data);
891 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
896 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
897 GError *g_error = NULL;
899 guint info, event_type;
900 tethering_error_e error;
901 tethering_type_e type;
902 tethering_h tethering = (tethering_h)user_data;
903 __tethering_h *th = (__tethering_h *)tethering;
904 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
905 tethering_disabled_cb dcb = NULL;
908 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
911 ERR("DBus error [%s]\n", g_error->message);
912 g_error_free(g_error);
916 g_variant_get(g_var, "(uu)", &event_type, &info);
917 DBG("cfm event : %d info : %d\n", event_type, info);
918 g_variant_unref(g_var);
919 error = __get_error(info);
920 DBG("cfm event : %d info : %d\n", event_type, error);
921 switch (event_type) {
922 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
923 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
924 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
925 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
926 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
928 type = TETHERING_TYPE_WIFI;
929 dcb = th->disabled_cb[type];
930 data = th->disabled_user_data[type];
932 dcb(error, type, code, data);
935 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
936 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
937 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
938 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
939 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
941 type = TETHERING_TYPE_BT;
942 dcb = th->disabled_cb[type];
943 data = th->disabled_user_data[type];
945 dcb(error, type, code, data);
949 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
950 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
951 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
952 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
953 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
955 type = TETHERING_TYPE_USB;
956 dcb = th->disabled_cb[type];
957 data = th->disabled_user_data[type];
959 dcb(error, type, code, data);
963 case MOBILE_AP_DISABLE_CFM:
965 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
966 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
967 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
968 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
969 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
970 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
971 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
972 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
973 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
974 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
975 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
976 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
978 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
979 dcb = th->disabled_cb[type];
982 data = th->disabled_user_data[type];
984 dcb(error, type, code, data);
989 ERR("Invalid event\n");
995 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1000 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1002 GError *g_error = NULL;
1005 guint64 tx_bytes, rx_bytes;
1006 __tethering_h *th = (__tethering_h *)user_data;
1007 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1010 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1013 ERR("DBus fail [%s]\n", g_error->message);
1014 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1015 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1017 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1022 if (th->data_usage_cb == NULL) {
1023 ERR("There is no data_usage_cb\n");
1027 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1029 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1030 th->data_usage_cb(TETHERING_ERROR_NONE,
1031 rx_bytes, tx_bytes, th->data_usage_user_data);
1032 g_variant_unref(g_var);
1034 th->data_usage_cb = NULL;
1035 th->data_usage_user_data = NULL;
1040 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1045 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1046 GError *g_error = NULL;
1049 __tethering_h *th = (__tethering_h *)user_data;
1050 tethering_error_e tethering_error;
1052 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1054 ERR("DBus fail [%s]\n", g_error->message);
1055 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1056 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1058 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1059 g_error_free(g_error);
1061 if (th->settings_reloaded_cb == NULL) {
1062 DBG("There is no settings_reloaded_cb\n-\n");
1065 g_variant_get(g_var, "(u)", &info);
1066 tethering_error = __get_error(info);
1067 g_variant_unref(g_var);
1069 th->settings_reloaded_cb(tethering_error,
1070 th->settings_reloaded_user_data);
1072 th->settings_reloaded_cb = NULL;
1073 th->settings_reloaded_user_data = NULL;
1077 static void __connect_signals(tethering_h tethering)
1080 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1082 __tethering_h *th = (__tethering_h *)tethering;
1083 GDBusConnection *connection = th->client_bus;
1086 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1087 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1088 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1089 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1090 sigs[i].cb, tethering, NULL);
1095 static void __disconnect_signals(tethering_h tethering)
1099 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1101 __tethering_h *th = (__tethering_h *)tethering;
1102 GDBusConnection *connection = th->client_bus;
1106 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1107 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1113 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1115 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1119 case TETHERING_TYPE_USB:
1120 g_strlcpy(buf, TETHERING_USB_IF, len);
1123 case TETHERING_TYPE_WIFI:
1124 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1127 case TETHERING_TYPE_BT:
1128 g_strlcpy(buf, TETHERING_BT_IF, len);
1132 ERR("Not supported type : %d\n", type);
1138 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1140 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1143 case TETHERING_TYPE_USB:
1144 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1147 case TETHERING_TYPE_WIFI:
1148 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1151 case TETHERING_TYPE_BT:
1152 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1156 ERR("Not supported type : %d\n", type);
1162 static int __get_common_ssid(char *ssid, unsigned int size)
1165 ERR("ssid is null\n"); //LCOV_EXCL_LINE
1166 return TETHERING_ERROR_INVALID_PARAMETER;
1170 char *ptr_tmp = NULL;
1172 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1174 ERR("vconf_get_str is failed and set default ssid");
1175 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1177 g_strlcpy(ssid, ptr, size);
1181 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1184 return TETHERING_ERROR_NONE;
1187 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1189 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1192 case TETHERING_WIFI_MODE_TYPE_B:
1193 *buf = g_strdup("b");
1195 case TETHERING_WIFI_MODE_TYPE_G:
1196 *buf = g_strdup("g");
1198 case TETHERING_WIFI_MODE_TYPE_A:
1199 *buf = g_strdup("a");
1201 case TETHERING_WIFI_MODE_TYPE_AD:
1202 *buf = g_strdup("ad");
1205 ERR("Not supported type : %d\n", type);
1211 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1215 __tethering_h *th = (__tethering_h *)tethering;
1216 tethering_error_e ret = TETHERING_ERROR_NONE;
1219 if (th == NULL || set == NULL) {
1220 ERR("null parameter\n-\n");
1221 return TETHERING_ERROR_INVALID_PARAMETER;
1224 if (th->ssid == NULL)
1225 __get_common_ssid(set->ssid, sizeof(set->ssid));
1227 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1229 ret = __get_security_type(&set->sec_type);
1230 if (ret != TETHERING_ERROR_NONE)
1231 set->sec_type = th->sec_type;
1233 ret = __get_visible(&set->visibility);
1234 if (ret != TETHERING_ERROR_NONE)
1235 set->visibility = th->visibility;
1237 set->mac_filter = th->mac_filter;
1238 set->channel = th->channel;
1240 __get_wifi_mode_type(th->mode_type, &ptr);
1242 g_strlcpy(set->mode, "", sizeof(set->mode));
1244 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1248 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1249 g_strlcpy(set->key, "", sizeof(set->key));
1251 GDBusProxy *proxy = th->client_bus_proxy;
1252 GVariant *parameters;
1253 GError *error = NULL;
1254 char *passphrase = NULL;
1255 unsigned int len = 0;
1257 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1258 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1262 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1264 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1265 ret = TETHERING_ERROR_PERMISSION_DENIED;
1267 ret = TETHERING_ERROR_OPERATION_FAILED;
1269 g_error_free(error);
1274 if (parameters != NULL) {
1275 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1276 g_variant_unref(parameters);
1279 g_strlcpy(set->key, passphrase, sizeof(set->key));
1282 return TETHERING_ERROR_NONE;
1285 static bool __check_precondition(tethering_type_e type)
1288 int cellular_state = 0;
1291 /* data network through cellular */
1292 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1293 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1294 ERR("Data Network can be connected later");
1298 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1299 if (dnet_state > VCONFKEY_DNET_OFF) {
1300 ERR("Data Network is connected");
1304 /* data network through wifi */
1305 if (type != TETHERING_TYPE_WIFI) {
1306 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1307 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1308 ERR("Wi-Fi is connected!");
1313 ERR("Network is not available!");
1319 * @brief Creates the handle of tethering.
1321 * @privlevel platform
1322 * @privilege http://tizen.org/privilege/tethering.admin
1323 * @remarks The @a tethering must be released tethering_destroy() by you.
1324 * @param[out] tethering A handle of a new mobile ap handle on success
1325 * @return 0 on success, otherwise a negative error value.
1326 * @retval #TETHERING_ERROR_NONE Successful
1327 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1328 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1329 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1330 * @see tethering_destroy()
1332 API int tethering_create(tethering_h *tethering)
1334 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1335 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1336 "parameter(tethering) is NULL\n");
1339 __tethering_h *th = NULL;
1340 GError *error = NULL;
1341 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1343 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1345 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1346 "malloc is failed\n");
1347 memset(th, 0x00, sizeof(__tethering_h));
1348 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1349 th->visibility = true;
1350 th->mac_filter = false;
1352 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1354 if (__generate_initial_passphrase(th->passphrase,
1355 sizeof(th->passphrase)) == 0) {
1356 ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
1358 return TETHERING_ERROR_OPERATION_FAILED;
1361 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1362 ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
1364 return TETHERING_ERROR_OPERATION_FAILED;
1367 #if !GLIB_CHECK_VERSION(2, 36, 0)
1370 GCancellable *cancellable = g_cancellable_new();
1371 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1374 ERR("Couldn't connect to the System bus[%s]", error->message);
1375 g_error_free(error);
1376 g_cancellable_cancel(cancellable);
1377 g_object_unref(cancellable);
1379 return TETHERING_ERROR_OPERATION_FAILED;
1382 th->cancellable = cancellable;
1384 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1385 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1386 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1387 if (!th->client_bus_proxy) {
1390 ERR("Couldn't create the proxy object because of %s\n", error->message);
1391 g_cancellable_cancel(th->cancellable);
1392 g_object_unref(th->cancellable);
1393 g_object_unref(th->client_bus);
1395 return TETHERING_ERROR_OPERATION_FAILED;
1399 __connect_signals((tethering_h)th);
1401 *tethering = (tethering_h)th;
1402 DBG("Tethering Handle : 0x%X\n", th);
1404 return TETHERING_ERROR_NONE;
1409 * @brief Destroys the handle of tethering.
1411 * @privlevel platform
1412 * @privilege http://tizen.org/privilege/tethering.admin
1413 * @param[in] tethering The handle of tethering
1414 * @return 0 on success, otherwise a negative error value.
1415 * @retval #TETHERING_ERROR_NONE Successful
1416 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1417 * @see tethering_create()
1419 API int tethering_destroy(tethering_h tethering)
1422 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1423 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1424 "parameter(tethering) is NULL\n");
1426 __tethering_h *th = (__tethering_h *)tethering;
1428 DBG("Tethering Handle : 0x%X\n", th);
1429 __disconnect_signals(tethering);
1434 g_object_unref(th->cancellable);
1435 g_object_unref(th->client_bus_proxy);
1436 g_object_unref(th->client_bus);
1437 memset(th, 0x00, sizeof(__tethering_h));
1441 return TETHERING_ERROR_NONE;
1446 * @brief Enables the tethering, asynchronously.
1448 * @privlevel platform
1449 * @privilege http://tizen.org/privilege/tethering.admin
1450 * @param[in] tethering The handle of tethering
1451 * @param[in] type The type of tethering
1452 * @return 0 on success, otherwise negative error value.
1453 * @retval #TETHERING_ERROR_NONE Successful
1454 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1455 * @post tethering_enabled_cb() will be invoked.
1456 * @see tethering_is_enabled()
1457 * @see tethering_disable()
1459 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1461 DBG("+ type : %d\n", type);
1462 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1463 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1464 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1465 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1467 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1468 "parameter(tethering) is NULL\n");
1470 tethering_error_e ret = TETHERING_ERROR_NONE;
1471 __tethering_h *th = (__tethering_h *)tethering;
1472 GDBusProxy *proxy = th->client_bus_proxy;
1473 GDBusConnection *connection = th->client_bus;
1475 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1477 if (__check_precondition(type) == FALSE) {
1480 return TETHERING_ERROR_OPERATION_FAILED;
1486 case TETHERING_TYPE_USB:
1487 g_dbus_connection_signal_unsubscribe(connection,
1488 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1490 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1491 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1492 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1496 case TETHERING_TYPE_WIFI: {
1497 _softap_settings_t set = {"", "", "", 0, false};
1499 ret = __prepare_wifi_settings(tethering, &set);
1500 if (ret != TETHERING_ERROR_NONE) {
1501 ERR("softap settings initialization failed\n");
1503 return TETHERING_ERROR_OPERATION_FAILED;
1505 g_dbus_connection_signal_unsubscribe(connection,
1506 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1508 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1509 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
1510 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1511 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1515 case TETHERING_TYPE_BT:
1516 g_dbus_connection_signal_unsubscribe(connection,
1517 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1519 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1520 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1521 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1526 case TETHERING_TYPE_ALL: {
1527 _softap_settings_t set = {"", "", "", 0, false};
1529 ret = __prepare_wifi_settings(tethering, &set);
1530 if (ret != TETHERING_ERROR_NONE) {
1531 ERR("softap settings initialization failed\n");
1532 return TETHERING_ERROR_OPERATION_FAILED;
1535 /* TETHERING_TYPE_USB */
1536 g_dbus_connection_signal_unsubscribe(connection,
1537 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1539 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1540 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1541 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1543 /* TETHERING_TYPE_WIFI */
1544 g_dbus_connection_signal_unsubscribe(connection,
1545 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1547 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1548 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1549 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1550 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1552 /* TETHERING_TYPE_BT */
1553 g_dbus_connection_signal_unsubscribe(connection,
1554 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1556 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1557 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1558 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1563 ERR("Unknown type : %d\n", type);
1565 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1568 return TETHERING_ERROR_INVALID_PARAMETER;
1571 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1573 return TETHERING_ERROR_NONE;
1578 * @brief Disables the tethering, asynchronously.
1580 * @privlevel platform
1581 * @privilege http://tizen.org/privilege/tethering.admin
1582 * @param[in] tethering The handle of tethering
1583 * @param[in] type The type of tethering
1584 * @return 0 on success, otherwise negative error value.
1585 * @retval #TETHERING_ERROR_NONE Successful
1586 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1587 * @post tethering_disabled_cb() will be invoked.
1588 * @see tethering_is_enabled()
1589 * @see tethering_enable()
1591 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1593 DBG("+ type : %d\n", type);
1594 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1595 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1596 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1598 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1599 "parameter(tethering) is NULL\n");
1601 __tethering_h *th = (__tethering_h *)tethering;
1602 GDBusProxy *proxy = th->client_bus_proxy;
1603 GDBusConnection *connection = th->client_bus;
1606 case TETHERING_TYPE_USB:
1607 g_dbus_connection_signal_unsubscribe(connection,
1608 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1610 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1611 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1612 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1616 case TETHERING_TYPE_WIFI:
1618 g_dbus_connection_signal_unsubscribe(connection,
1619 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1621 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1622 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1623 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1626 case TETHERING_TYPE_BT:
1628 g_dbus_connection_signal_unsubscribe(connection,
1629 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1631 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1632 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1633 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1636 case TETHERING_TYPE_ALL:
1637 g_dbus_connection_signal_unsubscribe(connection,
1638 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1640 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1641 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1642 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1644 g_dbus_connection_signal_unsubscribe(connection,
1645 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1647 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1648 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1649 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1651 g_dbus_connection_signal_unsubscribe(connection,
1652 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1654 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1655 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1656 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1660 ERR("Not supported tethering type [%d]\n", type);
1662 return TETHERING_ERROR_INVALID_PARAMETER;
1665 return TETHERING_ERROR_NONE;
1670 * @brief Checks whetehr the tethering is enabled or not.
1672 * @privlevel platform
1673 * @privilege http://tizen.org/privilege/tethering.admin
1674 * @param[in] tethering The handle of tethering
1675 * @param[in] type The type of tethering
1676 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1678 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1681 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1683 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1685 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1689 case TETHERING_TYPE_USB:
1690 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1693 case TETHERING_TYPE_WIFI:
1694 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1697 case TETHERING_TYPE_BT:
1698 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1702 ERR("Not supported type : %d\n", type);
1705 return is_on & vconf_type ? true : false;
1710 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1712 * @privlevel platform
1713 * @privilege http://tizen.org/privilege/tethering.admin
1714 * @remarks @a mac_address must be released with free() by you.
1715 * @param[in] tethering The handle of tethering
1716 * @param[in] type The type of tethering
1717 * @param[out] mac_address The MAC address
1718 * @return 0 on success, otherwise a negative error value.
1719 * @retval #TETHERING_ERROR_NONE Successful
1720 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1721 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1722 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1723 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1724 * @pre tethering must be enabled.
1725 * @see tethering_is_enabled()
1726 * @see tethering_enable()
1728 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1730 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1731 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1732 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1734 _retvm_if(tethering_is_enabled(tethering, type) == false,
1735 TETHERING_ERROR_NOT_ENABLED,
1736 "tethering type[%d] is not enabled\n", type);
1737 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1738 "parameter(tethering) is NULL\n");
1739 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1740 "parameter(mac_address) is NULL\n");
1744 char *macbuf = NULL;
1746 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1747 TETHERING_ERROR_OPERATION_FAILED,
1748 "getting interface name is failed\n");
1750 s = socket(AF_INET, SOCK_DGRAM, 0);
1751 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1752 "getting socket is failed\n");
1753 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1754 ERR("getting mac is failed\n");
1756 return TETHERING_ERROR_OPERATION_FAILED;
1760 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1761 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1762 "Not enough memory\n");
1763 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1764 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1765 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1766 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1767 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1768 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1769 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1771 *mac_address = macbuf;
1773 return TETHERING_ERROR_NONE;
1778 * @brief Gets the name of network interface. For example, usb0.
1780 * @privlevel platform
1781 * @privilege http://tizen.org/privilege/tethering.admin
1782 * @remarks @a interface_name must be released with free() by you.
1783 * @param[in] tethering The handle of tethering
1784 * @param[in] type The type of tethering
1785 * @param[out] interface_name The name of network interface
1786 * @return 0 on success, otherwise negative error value.
1787 * @retval #TETHERING_ERROR_NONE Successful
1788 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1789 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1790 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1791 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1792 * @pre tethering must be enabled.
1793 * @see tethering_is_enabled()
1794 * @see tethering_enable()
1796 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1798 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1799 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1800 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1802 _retvm_if(tethering_is_enabled(tethering, type) == false,
1803 TETHERING_ERROR_NOT_ENABLED,
1804 "tethering type[%d] is not enabled\n", type);
1805 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1806 "parameter(tethering) is NULL\n");
1807 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1808 "parameter(interface_name) is NULL\n");
1810 char intf[TETHERING_STR_INFO_LEN] = {0, };
1812 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1813 TETHERING_ERROR_OPERATION_FAILED,
1814 "getting interface name is failed\n");
1815 *interface_name = strdup(intf);
1816 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1817 "Not enough memory\n");
1819 return TETHERING_ERROR_NONE;
1824 * @brief Gets the local IP address.
1826 * @privlevel platform
1827 * @privilege http://tizen.org/privilege/tethering.admin
1828 * @remarks @a ip_address must be released with free() by you.
1829 * @param[in] tethering The handle of tethering
1830 * @param[in] type The type of tethering
1831 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1832 * @param[out] ip_address The local IP address
1833 * @return 0 on success, otherwise negative error value.
1834 * @retval #TETHERING_ERROR_NONE Successful
1835 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1836 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1837 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1838 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1839 * @pre tethering must be enabled.
1840 * @see tethering_is_enabled()
1841 * @see tethering_enable()
1843 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1846 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1847 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1848 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1850 _retvm_if(tethering_is_enabled(tethering, type) == false,
1851 TETHERING_ERROR_NOT_ENABLED,
1852 "tethering type[%d] is not enabled\n", type);
1853 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1854 "parameter(tethering) is NULL\n");
1855 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1856 "parameter(ip_address) is NULL\n");
1862 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1863 TETHERING_ERROR_OPERATION_FAILED,
1864 "getting interface name is failed\n");
1866 s = socket(AF_INET, SOCK_DGRAM, 0);
1867 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1868 "getting socket is failed\n");
1869 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1870 ERR("ioctl is failed\n");
1872 return TETHERING_ERROR_OPERATION_FAILED;
1876 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1877 *ip_address = strdup(ipbuf);
1878 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1879 "Not enough memory\n");
1881 return TETHERING_ERROR_NONE;
1886 * @brief Gets the Gateway address.
1888 * @privlevel platform
1889 * @privilege http://tizen.org/privilege/tethering.admin
1890 * @remarks @a gateway_address must be released with free() by you.
1891 * @param[in] tethering The handle of tethering
1892 * @param[in] type The type of tethering
1893 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1894 * @param[out] gateway_address The local IP address
1895 * @return 0 on success, otherwise negative error value.
1896 * @retval #TETHERING_ERROR_NONE Successful
1897 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1898 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1899 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1900 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1901 * @pre tethering must be enabled.
1902 * @see tethering_is_enabled()
1903 * @see tethering_enable()
1905 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1908 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1909 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1910 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1912 _retvm_if(tethering_is_enabled(tethering, type) == false,
1913 TETHERING_ERROR_NOT_ENABLED,
1914 "tethering type[%d] is not enabled\n", type);
1915 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1916 "parameter(tethering) is NULL\n");
1917 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1918 "parameter(gateway_address) is NULL\n");
1920 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1922 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1923 TETHERING_ERROR_OPERATION_FAILED,
1924 "getting gateway address is failed\n");
1926 *gateway_address = strdup(gateway_buf);
1928 return TETHERING_ERROR_NONE;
1933 * @brief Gets the Subnet Mask.
1935 * @privlevel platform
1936 * @privilege http://tizen.org/privilege/tethering.admin
1937 * @remarks @a subnet_mask must be released with free() by you.
1938 * @param[in] tethering The handle of tethering
1939 * @param[in] type The type of tethering
1940 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1941 * @param[out] subnet_mask The local IP address
1942 * @return 0 on success, otherwise negative error value.
1943 * @retval #TETHERING_ERROR_NONE Successful
1944 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1945 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1946 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1947 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1948 * @pre tethering must be enabled.
1949 * @see tethering_is_enabled()
1950 * @see tethering_enable()
1952 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1954 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1955 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1956 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1958 _retvm_if(tethering_is_enabled(tethering, type) == false,
1959 TETHERING_ERROR_NOT_ENABLED,
1960 "tethering is not enabled\n");
1961 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1962 "parameter(tethering) is NULL\n");
1963 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1964 "parameter(subnet_mask) is NULL\n");
1966 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
1967 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1968 "Not enough memory\n");
1970 return TETHERING_ERROR_NONE;
1975 * @brief Gets the data usage.
1977 * @privlevel platform
1978 * @privilege http://tizen.org/privilege/tethering.admin
1979 * @param[in] tethering The handle of tethering
1980 * @param[out] usage The data usage
1981 * @return 0 on success, otherwise negative error value.
1982 * @retval #TETHERING_ERROR_NONE Successful
1983 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1984 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1985 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1986 * @pre tethering must be enabled.
1987 * @see tethering_is_enabled()
1988 * @see tethering_enable()
1990 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
1992 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1994 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1995 "parameter(tethering) is NULL\n");
1996 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1997 "parameter(callback) is NULL\n");
1998 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1999 TETHERING_ERROR_NOT_ENABLED,
2000 "tethering is not enabled\n");
2002 __tethering_h *th = (__tethering_h *)tethering;
2003 GDBusProxy *proxy = th->client_bus_proxy;
2005 th->data_usage_cb = callback;
2006 th->data_usage_user_data = user_data;
2008 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2009 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2010 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2012 return TETHERING_ERROR_NONE;
2017 * @brief Gets the client which is connected by tethering "type".
2019 * @privlevel platform
2020 * @privilege http://tizen.org/privilege/tethering.admin
2021 * @param[in] tethering The handle of tethering
2022 * @param[in] type The type of tethering
2023 * @param[in] callback The callback function to invoke
2024 * @param[in] user_data The user data to be passed to the callback function
2025 * @retval #TETHERING_ERROR_NONE Successful
2026 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2027 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2028 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2029 * @pre tethering must be enabled.
2030 * @see tethering_is_enabled()
2031 * @see tethering_enable()
2033 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2036 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2037 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2038 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2040 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2041 "parameter(tethering) is NULL\n");
2042 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2043 "parameter(callback) is NULL\n");
2044 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2045 TETHERING_ERROR_NOT_ENABLED,
2046 "tethering is not enabled\n");
2048 mobile_ap_type_e interface;
2049 __tethering_h *th = (__tethering_h *)tethering;
2050 __tethering_client_h client = {0, };
2053 gchar *hostname = NULL;
2054 guint timestamp = 0;
2055 GError *error = NULL;
2056 GVariant *result = NULL;
2057 GVariantIter *outer_iter = NULL;
2058 GVariantIter *inner_iter = NULL;
2059 GVariant *station = NULL;
2060 GVariant *value = NULL;
2063 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2064 NULL, G_DBUS_CALL_FLAGS_NONE,
2065 -1, th->cancellable, &error);
2067 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2068 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2069 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2070 g_variant_get(station, "a{sv}", &inner_iter);
2071 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2072 if (g_strcmp0(key, "Type") == 0) {
2073 interface = g_variant_get_int32(value);
2074 if (interface == MOBILE_AP_TYPE_USB)
2075 client.interface = TETHERING_TYPE_USB;
2076 else if (interface == MOBILE_AP_TYPE_WIFI)
2077 client.interface = TETHERING_TYPE_WIFI;
2078 else if (interface == MOBILE_AP_TYPE_BT)
2079 client.interface = TETHERING_TYPE_BT;
2081 ERR("Invalid interface\n");
2083 g_variant_unref(value);
2086 DBG("interface is %d\n", client.interface);
2087 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2089 g_variant_unref(value);
2092 } else if (g_strcmp0(key, "IP") == 0) {
2093 g_variant_get(value, "s", &ip);
2094 SDBG("ip is %s\n", ip);
2095 g_strlcpy(client.ip, ip, sizeof(client.ip));
2096 } else if (g_strcmp0(key, "MAC") == 0) {
2097 g_variant_get(value, "s", &mac);
2098 SDBG("mac is %s\n", mac);
2099 g_strlcpy(client.mac, mac, sizeof(client.mac));
2100 } else if (g_strcmp0(key, "Name") == 0) {
2101 g_variant_get(value, "s", &hostname);
2102 SDBG("hsotname is %s\n", hostname);
2104 client.hostname = g_strdup(hostname);
2105 } else if (g_strcmp0(key, "Time") == 0) {
2106 timestamp = g_variant_get_int32(value);
2107 DBG("timestamp is %d\n", timestamp);
2108 client.tm = (time_t)timestamp;
2110 ERR("Key %s not required\n", key);
2116 g_variant_iter_free(inner_iter);
2117 if (callback((tethering_client_h)&client, user_data) == false) {
2118 DBG("iteration is stopped\n");
2119 g_free(client.hostname);
2120 g_variant_iter_free(outer_iter);
2121 g_variant_unref(station);
2122 g_variant_unref(result);
2124 return TETHERING_ERROR_OPERATION_FAILED;
2126 g_free(client.hostname);
2128 g_variant_iter_free(outer_iter);
2129 g_variant_unref(station);
2130 g_variant_unref(result);
2132 return TETHERING_ERROR_NONE;
2137 * @brief Registers the callback function called when tethering is enabled.
2139 * @privlevel platform
2140 * @privilege http://tizen.org/privilege/tethering.admin
2141 * @param[in] tethering The handle of tethering
2142 * @param[in] type The type of tethering
2143 * @param[in] callback The callback function to invoke
2144 * @param[in] user_data The user data to be passed to the callback function
2145 * @retval #TETHERING_ERROR_NONE Successful
2146 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2147 * @see tethering_unset_enabled_cb()
2149 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2151 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2152 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2153 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2155 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2156 "parameter(tethering) is NULL\n");
2157 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2158 "parameter(callback) is NULL\n");
2160 __tethering_h *th = (__tethering_h *)tethering;
2161 tethering_type_e ti;
2163 if (type != TETHERING_TYPE_ALL) {
2164 th->enabled_cb[type] = callback;
2165 th->enabled_user_data[type] = user_data;
2167 return TETHERING_ERROR_NONE;
2170 /* TETHERING_TYPE_ALL */
2171 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2172 th->enabled_cb[ti] = callback;
2173 th->enabled_user_data[ti] = user_data;
2176 return TETHERING_ERROR_NONE;
2181 * @brief Unregisters the callback function called when tethering is disabled.
2183 * @privlevel platform
2184 * @privilege http://tizen.org/privilege/tethering.admin
2185 * @param[in] tethering The handle of tethering
2186 * @param[in] type The type of tethering
2187 * @retval #TETHERING_ERROR_NONE Successful
2188 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2189 * @see tethering_set_enabled_cb()
2191 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2193 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2194 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2195 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2197 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2198 "parameter(tethering) is NULL\n");
2200 __tethering_h *th = (__tethering_h *)tethering;
2201 tethering_type_e ti;
2203 if (type != TETHERING_TYPE_ALL) {
2204 th->enabled_cb[type] = NULL;
2205 th->enabled_user_data[type] = NULL;
2207 return TETHERING_ERROR_NONE;
2210 /* TETHERING_TYPE_ALL */
2211 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2212 th->enabled_cb[ti] = NULL;
2213 th->enabled_user_data[ti] = NULL;
2216 return TETHERING_ERROR_NONE;
2221 * @brief Registers the callback function called when tethering is disabled.
2223 * @privlevel platform
2224 * @privilege http://tizen.org/privilege/tethering.admin
2225 * @param[in] tethering The handle of tethering
2226 * @param[in] type The type of tethering
2227 * @param[in] callback The callback function to invoke
2228 * @param[in] user_data The user data to be passed to the callback function
2229 * @retval #TETHERING_ERROR_NONE Successful
2230 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2231 * @see tethering_unset_disabled_cb()
2233 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2235 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2236 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2237 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2239 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2240 "parameter(tethering) is NULL\n");
2241 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2242 "parameter(callback) is NULL\n");
2244 __tethering_h *th = (__tethering_h *)tethering;
2245 tethering_type_e ti;
2247 if (type != TETHERING_TYPE_ALL) {
2248 th->disabled_cb[type] = callback;
2249 th->disabled_user_data[type] = user_data;
2251 return TETHERING_ERROR_NONE;
2254 /* TETHERING_TYPE_ALL */
2255 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2256 th->disabled_cb[ti] = callback;
2257 th->disabled_user_data[ti] = user_data;
2260 return TETHERING_ERROR_NONE;
2265 * @brief Unregisters the callback function called when tethering is disabled.
2267 * @privlevel platform
2268 * @privilege http://tizen.org/privilege/tethering.admin
2269 * @param[in] tethering The handle of tethering
2270 * @param[in] type The type of tethering
2271 * @retval #TETHERING_ERROR_NONE Successful
2272 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2273 * @see tethering_set_disabled_cb()
2275 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2277 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2278 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2279 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2281 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2282 "parameter(tethering) is NULL\n");
2284 __tethering_h *th = (__tethering_h *)tethering;
2285 tethering_type_e ti;
2287 if (type != TETHERING_TYPE_ALL) {
2288 th->disabled_cb[type] = NULL;
2289 th->disabled_user_data[type] = NULL;
2291 return TETHERING_ERROR_NONE;
2294 /* TETHERING_TYPE_ALL */
2295 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2296 th->disabled_cb[ti] = NULL;
2297 th->disabled_user_data[ti] = NULL;
2300 return TETHERING_ERROR_NONE;
2305 * @brief Registers the callback function called when the state of connection is changed.
2307 * @privlevel platform
2308 * @privilege http://tizen.org/privilege/tethering.admin
2309 * @param[in] tethering The handle of tethering
2310 * @param[in] type The type of tethering
2311 * @param[in] callback The callback function to invoke
2312 * @param[in] user_data The user data to be passed to the callback function
2313 * @retval #TETHERING_ERROR_NONE Successful
2314 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2315 * @see tethering_unset_connection_state_changed_cb_cb()
2317 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2319 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2320 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2321 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2323 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2324 "parameter(tethering) is NULL\n");
2325 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2326 "parameter(callback) is NULL\n");
2328 __tethering_h *th = (__tethering_h *)tethering;
2329 tethering_type_e ti;
2331 if (type != TETHERING_TYPE_ALL) {
2332 th->changed_cb[type] = callback;
2333 th->changed_user_data[type] = user_data;
2335 return TETHERING_ERROR_NONE;
2338 /* TETHERING_TYPE_ALL */
2339 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2340 th->changed_cb[ti] = callback;
2341 th->changed_user_data[ti] = user_data;
2344 return TETHERING_ERROR_NONE;
2349 * @brief Unregisters the callback function called when the state of connection is changed.
2351 * @privlevel platform
2352 * @privilege http://tizen.org/privilege/tethering.admin
2353 * @param[in] tethering The handle of tethering
2354 * @param[in] type The type of tethering
2355 * @retval #TETHERING_ERROR_NONE Successful
2356 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2357 * @see tethering_set_connection_state_changed_cb()
2359 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2361 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2362 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2363 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2365 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2366 "parameter(tethering) is NULL\n");
2368 __tethering_h *th = (__tethering_h *)tethering;
2369 tethering_type_e ti;
2371 if (type != TETHERING_TYPE_ALL) {
2372 th->changed_cb[type] = NULL;
2373 th->changed_user_data[type] = NULL;
2375 return TETHERING_ERROR_NONE;
2378 /* TETHERING_TYPE_ALL */
2379 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2380 th->changed_cb[ti] = NULL;
2381 th->changed_user_data[ti] = NULL;
2384 return TETHERING_ERROR_NONE;
2389 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2391 * @privlevel platform
2392 * @privilege http://tizen.org/privilege/tethering.admin
2393 * @param[in] tethering The handle of tethering
2394 * @param[in] callback The callback function to invoke
2395 * @param[in] user_data The user data to be passed to the callback function
2396 * @retval #TETHERING_ERROR_NONE Successful
2397 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2398 * @see tethering_wifi_unset_security_type_changed_cb()
2400 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2402 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2404 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2405 "parameter(tethering) is NULL\n");
2406 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2407 "parameter(callback) is NULL\n");
2409 __tethering_h *th = (__tethering_h *)tethering;
2411 th->security_type_changed_cb = callback;
2412 th->security_type_user_data = user_data;
2414 return TETHERING_ERROR_NONE;
2420 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2422 * @privlevel platform
2423 * @privilege http://tizen.org/privilege/tethering.admin
2424 * @param[in] tethering The handle of tethering
2425 * @param[in] type The type of tethering
2426 * @retval #TETHERING_ERROR_NONE Successful
2427 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2428 * @see tethering_wifi_set_security_type_changed_cb()
2430 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2432 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2434 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2435 "parameter(tethering) is NULL\n");
2437 __tethering_h *th = (__tethering_h *)tethering;
2439 th->security_type_changed_cb = NULL;
2440 th->security_type_user_data = NULL;
2442 return TETHERING_ERROR_NONE;
2447 * @brief Registers the callback function called when the visibility of SSID is changed.
2449 * @privlevel platform
2450 * @privilege http://tizen.org/privilege/tethering.admin
2451 * @param[in] tethering The handle of tethering
2452 * @param[in] callback The callback function to invoke
2453 * @param[in] user_data The user data to be passed to the callback function
2454 * @retval #TETHERING_ERROR_NONE Successful
2455 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2456 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2458 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2460 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2462 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2463 "parameter(tethering) is NULL\n");
2464 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2465 "parameter(callback) is NULL\n");
2467 __tethering_h *th = (__tethering_h *)tethering;
2469 th->ssid_visibility_changed_cb = callback;
2470 th->ssid_visibility_user_data = user_data;
2472 return TETHERING_ERROR_NONE;
2477 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2479 * @privlevel platform
2480 * @privilege http://tizen.org/privilege/tethering.admin
2481 * @param[in] tethering The handle of tethering
2482 * @retval #TETHERING_ERROR_NONE Successful
2483 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2484 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2486 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2488 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2490 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2491 "parameter(tethering) is NULL\n");
2493 __tethering_h *th = (__tethering_h *)tethering;
2495 th->ssid_visibility_changed_cb = NULL;
2496 th->ssid_visibility_user_data = NULL;
2498 return TETHERING_ERROR_NONE;
2503 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2505 * @privlevel platform
2506 * @privilege http://tizen.org/privilege/tethering.admin
2507 * @param[in] tethering The handle of tethering
2508 * @param[in] callback The callback function to invoke
2509 * @param[in] user_data The user data to be passed to the callback function
2510 * @retval #TETHERING_ERROR_NONE Successful
2511 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2512 * @see tethering_wifi_unset_passphrase_changed_cb()
2514 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2516 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2518 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2519 "parameter(tethering) is NULL\n");
2520 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2521 "parameter(callback) is NULL\n");
2523 __tethering_h *th = (__tethering_h *)tethering;
2525 th->passphrase_changed_cb = callback;
2526 th->passphrase_user_data = user_data;
2528 return TETHERING_ERROR_NONE;
2533 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2535 * @privlevel platform
2536 * @privilege http://tizen.org/privilege/tethering.admin
2537 * @param[in] tethering The handle of tethering
2538 * @retval #TETHERING_ERROR_NONE Successful
2539 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2540 * @see tethering_wifi_set_passphrase_changed_cb()
2542 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2544 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2546 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2547 "parameter(tethering) is NULL\n");
2549 __tethering_h *th = (__tethering_h *)tethering;
2551 th->passphrase_changed_cb = NULL;
2552 th->passphrase_user_data = NULL;
2554 return TETHERING_ERROR_NONE;
2559 * @brief Sets the security type of Wi-Fi tethering.
2561 * @privlevel platform
2562 * @privilege http://tizen.org/privilege/tethering.admin
2563 * @remarks This change is applied next time Wi-Fi tethering is enabled
2564 * @param[in] tethering The handle of tethering
2565 * @param[in] type The security type
2566 * @return 0 on success, otherwise negative error value.
2567 * @retval #TETHERING_ERROR_NONE Successful
2568 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2569 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2570 * @see tethering_wifi_get_security_type()
2572 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2574 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2576 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2577 "parameter(tethering) is NULL\n");
2579 __tethering_h *th = (__tethering_h *)tethering;
2580 tethering_error_e ret = TETHERING_ERROR_NONE;
2582 ret = __set_security_type(type);
2583 if (ret == TETHERING_ERROR_NONE) {
2585 __send_dbus_signal(th->client_bus,
2586 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2587 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2588 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2589 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2596 * @brief Gets the security type of Wi-Fi tethering.
2598 * @privlevel platform
2599 * @privilege http://tizen.org/privilege/tethering.admin
2600 * @param[in] tethering The handle of tethering
2601 * @param[out] type The security type
2602 * @return 0 on success, otherwise negative error value.
2603 * @retval #TETHERING_ERROR_NONE Successful
2604 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2605 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2606 * @see tethering_wifi_set_security_type()
2608 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2610 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2612 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2613 "parameter(type) is NULL\n");
2615 return __get_security_type(type);
2620 * @brief Sets the SSID (service set identifier).
2622 * @privlevel platform
2623 * @privilege http://tizen.org/privilege/tethering.admin
2624 * @details If SSID is not set, Device name is used as SSID
2625 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2626 * @param[in] tethering The handle of tethering
2627 * @param[out] ssid The SSID
2628 * @return 0 on success, otherwise negative error value.
2629 * @retval #TETHERING_ERROR_NONE Successful
2630 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2631 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2633 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2635 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2637 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2638 "parameter(tethering) is NULL\n");
2639 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2640 "parameter(ssid) is NULL\n");
2642 __tethering_h *th = (__tethering_h *)tethering;
2643 char *p_ssid = NULL;
2646 ssid_len = strlen(ssid);
2647 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2648 ERR("parameter(ssid) is too long");
2649 return TETHERING_ERROR_INVALID_PARAMETER;
2652 p_ssid = strdup(ssid);
2653 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2654 "strdup is failed\n");
2660 return TETHERING_ERROR_NONE;
2665 * @brief Gets the SSID (service set identifier).
2667 * @privlevel platform
2668 * @privilege http://tizen.org/privilege/tethering.admin
2669 * @remarks @a ssid must be released with free() by you.
2670 * @param[in] tethering The handle of tethering
2671 * @param[out] ssid The SSID
2672 * @return 0 on success, otherwise negative error value.
2673 * @retval #TETHERING_ERROR_NONE Successful
2674 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2675 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2676 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2678 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2680 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2682 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2683 "parameter(tethering) is NULL\n");
2684 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2685 "parameter(ssid) is NULL\n");
2688 __tethering_h *th = (__tethering_h *)tethering;
2689 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2691 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2692 if (th->ssid != NULL) {
2693 DBG("Private SSID is set\n");
2694 *ssid = strdup(th->ssid);
2696 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2697 val, sizeof(val)) == false) {
2698 return TETHERING_ERROR_OPERATION_FAILED;
2700 *ssid = strdup(val);
2703 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2704 val, sizeof(val)) == false) {
2705 return TETHERING_ERROR_OPERATION_FAILED;
2707 *ssid = strdup(val);
2710 if (*ssid == NULL) {
2711 ERR("strdup is failed\n");
2712 return TETHERING_ERROR_OUT_OF_MEMORY;
2715 return TETHERING_ERROR_NONE;
2720 * @brief Sets the visibility of SSID(service set identifier).
2722 * @privlevel platform
2723 * @privilege http://tizen.org/privilege/tethering.admin
2724 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2725 * @remarks This change is applied next time Wi-Fi tethering is enabled
2726 * @param[in] tethering The handle of tethering
2727 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2728 * @return 0 on success, otherwise negative error value.
2729 * @retval #TETHERING_ERROR_NONE Successful
2730 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2731 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2732 * @see tethering_wifi_get_ssid_visibility()
2734 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2736 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2738 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2739 "parameter(tethering) is NULL\n");
2741 __tethering_h *th = (__tethering_h *)tethering;
2742 tethering_error_e ret = TETHERING_ERROR_NONE;
2744 ret = __set_visible(visible);
2745 if (ret == TETHERING_ERROR_NONE) {
2747 __send_dbus_signal(th->client_bus,
2748 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2749 visible ? SIGNAL_MSG_SSID_VISIBLE :
2750 SIGNAL_MSG_SSID_HIDE);
2757 * @brief Gets the visibility of SSID(service set identifier).
2759 * @privlevel platform
2760 * @privilege http://tizen.org/privilege/tethering.admin
2761 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2762 * @param[in] tethering The handle of tethering
2763 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2764 * @return 0 on success, otherwise negative error value.
2765 * @retval #TETHERING_ERROR_NONE Successful
2766 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2767 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2768 * @see tethering_wifi_set_ssid_visibility()
2770 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2772 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2774 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2775 "parameter(visible) is NULL\n");
2777 return __get_visible(visible);
2782 * @brief Sets the passphrase.
2784 * @privlevel platform
2785 * @privilege http://tizen.org/privilege/tethering.admin
2786 * @remarks This change is applied next time Wi-Fi tethering is enabled
2787 * @param[in] tethering The handle of tethering
2788 * @param[in] passphrase The passphrase
2789 * @return 0 on success, otherwise negative error value.
2790 * @retval #TETHERING_ERROR_NONE Successful
2791 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2792 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2793 * @see tethering_wifi_get_passphrase()
2795 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2797 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2799 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2800 "parameter(tethering) is NULL\n");
2801 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2802 "parameter(passphrase) is NULL\n");
2804 __tethering_h *th = (__tethering_h *)tethering;
2805 GDBusProxy *proxy = th->client_bus_proxy;
2806 GVariant *parameters;
2807 GError *error = NULL;
2808 int passphrase_len = 0;
2812 passphrase_len = strlen(passphrase);
2813 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
2814 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
2815 ERR("parameter(passphrase) is too short or long\n");
2816 return TETHERING_ERROR_INVALID_PARAMETER;
2819 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
2820 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2824 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2826 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2827 ret = TETHERING_ERROR_PERMISSION_DENIED;
2829 ret = TETHERING_ERROR_OPERATION_FAILED;
2831 g_error_free(error);
2836 g_variant_get(parameters, "(u)", &ret);
2837 g_variant_unref(parameters);
2839 if (ret == TETHERING_ERROR_NONE) {
2840 __send_dbus_signal(th->client_bus,
2841 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
2850 * @brief Gets the passphrase.
2852 * @privlevel platform
2853 * @privilege http://tizen.org/privilege/tethering.admin
2854 * @remarks @a passphrase must be released with free() by you.
2855 * @param[in] tethering The handle of tethering
2856 * @param[out] passphrase The passphrase
2857 * @return 0 on success, otherwise negative error value.
2858 * @retval #TETHERING_ERROR_NONE Successful
2859 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2860 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2861 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2862 * @see tethering_wifi_set_passphrase()
2864 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2866 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2868 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2869 "parameter(tethering) is NULL\n");
2870 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2871 "parameter(passphrase) is NULL\n");
2873 __tethering_h *th = (__tethering_h *)tethering;
2874 GDBusProxy *proxy = th->client_bus_proxy;
2875 GVariant *parameters;
2876 GError *error = NULL;
2877 unsigned int len = 0;
2878 tethering_error_e ret = TETHERING_ERROR_NONE;
2880 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
2881 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2885 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2887 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2888 ret = TETHERING_ERROR_PERMISSION_DENIED;
2890 ret = TETHERING_ERROR_OPERATION_FAILED;
2892 g_error_free(error);
2897 if (parameters != NULL) {
2898 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
2899 g_variant_unref(parameters);
2902 return TETHERING_ERROR_NONE;
2905 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
2907 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2908 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2909 "parameter(tethering) is NULL\n");
2911 __tethering_h *th = (__tethering_h *)tethering;
2912 th->channel = channel;
2914 return TETHERING_ERROR_NONE;
2917 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
2919 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2920 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2921 "parameter(tethering) is NULL\n");
2923 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2924 "parameter(channel) is NULL\n");
2926 __tethering_h *th = (__tethering_h *)tethering;
2927 *channel = th->channel;
2929 return TETHERING_ERROR_NONE;
2932 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
2934 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2935 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2936 "parameter(tethering) is NULL\n");
2938 __tethering_h *th = (__tethering_h *)tethering;
2940 th->mode_type = type;
2942 return TETHERING_ERROR_NONE;
2945 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
2947 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2948 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2949 "parameter(tethering) is NULL\n");
2950 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2951 "parameter(type) is NULL\n");
2953 __tethering_h *th = (__tethering_h *)tethering;
2954 *type = th->mode_type;
2956 return TETHERING_ERROR_NONE;
2962 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
2964 * @privlevel platform
2965 * @privilege http://tizen.org/privilege/tethering.admin
2966 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
2967 * @param[in] tethering The handle of tethering
2968 * @param[in] callback The callback function to invoke
2969 * @param[in] user_data The user data to be passed to the callback function
2970 * @return 0 on success, otherwise negative error value.
2971 * @retval #TETHERING_ERROR_NONE Successful
2972 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2973 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2975 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
2978 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2980 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2981 "parameter(tethering) is NULL\n");
2982 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2983 "parameter(callback) is NULL\n");
2985 __tethering_h *th = (__tethering_h *)tethering;
2986 _softap_settings_t set = {"", "", "", 0, false};
2987 GDBusProxy *proxy = th->client_bus_proxy;
2992 if (th->settings_reloaded_cb) {
2993 ERR("Operation in progress\n");
2994 return TETHERING_ERROR_OPERATION_FAILED;
2997 ret = __prepare_wifi_settings(tethering, &set);
2998 if (ret != TETHERING_ERROR_NONE) {
2999 ERR("softap settings initialization failed\n");
3000 return TETHERING_ERROR_OPERATION_FAILED;
3003 th->settings_reloaded_cb = callback;
3004 th->settings_reloaded_user_data = user_data;
3006 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3007 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
3008 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3009 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3011 return TETHERING_ERROR_NONE;
3014 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3016 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3018 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3019 "parameter(tethering) is NULL\n");
3021 __tethering_h *th = (__tethering_h *)tethering;
3022 th->mac_filter = mac_filter;
3024 return TETHERING_ERROR_NONE;
3027 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3029 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3031 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3032 "parameter(mac_filter) is NULL\n");
3033 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3034 "parameter(mac_filter) is NULL\n");
3036 __tethering_h *th = (__tethering_h *)tethering;
3037 *mac_filter = th->mac_filter;
3039 return TETHERING_ERROR_NONE;
3042 static int __add_mac_to_file(const char *filepath, const char *mac)
3045 char line[MAX_BUF_SIZE] = "\0";
3046 bool mac_exist = false;
3049 p_mac = strdup(mac);
3050 if (p_mac == NULL) {
3051 ERR("strdup failed\n");
3052 return TETHERING_ERROR_OUT_OF_MEMORY;
3055 fp = fopen(filepath, "a+");
3057 ERR("fopen is failed\n");
3058 return TETHERING_ERROR_OPERATION_FAILED;
3061 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3062 if (strncmp(mac, line, 17) == 0) {
3063 DBG("MAC %s already exist in the list\n", mac);
3070 fprintf(fp, "%s\n", mac);
3072 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3073 allowed_list = g_slist_append(allowed_list, p_mac);
3074 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3075 blocked_list = g_slist_append(blocked_list, p_mac);
3080 return TETHERING_ERROR_NONE;
3083 static int __remove_mac_from_file(const char *filepath, const char *mac)
3087 char line[MAX_BUF_SIZE] = "\0";
3089 fp = fopen(filepath, "r");
3091 ERR("fopen is failed\n");
3092 return TETHERING_ERROR_OPERATION_FAILED;
3095 fp1 = fopen(TEMP_LIST, "w+");
3098 ERR("fopen is failed\n");
3099 return TETHERING_ERROR_OPERATION_FAILED;
3102 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3103 if (strncmp(mac, line, 17) == 0) {
3104 DBG("MAC %s found in the list\n", mac);
3106 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3107 GSList *list = NULL;
3108 for (list = allowed_list; list != NULL; list = list->next) {
3109 char *p_mac = (char *)list->data;
3110 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3111 allowed_list = g_slist_remove(allowed_list, p_mac);
3113 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3114 GSList *list = NULL;
3115 for (list = blocked_list; list != NULL; list = list->next) {
3116 char *p_mac = (char *)list->data;
3117 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3118 blocked_list = g_slist_remove(blocked_list, p_mac);
3122 fprintf(fp1, "%s", line);
3129 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3130 rename(TEMP_LIST, ALLOWED_LIST);
3131 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3132 rename(TEMP_LIST, BLOCKED_LIST);
3134 return TETHERING_ERROR_NONE;
3137 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3139 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3141 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3142 "parameter(tethering) is NULL\n");
3143 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3144 "parameter(mac) is NULL\n");
3146 return __add_mac_to_file(ALLOWED_LIST, mac);
3149 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3151 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3152 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3153 "parameter(tethering) is NULL\n");
3154 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3155 "parameter(mac) is NULL\n");
3157 return __remove_mac_from_file(ALLOWED_LIST, mac);
3160 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3162 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3163 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3164 "parameter(tethering) is NULL\n");
3165 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3166 "parameter(allowed_mac_list) is NULL\n");
3168 *allowed_mac_list = g_slist_copy(allowed_list);
3169 return TETHERING_ERROR_NONE;
3172 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3174 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3175 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3176 "parameter(tethering) is NULL\n");
3177 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3178 "parameter(mac) is NULL\n");
3180 return __add_mac_to_file(BLOCKED_LIST, mac);
3183 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3185 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3186 "parameter(tethering) is NULL\n");
3187 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3188 "parameter(mac) is NULL\n");
3190 return __remove_mac_from_file(BLOCKED_LIST, mac);
3193 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3195 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3197 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3198 "parameter(tethering) is NULL\n");
3199 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3200 "parameter(blocked_mac_list) is NULL\n");
3202 *blocked_mac_list = g_slist_copy(blocked_list);
3203 return TETHERING_ERROR_NONE;
3206 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3208 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3210 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3211 "parameter(tethering) is NULL\n");
3213 GVariant *parameters;
3214 GError *error = NULL;
3217 __tethering_h *th = (__tethering_h *)tethering;
3219 GDBusProxy *proxy = th->client_bus_proxy;
3221 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3222 g_variant_new("(b)", enable),
3223 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3226 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3227 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3228 result = TETHERING_ERROR_PERMISSION_DENIED;
3230 result = TETHERING_ERROR_OPERATION_FAILED;
3232 g_error_free(error);
3233 th->dhcp_enabled = false;
3238 g_variant_get(parameters, "(u)", &result);
3239 g_variant_unref(parameters);
3242 th->dhcp_enabled = true;
3244 th->dhcp_enabled = false;
3246 return TETHERING_ERROR_NONE;
3249 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3251 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3253 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3254 "parameter(tethering) is NULL\n");
3255 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3256 "parameter(rangestart) is NULL\n");
3257 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3258 "parameter(rangestop) is NULL\n");
3260 GVariant *parameters;
3261 GError *error = NULL;
3264 __tethering_h *th = (__tethering_h *)tethering;
3266 GDBusProxy *proxy = th->client_bus_proxy;
3268 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3269 g_variant_new("(ss)", rangestart, rangestop),
3270 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3272 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3274 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3275 result = TETHERING_ERROR_PERMISSION_DENIED;
3277 result = TETHERING_ERROR_OPERATION_FAILED;
3279 g_error_free(error);
3280 th->dhcp_enabled = false;
3285 g_variant_get(parameters, "(u)", &result);
3286 g_variant_unref(parameters);
3288 th->dhcp_enabled = true;
3290 return TETHERING_ERROR_NONE;
3293 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3295 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3296 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3297 "parameter(tethering) is NULL\n");
3298 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3299 "parameter(dhcp_enabled) is NULL\n");
3301 __tethering_h *th = (__tethering_h *)tethering;
3302 *dhcp_enabled = th->dhcp_enabled;
3304 return TETHERING_ERROR_NONE;
3307 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3309 GError *error = NULL;
3310 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3312 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3313 "parameter(tethering) is NULL\n");
3314 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3315 TETHERING_ERROR_NOT_ENABLED,
3316 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3317 __tethering_h *th = (__tethering_h *)tethering;
3319 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3320 g_variant_new("(u)", txpower),
3321 G_DBUS_CALL_FLAGS_NONE,
3322 -1, th->cancellable, &error);
3324 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3325 g_clear_error(&error);
3326 return TETHERING_ERROR_OPERATION_FAILED;
3328 return TETHERING_ERROR_NONE;
3331 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3333 GError *error = NULL;
3334 GVariant *result = NULL;
3335 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3337 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3338 "parameter(tethering) is NULL\n");
3339 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3340 TETHERING_ERROR_NOT_ENABLED,
3341 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3343 __tethering_h *th = (__tethering_h *)tethering;
3345 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3347 G_DBUS_CALL_FLAGS_NONE,
3348 -1, th->cancellable, &error);
3350 if (result != NULL) {
3351 g_variant_get(result, "(u)", txpower);
3352 g_variant_unref(result);
3355 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3356 g_clear_error(&error);
3357 return TETHERING_ERROR_OPERATION_FAILED;
3359 g_clear_error(&error);
3360 return TETHERING_ERROR_NONE;