2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
24 #include <arpa/inet.h>
26 #include <dbus/dbus.h>
29 #include <openssl/evp.h>
30 #include <openssl/sha.h>
31 #include <ckmc/ckmc-manager.h>
32 #include "tethering_private.h"
34 #define ALLOWED_LIST "/etc/hostapd.accept"
35 #define BLOCKED_LIST "/etc/hostapd.deny"
36 #define TEMP_LIST "/etc/hostapd_tmp"
37 #define MAC_ADDR_LEN 18
38 #define MAX_BUF_SIZE 80
40 static GSList *allowed_list = NULL;
41 static GSList *blocked_list = NULL;
43 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
44 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
45 GVariant *parameters, gpointer user_data);
47 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
48 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
49 GVariant *parameters, gpointer user_data);
51 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
52 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
53 GVariant *parameters, gpointer user_data);
55 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
56 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
57 GVariant *parameters, gpointer user_data);
59 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
60 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
61 GVariant *parameters, gpointer user_data);
63 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
64 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
65 GVariant *parameters, gpointer user_data);
67 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
68 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
69 GVariant *parameters, gpointer user_data);
71 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
72 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
73 GVariant *parameters, gpointer user_data);
75 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
76 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
77 GVariant *parameters, gpointer user_data);
79 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
80 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
81 GVariant *parameters, gpointer user_data);
83 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
84 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
85 GVariant *parameters, gpointer user_data);
87 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
88 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
89 GVariant *parameters, gpointer user_data);
91 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
92 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
93 GVariant *parameters, gpointer user_data);
95 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
96 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
97 GVariant *parameters, gpointer user_data);
99 static __tethering_sig_t sigs[] = {
100 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
101 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
102 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
103 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
104 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
105 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
106 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
107 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
108 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
109 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
110 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
111 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
112 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
113 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
116 static int retry = 0;
118 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
120 if (conn == NULL || signal_name == NULL)
123 GVariant *message = NULL;
124 GError *error = NULL;
127 message = g_variant_new("(s)", arg);
129 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
130 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
132 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
135 g_variant_unref(message);
138 static bool __any_tethering_is_enabled(tethering_h tethering)
140 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
141 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
142 tethering_is_enabled(tethering, TETHERING_TYPE_BT))
148 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
150 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
151 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
152 ERR("Invalid param\n");
153 return TETHERING_ERROR_INVALID_PARAMETER;
156 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
157 ERR("vconf_set_int is failed\n");
158 return TETHERING_ERROR_OPERATION_FAILED;
161 return TETHERING_ERROR_NONE;
164 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
166 if (security_type == NULL) {
167 ERR("Invalid param\n");
168 return TETHERING_ERROR_INVALID_PARAMETER;
171 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
172 (int *)security_type) < 0) {
173 ERR("vconf_get_int is failed\n");
174 return TETHERING_ERROR_OPERATION_FAILED;
177 return TETHERING_ERROR_NONE;
180 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
182 if (path == NULL || ssid == NULL || size == 0)
186 char *ptr_tmp = NULL;
188 ptr = vconf_get_str(path);
192 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
195 g_strlcpy(ssid, ptr, size);
201 static tethering_error_e __set_visible(const bool visible)
203 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
204 ERR("vconf_set_int is failed\n");
205 return TETHERING_ERROR_OPERATION_FAILED;
208 return TETHERING_ERROR_NONE;
211 static tethering_error_e __get_visible(bool *visible)
213 if (visible == NULL) {
214 ERR("Invalid param\n");
215 return TETHERING_ERROR_INVALID_PARAMETER;
220 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
221 ERR("vconf_get_int is failed\n");
222 return TETHERING_ERROR_OPERATION_FAILED;
229 return TETHERING_ERROR_NONE;
232 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
234 if (passphrase == NULL ||
235 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
238 guint32 rand_int = 0;
241 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
242 rand_int = g_random_int_range('a', 'z');
243 passphrase[index] = rand_int;
245 passphrase[index] = '\0';
250 static tethering_error_e __get_error(int agent_error)
252 tethering_error_e err = TETHERING_ERROR_NONE;
254 switch (agent_error) {
255 case MOBILE_AP_ERROR_NONE:
256 err = TETHERING_ERROR_NONE;
259 case MOBILE_AP_ERROR_RESOURCE:
260 err = TETHERING_ERROR_OUT_OF_MEMORY;
263 case MOBILE_AP_ERROR_INTERNAL:
264 err = TETHERING_ERROR_OPERATION_FAILED;
267 case MOBILE_AP_ERROR_INVALID_PARAM:
268 err = TETHERING_ERROR_INVALID_PARAMETER;
271 case MOBILE_AP_ERROR_ALREADY_ENABLED:
272 err = TETHERING_ERROR_OPERATION_FAILED;
275 case MOBILE_AP_ERROR_NOT_ENABLED:
276 err = TETHERING_ERROR_NOT_ENABLED;
279 case MOBILE_AP_ERROR_NET_OPEN:
280 err = TETHERING_ERROR_OPERATION_FAILED;
283 case MOBILE_AP_ERROR_NET_CLOSE:
284 err = TETHERING_ERROR_OPERATION_FAILED;
287 case MOBILE_AP_ERROR_DHCP:
288 err = TETHERING_ERROR_OPERATION_FAILED;
291 case MOBILE_AP_ERROR_IN_PROGRESS:
292 err = TETHERING_ERROR_OPERATION_FAILED;
295 case MOBILE_AP_ERROR_NOT_PERMITTED:
296 err = TETHERING_ERROR_NOT_PERMITTED;
299 case MOBILE_AP_ERROR_PERMISSION_DENIED:
300 err = TETHERING_ERROR_PERMISSION_DENIED;
304 ERR("Not defined error : %d\n", agent_error);
305 err = TETHERING_ERROR_OPERATION_FAILED;
312 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
313 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
314 GVariant *parameters, gpointer user_data)
318 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
320 __tethering_h *th = (__tethering_h *)user_data;
322 tethering_type_e type = 0;
323 mobile_ap_type_e ap_type = 0;
324 tethering_connection_state_changed_cb ccb = NULL;
325 __tethering_client_h client;
333 memset(&client, 0, sizeof(__tethering_client_h));
334 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
336 if (!g_strcmp0(buf, "DhcpConnected")) {
338 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
341 ERR("Unknown event [%s]\n", buf);
345 if (ap_type == MOBILE_AP_TYPE_USB)
346 type = TETHERING_TYPE_USB;
347 else if (ap_type == MOBILE_AP_TYPE_WIFI)
348 type = TETHERING_TYPE_WIFI;
349 else if (ap_type == MOBILE_AP_TYPE_BT)
350 type = TETHERING_TYPE_BT;
352 ERR("Not supported tethering type [%d]\n", ap_type);
356 ccb = th->changed_cb[type];
359 data = th->changed_user_data[type];
361 client.interface = type;
362 g_strlcpy(client.ip, ip, sizeof(client.ip));
363 g_strlcpy(client.mac, mac, sizeof(client.mac));
365 client.hostname = g_strdup(name);
366 client.tm = (time_t)timestamp;
368 ccb((tethering_client_h)&client, opened, data);
369 g_free(client.hostname);
378 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
379 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
380 GVariant *parameters, gpointer user_data)
384 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
386 __tethering_h *th = (__tethering_h *)user_data;
387 tethering_type_e type = 0;
388 tethering_disabled_cb dcb = NULL;
390 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
392 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
393 dcb = th->disabled_cb[type];
396 data = th->disabled_user_data[type];
398 dcb(TETHERING_ERROR_NONE, type, code, data);
404 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
405 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
406 GVariant *parameters, gpointer user_data)
410 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
412 __tethering_h *th = (__tethering_h *)user_data;
413 tethering_type_e type = TETHERING_TYPE_WIFI;
414 bool is_requested = false;
415 tethering_enabled_cb ecb = NULL;
418 ecb = th->enabled_cb[type];
421 data = th->enabled_user_data[type];
423 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
427 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
428 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
429 GVariant *parameters, gpointer user_data)
433 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
435 __tethering_h *th = (__tethering_h *)user_data;
436 tethering_type_e type = TETHERING_TYPE_WIFI;
437 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
438 tethering_disabled_cb dcb = NULL;
442 dcb = th->disabled_cb[type];
445 data = th->disabled_user_data[type];
446 g_variant_get(parameters, "(s)", &buf);
447 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
448 code = TETHERING_DISABLED_BY_WIFI_ON;
449 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
450 code = TETHERING_DISABLED_BY_TIMEOUT;
453 dcb(TETHERING_ERROR_NONE, type, code, data);
458 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
459 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
460 GVariant *parameters, gpointer user_data)
464 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
466 __tethering_h *th = (__tethering_h *)user_data;
467 tethering_type_e type = TETHERING_TYPE_USB;
468 bool is_requested = false;
469 tethering_enabled_cb ecb = NULL;
472 ecb = th->enabled_cb[type];
475 data = th->enabled_user_data[type];
477 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
481 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
482 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
483 GVariant *parameters, gpointer user_data)
487 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
489 __tethering_h *th = (__tethering_h *)user_data;
490 tethering_type_e type = TETHERING_TYPE_USB;
491 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
492 tethering_disabled_cb dcb = NULL;
496 dcb = th->disabled_cb[type];
499 data = th->disabled_user_data[type];
501 g_variant_get(parameters, "(s)", &buf);
502 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
503 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
505 dcb(TETHERING_ERROR_NONE, type, code, data);
510 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
511 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
512 GVariant *parameters, gpointer user_data)
516 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
518 __tethering_h *th = (__tethering_h *)user_data;
519 tethering_type_e type = TETHERING_TYPE_BT;
520 bool is_requested = false;
521 tethering_enabled_cb ecb = NULL;
524 ecb = th->enabled_cb[type];
527 data = th->enabled_user_data[type];
529 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
533 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
534 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
535 GVariant *parameters, gpointer user_data)
539 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
541 __tethering_h *th = (__tethering_h *)user_data;
542 tethering_type_e type = TETHERING_TYPE_BT;
543 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
544 tethering_disabled_cb dcb = NULL;
548 dcb = th->disabled_cb[type];
551 data = th->disabled_user_data[type];
552 g_variant_get(parameters, "(s)", &buf);
553 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
554 code = TETHERING_DISABLED_BY_BT_OFF;
555 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
556 code = TETHERING_DISABLED_BY_TIMEOUT;
558 dcb(TETHERING_ERROR_NONE, type, code, data);
564 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
565 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
566 GVariant *parameters, gpointer user_data)
570 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
572 __tethering_h *th = (__tethering_h *)user_data;
573 tethering_type_e type = 0;
574 tethering_disabled_cb dcb = NULL;
576 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
578 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
579 dcb = th->disabled_cb[type];
582 data = th->disabled_user_data[type];
584 dcb(TETHERING_ERROR_NONE, type, code, data);
589 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
590 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
591 GVariant *parameters, gpointer user_data)
595 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
597 __tethering_h *th = (__tethering_h *)user_data;
598 tethering_type_e type = 0;
599 tethering_disabled_cb dcb = NULL;
601 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
603 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
604 dcb = th->disabled_cb[type];
607 data = th->disabled_user_data[type];
609 dcb(TETHERING_ERROR_NONE, type, code, data);
614 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
615 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
616 GVariant *parameters, gpointer user_data)
620 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
622 __tethering_h *th = (__tethering_h *)user_data;
623 tethering_type_e type = 0;
624 tethering_disabled_cb dcb = NULL;
626 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
628 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
629 dcb = th->disabled_cb[type];
632 data = th->disabled_user_data[type];
634 dcb(TETHERING_ERROR_NONE, type, code, data);
639 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
640 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
641 GVariant *parameters, gpointer user_data)
646 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
647 __tethering_h *th = (__tethering_h *)user_data;
649 tethering_wifi_security_type_changed_cb scb = NULL;
651 tethering_wifi_security_type_e security_type;
654 scb = th->security_type_changed_cb;
658 g_variant_get(parameters, "(s)", &buf);
659 data = th->security_type_user_data;
660 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
661 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
662 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
663 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
665 SERR("Unknown type : %s\n", buf);
670 scb(security_type, data);
675 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
676 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
677 GVariant *parameters, gpointer user_data)
681 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
682 __tethering_h *th = (__tethering_h *)user_data;
684 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
686 bool visible = false;
689 scb = th->ssid_visibility_changed_cb;
694 g_variant_get(parameters, "(s)", &buf);
695 data = th->ssid_visibility_user_data;
696 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
704 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
705 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
706 GVariant *parameters, gpointer user_data)
710 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
711 __tethering_h *th = (__tethering_h *)user_data;
713 tethering_wifi_passphrase_changed_cb pcb = NULL;
716 pcb = th->passphrase_changed_cb;
720 data = th->passphrase_user_data;
726 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
731 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
732 GError *g_error = NULL;
735 tethering_error_e error;
736 __tethering_h *th = (__tethering_h *)user_data;
737 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
738 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
740 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
742 ERR("DBus error [%s]\n", g_error->message);
743 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
744 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
745 g_error_free(g_error);
746 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
748 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
749 error = TETHERING_ERROR_PERMISSION_DENIED;
751 error = TETHERING_ERROR_OPERATION_FAILED;
752 g_error_free(g_error);
754 g_variant_get(g_var, "(u)", &info);
755 error = __get_error(info);
759 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
760 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
761 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
762 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
768 ecb(error, TETHERING_TYPE_WIFI, true, data);
769 g_variant_unref(g_var);
773 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
777 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
778 GError *g_error = NULL;
781 tethering_error_e error;
783 __tethering_h *th = (__tethering_h *)user_data;
784 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
785 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
787 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
789 ERR("DBus error [%s]\n", g_error->message);
790 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
791 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
792 g_error_free(g_error);
793 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
797 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
798 error = TETHERING_ERROR_PERMISSION_DENIED;
800 error = TETHERING_ERROR_OPERATION_FAILED;
801 g_error_free(g_error);
803 g_variant_get(g_var, "(u)", &info);
804 g_variant_unref(g_var);
805 error = __get_error(info);
809 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
810 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
811 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
812 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
819 ecb(error, TETHERING_TYPE_BT, true, data);
823 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
828 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
829 __tethering_h *th = (__tethering_h *)user_data;
830 GError *g_error = NULL;
833 tethering_error_e error;
834 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
835 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
837 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
839 ERR("DBus error [%s]\n", g_error->message);
840 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
841 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
842 g_error_free(g_error);
843 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
847 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
848 error = TETHERING_ERROR_PERMISSION_DENIED;
850 error = TETHERING_ERROR_OPERATION_FAILED;
851 g_error_free(g_error);
853 g_variant_get(g_var, "(u)", &info);
854 g_variant_unref(g_var);
855 error = __get_error(info);
859 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
860 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
861 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
862 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
869 ecb(error, TETHERING_TYPE_USB, true, data);
873 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
878 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
879 GError *g_error = NULL;
881 guint info, event_type;
882 tethering_error_e error;
883 tethering_type_e type;
884 tethering_h tethering = (tethering_h)user_data;
885 __tethering_h *th = (__tethering_h *)tethering;
886 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
887 tethering_disabled_cb dcb = NULL;
890 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
892 ERR("DBus error [%s]\n", g_error->message);
893 g_error_free(g_error);
896 g_variant_get(g_var, "(uu)", &event_type, &info);
897 DBG("cfm event : %d info : %d\n", event_type, info);
898 g_variant_unref(g_var);
899 error = __get_error(info);
900 DBG("cfm event : %d info : %d\n", event_type, error);
901 switch (event_type) {
902 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
903 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
904 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
905 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
906 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
908 type = TETHERING_TYPE_WIFI;
909 dcb = th->disabled_cb[type];
910 data = th->disabled_user_data[type];
912 dcb(error, type, code, data);
915 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
916 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
917 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
918 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
919 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
921 type = TETHERING_TYPE_BT;
922 dcb = th->disabled_cb[type];
923 data = th->disabled_user_data[type];
925 dcb(error, type, code, data);
928 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
929 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
930 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
931 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
932 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
934 type = TETHERING_TYPE_USB;
935 dcb = th->disabled_cb[type];
936 data = th->disabled_user_data[type];
938 dcb(error, type, code, data);
941 case MOBILE_AP_DISABLE_CFM:
943 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
944 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
945 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
946 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
947 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
948 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
949 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
950 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
951 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
952 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
953 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
954 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
956 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
957 dcb = th->disabled_cb[type];
960 data = th->disabled_user_data[type];
962 dcb(error, type, code, data);
967 ERR("Invalid event\n");
973 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
978 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
980 GError *g_error = NULL;
983 guint64 tx_bytes, rx_bytes;
984 __tethering_h *th = (__tethering_h *)user_data;
985 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
988 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
990 ERR("DBus fail [%s]\n", g_error->message);
991 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
992 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
994 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
998 if (th->data_usage_cb == NULL) {
999 ERR("There is no data_usage_cb\n");
1003 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1005 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1006 th->data_usage_cb(TETHERING_ERROR_NONE,
1007 rx_bytes, tx_bytes, th->data_usage_user_data);
1008 g_variant_unref(g_var);
1010 th->data_usage_cb = NULL;
1011 th->data_usage_user_data = NULL;
1016 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1021 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1022 GError *g_error = NULL;
1025 __tethering_h *th = (__tethering_h *)user_data;
1026 tethering_error_e tethering_error;
1028 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1030 ERR("DBus fail [%s]\n", g_error->message);
1031 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1032 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1034 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1035 g_error_free(g_error);
1037 if (th->settings_reloaded_cb == NULL) {
1038 DBG("There is no settings_reloaded_cb\n-\n");
1041 g_variant_get(g_var, "(u)", &info);
1042 tethering_error = __get_error(info);
1043 g_variant_unref(g_var);
1045 th->settings_reloaded_cb(tethering_error,
1046 th->settings_reloaded_user_data);
1048 th->settings_reloaded_cb = NULL;
1049 th->settings_reloaded_user_data = NULL;
1053 static void __connect_signals(tethering_h tethering)
1056 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1058 __tethering_h *th = (__tethering_h *)tethering;
1059 GDBusConnection *connection = th->client_bus;
1062 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1063 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1064 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1065 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1066 sigs[i].cb, tethering, NULL);
1071 static void __disconnect_signals(tethering_h tethering)
1075 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1077 __tethering_h *th = (__tethering_h *)tethering;
1078 GDBusConnection *connection = th->client_bus;
1082 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1083 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1089 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1091 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1094 case TETHERING_TYPE_USB:
1095 g_strlcpy(buf, TETHERING_USB_IF, len);
1098 case TETHERING_TYPE_WIFI:
1099 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1102 case TETHERING_TYPE_BT:
1103 g_strlcpy(buf, TETHERING_BT_IF, len);
1107 ERR("Not supported type : %d\n", type);
1113 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1115 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1118 case TETHERING_TYPE_USB:
1119 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1122 case TETHERING_TYPE_WIFI:
1123 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1126 case TETHERING_TYPE_BT:
1127 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1131 ERR("Not supported type : %d\n", type);
1137 static int __get_common_ssid(char *ssid, unsigned int size)
1140 ERR("ssid is null\n");
1141 return TETHERING_ERROR_INVALID_PARAMETER;
1145 char *ptr_tmp = NULL;
1147 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1149 ERR("vconf_get_str is failed and set default ssid");
1150 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1152 g_strlcpy(ssid, ptr, size);
1156 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1159 return TETHERING_ERROR_NONE;
1162 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1164 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1167 case TETHERING_WIFI_MODE_TYPE_B:
1168 *buf = g_strdup("b");
1170 case TETHERING_WIFI_MODE_TYPE_G:
1171 *buf = g_strdup("g");
1173 case TETHERING_WIFI_MODE_TYPE_A:
1174 *buf = g_strdup("a");
1176 case TETHERING_WIFI_MODE_TYPE_AD:
1177 *buf = g_strdup("ad");
1180 ERR("Not supported type : %d\n", type);
1186 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1190 __tethering_h *th = (__tethering_h *)tethering;
1191 tethering_error_e ret = TETHERING_ERROR_NONE;
1194 if (th == NULL || set == NULL) {
1195 ERR("null parameter\n-\n");
1196 return TETHERING_ERROR_INVALID_PARAMETER;
1199 if (th->ssid == NULL)
1200 __get_common_ssid(set->ssid, sizeof(set->ssid));
1202 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1204 ret = __get_security_type(&set->sec_type);
1205 if (ret != TETHERING_ERROR_NONE)
1206 set->sec_type = th->sec_type;
1208 ret = __get_visible(&set->visibility);
1209 if (ret != TETHERING_ERROR_NONE)
1210 set->visibility = th->visibility;
1212 set->mac_filter = th->mac_filter;
1213 set->channel = th->channel;
1215 __get_wifi_mode_type(th->mode_type, &ptr);
1217 g_strlcpy(set->mode, "", sizeof(set->mode));
1219 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1223 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1224 g_strlcpy(set->key, "", sizeof(set->key));
1226 GDBusProxy *proxy = th->client_bus_proxy;
1227 GVariant *parameters;
1228 GError *error = NULL;
1229 char *passphrase = NULL;
1230 unsigned int len = 0;
1232 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1233 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1236 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1238 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1239 ret = TETHERING_ERROR_PERMISSION_DENIED;
1241 ret = TETHERING_ERROR_OPERATION_FAILED;
1243 g_error_free(error);
1247 if (parameters != NULL) {
1248 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1249 g_variant_unref(parameters);
1252 g_strlcpy(set->key, passphrase, sizeof(set->key));
1255 return TETHERING_ERROR_NONE;
1258 static bool __check_precondition(tethering_type_e type)
1261 int cellular_state = 0;
1264 /* data network through cellular */
1265 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1266 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1267 ERR("Data Network can be connected later");
1271 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1272 if (dnet_state > VCONFKEY_DNET_OFF) {
1273 ERR("Data Network is connected");
1277 /* data network through wifi */
1278 if (type != TETHERING_TYPE_WIFI) {
1279 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1280 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1281 ERR("Wi-Fi is connected!");
1286 ERR("Network is not available!");
1292 * @brief Creates the handle of tethering.
1294 * @privlevel platform
1295 * @privilege http://tizen.org/privilege/tethering.admin
1296 * @remarks The @a tethering must be released tethering_destroy() by you.
1297 * @param[out] tethering A handle of a new mobile ap handle on success
1298 * @return 0 on success, otherwise a negative error value.
1299 * @retval #TETHERING_ERROR_NONE Successful
1300 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1301 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1302 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1303 * @see tethering_destroy()
1305 API int tethering_create(tethering_h *tethering)
1307 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1308 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1309 "parameter(tethering) is NULL\n");
1312 __tethering_h *th = NULL;
1313 GError *error = NULL;
1314 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1316 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1318 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1319 "malloc is failed\n");
1320 memset(th, 0x00, sizeof(__tethering_h));
1321 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1322 th->visibility = true;
1323 th->mac_filter = false;
1325 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1327 if (__generate_initial_passphrase(th->passphrase,
1328 sizeof(th->passphrase)) == 0) {
1329 ERR("random passphrase generation failed\n");
1331 return TETHERING_ERROR_OPERATION_FAILED;
1334 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1335 ERR("common ssid get failed\n");
1337 return TETHERING_ERROR_OPERATION_FAILED;
1340 #if !GLIB_CHECK_VERSION(2, 36, 0)
1343 GCancellable *cancellable = g_cancellable_new();
1344 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1346 ERR("Couldn't connect to the System bus[%s]", error->message);
1347 g_error_free(error);
1348 g_cancellable_cancel(cancellable);
1349 g_object_unref(cancellable);
1351 return TETHERING_ERROR_OPERATION_FAILED;
1353 th->cancellable = cancellable;
1355 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1356 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1357 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1358 if (!th->client_bus_proxy) {
1360 ERR("Couldn't create the proxy object because of %s\n", error->message);
1361 g_cancellable_cancel(th->cancellable);
1362 g_object_unref(th->cancellable);
1363 g_object_unref(th->client_bus);
1365 return TETHERING_ERROR_OPERATION_FAILED;
1368 __connect_signals((tethering_h)th);
1370 *tethering = (tethering_h)th;
1371 DBG("Tethering Handle : 0x%X\n", th);
1373 return TETHERING_ERROR_NONE;
1378 * @brief Destroys the handle of tethering.
1380 * @privlevel platform
1381 * @privilege http://tizen.org/privilege/tethering.admin
1382 * @param[in] tethering The handle of tethering
1383 * @return 0 on success, otherwise a negative error value.
1384 * @retval #TETHERING_ERROR_NONE Successful
1385 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1386 * @see tethering_create()
1388 API int tethering_destroy(tethering_h tethering)
1391 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1392 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1393 "parameter(tethering) is NULL\n");
1395 __tethering_h *th = (__tethering_h *)tethering;
1397 DBG("Tethering Handle : 0x%X\n", th);
1398 __disconnect_signals(tethering);
1403 g_object_unref(th->cancellable);
1404 g_object_unref(th->client_bus_proxy);
1405 g_object_unref(th->client_bus);
1406 memset(th, 0x00, sizeof(__tethering_h));
1410 return TETHERING_ERROR_NONE;
1415 * @brief Enables the tethering, asynchronously.
1417 * @privlevel platform
1418 * @privilege http://tizen.org/privilege/tethering.admin
1419 * @param[in] tethering The handle of tethering
1420 * @param[in] type The type of tethering
1421 * @return 0 on success, otherwise negative error value.
1422 * @retval #TETHERING_ERROR_NONE Successful
1423 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1424 * @post tethering_enabled_cb() will be invoked.
1425 * @see tethering_is_enabled()
1426 * @see tethering_disable()
1428 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1430 DBG("+ type : %d\n", type);
1431 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1432 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1433 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1434 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1436 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1437 "parameter(tethering) is NULL\n");
1439 tethering_error_e ret = TETHERING_ERROR_NONE;
1440 __tethering_h *th = (__tethering_h *)tethering;
1441 GDBusProxy *proxy = th->client_bus_proxy;
1442 GDBusConnection *connection = th->client_bus;
1444 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1446 if (__check_precondition(type) == FALSE) {
1448 return TETHERING_ERROR_OPERATION_FAILED;
1452 case TETHERING_TYPE_USB:
1453 g_dbus_connection_signal_unsubscribe(connection,
1454 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1456 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1457 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1458 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1461 case TETHERING_TYPE_WIFI: {
1462 _softap_settings_t set = {"", "", "", 0, false};
1464 ret = __prepare_wifi_settings(tethering, &set);
1465 if (ret != TETHERING_ERROR_NONE) {
1466 ERR("softap settings initialization failed\n");
1468 return TETHERING_ERROR_OPERATION_FAILED;
1470 g_dbus_connection_signal_unsubscribe(connection,
1471 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1473 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1474 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
1475 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1476 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1480 case TETHERING_TYPE_BT:
1481 g_dbus_connection_signal_unsubscribe(connection,
1482 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1484 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1485 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1486 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1490 case TETHERING_TYPE_ALL: {
1491 _softap_settings_t set = {"", "", "", 0, false};
1493 ret = __prepare_wifi_settings(tethering, &set);
1494 if (ret != TETHERING_ERROR_NONE) {
1495 ERR("softap settings initialization failed\n");
1496 return TETHERING_ERROR_OPERATION_FAILED;
1499 /* TETHERING_TYPE_USB */
1500 g_dbus_connection_signal_unsubscribe(connection,
1501 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1503 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1504 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1505 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1507 /* TETHERING_TYPE_WIFI */
1508 g_dbus_connection_signal_unsubscribe(connection,
1509 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1511 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1512 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1513 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1514 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1516 /* TETHERING_TYPE_BT */
1517 g_dbus_connection_signal_unsubscribe(connection,
1518 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1520 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1521 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1522 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1526 ERR("Unknown type : %d\n", type);
1528 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1531 return TETHERING_ERROR_INVALID_PARAMETER;
1534 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1536 return TETHERING_ERROR_NONE;
1541 * @brief Disables the tethering, asynchronously.
1543 * @privlevel platform
1544 * @privilege http://tizen.org/privilege/tethering.admin
1545 * @param[in] tethering The handle of tethering
1546 * @param[in] type The type of tethering
1547 * @return 0 on success, otherwise negative error value.
1548 * @retval #TETHERING_ERROR_NONE Successful
1549 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1550 * @post tethering_disabled_cb() will be invoked.
1551 * @see tethering_is_enabled()
1552 * @see tethering_enable()
1554 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1556 DBG("+ type : %d\n", type);
1557 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1558 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1559 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1561 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1562 "parameter(tethering) is NULL\n");
1564 __tethering_h *th = (__tethering_h *)tethering;
1565 GDBusProxy *proxy = th->client_bus_proxy;
1566 GDBusConnection *connection = th->client_bus;
1569 case TETHERING_TYPE_USB:
1570 g_dbus_connection_signal_unsubscribe(connection,
1571 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1573 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1574 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1575 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1579 case TETHERING_TYPE_WIFI:
1581 g_dbus_connection_signal_unsubscribe(connection,
1582 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1584 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1585 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1586 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1589 case TETHERING_TYPE_BT:
1591 g_dbus_connection_signal_unsubscribe(connection,
1592 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1594 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1595 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1596 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1599 case TETHERING_TYPE_ALL:
1600 g_dbus_connection_signal_unsubscribe(connection,
1601 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1603 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1604 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1605 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1607 g_dbus_connection_signal_unsubscribe(connection,
1608 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1610 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1611 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1612 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1614 g_dbus_connection_signal_unsubscribe(connection,
1615 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1617 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1618 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1619 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1623 ERR("Not supported tethering type [%d]\n", type);
1625 return TETHERING_ERROR_INVALID_PARAMETER;
1628 return TETHERING_ERROR_NONE;
1633 * @brief Checks whetehr the tethering is enabled or not.
1635 * @privlevel platform
1636 * @privilege http://tizen.org/privilege/tethering.admin
1637 * @param[in] tethering The handle of tethering
1638 * @param[in] type The type of tethering
1639 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1641 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1644 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1646 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1648 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1652 case TETHERING_TYPE_USB:
1653 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1656 case TETHERING_TYPE_WIFI:
1657 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1660 case TETHERING_TYPE_BT:
1661 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1665 ERR("Not supported type : %d\n", type);
1668 return is_on & vconf_type ? true : false;
1673 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1675 * @privlevel platform
1676 * @privilege http://tizen.org/privilege/tethering.admin
1677 * @remarks @a mac_address must be released with free() by you.
1678 * @param[in] tethering The handle of tethering
1679 * @param[in] type The type of tethering
1680 * @param[out] mac_address The MAC address
1681 * @return 0 on success, otherwise a negative error value.
1682 * @retval #TETHERING_ERROR_NONE Successful
1683 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1684 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1685 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1686 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1687 * @pre tethering must be enabled.
1688 * @see tethering_is_enabled()
1689 * @see tethering_enable()
1691 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1693 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1694 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1695 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1697 _retvm_if(tethering_is_enabled(tethering, type) == false,
1698 TETHERING_ERROR_NOT_ENABLED,
1699 "tethering type[%d] is not enabled\n", type);
1700 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1701 "parameter(tethering) is NULL\n");
1702 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1703 "parameter(mac_address) is NULL\n");
1707 char *macbuf = NULL;
1709 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1710 TETHERING_ERROR_OPERATION_FAILED,
1711 "getting interface name is failed\n");
1713 s = socket(AF_INET, SOCK_DGRAM, 0);
1714 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1715 "getting socket is failed\n");
1716 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1717 ERR("getting mac is failed\n");
1719 return TETHERING_ERROR_OPERATION_FAILED;
1723 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1724 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1725 "Not enough memory\n");
1726 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1727 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1728 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1729 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1730 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1731 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1732 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1734 *mac_address = macbuf;
1736 return TETHERING_ERROR_NONE;
1741 * @brief Gets the name of network interface. For example, usb0.
1743 * @privlevel platform
1744 * @privilege http://tizen.org/privilege/tethering.admin
1745 * @remarks @a interface_name must be released with free() by you.
1746 * @param[in] tethering The handle of tethering
1747 * @param[in] type The type of tethering
1748 * @param[out] interface_name The name of network interface
1749 * @return 0 on success, otherwise negative error value.
1750 * @retval #TETHERING_ERROR_NONE Successful
1751 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1752 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1753 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1754 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1755 * @pre tethering must be enabled.
1756 * @see tethering_is_enabled()
1757 * @see tethering_enable()
1759 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1761 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1762 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1763 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1765 _retvm_if(tethering_is_enabled(tethering, type) == false,
1766 TETHERING_ERROR_NOT_ENABLED,
1767 "tethering type[%d] is not enabled\n", type);
1768 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1769 "parameter(tethering) is NULL\n");
1770 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1771 "parameter(interface_name) is NULL\n");
1773 char intf[TETHERING_STR_INFO_LEN] = {0, };
1775 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1776 TETHERING_ERROR_OPERATION_FAILED,
1777 "getting interface name is failed\n");
1778 *interface_name = strdup(intf);
1779 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1780 "Not enough memory\n");
1782 return TETHERING_ERROR_NONE;
1787 * @brief Gets the local IP address.
1789 * @privlevel platform
1790 * @privilege http://tizen.org/privilege/tethering.admin
1791 * @remarks @a ip_address must be released with free() by you.
1792 * @param[in] tethering The handle of tethering
1793 * @param[in] type The type of tethering
1794 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1795 * @param[out] ip_address The local IP address
1796 * @return 0 on success, otherwise negative error value.
1797 * @retval #TETHERING_ERROR_NONE Successful
1798 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1799 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1800 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1801 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1802 * @pre tethering must be enabled.
1803 * @see tethering_is_enabled()
1804 * @see tethering_enable()
1806 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1809 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1810 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1811 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1813 _retvm_if(tethering_is_enabled(tethering, type) == false,
1814 TETHERING_ERROR_NOT_ENABLED,
1815 "tethering type[%d] is not enabled\n", type);
1816 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1817 "parameter(tethering) is NULL\n");
1818 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1819 "parameter(ip_address) is NULL\n");
1825 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1826 TETHERING_ERROR_OPERATION_FAILED,
1827 "getting interface name is failed\n");
1829 s = socket(AF_INET, SOCK_DGRAM, 0);
1830 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1831 "getting socket is failed\n");
1832 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1833 ERR("ioctl is failed\n");
1835 return TETHERING_ERROR_OPERATION_FAILED;
1839 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1840 *ip_address = strdup(ipbuf);
1841 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1842 "Not enough memory\n");
1844 return TETHERING_ERROR_NONE;
1849 * @brief Gets the Gateway address.
1851 * @privlevel platform
1852 * @privilege http://tizen.org/privilege/tethering.admin
1853 * @remarks @a gateway_address must be released with free() by you.
1854 * @param[in] tethering The handle of tethering
1855 * @param[in] type The type of tethering
1856 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1857 * @param[out] gateway_address The local IP address
1858 * @return 0 on success, otherwise negative error value.
1859 * @retval #TETHERING_ERROR_NONE Successful
1860 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1861 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1862 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1863 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1864 * @pre tethering must be enabled.
1865 * @see tethering_is_enabled()
1866 * @see tethering_enable()
1868 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1871 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1872 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1873 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1875 _retvm_if(tethering_is_enabled(tethering, type) == false,
1876 TETHERING_ERROR_NOT_ENABLED,
1877 "tethering type[%d] is not enabled\n", type);
1878 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1879 "parameter(tethering) is NULL\n");
1880 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1881 "parameter(gateway_address) is NULL\n");
1883 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1885 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1886 TETHERING_ERROR_OPERATION_FAILED,
1887 "getting gateway address is failed\n");
1889 *gateway_address = strdup(gateway_buf);
1891 return TETHERING_ERROR_NONE;
1896 * @brief Gets the Subnet Mask.
1898 * @privlevel platform
1899 * @privilege http://tizen.org/privilege/tethering.admin
1900 * @remarks @a subnet_mask must be released with free() by you.
1901 * @param[in] tethering The handle of tethering
1902 * @param[in] type The type of tethering
1903 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1904 * @param[out] subnet_mask The local IP address
1905 * @return 0 on success, otherwise negative error value.
1906 * @retval #TETHERING_ERROR_NONE Successful
1907 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1908 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1909 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1910 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1911 * @pre tethering must be enabled.
1912 * @see tethering_is_enabled()
1913 * @see tethering_enable()
1915 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1917 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1918 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1919 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1921 _retvm_if(tethering_is_enabled(tethering, type) == false,
1922 TETHERING_ERROR_NOT_ENABLED,
1923 "tethering is not enabled\n");
1924 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1925 "parameter(tethering) is NULL\n");
1926 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1927 "parameter(subnet_mask) is NULL\n");
1929 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
1930 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1931 "Not enough memory\n");
1933 return TETHERING_ERROR_NONE;
1938 * @brief Gets the data usage.
1940 * @privlevel platform
1941 * @privilege http://tizen.org/privilege/tethering.admin
1942 * @param[in] tethering The handle of tethering
1943 * @param[out] usage The data usage
1944 * @return 0 on success, otherwise negative error value.
1945 * @retval #TETHERING_ERROR_NONE Successful
1946 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1947 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1948 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1949 * @pre tethering must be enabled.
1950 * @see tethering_is_enabled()
1951 * @see tethering_enable()
1953 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
1955 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1957 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1958 "parameter(tethering) is NULL\n");
1959 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1960 "parameter(callback) is NULL\n");
1961 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1962 TETHERING_ERROR_NOT_ENABLED,
1963 "tethering is not enabled\n");
1965 __tethering_h *th = (__tethering_h *)tethering;
1966 GDBusProxy *proxy = th->client_bus_proxy;
1968 th->data_usage_cb = callback;
1969 th->data_usage_user_data = user_data;
1971 g_dbus_proxy_call(proxy, "get_data_packet_usage",
1972 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1973 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
1975 return TETHERING_ERROR_NONE;
1980 * @brief Gets the client which is connected by tethering "type".
1982 * @privlevel platform
1983 * @privilege http://tizen.org/privilege/tethering.admin
1984 * @param[in] tethering The handle of tethering
1985 * @param[in] type The type of tethering
1986 * @param[in] callback The callback function to invoke
1987 * @param[in] user_data The user data to be passed to the callback function
1988 * @retval #TETHERING_ERROR_NONE Successful
1989 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1990 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1991 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1992 * @pre tethering must be enabled.
1993 * @see tethering_is_enabled()
1994 * @see tethering_enable()
1996 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
1999 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2000 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2001 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2003 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2004 "parameter(tethering) is NULL\n");
2005 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2006 "parameter(callback) is NULL\n");
2007 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2008 TETHERING_ERROR_NOT_ENABLED,
2009 "tethering is not enabled\n");
2011 mobile_ap_type_e interface;
2012 __tethering_h *th = (__tethering_h *)tethering;
2013 __tethering_client_h client = {0, };
2016 gchar *hostname = NULL;
2017 guint timestamp = 0;
2018 GError *error = NULL;
2019 GVariant *result = NULL;
2020 GVariantIter *outer_iter = NULL;
2021 GVariantIter *inner_iter = NULL;
2022 GVariant *station = NULL;
2023 GVariant *value = NULL;
2026 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2027 NULL, G_DBUS_CALL_FLAGS_NONE,
2028 -1, th->cancellable, &error);
2030 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2031 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2032 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2033 g_variant_get(station, "a{sv}", &inner_iter);
2034 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2035 if (g_strcmp0(key, "Type") == 0) {
2036 interface = g_variant_get_int32(value);
2037 if (interface == MOBILE_AP_TYPE_USB)
2038 client.interface = TETHERING_TYPE_USB;
2039 else if (interface == MOBILE_AP_TYPE_WIFI)
2040 client.interface = TETHERING_TYPE_WIFI;
2041 else if (interface == MOBILE_AP_TYPE_BT)
2042 client.interface = TETHERING_TYPE_BT;
2044 ERR("Invalid interface\n");
2046 g_variant_unref(value);
2049 DBG("interface is %d\n", client.interface);
2050 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2052 g_variant_unref(value);
2055 } else if (g_strcmp0(key, "IP") == 0) {
2056 g_variant_get(value, "s", &ip);
2057 SDBG("ip is %s\n", ip);
2058 g_strlcpy(client.ip, ip, sizeof(client.ip));
2059 } else if (g_strcmp0(key, "MAC") == 0) {
2060 g_variant_get(value, "s", &mac);
2061 SDBG("mac is %s\n", mac);
2062 g_strlcpy(client.mac, mac, sizeof(client.mac));
2063 } else if (g_strcmp0(key, "Name") == 0) {
2064 g_variant_get(value, "s", &hostname);
2065 SDBG("hsotname is %s\n", hostname);
2067 client.hostname = g_strdup(hostname);
2068 } else if (g_strcmp0(key, "Time") == 0) {
2069 timestamp = g_variant_get_int32(value);
2070 DBG("timestamp is %d\n", timestamp);
2071 client.tm = (time_t)timestamp;
2073 ERR("Key %s not required\n", key);
2079 g_variant_iter_free(inner_iter);
2080 if (callback((tethering_client_h)&client, user_data) == false) {
2081 DBG("iteration is stopped\n");
2082 g_free(client.hostname);
2083 g_variant_iter_free(outer_iter);
2084 g_variant_unref(station);
2085 g_variant_unref(result);
2087 return TETHERING_ERROR_OPERATION_FAILED;
2089 g_free(client.hostname);
2091 g_variant_iter_free(outer_iter);
2092 g_variant_unref(station);
2093 g_variant_unref(result);
2095 return TETHERING_ERROR_NONE;
2100 * @brief Registers the callback function called when tethering is enabled.
2102 * @privlevel platform
2103 * @privilege http://tizen.org/privilege/tethering.admin
2104 * @param[in] tethering The handle of tethering
2105 * @param[in] type The type of tethering
2106 * @param[in] callback The callback function to invoke
2107 * @param[in] user_data The user data to be passed to the callback function
2108 * @retval #TETHERING_ERROR_NONE Successful
2109 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2110 * @see tethering_unset_enabled_cb()
2112 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2114 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2115 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2116 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2118 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2119 "parameter(tethering) is NULL\n");
2120 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2121 "parameter(callback) is NULL\n");
2123 __tethering_h *th = (__tethering_h *)tethering;
2124 tethering_type_e ti;
2126 if (type != TETHERING_TYPE_ALL) {
2127 th->enabled_cb[type] = callback;
2128 th->enabled_user_data[type] = user_data;
2130 return TETHERING_ERROR_NONE;
2133 /* TETHERING_TYPE_ALL */
2134 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2135 th->enabled_cb[ti] = callback;
2136 th->enabled_user_data[ti] = user_data;
2139 return TETHERING_ERROR_NONE;
2144 * @brief Unregisters the callback function called when tethering is disabled.
2146 * @privlevel platform
2147 * @privilege http://tizen.org/privilege/tethering.admin
2148 * @param[in] tethering The handle of tethering
2149 * @param[in] type The type of tethering
2150 * @retval #TETHERING_ERROR_NONE Successful
2151 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2152 * @see tethering_set_enabled_cb()
2154 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2156 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2157 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2158 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2160 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2161 "parameter(tethering) is NULL\n");
2163 __tethering_h *th = (__tethering_h *)tethering;
2164 tethering_type_e ti;
2166 if (type != TETHERING_TYPE_ALL) {
2167 th->enabled_cb[type] = NULL;
2168 th->enabled_user_data[type] = NULL;
2170 return TETHERING_ERROR_NONE;
2173 /* TETHERING_TYPE_ALL */
2174 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2175 th->enabled_cb[ti] = NULL;
2176 th->enabled_user_data[ti] = NULL;
2179 return TETHERING_ERROR_NONE;
2184 * @brief Registers the callback function called when tethering is disabled.
2186 * @privlevel platform
2187 * @privilege http://tizen.org/privilege/tethering.admin
2188 * @param[in] tethering The handle of tethering
2189 * @param[in] type The type of tethering
2190 * @param[in] callback The callback function to invoke
2191 * @param[in] user_data The user data to be passed to the callback function
2192 * @retval #TETHERING_ERROR_NONE Successful
2193 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2194 * @see tethering_unset_disabled_cb()
2196 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2198 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2199 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2200 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2202 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2203 "parameter(tethering) is NULL\n");
2204 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2205 "parameter(callback) is NULL\n");
2207 __tethering_h *th = (__tethering_h *)tethering;
2208 tethering_type_e ti;
2210 if (type != TETHERING_TYPE_ALL) {
2211 th->disabled_cb[type] = callback;
2212 th->disabled_user_data[type] = user_data;
2214 return TETHERING_ERROR_NONE;
2217 /* TETHERING_TYPE_ALL */
2218 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2219 th->disabled_cb[ti] = callback;
2220 th->disabled_user_data[ti] = user_data;
2223 return TETHERING_ERROR_NONE;
2228 * @brief Unregisters the callback function called when tethering is disabled.
2230 * @privlevel platform
2231 * @privilege http://tizen.org/privilege/tethering.admin
2232 * @param[in] tethering The handle of tethering
2233 * @param[in] type The type of tethering
2234 * @retval #TETHERING_ERROR_NONE Successful
2235 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2236 * @see tethering_set_disabled_cb()
2238 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2240 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2241 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2242 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2244 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2245 "parameter(tethering) is NULL\n");
2247 __tethering_h *th = (__tethering_h *)tethering;
2248 tethering_type_e ti;
2250 if (type != TETHERING_TYPE_ALL) {
2251 th->disabled_cb[type] = NULL;
2252 th->disabled_user_data[type] = NULL;
2254 return TETHERING_ERROR_NONE;
2257 /* TETHERING_TYPE_ALL */
2258 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2259 th->disabled_cb[ti] = NULL;
2260 th->disabled_user_data[ti] = NULL;
2263 return TETHERING_ERROR_NONE;
2268 * @brief Registers the callback function called when the state of connection is changed.
2270 * @privlevel platform
2271 * @privilege http://tizen.org/privilege/tethering.admin
2272 * @param[in] tethering The handle of tethering
2273 * @param[in] type The type of tethering
2274 * @param[in] callback The callback function to invoke
2275 * @param[in] user_data The user data to be passed to the callback function
2276 * @retval #TETHERING_ERROR_NONE Successful
2277 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2278 * @see tethering_unset_connection_state_changed_cb_cb()
2280 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2282 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2283 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2284 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2286 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2287 "parameter(tethering) is NULL\n");
2288 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2289 "parameter(callback) is NULL\n");
2291 __tethering_h *th = (__tethering_h *)tethering;
2292 tethering_type_e ti;
2294 if (type != TETHERING_TYPE_ALL) {
2295 th->changed_cb[type] = callback;
2296 th->changed_user_data[type] = user_data;
2298 return TETHERING_ERROR_NONE;
2301 /* TETHERING_TYPE_ALL */
2302 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2303 th->changed_cb[ti] = callback;
2304 th->changed_user_data[ti] = user_data;
2307 return TETHERING_ERROR_NONE;
2312 * @brief Unregisters the callback function called when the state of connection is changed.
2314 * @privlevel platform
2315 * @privilege http://tizen.org/privilege/tethering.admin
2316 * @param[in] tethering The handle of tethering
2317 * @param[in] type The type of tethering
2318 * @retval #TETHERING_ERROR_NONE Successful
2319 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2320 * @see tethering_set_connection_state_changed_cb()
2322 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2324 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2325 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2326 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2328 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2329 "parameter(tethering) is NULL\n");
2331 __tethering_h *th = (__tethering_h *)tethering;
2332 tethering_type_e ti;
2334 if (type != TETHERING_TYPE_ALL) {
2335 th->changed_cb[type] = NULL;
2336 th->changed_user_data[type] = NULL;
2338 return TETHERING_ERROR_NONE;
2341 /* TETHERING_TYPE_ALL */
2342 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2343 th->changed_cb[ti] = NULL;
2344 th->changed_user_data[ti] = NULL;
2347 return TETHERING_ERROR_NONE;
2352 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2354 * @privlevel platform
2355 * @privilege http://tizen.org/privilege/tethering.admin
2356 * @param[in] tethering The handle of tethering
2357 * @param[in] callback The callback function to invoke
2358 * @param[in] user_data The user data to be passed to the callback function
2359 * @retval #TETHERING_ERROR_NONE Successful
2360 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2361 * @see tethering_wifi_unset_security_type_changed_cb()
2363 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2365 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2367 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2368 "parameter(tethering) is NULL\n");
2369 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2370 "parameter(callback) is NULL\n");
2372 __tethering_h *th = (__tethering_h *)tethering;
2374 th->security_type_changed_cb = callback;
2375 th->security_type_user_data = user_data;
2377 return TETHERING_ERROR_NONE;
2383 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2385 * @privlevel platform
2386 * @privilege http://tizen.org/privilege/tethering.admin
2387 * @param[in] tethering The handle of tethering
2388 * @param[in] type The type of tethering
2389 * @retval #TETHERING_ERROR_NONE Successful
2390 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2391 * @see tethering_wifi_set_security_type_changed_cb()
2393 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2395 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2397 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2398 "parameter(tethering) is NULL\n");
2400 __tethering_h *th = (__tethering_h *)tethering;
2402 th->security_type_changed_cb = NULL;
2403 th->security_type_user_data = NULL;
2405 return TETHERING_ERROR_NONE;
2410 * @brief Registers the callback function called when the visibility of SSID is changed.
2412 * @privlevel platform
2413 * @privilege http://tizen.org/privilege/tethering.admin
2414 * @param[in] tethering The handle of tethering
2415 * @param[in] callback The callback function to invoke
2416 * @param[in] user_data The user data to be passed to the callback function
2417 * @retval #TETHERING_ERROR_NONE Successful
2418 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2419 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2421 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2423 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2425 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2426 "parameter(tethering) is NULL\n");
2427 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2428 "parameter(callback) is NULL\n");
2430 __tethering_h *th = (__tethering_h *)tethering;
2432 th->ssid_visibility_changed_cb = callback;
2433 th->ssid_visibility_user_data = user_data;
2435 return TETHERING_ERROR_NONE;
2440 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2442 * @privlevel platform
2443 * @privilege http://tizen.org/privilege/tethering.admin
2444 * @param[in] tethering The handle of tethering
2445 * @retval #TETHERING_ERROR_NONE Successful
2446 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2447 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2449 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2451 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2453 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2454 "parameter(tethering) is NULL\n");
2456 __tethering_h *th = (__tethering_h *)tethering;
2458 th->ssid_visibility_changed_cb = NULL;
2459 th->ssid_visibility_user_data = NULL;
2461 return TETHERING_ERROR_NONE;
2466 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2468 * @privlevel platform
2469 * @privilege http://tizen.org/privilege/tethering.admin
2470 * @param[in] tethering The handle of tethering
2471 * @param[in] callback The callback function to invoke
2472 * @param[in] user_data The user data to be passed to the callback function
2473 * @retval #TETHERING_ERROR_NONE Successful
2474 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2475 * @see tethering_wifi_unset_passphrase_changed_cb()
2477 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2479 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2481 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2482 "parameter(tethering) is NULL\n");
2483 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2484 "parameter(callback) is NULL\n");
2486 __tethering_h *th = (__tethering_h *)tethering;
2488 th->passphrase_changed_cb = callback;
2489 th->passphrase_user_data = user_data;
2491 return TETHERING_ERROR_NONE;
2496 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2498 * @privlevel platform
2499 * @privilege http://tizen.org/privilege/tethering.admin
2500 * @param[in] tethering The handle of tethering
2501 * @retval #TETHERING_ERROR_NONE Successful
2502 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2503 * @see tethering_wifi_set_passphrase_changed_cb()
2505 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2507 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2509 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2510 "parameter(tethering) is NULL\n");
2512 __tethering_h *th = (__tethering_h *)tethering;
2514 th->passphrase_changed_cb = NULL;
2515 th->passphrase_user_data = NULL;
2517 return TETHERING_ERROR_NONE;
2522 * @brief Sets the security type of Wi-Fi tethering.
2524 * @privlevel platform
2525 * @privilege http://tizen.org/privilege/tethering.admin
2526 * @remarks This change is applied next time Wi-Fi tethering is enabled
2527 * @param[in] tethering The handle of tethering
2528 * @param[in] type The security type
2529 * @return 0 on success, otherwise negative error value.
2530 * @retval #TETHERING_ERROR_NONE Successful
2531 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2532 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2533 * @see tethering_wifi_get_security_type()
2535 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2537 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2539 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2540 "parameter(tethering) is NULL\n");
2542 __tethering_h *th = (__tethering_h *)tethering;
2543 tethering_error_e ret = TETHERING_ERROR_NONE;
2545 ret = __set_security_type(type);
2546 if (ret == TETHERING_ERROR_NONE) {
2548 __send_dbus_signal(th->client_bus,
2549 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2550 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2551 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2552 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2559 * @brief Gets the security type of Wi-Fi tethering.
2561 * @privlevel platform
2562 * @privilege http://tizen.org/privilege/tethering.admin
2563 * @param[in] tethering The handle of tethering
2564 * @param[out] type The security type
2565 * @return 0 on success, otherwise negative error value.
2566 * @retval #TETHERING_ERROR_NONE Successful
2567 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2568 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2569 * @see tethering_wifi_set_security_type()
2571 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2573 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2575 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2576 "parameter(type) is NULL\n");
2578 return __get_security_type(type);
2583 * @brief Sets the SSID (service set identifier).
2585 * @privlevel platform
2586 * @privilege http://tizen.org/privilege/tethering.admin
2587 * @details If SSID is not set, Device name is used as SSID
2588 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2589 * @param[in] tethering The handle of tethering
2590 * @param[out] ssid The SSID
2591 * @return 0 on success, otherwise negative error value.
2592 * @retval #TETHERING_ERROR_NONE Successful
2593 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2594 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2596 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2598 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2600 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2601 "parameter(tethering) is NULL\n");
2602 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2603 "parameter(ssid) is NULL\n");
2605 __tethering_h *th = (__tethering_h *)tethering;
2606 char *p_ssid = NULL;
2609 ssid_len = strlen(ssid);
2610 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2611 ERR("parameter(ssid) is too long");
2612 return TETHERING_ERROR_INVALID_PARAMETER;
2615 p_ssid = strdup(ssid);
2616 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2617 "strdup is failed\n");
2623 return TETHERING_ERROR_NONE;
2628 * @brief Gets the SSID (service set identifier).
2630 * @privlevel platform
2631 * @privilege http://tizen.org/privilege/tethering.admin
2632 * @remarks @a ssid must be released with free() by you.
2633 * @param[in] tethering The handle of tethering
2634 * @param[out] ssid The SSID
2635 * @return 0 on success, otherwise negative error value.
2636 * @retval #TETHERING_ERROR_NONE Successful
2637 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2638 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2639 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2641 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2643 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2645 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2646 "parameter(tethering) is NULL\n");
2647 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2648 "parameter(ssid) is NULL\n");
2651 __tethering_h *th = (__tethering_h *)tethering;
2652 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2654 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2655 if (th->ssid != NULL) {
2656 DBG("Private SSID is set\n");
2657 *ssid = strdup(th->ssid);
2659 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2660 val, sizeof(val)) == false) {
2661 return TETHERING_ERROR_OPERATION_FAILED;
2663 *ssid = strdup(val);
2666 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2667 val, sizeof(val)) == false) {
2668 return TETHERING_ERROR_OPERATION_FAILED;
2670 *ssid = strdup(val);
2673 if (*ssid == NULL) {
2674 ERR("strdup is failed\n");
2675 return TETHERING_ERROR_OUT_OF_MEMORY;
2678 return TETHERING_ERROR_NONE;
2683 * @brief Sets the visibility of SSID(service set identifier).
2685 * @privlevel platform
2686 * @privilege http://tizen.org/privilege/tethering.admin
2687 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2688 * @remarks This change is applied next time Wi-Fi tethering is enabled
2689 * @param[in] tethering The handle of tethering
2690 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2691 * @return 0 on success, otherwise negative error value.
2692 * @retval #TETHERING_ERROR_NONE Successful
2693 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2694 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2695 * @see tethering_wifi_get_ssid_visibility()
2697 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2699 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2701 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2702 "parameter(tethering) is NULL\n");
2704 __tethering_h *th = (__tethering_h *)tethering;
2705 tethering_error_e ret = TETHERING_ERROR_NONE;
2707 ret = __set_visible(visible);
2708 if (ret == TETHERING_ERROR_NONE) {
2710 __send_dbus_signal(th->client_bus,
2711 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2712 visible ? SIGNAL_MSG_SSID_VISIBLE :
2713 SIGNAL_MSG_SSID_HIDE);
2720 * @brief Gets the visibility of SSID(service set identifier).
2722 * @privlevel platform
2723 * @privilege http://tizen.org/privilege/tethering.admin
2724 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2725 * @param[in] tethering The handle of tethering
2726 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2727 * @return 0 on success, otherwise negative error value.
2728 * @retval #TETHERING_ERROR_NONE Successful
2729 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2730 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2731 * @see tethering_wifi_set_ssid_visibility()
2733 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2735 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2737 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2738 "parameter(visible) is NULL\n");
2740 return __get_visible(visible);
2745 * @brief Sets the passphrase.
2747 * @privlevel platform
2748 * @privilege http://tizen.org/privilege/tethering.admin
2749 * @remarks This change is applied next time Wi-Fi tethering is enabled
2750 * @param[in] tethering The handle of tethering
2751 * @param[in] passphrase The passphrase
2752 * @return 0 on success, otherwise negative error value.
2753 * @retval #TETHERING_ERROR_NONE Successful
2754 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2755 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2756 * @see tethering_wifi_get_passphrase()
2758 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2760 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2762 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2763 "parameter(tethering) is NULL\n");
2764 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2765 "parameter(passphrase) is NULL\n");
2767 __tethering_h *th = (__tethering_h *)tethering;
2768 GDBusProxy *proxy = th->client_bus_proxy;
2769 GVariant *parameters;
2770 GError *error = NULL;
2771 int passphrase_len = 0;
2775 passphrase_len = strlen(passphrase);
2776 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
2777 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
2778 ERR("parameter(passphrase) is too short or long\n");
2779 return TETHERING_ERROR_INVALID_PARAMETER;
2782 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
2783 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2786 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2788 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2789 ret = TETHERING_ERROR_PERMISSION_DENIED;
2791 ret = TETHERING_ERROR_OPERATION_FAILED;
2793 g_error_free(error);
2797 g_variant_get(parameters, "(u)", &ret);
2798 g_variant_unref(parameters);
2800 if (ret == TETHERING_ERROR_NONE) {
2801 __send_dbus_signal(th->client_bus,
2802 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
2811 * @brief Gets the passphrase.
2813 * @privlevel platform
2814 * @privilege http://tizen.org/privilege/tethering.admin
2815 * @remarks @a passphrase must be released with free() by you.
2816 * @param[in] tethering The handle of tethering
2817 * @param[out] passphrase The passphrase
2818 * @return 0 on success, otherwise negative error value.
2819 * @retval #TETHERING_ERROR_NONE Successful
2820 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2821 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2822 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2823 * @see tethering_wifi_set_passphrase()
2825 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2827 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2829 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2830 "parameter(tethering) is NULL\n");
2831 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2832 "parameter(passphrase) is NULL\n");
2834 __tethering_h *th = (__tethering_h *)tethering;
2835 GDBusProxy *proxy = th->client_bus_proxy;
2836 GVariant *parameters;
2837 GError *error = NULL;
2838 unsigned int len = 0;
2839 tethering_error_e ret = TETHERING_ERROR_NONE;
2841 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
2842 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2845 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2847 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2848 ret = TETHERING_ERROR_PERMISSION_DENIED;
2850 ret = TETHERING_ERROR_OPERATION_FAILED;
2852 g_error_free(error);
2856 if (parameters != NULL) {
2857 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
2858 g_variant_unref(parameters);
2861 return TETHERING_ERROR_NONE;
2864 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
2866 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2867 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2868 "parameter(tethering) is NULL\n");
2870 __tethering_h *th = (__tethering_h *)tethering;
2871 th->channel = channel;
2873 return TETHERING_ERROR_NONE;
2876 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
2878 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2879 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2880 "parameter(tethering) is NULL\n");
2882 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2883 "parameter(channel) is NULL\n");
2885 __tethering_h *th = (__tethering_h *)tethering;
2886 *channel = th->channel;
2888 return TETHERING_ERROR_NONE;
2891 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
2893 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2894 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2895 "parameter(tethering) is NULL\n");
2897 __tethering_h *th = (__tethering_h *)tethering;
2899 th->mode_type = type;
2901 return TETHERING_ERROR_NONE;
2904 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
2906 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2907 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2908 "parameter(tethering) is NULL\n");
2909 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2910 "parameter(type) is NULL\n");
2912 __tethering_h *th = (__tethering_h *)tethering;
2913 *type = th->mode_type;
2915 return TETHERING_ERROR_NONE;
2921 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
2923 * @privlevel platform
2924 * @privilege http://tizen.org/privilege/tethering.admin
2925 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
2926 * @param[in] tethering The handle of tethering
2927 * @param[in] callback The callback function to invoke
2928 * @param[in] user_data The user data to be passed to the callback function
2929 * @return 0 on success, otherwise negative error value.
2930 * @retval #TETHERING_ERROR_NONE Successful
2931 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2932 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2934 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
2937 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2939 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2940 "parameter(tethering) is NULL\n");
2941 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2942 "parameter(callback) is NULL\n");
2944 __tethering_h *th = (__tethering_h *)tethering;
2945 _softap_settings_t set = {"", "", "", 0, false};
2946 GDBusProxy *proxy = th->client_bus_proxy;
2951 if (th->settings_reloaded_cb) {
2952 ERR("Operation in progress\n");
2953 return TETHERING_ERROR_OPERATION_FAILED;
2956 ret = __prepare_wifi_settings(tethering, &set);
2957 if (ret != TETHERING_ERROR_NONE) {
2958 ERR("softap settings initialization failed\n");
2959 return TETHERING_ERROR_OPERATION_FAILED;
2962 th->settings_reloaded_cb = callback;
2963 th->settings_reloaded_user_data = user_data;
2965 g_dbus_proxy_call(proxy, "reload_wifi_settings",
2966 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
2967 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2968 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
2970 return TETHERING_ERROR_NONE;
2973 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
2975 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2977 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2978 "parameter(tethering) is NULL\n");
2980 __tethering_h *th = (__tethering_h *)tethering;
2981 th->mac_filter = mac_filter;
2983 return TETHERING_ERROR_NONE;
2986 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
2988 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2990 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2991 "parameter(mac_filter) is NULL\n");
2993 __tethering_h *th = (__tethering_h *)tethering;
2994 *mac_filter = th->mac_filter;
2996 return TETHERING_ERROR_NONE;
2999 static int __add_mac_to_file(const char *filepath, const char *mac)
3002 char line[MAX_BUF_SIZE] = "\0";
3003 bool mac_exist = false;
3006 p_mac = strdup(mac);
3007 if (p_mac == NULL) {
3008 ERR("strdup failed\n");
3009 return TETHERING_ERROR_OUT_OF_MEMORY;
3012 fp = fopen(filepath, "a+");
3014 ERR("fopen is failed\n");
3015 return TETHERING_ERROR_OPERATION_FAILED;
3018 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3019 if (strncmp(mac, line, 17) == 0) {
3020 DBG("MAC %s already exist in the list\n", mac);
3027 fprintf(fp, "%s\n", mac);
3029 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3030 allowed_list = g_slist_append(allowed_list, p_mac);
3031 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3032 blocked_list = g_slist_append(blocked_list, p_mac);
3037 return TETHERING_ERROR_NONE;
3040 static int __remove_mac_from_file(const char *filepath, const char *mac)
3044 char line[MAX_BUF_SIZE] = "\0";
3046 fp = fopen(filepath, "r");
3048 ERR("fopen is failed\n");
3049 return TETHERING_ERROR_OPERATION_FAILED;
3052 fp1 = fopen(TEMP_LIST, "w+");
3055 ERR("fopen is failed\n");
3056 return TETHERING_ERROR_OPERATION_FAILED;
3059 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3060 if (strncmp(mac, line, 17) == 0) {
3061 DBG("MAC %s found in the list\n", mac);
3063 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3064 GSList *list = NULL;
3065 for (list = allowed_list; list != NULL; list = list->next) {
3066 char *p_mac = (char *)list->data;
3067 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3068 allowed_list = g_slist_remove(allowed_list, p_mac);
3070 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3071 GSList *list = NULL;
3072 for (list = blocked_list; list != NULL; list = list->next) {
3073 char *p_mac = (char *)list->data;
3074 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3075 blocked_list = g_slist_remove(blocked_list, p_mac);
3079 fprintf(fp1, "%s", line);
3086 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3087 rename(TEMP_LIST, ALLOWED_LIST);
3088 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3089 rename(TEMP_LIST, BLOCKED_LIST);
3091 return TETHERING_ERROR_NONE;
3094 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3096 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3098 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3099 "parameter(tethering) is NULL\n");
3100 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3101 "parameter(mac) is NULL\n");
3103 return __add_mac_to_file(ALLOWED_LIST, mac);
3106 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3108 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3109 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3110 "parameter(tethering) is NULL\n");
3111 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3112 "parameter(mac) is NULL\n");
3114 return __remove_mac_from_file(ALLOWED_LIST, mac);
3117 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3119 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3120 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3121 "parameter(tethering) is NULL\n");
3122 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3123 "parameter(allowed_mac_list) is NULL\n");
3125 *allowed_mac_list = g_slist_copy(allowed_list);
3126 return TETHERING_ERROR_NONE;
3129 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3131 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3132 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3133 "parameter(tethering) is NULL\n");
3134 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3135 "parameter(mac) is NULL\n");
3137 return __add_mac_to_file(BLOCKED_LIST, mac);
3140 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3142 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3143 "parameter(tethering) is NULL\n");
3144 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3145 "parameter(mac) is NULL\n");
3147 return __remove_mac_from_file(BLOCKED_LIST, mac);
3150 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3152 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3154 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3155 "parameter(tethering) is NULL\n");
3156 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3157 "parameter(blocked_mac_list) is NULL\n");
3159 *blocked_mac_list = g_slist_copy(blocked_list);
3160 return TETHERING_ERROR_NONE;
3163 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3165 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3167 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3168 "parameter(tethering) is NULL\n");
3170 GVariant *parameters;
3171 GError *error = NULL;
3174 __tethering_h *th = (__tethering_h *)tethering;
3176 GDBusProxy *proxy = th->client_bus_proxy;
3178 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3179 g_variant_new("(b)", enable),
3180 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3183 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3184 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3185 result = TETHERING_ERROR_PERMISSION_DENIED;
3187 result = TETHERING_ERROR_OPERATION_FAILED;
3189 g_error_free(error);
3190 th->dhcp_enabled = false;
3195 g_variant_get(parameters, "(u)", &result);
3196 g_variant_unref(parameters);
3199 th->dhcp_enabled = true;
3201 th->dhcp_enabled = false;
3203 return TETHERING_ERROR_NONE;
3206 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3208 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3210 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3211 "parameter(tethering) is NULL\n");
3212 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3213 "parameter(rangestart) is NULL\n");
3214 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3215 "parameter(rangestop) is NULL\n");
3217 GVariant *parameters;
3218 GError *error = NULL;
3221 __tethering_h *th = (__tethering_h *)tethering;
3223 GDBusProxy *proxy = th->client_bus_proxy;
3225 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3226 g_variant_new("(ss)", rangestart, rangestop),
3227 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3229 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3231 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3232 result = TETHERING_ERROR_PERMISSION_DENIED;
3234 result = TETHERING_ERROR_OPERATION_FAILED;
3236 g_error_free(error);
3237 th->dhcp_enabled = false;
3242 g_variant_get(parameters, "(u)", &result);
3243 g_variant_unref(parameters);
3245 th->dhcp_enabled = true;
3247 return TETHERING_ERROR_NONE;
3250 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3252 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(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3256 "parameter(dhcp_enabled) is NULL\n");
3258 __tethering_h *th = (__tethering_h *)tethering;
3259 *dhcp_enabled = th->dhcp_enabled;
3261 return TETHERING_ERROR_NONE;