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>
29 #include "tethering-client-stub.h"
31 #include "tethering_private.h"
33 static void __handle_wifi_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data);
34 static void __handle_wifi_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data);
35 static void __handle_usb_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data);
36 static void __handle_usb_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data);
37 static void __handle_bt_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data);
38 static void __handle_bt_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data);
39 static void __handle_net_closed(DBusGProxy *proxy, const char *value_name, gpointer user_data);
40 static void __handle_no_data_timeout(DBusGProxy *proxy, const char *value_name, gpointer user_data);
41 static void __handle_low_battery_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data);
42 static void __handle_flight_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data);
43 static void __handle_security_type_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data);
44 static void __handle_ssid_visibility_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data);
45 static void __handle_passphrase_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data);
47 static __tethering_sig_t sigs[] = {
48 {SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
49 {SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
50 {SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
51 {SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
52 {SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
53 {SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
54 {SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
55 {SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
56 {SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
57 {SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
58 {SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
59 {SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
60 {SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
63 static bool __any_tethering_is_enabled(tethering_h tethering)
65 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
66 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
67 tethering_is_enabled(tethering, TETHERING_TYPE_BT))
73 static tethering_error_e __get_error(int agent_error)
75 tethering_error_e err = TETHERING_ERROR_NONE;
77 switch (agent_error) {
78 case MOBILE_AP_ERROR_NONE:
79 err = TETHERING_ERROR_NONE;
82 case MOBILE_AP_ERROR_RESOURCE:
83 err = TETHERING_ERROR_OUT_OF_MEMORY;
86 case MOBILE_AP_ERROR_INTERNAL:
87 err = TETHERING_ERROR_OPERATION_FAILED;
90 case MOBILE_AP_ERROR_INVALID_PARAM:
91 err = TETHERING_ERROR_INVALID_PARAMETER;
94 case MOBILE_AP_ERROR_ALREADY_ENABLED:
95 err = TETHERING_ERROR_OPERATION_FAILED;
98 case MOBILE_AP_ERROR_NOT_ENABLED:
99 err = TETHERING_ERROR_NOT_ENABLED;
102 case MOBILE_AP_ERROR_NET_OPEN:
103 err = TETHERING_ERROR_OPERATION_FAILED;
106 case MOBILE_AP_ERROR_NET_CLOSE:
107 err = TETHERING_ERROR_OPERATION_FAILED;
110 case MOBILE_AP_ERROR_DHCP:
111 err = TETHERING_ERROR_OPERATION_FAILED;
114 case MOBILE_AP_ERROR_IN_PROGRESS:
115 err = TETHERING_ERROR_OPERATION_FAILED;
118 case MOBILE_AP_ERROR_NOT_PERMITTED:
119 err = TETHERING_ERROR_OPERATION_FAILED;
123 ERR("Not defined error : %d\n", agent_error);
124 err = TETHERING_ERROR_OPERATION_FAILED;
131 static void __handle_dhcp(DBusGProxy *proxy, const char *member,
132 guint interface, const char *ip, const char *mac,
133 const char *name, gpointer user_data)
137 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
139 __tethering_h *th = (__tethering_h *)user_data;
141 tethering_type_e type = 0;
142 tethering_connection_state_changed_cb ccb = NULL;
143 __tethering_client_h client = {0, };
146 if (!g_strcmp0(member, "DhcpConnected")) {
148 } else if (!g_strcmp0(member, "DhcpLeaseDeleted")) {
151 ERR("Unknown event [%s]\n", member);
155 if (interface == MOBILE_AP_TYPE_USB)
156 type = TETHERING_TYPE_USB;
157 else if (interface == MOBILE_AP_TYPE_WIFI)
158 type = TETHERING_TYPE_WIFI;
159 else if (interface == MOBILE_AP_TYPE_BT)
160 type = TETHERING_TYPE_BT;
162 ERR("Not supported tethering type [%d]\n", interface);
166 ccb = th->changed_cb[type];
169 data = th->changed_user_data[type];
171 client.interface = type;
172 g_strlcpy(client.ip, ip, sizeof(client.ip));
173 g_strlcpy(client.mac, mac, sizeof(client.mac));
174 g_strlcpy(client.hostname, name, sizeof(client.hostname));
176 ccb((tethering_client_h)&client, opened, data);
181 static void __handle_net_closed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
185 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
187 __tethering_h *th = (__tethering_h *)user_data;
188 tethering_type_e type = 0;
189 tethering_disabled_cb dcb = NULL;
191 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
193 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
194 dcb = th->disabled_cb[type];
197 data = th->disabled_user_data[type];
199 dcb(TETHERING_ERROR_NONE, type, code, data);
205 static void __handle_wifi_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data)
209 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
211 __tethering_h *th = (__tethering_h *)user_data;
212 tethering_type_e type = TETHERING_TYPE_WIFI;
213 bool is_requested = false;
214 tethering_enabled_cb ecb = NULL;
217 ecb = th->enabled_cb[type];
220 data = th->enabled_user_data[type];
222 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
225 static void __handle_wifi_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data)
229 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
231 __tethering_h *th = (__tethering_h *)user_data;
232 tethering_type_e type = TETHERING_TYPE_WIFI;
233 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
234 tethering_disabled_cb dcb = NULL;
237 dcb = th->disabled_cb[type];
240 data = th->disabled_user_data[type];
242 if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
243 code = TETHERING_DISABLED_BY_WIFI_ON;
244 else if (!g_strcmp0(value_name, SIGNAL_MSG_TIMEOUT))
245 code = TETHERING_DISABLED_BY_TIMEOUT;
247 dcb(TETHERING_ERROR_NONE, type, code, data);
252 static void __handle_usb_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data)
256 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
258 __tethering_h *th = (__tethering_h *)user_data;
259 tethering_type_e type = TETHERING_TYPE_USB;
260 bool is_requested = false;
261 tethering_enabled_cb ecb = NULL;
264 ecb = th->enabled_cb[type];
267 data = th->enabled_user_data[type];
269 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
272 static void __handle_usb_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data)
276 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
278 __tethering_h *th = (__tethering_h *)user_data;
279 tethering_type_e type = TETHERING_TYPE_USB;
280 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
281 tethering_disabled_cb dcb = NULL;
284 dcb = th->disabled_cb[type];
287 data = th->disabled_user_data[type];
289 if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
290 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
292 dcb(TETHERING_ERROR_NONE, type, code, data);
297 static void __handle_bt_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data)
301 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
303 __tethering_h *th = (__tethering_h *)user_data;
304 tethering_type_e type = TETHERING_TYPE_BT;
305 bool is_requested = false;
306 tethering_enabled_cb ecb = NULL;
309 ecb = th->enabled_cb[type];
312 data = th->enabled_user_data[type];
314 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
317 static void __handle_bt_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data)
321 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
323 __tethering_h *th = (__tethering_h *)user_data;
324 tethering_type_e type = TETHERING_TYPE_BT;
325 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
326 tethering_disabled_cb dcb = NULL;
329 dcb = th->disabled_cb[type];
332 data = th->disabled_user_data[type];
334 if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
335 code = TETHERING_DISABLED_BY_BT_OFF;
336 else if (!g_strcmp0(value_name, SIGNAL_MSG_TIMEOUT))
337 code = TETHERING_DISABLED_BY_TIMEOUT;
339 dcb(TETHERING_ERROR_NONE, type, code, data);
344 static void __handle_no_data_timeout(DBusGProxy *proxy, const char *value_name, gpointer user_data)
348 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
350 __tethering_h *th = (__tethering_h *)user_data;
351 tethering_type_e type = 0;
352 tethering_disabled_cb dcb = NULL;
354 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
356 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
357 dcb = th->disabled_cb[type];
360 data = th->disabled_user_data[type];
362 dcb(TETHERING_ERROR_NONE, type, code, data);
366 static void __handle_low_battery_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data)
370 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
372 __tethering_h *th = (__tethering_h *)user_data;
373 tethering_type_e type = 0;
374 tethering_disabled_cb dcb = NULL;
376 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
378 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
379 dcb = th->disabled_cb[type];
382 data = th->disabled_user_data[type];
384 dcb(TETHERING_ERROR_NONE, type, code, data);
388 static void __handle_flight_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data)
392 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
394 __tethering_h *th = (__tethering_h *)user_data;
395 tethering_type_e type = 0;
396 tethering_disabled_cb dcb = NULL;
398 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
400 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
401 dcb = th->disabled_cb[type];
404 data = th->disabled_user_data[type];
406 dcb(TETHERING_ERROR_NONE, type, code, data);
410 static void __handle_security_type_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
414 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
416 __tethering_h *th = (__tethering_h *)user_data;
417 tethering_wifi_security_type_changed_cb scb = NULL;
419 tethering_wifi_security_type_e security_type;
421 scb = th->security_type_changed_cb;
425 data = th->security_type_user_data;
426 if (g_strcmp0(value_name, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
427 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
428 else if (g_strcmp0(value_name, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
429 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
431 ERR("Unknown security type : %s\n", value_name);
435 scb(security_type, data);
440 static void __handle_ssid_visibility_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
444 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
446 __tethering_h *th = (__tethering_h *)user_data;
447 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
449 bool visible = false;
451 scb = th->ssid_visibility_changed_cb;
455 data = th->ssid_visibility_user_data;
456 if (g_strcmp0(value_name, SIGNAL_MSG_SSID_VISIBLE) == 0)
464 static void __handle_passphrase_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
468 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
470 __tethering_h *th = (__tethering_h *)user_data;
471 tethering_wifi_passphrase_changed_cb pcb = NULL;
474 pcb = th->passphrase_changed_cb;
478 data = th->passphrase_user_data;
485 static void __cfm_cb(DBusGProxy *remoteobj, guint event, guint info,
486 GError *g_error, gpointer user_data)
490 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
492 tethering_h tethering = (tethering_h)user_data;
493 __tethering_h *th = (__tethering_h *)tethering;
494 DBusGProxy *proxy = th->client_bus_proxy;
496 tethering_type_e type = 0;
497 tethering_error_e error = __get_error(info);
498 bool is_requested = true;
499 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
501 tethering_enabled_cb ecb = NULL;
502 tethering_disabled_cb dcb = NULL;
506 ERR("DBus error [%s]\n", g_error->message);
507 g_error_free(g_error);
511 DBG("cfm event : %d info : %d\n", event, info);
513 case MOBILE_AP_ENABLE_WIFI_TETHERING_CFM:
514 type = TETHERING_TYPE_WIFI;
515 ecb = th->enabled_cb[type];
516 data = th->enabled_user_data[type];
518 ecb(error, type, is_requested, data);
519 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
520 G_CALLBACK(__handle_wifi_tether_on),
521 (gpointer)tethering, NULL);
524 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
525 type = TETHERING_TYPE_WIFI;
526 dcb = th->disabled_cb[type];
527 data = th->disabled_user_data[type];
529 dcb(error, type, code, data);
530 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
531 G_CALLBACK(__handle_wifi_tether_off),
532 (gpointer)tethering, NULL);
535 case MOBILE_AP_ENABLE_BT_TETHERING_CFM:
536 type = TETHERING_TYPE_BT;
537 ecb = th->enabled_cb[type];
538 data = th->enabled_user_data[type];
540 ecb(error, type, is_requested, data);
541 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
542 G_CALLBACK(__handle_bt_tether_on),
543 (gpointer)tethering, NULL);
546 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
547 type = TETHERING_TYPE_BT;
548 dcb = th->disabled_cb[type];
549 data = th->disabled_user_data[type];
551 dcb(error, type, code, data);
552 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
553 G_CALLBACK(__handle_bt_tether_off),
554 (gpointer)tethering, NULL);
557 case MOBILE_AP_ENABLE_USB_TETHERING_CFM:
558 type = TETHERING_TYPE_USB;
559 ecb = th->enabled_cb[type];
560 data = th->enabled_user_data[type];
562 ecb(error, type, is_requested, data);
563 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
564 G_CALLBACK(__handle_usb_tether_on),
565 (gpointer)tethering, NULL);
568 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
569 type = TETHERING_TYPE_USB;
570 dcb = th->disabled_cb[type];
571 data = th->disabled_user_data[type];
573 dcb(error, type, code, data);
574 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
575 G_CALLBACK(__handle_usb_tether_off),
576 (gpointer)tethering, NULL);
579 case MOBILE_AP_DISABLE_CFM:
580 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
581 dcb = th->disabled_cb[type];
584 data = th->disabled_user_data[type];
586 dcb(error, type, code, data);
589 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
590 G_CALLBACK(__handle_usb_tether_off),
591 (gpointer)tethering, NULL);
592 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
593 G_CALLBACK(__handle_wifi_tether_off),
594 (gpointer)tethering, NULL);
595 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
596 G_CALLBACK(__handle_bt_tether_off),
597 (gpointer)tethering, NULL);
601 ERR("Invalid event\n");
608 static void __get_data_usage_cb(DBusGProxy *remoteobj, guint event,
609 guint64 tx_bytes, guint64 rx_bytes,
610 GError *error, gpointer user_data)
612 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
614 __tethering_h *th = (__tethering_h *)user_data;
616 if (th->data_usage_cb == NULL) {
617 ERR("There is no data_usage_cb\n");
621 if (error || event != MOBILE_AP_GET_DATA_PACKET_USAGE_CFM) {
623 ERR("DBus fail [%s]\n", error->message);
627 th->data_usage_cb(TETHERING_ERROR_OPERATION_FAILED,
628 0LL, 0LL, th->data_usage_user_data);
630 th->data_usage_cb = NULL;
631 th->data_usage_user_data = NULL;
636 th->data_usage_cb(TETHERING_ERROR_NONE,
637 rx_bytes, tx_bytes, th->data_usage_user_data);
639 th->data_usage_cb = NULL;
640 th->data_usage_user_data = NULL;
645 static void __connect_signals(tethering_h tethering)
647 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
649 __tethering_h *th = (__tethering_h *)tethering;
650 DBusGProxy *proxy = th->client_bus_proxy;
653 for (i = 0; sigs[i].cb != NULL; i++) {
654 dbus_g_proxy_add_signal(proxy, sigs[i].name,
655 G_TYPE_STRING, G_TYPE_INVALID);
656 dbus_g_proxy_connect_signal(proxy, sigs[i].name,
657 G_CALLBACK(sigs[i].cb), (gpointer)tethering, NULL);
660 dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_STRING_STRING_STRING,
661 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING,
662 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
663 dbus_g_proxy_add_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
664 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING,
665 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
666 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
667 G_CALLBACK(__handle_dhcp), (gpointer)tethering, NULL);
672 static void __disconnect_signals(tethering_h tethering)
674 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
676 __tethering_h *th = (__tethering_h *)tethering;
677 DBusGProxy *proxy = th->client_bus_proxy;
681 for (i = 0; sigs[i].cb != NULL; i++) {
682 dbus_g_proxy_disconnect_signal(proxy, sigs[i].name,
683 G_CALLBACK(sigs[i].cb), (gpointer)tethering);
686 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
687 G_CALLBACK(__handle_dhcp), (gpointer)tethering);
692 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
694 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
697 case TETHERING_TYPE_USB:
698 g_strlcpy(buf, TETHERING_USB_IF, len);
701 case TETHERING_TYPE_WIFI:
702 g_strlcpy(buf, TETHERING_WIFI_IF, len);
705 case TETHERING_TYPE_BT:
706 g_strlcpy(buf, TETHERING_BT_IF, len);
710 ERR("Not supported type : %d\n", type);
717 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
719 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
722 case TETHERING_TYPE_USB:
723 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
726 case TETHERING_TYPE_WIFI:
727 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
730 case TETHERING_TYPE_BT:
731 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
735 ERR("Not supported type : %d\n", type);
742 static void __deinit_cb(DBusGProxy *remoteobj,
743 GError *error, gpointer user_data)
745 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
748 ERR("DBus fail [%s]\n", error->message);
755 static void __wifi_set_security_type_cb(DBusGProxy *remoteobj,
756 GError *error, gpointer user_data)
758 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
760 tethering_h tethering = (tethering_h)user_data;
761 __tethering_h *th = (__tethering_h *)tethering;
762 DBusGProxy *proxy = th->client_bus_proxy;
765 ERR("DBus fail [%s]\n", error->message);
769 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_SECURITY_TYPE_CHANGED,
770 G_CALLBACK(__handle_security_type_changed),
771 (gpointer)tethering, NULL);
776 static void __wifi_set_ssid_visibility_cb(DBusGProxy *remoteobj,
777 GError *error, gpointer user_data)
779 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
781 tethering_h tethering = (tethering_h)user_data;
782 __tethering_h *th = (__tethering_h *)tethering;
783 DBusGProxy *proxy = th->client_bus_proxy;
786 ERR("DBus fail [%s]\n", error->message);
790 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
791 G_CALLBACK(__handle_ssid_visibility_changed),
792 (gpointer)tethering, NULL);
797 static void __wifi_set_passphrase_cb(DBusGProxy *remoteobj,
798 GError *error, gpointer user_data)
800 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
802 tethering_h tethering = (tethering_h)user_data;
803 __tethering_h *th = (__tethering_h *)tethering;
804 DBusGProxy *proxy = th->client_bus_proxy;
807 ERR("DBus fail [%s]\n", error->message);
811 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED,
812 G_CALLBACK(__handle_passphrase_changed),
813 (gpointer)tethering, NULL);
819 * @brief Creates the handle of tethering.
820 * @remarks The @a tethering must be released tethering_destroy() by you.
821 * @param[out] tethering A handle of a new mobile ap handle on success
822 * @return 0 on success, otherwise a negative error value.
823 * @retval #TETHERING_ERROR_NONE Successful
824 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
825 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
826 * @see tethering_destroy()
828 API int tethering_create(tethering_h *tethering)
830 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
831 "parameter(tethering) is NULL\n");
833 __tethering_h *th = NULL;
834 GError *error = NULL;
836 th = (__tethering_h *)malloc(sizeof(__tethering_h));
837 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
838 "malloc is failed\n");
839 memset(th, 0x00, sizeof(__tethering_h));
841 #if !GLIB_CHECK_VERSION(2,35,0)
844 th->client_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
846 ERR("Couldn't connect to the System bus[%s]", error->message);
849 return TETHERING_ERROR_OPERATION_FAILED;
852 th->client_bus_proxy = dbus_g_proxy_new_for_name(th->client_bus,
853 TETHERING_SERVICE_NAME,
854 TETHERING_SERVICE_OBJECT_PATH,
855 TETHERING_SERVICE_INTERFACE);
856 if (!th->client_bus_proxy) {
857 ERR("Couldn't create the proxy object");
858 dbus_g_connection_unref(th->client_bus);
860 return TETHERING_ERROR_OPERATION_FAILED;
863 __connect_signals((tethering_h)th);
865 *tethering = (tethering_h)th;
866 DBG("Tethering Handle : 0x%X\n", th);
868 return TETHERING_ERROR_NONE;
872 * @brief Destroys the handle of tethering.
873 * @param[in] tethering The handle of tethering
874 * @return 0 on success, otherwise a negative error value.
875 * @retval #TETHERING_ERROR_NONE Successful
876 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
877 * @see tethering_create()
879 API int tethering_destroy(tethering_h tethering)
881 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
882 "parameter(tethering) is NULL\n");
884 __tethering_h *th = (__tethering_h *)tethering;
886 DBG("Tethering Handle : 0x%X\n", th);
887 __disconnect_signals(tethering);
889 org_tizen_tethering_deinit_async(th->client_bus_proxy, __deinit_cb,
890 (gpointer)tethering);
892 g_object_unref(th->client_bus_proxy);
893 dbus_g_connection_unref(th->client_bus);
894 memset(th, 0x00, sizeof(__tethering_h));
897 return TETHERING_ERROR_NONE;
901 * @brief Enables the tethering, asynchronously.
902 * @param[in] tethering The handle of tethering
903 * @param[in] type The type of tethering
904 * @return 0 on success, otherwise negative error value.
905 * @retval #TETHERING_ERROR_NONE Successful
906 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
907 * @post tethering_enabled_cb() will be invoked.
908 * @see tethering_is_enabled()
909 * @see tethering_disable()
911 int tethering_enable(tethering_h tethering, tethering_type_e type)
915 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
916 "parameter(tethering) is NULL\n");
918 __tethering_h *th = (__tethering_h *)tethering;
919 DBusGProxy *proxy = th->client_bus_proxy;
922 case TETHERING_TYPE_USB:
923 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
924 G_CALLBACK(__handle_usb_tether_on),
925 (gpointer)tethering);
926 org_tizen_tethering_enable_usb_tethering_async(proxy,
927 __cfm_cb, (gpointer)tethering);
930 case TETHERING_TYPE_WIFI:
931 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
932 G_CALLBACK(__handle_wifi_tether_on),
933 (gpointer)tethering);
934 org_tizen_tethering_enable_wifi_tethering_async(proxy, "", "", false,
935 __cfm_cb, (gpointer)tethering);
938 case TETHERING_TYPE_BT:
939 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
940 G_CALLBACK(__handle_bt_tether_on),
941 (gpointer)tethering);
942 org_tizen_tethering_enable_bt_tethering_async(proxy,
943 __cfm_cb, (gpointer)tethering);
947 case TETHERING_TYPE_ALL:
948 /* TETHERING_TYPE_USB */
949 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
950 G_CALLBACK(__handle_usb_tether_on),
951 (gpointer)tethering);
952 org_tizen_tethering_enable_usb_tethering_async(proxy,
953 __cfm_cb, (gpointer)tethering);
955 /* TETHERING_TYPE_WIFI */
956 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
957 G_CALLBACK(__handle_wifi_tether_on),
958 (gpointer)tethering);
959 org_tizen_tethering_enable_wifi_tethering_async(proxy, "", "", false,
960 __cfm_cb, (gpointer)tethering);
962 /* TETHERING_TYPE_BT */
963 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
964 G_CALLBACK(__handle_bt_tether_on),
965 (gpointer)tethering);
966 org_tizen_tethering_enable_bt_tethering_async(proxy,
967 __cfm_cb, (gpointer)tethering);
971 ERR("Unknown type : %d\n", type);
972 return TETHERING_ERROR_INVALID_PARAMETER;
975 return TETHERING_ERROR_NONE;
979 * @brief Disables the tethering, asynchronously.
980 * @param[in] tethering The handle of tethering
981 * @param[in] type The type of tethering
982 * @return 0 on success, otherwise negative error value.
983 * @retval #TETHERING_ERROR_NONE Successful
984 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
985 * @post tethering_disabled_cb() will be invoked.
986 * @see tethering_is_enabled()
987 * @see tethering_enable()
989 API int tethering_disable(tethering_h tethering, tethering_type_e type)
991 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
992 "parameter(tethering) is NULL\n");
994 __tethering_h *th = (__tethering_h *)tethering;
995 DBusGProxy *proxy = th->client_bus_proxy;
998 case TETHERING_TYPE_USB:
999 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
1000 G_CALLBACK(__handle_usb_tether_off),
1001 (gpointer)tethering);
1002 org_tizen_tethering_disable_usb_tethering_async(proxy,
1003 __cfm_cb, (gpointer)tethering);
1006 case TETHERING_TYPE_WIFI:
1007 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
1008 G_CALLBACK(__handle_wifi_tether_off),
1009 (gpointer)tethering);
1010 org_tizen_tethering_disable_wifi_tethering_async(proxy,
1011 __cfm_cb, (gpointer)tethering);
1013 case TETHERING_TYPE_BT:
1014 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
1015 G_CALLBACK(__handle_bt_tether_off),
1016 (gpointer)tethering);
1017 org_tizen_tethering_disable_bt_tethering_async(proxy,
1018 __cfm_cb, (gpointer)tethering);
1021 case TETHERING_TYPE_ALL:
1022 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
1023 G_CALLBACK(__handle_usb_tether_off),
1024 (gpointer)tethering);
1025 org_tizen_tethering_disable_usb_tethering_async(proxy,
1026 __cfm_cb, (gpointer)tethering);
1028 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
1029 G_CALLBACK(__handle_wifi_tether_off),
1030 (gpointer)tethering);
1031 org_tizen_tethering_disable_wifi_tethering_async(proxy,
1032 __cfm_cb, (gpointer)tethering);
1034 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
1035 G_CALLBACK(__handle_bt_tether_off),
1036 (gpointer)tethering);
1037 org_tizen_tethering_disable_bt_tethering_async(proxy,
1038 __cfm_cb, (gpointer)tethering);
1042 ERR("Not supported tethering type [%d]\n", type);
1043 return TETHERING_ERROR_INVALID_PARAMETER;
1047 return TETHERING_ERROR_NONE;
1051 * @brief Checks whetehr the tethering is enabled or not.
1052 * @param[in] tethering The handle of tethering
1053 * @param[in] type The type of tethering
1054 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1056 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1059 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1061 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) {
1066 case TETHERING_TYPE_USB:
1067 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1070 case TETHERING_TYPE_WIFI:
1071 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1074 case TETHERING_TYPE_BT:
1075 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1079 ERR("Not supported type : %d\n", type);
1083 return is_on & vconf_type ? true : false;
1087 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1088 * @remarks @a mac_address must be released with free() by you.
1089 * @param[in] tethering The handle of tethering
1090 * @param[in] type The type of tethering
1091 * @param[out] mac_address The MAC address
1092 * @return 0 on success, otherwise a negative error value.
1093 * @retval #TETHERING_ERROR_NONE Successful
1094 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1095 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1096 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1097 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1098 * @pre tethering must be enabled.
1099 * @see tethering_is_enabled()
1100 * @see tethering_enable()
1102 int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1104 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1105 "parameter(tethering) is NULL\n");
1106 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1107 "parameter(mac_address) is NULL\n");
1108 _retvm_if(tethering_is_enabled(tethering, type) == false,
1109 TETHERING_ERROR_NOT_ENABLED,
1110 "tethering type[%d] is not enabled\n", type);
1114 char *macbuf = NULL;
1116 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1117 TETHERING_ERROR_OPERATION_FAILED,
1118 "getting interface name is failed\n");
1120 s = socket(AF_INET, SOCK_DGRAM, 0);
1121 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1122 "getting socket is failed\n");
1123 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1124 ERR("getting mac is failed\n");
1126 return TETHERING_ERROR_OPERATION_FAILED;
1130 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1131 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1132 "Not enough memory\n");
1133 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1134 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1135 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1136 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1137 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1138 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1139 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1141 *mac_address = macbuf;
1143 return TETHERING_ERROR_NONE;
1147 * @brief Gets the name of network interface. For example, usb0.
1148 * @remarks @a interface_name must be released with free() by you.
1149 * @param[in] tethering The handle of tethering
1150 * @param[in] type The type of tethering
1151 * @param[out] interface_name The name of network interface
1152 * @return 0 on success, otherwise negative error value.
1153 * @retval #TETHERING_ERROR_NONE Successful
1154 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1155 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1156 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1157 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1158 * @pre tethering must be enabled.
1159 * @see tethering_is_enabled()
1160 * @see tethering_enable()
1162 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1164 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1165 "parameter(tethering) is NULL\n");
1166 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1167 "parameter(interface_name) is NULL\n");
1168 _retvm_if(tethering_is_enabled(tethering, type) == false,
1169 TETHERING_ERROR_NOT_ENABLED,
1170 "tethering type[%d] is not enabled\n", type);
1172 char intf[TETHERING_STR_INFO_LEN] = {0, };
1174 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1175 TETHERING_ERROR_OPERATION_FAILED,
1176 "getting interface name is failed\n");
1177 *interface_name = strdup(intf);
1178 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1179 "Not enough memory\n");
1181 return TETHERING_ERROR_NONE;
1185 * @brief Gets the local IP address.
1186 * @remarks @a ip_address must be released with free() by you.
1187 * @param[in] tethering The handle of tethering
1188 * @param[in] type The type of tethering
1189 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1190 * @param[out] ip_address The local IP address
1191 * @return 0 on success, otherwise negative error value.
1192 * @retval #TETHERING_ERROR_NONE Successful
1193 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1194 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1195 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1196 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1197 * @pre tethering must be enabled.
1198 * @see tethering_is_enabled()
1199 * @see tethering_enable()
1201 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1203 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1204 "parameter(tethering) is NULL\n");
1205 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1206 "parameter(ip_address) is NULL\n");
1207 _retvm_if(tethering_is_enabled(tethering, type) == false,
1208 TETHERING_ERROR_NOT_ENABLED,
1209 "tethering type[%d] is not enabled\n", type);
1215 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1216 TETHERING_ERROR_OPERATION_FAILED,
1217 "getting interface name is failed\n");
1219 s = socket(AF_INET, SOCK_DGRAM, 0);
1220 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1221 "getting socket is failed\n");
1222 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1223 ERR("ioctl is failed\n");
1225 return TETHERING_ERROR_OPERATION_FAILED;
1229 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1230 *ip_address = strdup(ipbuf);
1231 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1232 "Not enough memory\n");
1234 return TETHERING_ERROR_NONE;
1238 * @brief Gets the Gateway address.
1239 * @remarks @a gateway_address must be released with free() by you.
1240 * @param[in] tethering The handle of tethering
1241 * @param[in] type The type of tethering
1242 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1243 * @param[out] gateway_address The local IP address
1244 * @return 0 on success, otherwise negative error value.
1245 * @retval #TETHERING_ERROR_NONE Successful
1246 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1247 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1248 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1249 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1250 * @pre tethering must be enabled.
1251 * @see tethering_is_enabled()
1252 * @see tethering_enable()
1254 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1256 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1257 "parameter(tethering) is NULL\n");
1258 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1259 "parameter(gateway_address) is NULL\n");
1260 _retvm_if(tethering_is_enabled(tethering, type) == false,
1261 TETHERING_ERROR_NOT_ENABLED,
1262 "tethering type[%d] is not enabled\n", type);
1264 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1266 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1267 TETHERING_ERROR_OPERATION_FAILED,
1268 "getting gateway address is failed\n");
1270 *gateway_address = strdup(gateway_buf);
1272 return TETHERING_ERROR_NONE;
1276 * @brief Gets the Subnet Mask.
1277 * @remarks @a subnet_mask must be released with free() by you.
1278 * @param[in] tethering The handle of tethering
1279 * @param[in] type The type of tethering
1280 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1281 * @param[out] subnet_mask The local IP address
1282 * @return 0 on success, otherwise negative error value.
1283 * @retval #TETHERING_ERROR_NONE Successful
1284 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1285 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1286 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1287 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1288 * @pre tethering must be enabled.
1289 * @see tethering_is_enabled()
1290 * @see tethering_enable()
1292 int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1294 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1295 "parameter(tethering) is NULL\n");
1296 _retvm_if(tethering_is_enabled(tethering, type) == false,
1297 TETHERING_ERROR_NOT_ENABLED,
1298 "tethering is not enabled\n");
1299 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1300 "parameter(subnet_mask) is NULL\n");
1302 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
1303 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1304 "Not enough memory\n");
1306 return TETHERING_ERROR_NONE;
1310 * @brief Gets the data usage.
1311 * @param[in] tethering The handle of tethering
1312 * @param[out] usage The data usage
1313 * @return 0 on success, otherwise negative error value.
1314 * @retval #TETHERING_ERROR_NONE Successful
1315 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1316 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1317 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1318 * @pre tethering must be enabled.
1319 * @see tethering_is_enabled()
1320 * @see tethering_enable()
1322 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
1324 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1325 "parameter(tethering) is NULL\n");
1326 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1327 "parameter(callback) is NULL\n");
1328 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1329 TETHERING_ERROR_NOT_ENABLED,
1330 "tethering is not enabled\n");
1332 __tethering_h *th = (__tethering_h *)tethering;
1333 DBusGProxy *proxy = th->client_bus_proxy;
1335 th->data_usage_cb = callback;
1336 th->data_usage_user_data = user_data;
1338 org_tizen_tethering_get_data_packet_usage_async(proxy,
1339 __get_data_usage_cb, (gpointer)th);
1341 return TETHERING_ERROR_NONE;
1345 * @brief Gets the client which is connected by USB tethering.
1346 * @param[in] tethering The handle of tethering
1347 * @param[in] type The type of tethering
1348 * @param[in] callback The callback function to invoke
1349 * @param[in] user_data The user data to be passed to the callback function
1350 * @retval #TETHERING_ERROR_NONE Successful
1351 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1352 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1353 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1354 * @pre tethering must be enabled.
1355 * @see tethering_is_enabled()
1356 * @see tethering_enable()
1358 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
1360 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1361 "parameter(tethering) is NULL\n");
1362 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1363 "parameter(callback) is NULL\n");
1364 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1365 TETHERING_ERROR_NOT_ENABLED,
1366 "tethering is not enabled\n");
1368 __tethering_h *th = (__tethering_h *)tethering;
1369 __tethering_client_h client = {0, };
1372 GPtrArray *array = NULL;
1373 GValue value = {0, {{0}}};
1374 GError *error = NULL;
1376 int no_of_client = 0;
1377 guint interface = 0;
1380 gchar *hostname = NULL;
1382 org_tizen_tethering_get_station_info(th->client_bus_proxy, &event,
1384 if (error != NULL) {
1385 ERR("DBus fail : %s\n", error->message);
1386 g_error_free(error);
1387 return TETHERING_ERROR_OPERATION_FAILED;
1390 g_value_init(&value, DBUS_STRUCT_STATIONS);
1391 no_of_client = array->len;
1392 for (i = 0; i < no_of_client; i++) {
1393 g_value_set_boxed(&value, g_ptr_array_index(array, i));
1395 dbus_g_type_struct_get(&value, 0, &interface, 1, &ip,
1396 2, &mac, 3, &hostname, G_MAXUINT);
1398 if (interface == MOBILE_AP_TYPE_USB)
1399 client.interface = TETHERING_TYPE_USB;
1400 else if (interface == MOBILE_AP_TYPE_WIFI)
1401 client.interface = TETHERING_TYPE_WIFI;
1402 else if (interface == MOBILE_AP_TYPE_BT)
1403 client.interface = TETHERING_TYPE_BT;
1405 if (client.interface != type && TETHERING_TYPE_ALL != type)
1408 g_strlcpy(client.ip, ip, sizeof(client.ip));
1409 g_strlcpy(client.mac, mac, sizeof(client.mac));
1410 g_strlcpy(client.hostname, hostname, sizeof(client.hostname));
1412 if (callback((tethering_client_h)&client, user_data) == false) {
1413 DBG("iteration is stopped\n");
1414 return TETHERING_ERROR_NONE;
1419 g_ptr_array_free(array, TRUE);
1421 return TETHERING_ERROR_NONE;
1425 * @brief Registers the callback function called when tethering is enabled.
1426 * @param[in] tethering The handle of tethering
1427 * @param[in] type The type of tethering
1428 * @param[in] callback The callback function to invoke
1429 * @param[in] user_data The user data to be passed to the callback function
1430 * @retval #TETHERING_ERROR_NONE Successful
1431 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1432 * @see tethering_unset_enabled_cb()
1434 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
1436 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1437 "parameter(tethering) is NULL\n");
1438 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1439 "parameter(callback) is NULL\n");
1441 __tethering_h *th = (__tethering_h *)tethering;
1442 tethering_type_e ti;
1444 if (type != TETHERING_TYPE_ALL) {
1445 th->enabled_cb[type] = callback;
1446 th->enabled_user_data[type] = user_data;
1448 return TETHERING_ERROR_NONE;
1451 /* TETHERING_TYPE_ALL */
1452 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1453 th->enabled_cb[ti] = callback;
1454 th->enabled_user_data[ti] = user_data;
1457 return TETHERING_ERROR_NONE;
1461 * @brief Unregisters the callback function called when tethering is disabled.
1462 * @param[in] tethering The handle of tethering
1463 * @param[in] type The type of tethering
1464 * @retval #TETHERING_ERROR_NONE Successful
1465 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1466 * @see tethering_set_enabled_cb()
1468 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
1470 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1471 "parameter(tethering) is NULL\n");
1473 __tethering_h *th = (__tethering_h *)tethering;
1474 tethering_type_e ti;
1476 if (type != TETHERING_TYPE_ALL) {
1477 th->enabled_cb[type] = NULL;
1478 th->enabled_user_data[type] = NULL;
1480 return TETHERING_ERROR_NONE;
1483 /* TETHERING_TYPE_ALL */
1484 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1485 th->enabled_cb[ti] = NULL;
1486 th->enabled_user_data[ti] = NULL;
1489 return TETHERING_ERROR_NONE;
1493 * @brief Registers the callback function called when tethering is disabled.
1494 * @param[in] tethering The handle of tethering
1495 * @param[in] type The type of tethering
1496 * @param[in] callback The callback function to invoke
1497 * @param[in] user_data The user data to be passed to the callback function
1498 * @retval #TETHERING_ERROR_NONE Successful
1499 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1500 * @see tethering_unset_disabled_cb()
1502 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
1504 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1505 "parameter(tethering) is NULL\n");
1506 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1507 "parameter(callback) is NULL\n");
1509 __tethering_h *th = (__tethering_h *)tethering;
1510 tethering_type_e ti;
1512 if (type != TETHERING_TYPE_ALL) {
1513 th->disabled_cb[type] = callback;
1514 th->disabled_user_data[type] = user_data;
1516 return TETHERING_ERROR_NONE;
1519 /* TETHERING_TYPE_ALL */
1520 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1521 th->disabled_cb[ti] = callback;
1522 th->disabled_user_data[ti] = user_data;
1525 return TETHERING_ERROR_NONE;
1529 * @brief Unregisters the callback function called when tethering is disabled.
1530 * @param[in] tethering The handle of tethering
1531 * @param[in] type The type of tethering
1532 * @retval #TETHERING_ERROR_NONE Successful
1533 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1534 * @see tethering_set_disabled_cb()
1536 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
1538 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1539 "parameter(tethering) is NULL\n");
1541 __tethering_h *th = (__tethering_h *)tethering;
1542 tethering_type_e ti;
1544 if (type != TETHERING_TYPE_ALL) {
1545 th->disabled_cb[type] = NULL;
1546 th->disabled_user_data[type] = NULL;
1548 return TETHERING_ERROR_NONE;
1551 /* TETHERING_TYPE_ALL */
1552 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1553 th->disabled_cb[ti] = NULL;
1554 th->disabled_user_data[ti] = NULL;
1557 return TETHERING_ERROR_NONE;
1561 * @brief Registers the callback function called when the state of connection is changed.
1562 * @param[in] tethering The handle of tethering
1563 * @param[in] type The type of tethering
1564 * @param[in] callback The callback function to invoke
1565 * @param[in] user_data The user data to be passed to the callback function
1566 * @retval #TETHERING_ERROR_NONE Successful
1567 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1568 * @see tethering_unset_connection_state_changed_cb_cb()
1570 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
1572 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1573 "parameter(tethering) is NULL\n");
1574 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1575 "parameter(callback) is NULL\n");
1577 __tethering_h *th = (__tethering_h *)tethering;
1578 tethering_type_e ti;
1580 if (type != TETHERING_TYPE_ALL) {
1581 th->changed_cb[type] = callback;
1582 th->changed_user_data[type] = user_data;
1584 return TETHERING_ERROR_NONE;
1587 /* TETHERING_TYPE_ALL */
1588 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1589 th->changed_cb[ti] = callback;
1590 th->changed_user_data[ti] = user_data;
1593 return TETHERING_ERROR_NONE;
1597 * @brief Unregisters the callback function called when the state of connection is changed.
1598 * @param[in] tethering The handle of tethering
1599 * @param[in] type The type of tethering
1600 * @retval #TETHERING_ERROR_NONE Successful
1601 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1602 * @see tethering_set_connection_state_changed_cb()
1604 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
1606 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1607 "parameter(tethering) is NULL\n");
1609 __tethering_h *th = (__tethering_h *)tethering;
1610 tethering_type_e ti;
1612 if (type != TETHERING_TYPE_ALL) {
1613 th->changed_cb[type] = NULL;
1614 th->changed_user_data[type] = NULL;
1616 return TETHERING_ERROR_NONE;
1619 /* TETHERING_TYPE_ALL */
1620 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1621 th->changed_cb[ti] = NULL;
1622 th->changed_user_data[ti] = NULL;
1625 return TETHERING_ERROR_NONE;
1629 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
1630 * @param[in] tethering The handle of tethering
1631 * @param[in] callback The callback function to invoke
1632 * @param[in] user_data The user data to be passed to the callback function
1633 * @retval #TETHERING_ERROR_NONE Successful
1634 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1635 * @see tethering_wifi_unset_security_type_changed_cb()
1637 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
1639 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1640 "parameter(tethering) is NULL\n");
1641 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1642 "parameter(callback) is NULL\n");
1644 __tethering_h *th = (__tethering_h *)tethering;
1646 th->security_type_changed_cb = callback;
1647 th->security_type_user_data = user_data;
1649 return TETHERING_ERROR_NONE;
1654 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
1655 * @param[in] tethering The handle of tethering
1656 * @param[in] type The type of tethering
1657 * @retval #TETHERING_ERROR_NONE Successful
1658 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1659 * @see tethering_wifi_set_security_type_changed_cb()
1661 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
1663 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1664 "parameter(tethering) is NULL\n");
1666 __tethering_h *th = (__tethering_h *)tethering;
1668 th->security_type_changed_cb = NULL;
1669 th->security_type_user_data = NULL;
1671 return TETHERING_ERROR_NONE;
1675 * @brief Registers the callback function called when the visibility of SSID is changed.
1676 * @param[in] tethering The handle of tethering
1677 * @param[in] callback The callback function to invoke
1678 * @param[in] user_data The user data to be passed to the callback function
1679 * @retval #TETHERING_ERROR_NONE Successful
1680 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1681 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
1683 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
1685 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1686 "parameter(tethering) is NULL\n");
1687 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1688 "parameter(callback) is NULL\n");
1690 __tethering_h *th = (__tethering_h *)tethering;
1692 th->ssid_visibility_changed_cb = callback;
1693 th->ssid_visibility_user_data = user_data;
1695 return TETHERING_ERROR_NONE;
1699 * @brief Unregisters the callback function called when the visibility of SSID is changed.
1700 * @param[in] tethering The handle of tethering
1701 * @retval #TETHERING_ERROR_NONE Successful
1702 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1703 * @see tethering_wifi_set_ssid_visibility_changed_cb()
1705 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
1707 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1708 "parameter(tethering) is NULL\n");
1710 __tethering_h *th = (__tethering_h *)tethering;
1712 th->ssid_visibility_changed_cb = NULL;
1713 th->ssid_visibility_user_data = NULL;
1715 return TETHERING_ERROR_NONE;
1719 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
1720 * @param[in] tethering The handle of tethering
1721 * @param[in] callback The callback function to invoke
1722 * @param[in] user_data The user data to be passed to the callback function
1723 * @retval #TETHERING_ERROR_NONE Successful
1724 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1725 * @see tethering_wifi_unset_passphrase_changed_cb()
1727 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
1729 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1730 "parameter(tethering) is NULL\n");
1731 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1732 "parameter(callback) is NULL\n");
1734 __tethering_h *th = (__tethering_h *)tethering;
1736 th->passphrase_changed_cb = callback;
1737 th->passphrase_user_data = user_data;
1739 return TETHERING_ERROR_NONE;
1743 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
1744 * @param[in] tethering The handle of tethering
1745 * @retval #TETHERING_ERROR_NONE Successful
1746 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1747 * @see tethering_wifi_set_passphrase_changed_cb()
1749 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
1751 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1752 "parameter(tethering) is NULL\n");
1754 __tethering_h *th = (__tethering_h *)tethering;
1756 th->passphrase_changed_cb = NULL;
1757 th->passphrase_user_data = NULL;
1759 return TETHERING_ERROR_NONE;
1763 * @brief Sets the security type of Wi-Fi tethering.
1764 * @remarks This change is applied next time Wi-Fi tethering is enabled
1765 * @param[in] tethering The handle of tethering
1766 * @param[in] type The security type
1767 * @return 0 on success, otherwise negative error value.
1768 * @retval #TETHERING_ERROR_NONE Successful
1769 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1770 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1771 * @see tethering_wifi_get_security_type()
1773 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
1775 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1776 "parameter(tethering) is NULL\n");
1779 __tethering_h *th = (__tethering_h *)tethering;
1780 DBusGProxy *proxy = th->client_bus_proxy;
1781 char *type_str = NULL;
1783 if (type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1784 type_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
1785 } else if (type == TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
1786 type_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
1788 ERR("Unsupported type\n");
1789 return TETHERING_ERROR_INVALID_PARAMETER;
1792 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SECURITY_TYPE_CHANGED,
1793 G_CALLBACK(__handle_security_type_changed),
1794 (gpointer)tethering);
1796 org_tizen_tethering_set_wifi_tethering_security_type_async(proxy, type_str,
1797 __wifi_set_security_type_cb, (gpointer)tethering);
1800 return TETHERING_ERROR_NONE;
1804 * @brief Gets the security type of Wi-Fi tethering.
1805 * @param[in] tethering The handle of tethering
1806 * @param[out] type The security type
1807 * @return 0 on success, otherwise negative error value.
1808 * @retval #TETHERING_ERROR_NONE Successful
1809 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1810 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1811 * @see tethering_wifi_set_security_type()
1813 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
1815 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1816 "parameter(tethering) is NULL\n");
1817 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1818 "parameter(type) is NULL\n");
1821 __tethering_h *th = (__tethering_h *)tethering;
1822 DBusGProxy *proxy = th->client_bus_proxy;
1823 GError *error = NULL;
1824 char *type_str = NULL;
1826 org_tizen_tethering_get_wifi_tethering_security_type(proxy, &type_str, &error);
1827 if (error != NULL) {
1828 ERR("DBus fail : %s\n", error->message);
1829 g_error_free(error);
1830 return TETHERING_ERROR_OPERATION_FAILED;
1833 if (type_str == NULL)
1834 return TETHERING_ERROR_OPERATION_FAILED;
1836 DBG("security type : %s\n", type_str);
1837 if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
1838 *type = TETHERING_WIFI_SECURITY_TYPE_NONE;
1839 else if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
1840 *type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1842 ERR("Unknown security type : %s\n", type_str);
1844 return TETHERING_ERROR_OPERATION_FAILED;
1850 return TETHERING_ERROR_NONE;
1854 * @brief Gets the SSID (service set identifier).
1855 * @remarks @a ssid must be released with free() by you.
1856 * @param[in] tethering The handle of tethering
1857 * @param[out] ssid The SSID
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
1864 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
1866 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1867 "parameter(tethering) is NULL\n");
1868 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1869 "parameter(ssid) is NULL\n");
1872 __tethering_h *th = (__tethering_h *)tethering;
1873 DBusGProxy *proxy = th->client_bus_proxy;
1874 GError *error = NULL;
1875 char *ssid_buf = NULL;
1877 org_tizen_tethering_get_wifi_tethering_ssid(proxy, &ssid_buf, &error);
1878 if (error != NULL) {
1879 ERR("dbus fail : %s\n", error->message);
1880 g_error_free(error);
1881 return TETHERING_ERROR_OPERATION_FAILED;
1884 if (ssid_buf == NULL)
1885 return TETHERING_ERROR_OPERATION_FAILED;
1887 *ssid = strdup(ssid_buf);
1888 if (*ssid == NULL) {
1889 ERR("Memory allocation failed\n");
1890 return TETHERING_ERROR_OUT_OF_MEMORY;
1896 return TETHERING_ERROR_NONE;
1900 * @brief Sets the visibility of SSID(service set identifier).
1901 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
1902 * @remarks This change is applied next time Wi-Fi tethering is enabled
1903 * @param[in] tethering The handle of tethering
1904 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
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_OPERATION_FAILED Operation failed
1909 * @see tethering_wifi_get_ssid_visibility()
1911 int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
1913 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1914 "parameter(tethering) is NULL\n");
1917 __tethering_h *th = (__tethering_h *)tethering;
1918 DBusGProxy *proxy = th->client_bus_proxy;
1922 hide_mode = VCONFKEY_MOBILE_AP_HIDE_OFF;
1924 hide_mode = VCONFKEY_MOBILE_AP_HIDE_ON;
1926 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
1927 G_CALLBACK(__handle_ssid_visibility_changed),
1928 (gpointer)tethering);
1930 org_tizen_tethering_set_wifi_tethering_hide_mode_async(proxy, hide_mode,
1931 __wifi_set_ssid_visibility_cb, (gpointer)tethering);
1934 return TETHERING_ERROR_NONE;
1938 * @brief Gets the visibility of SSID(service set identifier).
1939 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
1940 * @param[in] tethering The handle of tethering
1941 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
1942 * @return 0 on success, otherwise negative error value.
1943 * @retval #TETHERING_ERROR_NONE Successful
1944 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1945 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1946 * @see tethering_wifi_set_ssid_visibility()
1948 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
1950 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1951 "parameter(tethering) is NULL\n");
1952 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1953 "parameter(visible) is NULL\n");
1956 __tethering_h *th = (__tethering_h *)tethering;
1957 DBusGProxy *proxy = th->client_bus_proxy;
1958 GError *error = NULL;
1961 org_tizen_tethering_get_wifi_tethering_hide_mode(proxy, &hide_mode, &error);
1962 if (error != NULL) {
1963 ERR("dbus fail : %s\n", error->message);
1964 g_error_free(error);
1965 return TETHERING_ERROR_OPERATION_FAILED;
1967 DBG("hide mode : %d\n", hide_mode);
1969 if (hide_mode == VCONFKEY_MOBILE_AP_HIDE_OFF)
1975 return TETHERING_ERROR_NONE;
1979 * @brief Sets the passphrase.
1980 * @remarks This change is applied next time Wi-Fi tethering is enabled
1981 * @param[in] tethering The handle of tethering
1982 * @param[in] passphrase The passphrase
1983 * @return 0 on success, otherwise negative error value.
1984 * @retval #TETHERING_ERROR_NONE Successful
1985 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1986 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1987 * @see tethering_wifi_get_passphrase()
1989 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
1991 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1992 "parameter(tethering) is NULL\n");
1993 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1994 "parameter(passphrase) is NULL\n");
1997 __tethering_h *th = (__tethering_h *)tethering;
1998 DBusGProxy *proxy = th->client_bus_proxy;
2000 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED,
2001 G_CALLBACK(__handle_passphrase_changed),
2002 (gpointer)tethering);
2004 org_tizen_tethering_set_wifi_tethering_passphrase_async(proxy,
2005 passphrase, strlen(passphrase),
2006 __wifi_set_passphrase_cb, (gpointer)tethering);
2009 return TETHERING_ERROR_NONE;
2013 * @brief Gets the passphrase.
2014 * @remarks @a passphrase must be released with free() by you.
2015 * @param[in] tethering The handle of tethering
2016 * @param[out] passphrase The passphrase
2017 * @return 0 on success, otherwise negative error value.
2018 * @retval #TETHERING_ERROR_NONE Successful
2019 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2020 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2021 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2022 * @see tethering_wifi_set_passphrase()
2024 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2026 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2027 "parameter(tethering) is NULL\n");
2028 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2029 "parameter(passphrase) is NULL\n");
2032 __tethering_h *th = (__tethering_h *)tethering;
2033 DBusGProxy *proxy = th->client_bus_proxy;
2034 GError *error = NULL;
2035 char *passphrase_buf = NULL;
2036 unsigned int len = 0;
2038 org_tizen_tethering_get_wifi_tethering_passphrase(proxy,
2039 &passphrase_buf, &len, &error);
2040 if (error != NULL) {
2041 ERR("dbus fail : %s\n", error->message);
2042 g_error_free(error);
2043 return TETHERING_ERROR_OPERATION_FAILED;
2046 if (passphrase_buf == NULL)
2047 return TETHERING_ERROR_OPERATION_FAILED;
2049 *passphrase = strdup(passphrase_buf);
2050 if (*passphrase == NULL) {
2051 ERR("Memory allocation failed\n");
2052 return TETHERING_ERROR_OUT_OF_MEMORY;
2055 g_free(passphrase_buf);
2058 return TETHERING_ERROR_NONE;