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));
842 th->client_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
844 ERR("Couldn't connect to the System bus[%s]", error->message);
847 return TETHERING_ERROR_OPERATION_FAILED;
850 th->client_bus_proxy = dbus_g_proxy_new_for_name(th->client_bus,
851 TETHERING_SERVICE_NAME,
852 TETHERING_SERVICE_OBJECT_PATH,
853 TETHERING_SERVICE_INTERFACE);
854 if (!th->client_bus_proxy) {
855 ERR("Couldn't create the proxy object");
856 dbus_g_connection_unref(th->client_bus);
858 return TETHERING_ERROR_OPERATION_FAILED;
861 __connect_signals((tethering_h)th);
863 *tethering = (tethering_h)th;
864 DBG("Tethering Handle : 0x%X\n", th);
866 return TETHERING_ERROR_NONE;
870 * @brief Destroys the handle of tethering.
871 * @param[in] tethering The handle of tethering
872 * @return 0 on success, otherwise a negative error value.
873 * @retval #TETHERING_ERROR_NONE Successful
874 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
875 * @see tethering_create()
877 API int tethering_destroy(tethering_h tethering)
879 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
880 "parameter(tethering) is NULL\n");
882 __tethering_h *th = (__tethering_h *)tethering;
884 DBG("Tethering Handle : 0x%X\n", th);
885 __disconnect_signals(tethering);
887 org_tizen_tethering_deinit_async(th->client_bus_proxy, __deinit_cb,
888 (gpointer)tethering);
890 g_object_unref(th->client_bus_proxy);
891 dbus_g_connection_unref(th->client_bus);
892 memset(th, 0x00, sizeof(__tethering_h));
895 return TETHERING_ERROR_NONE;
899 * @brief Enables the tethering, asynchronously.
900 * @param[in] tethering The handle of tethering
901 * @param[in] type The type of tethering
902 * @return 0 on success, otherwise negative error value.
903 * @retval #TETHERING_ERROR_NONE Successful
904 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
905 * @post tethering_enabled_cb() will be invoked.
906 * @see tethering_is_enabled()
907 * @see tethering_disable()
909 int tethering_enable(tethering_h tethering, tethering_type_e type)
913 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
914 "parameter(tethering) is NULL\n");
916 __tethering_h *th = (__tethering_h *)tethering;
917 DBusGProxy *proxy = th->client_bus_proxy;
920 case TETHERING_TYPE_USB:
921 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
922 G_CALLBACK(__handle_usb_tether_on),
923 (gpointer)tethering);
924 org_tizen_tethering_enable_usb_tethering_async(proxy,
925 __cfm_cb, (gpointer)tethering);
928 case TETHERING_TYPE_WIFI:
929 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
930 G_CALLBACK(__handle_wifi_tether_on),
931 (gpointer)tethering);
932 org_tizen_tethering_enable_wifi_tethering_async(proxy, "", "", false,
933 __cfm_cb, (gpointer)tethering);
936 case TETHERING_TYPE_BT:
937 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
938 G_CALLBACK(__handle_bt_tether_on),
939 (gpointer)tethering);
940 org_tizen_tethering_enable_bt_tethering_async(proxy,
941 __cfm_cb, (gpointer)tethering);
945 case TETHERING_TYPE_ALL:
946 /* TETHERING_TYPE_USB */
947 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
948 G_CALLBACK(__handle_usb_tether_on),
949 (gpointer)tethering);
950 org_tizen_tethering_enable_usb_tethering_async(proxy,
951 __cfm_cb, (gpointer)tethering);
953 /* TETHERING_TYPE_WIFI */
954 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
955 G_CALLBACK(__handle_wifi_tether_on),
956 (gpointer)tethering);
957 org_tizen_tethering_enable_wifi_tethering_async(proxy, "", "", false,
958 __cfm_cb, (gpointer)tethering);
960 /* TETHERING_TYPE_BT */
961 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
962 G_CALLBACK(__handle_bt_tether_on),
963 (gpointer)tethering);
964 org_tizen_tethering_enable_bt_tethering_async(proxy,
965 __cfm_cb, (gpointer)tethering);
969 ERR("Unknown type : %d\n", type);
970 return TETHERING_ERROR_INVALID_PARAMETER;
973 return TETHERING_ERROR_NONE;
977 * @brief Disables the tethering, asynchronously.
978 * @param[in] tethering The handle of tethering
979 * @param[in] type The type of tethering
980 * @return 0 on success, otherwise negative error value.
981 * @retval #TETHERING_ERROR_NONE Successful
982 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
983 * @post tethering_disabled_cb() will be invoked.
984 * @see tethering_is_enabled()
985 * @see tethering_enable()
987 API int tethering_disable(tethering_h tethering, tethering_type_e type)
989 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
990 "parameter(tethering) is NULL\n");
992 __tethering_h *th = (__tethering_h *)tethering;
993 DBusGProxy *proxy = th->client_bus_proxy;
996 case TETHERING_TYPE_USB:
997 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
998 G_CALLBACK(__handle_usb_tether_off),
999 (gpointer)tethering);
1000 org_tizen_tethering_disable_usb_tethering_async(proxy,
1001 __cfm_cb, (gpointer)tethering);
1004 case TETHERING_TYPE_WIFI:
1005 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
1006 G_CALLBACK(__handle_wifi_tether_off),
1007 (gpointer)tethering);
1008 org_tizen_tethering_disable_wifi_tethering_async(proxy,
1009 __cfm_cb, (gpointer)tethering);
1011 case TETHERING_TYPE_BT:
1012 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
1013 G_CALLBACK(__handle_bt_tether_off),
1014 (gpointer)tethering);
1015 org_tizen_tethering_disable_bt_tethering_async(proxy,
1016 __cfm_cb, (gpointer)tethering);
1019 case TETHERING_TYPE_ALL:
1020 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
1021 G_CALLBACK(__handle_usb_tether_off),
1022 (gpointer)tethering);
1023 org_tizen_tethering_disable_usb_tethering_async(proxy,
1024 __cfm_cb, (gpointer)tethering);
1026 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
1027 G_CALLBACK(__handle_wifi_tether_off),
1028 (gpointer)tethering);
1029 org_tizen_tethering_disable_wifi_tethering_async(proxy,
1030 __cfm_cb, (gpointer)tethering);
1032 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
1033 G_CALLBACK(__handle_bt_tether_off),
1034 (gpointer)tethering);
1035 org_tizen_tethering_disable_bt_tethering_async(proxy,
1036 __cfm_cb, (gpointer)tethering);
1040 ERR("Not supported tethering type [%d]\n", type);
1041 return TETHERING_ERROR_INVALID_PARAMETER;
1045 return TETHERING_ERROR_NONE;
1049 * @brief Checks whetehr the tethering is enabled or not.
1050 * @param[in] tethering The handle of tethering
1051 * @param[in] type The type of tethering
1052 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1054 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1057 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1059 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) {
1064 case TETHERING_TYPE_USB:
1065 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1068 case TETHERING_TYPE_WIFI:
1069 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1072 case TETHERING_TYPE_BT:
1073 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1077 ERR("Not supported type : %d\n", type);
1081 return is_on & vconf_type ? true : false;
1085 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1086 * @remarks @a mac_address must be released with free() by you.
1087 * @param[in] tethering The handle of tethering
1088 * @param[in] type The type of tethering
1089 * @param[out] mac_address The MAC address
1090 * @return 0 on success, otherwise a negative error value.
1091 * @retval #TETHERING_ERROR_NONE Successful
1092 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1093 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1094 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1095 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1096 * @pre tethering must be enabled.
1097 * @see tethering_is_enabled()
1098 * @see tethering_enable()
1100 int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1102 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1103 "parameter(tethering) is NULL\n");
1104 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1105 "parameter(mac_address) is NULL\n");
1106 _retvm_if(tethering_is_enabled(tethering, type) == false,
1107 TETHERING_ERROR_NOT_ENABLED,
1108 "tethering type[%d] is not enabled\n", type);
1112 char *macbuf = NULL;
1114 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1115 TETHERING_ERROR_OPERATION_FAILED,
1116 "getting interface name is failed\n");
1118 s = socket(AF_INET, SOCK_DGRAM, 0);
1119 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1120 "getting socket is failed\n");
1121 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1122 ERR("getting mac is failed\n");
1124 return TETHERING_ERROR_OPERATION_FAILED;
1128 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1129 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1130 "Not enough memory\n");
1131 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1132 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1133 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1134 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1135 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1136 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1137 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1139 *mac_address = macbuf;
1141 return TETHERING_ERROR_NONE;
1145 * @brief Gets the name of network interface. For example, usb0.
1146 * @remarks @a interface_name must be released with free() by you.
1147 * @param[in] tethering The handle of tethering
1148 * @param[in] type The type of tethering
1149 * @param[out] interface_name The name of network interface
1150 * @return 0 on success, otherwise negative error value.
1151 * @retval #TETHERING_ERROR_NONE Successful
1152 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1153 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1154 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1155 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1156 * @pre tethering must be enabled.
1157 * @see tethering_is_enabled()
1158 * @see tethering_enable()
1160 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1162 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1163 "parameter(tethering) is NULL\n");
1164 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1165 "parameter(interface_name) is NULL\n");
1166 _retvm_if(tethering_is_enabled(tethering, type) == false,
1167 TETHERING_ERROR_NOT_ENABLED,
1168 "tethering type[%d] is not enabled\n", type);
1170 char intf[TETHERING_STR_INFO_LEN] = {0, };
1172 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1173 TETHERING_ERROR_OPERATION_FAILED,
1174 "getting interface name is failed\n");
1175 *interface_name = strdup(intf);
1176 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1177 "Not enough memory\n");
1179 return TETHERING_ERROR_NONE;
1183 * @brief Gets the local IP address.
1184 * @remarks @a ip_address must be released with free() by you.
1185 * @param[in] tethering The handle of tethering
1186 * @param[in] type The type of tethering
1187 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1188 * @param[out] ip_address The local IP address
1189 * @return 0 on success, otherwise negative error value.
1190 * @retval #TETHERING_ERROR_NONE Successful
1191 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1192 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1193 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1194 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1195 * @pre tethering must be enabled.
1196 * @see tethering_is_enabled()
1197 * @see tethering_enable()
1199 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1201 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1202 "parameter(tethering) is NULL\n");
1203 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1204 "parameter(ip_address) is NULL\n");
1205 _retvm_if(tethering_is_enabled(tethering, type) == false,
1206 TETHERING_ERROR_NOT_ENABLED,
1207 "tethering type[%d] is not enabled\n", type);
1213 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1214 TETHERING_ERROR_OPERATION_FAILED,
1215 "getting interface name is failed\n");
1217 s = socket(AF_INET, SOCK_DGRAM, 0);
1218 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1219 "getting socket is failed\n");
1220 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1221 ERR("ioctl is failed\n");
1223 return TETHERING_ERROR_OPERATION_FAILED;
1227 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1228 *ip_address = strdup(ipbuf);
1229 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1230 "Not enough memory\n");
1232 return TETHERING_ERROR_NONE;
1236 * @brief Gets the Gateway address.
1237 * @remarks @a gateway_address must be released with free() by you.
1238 * @param[in] tethering The handle of tethering
1239 * @param[in] type The type of tethering
1240 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1241 * @param[out] gateway_address The local IP address
1242 * @return 0 on success, otherwise negative error value.
1243 * @retval #TETHERING_ERROR_NONE Successful
1244 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1245 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1246 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1247 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1248 * @pre tethering must be enabled.
1249 * @see tethering_is_enabled()
1250 * @see tethering_enable()
1252 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1254 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1255 "parameter(tethering) is NULL\n");
1256 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1257 "parameter(gateway_address) is NULL\n");
1258 _retvm_if(tethering_is_enabled(tethering, type) == false,
1259 TETHERING_ERROR_NOT_ENABLED,
1260 "tethering type[%d] is not enabled\n", type);
1262 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1264 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1265 TETHERING_ERROR_OPERATION_FAILED,
1266 "getting gateway address is failed\n");
1268 *gateway_address = strdup(gateway_buf);
1270 return TETHERING_ERROR_NONE;
1274 * @brief Gets the Subnet Mask.
1275 * @remarks @a subnet_mask must be released with free() by you.
1276 * @param[in] tethering The handle of tethering
1277 * @param[in] type The type of tethering
1278 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1279 * @param[out] subnet_mask The local IP address
1280 * @return 0 on success, otherwise negative error value.
1281 * @retval #TETHERING_ERROR_NONE Successful
1282 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1283 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1284 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1285 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1286 * @pre tethering must be enabled.
1287 * @see tethering_is_enabled()
1288 * @see tethering_enable()
1290 int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1292 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1293 "parameter(tethering) is NULL\n");
1294 _retvm_if(tethering_is_enabled(tethering, type) == false,
1295 TETHERING_ERROR_NOT_ENABLED,
1296 "tethering is not enabled\n");
1297 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1298 "parameter(subnet_mask) is NULL\n");
1300 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
1301 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1302 "Not enough memory\n");
1304 return TETHERING_ERROR_NONE;
1308 * @brief Gets the data usage.
1309 * @param[in] tethering The handle of tethering
1310 * @param[out] usage The data usage
1311 * @return 0 on success, otherwise negative error value.
1312 * @retval #TETHERING_ERROR_NONE Successful
1313 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1314 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1315 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1316 * @pre tethering must be enabled.
1317 * @see tethering_is_enabled()
1318 * @see tethering_enable()
1320 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
1322 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1323 "parameter(tethering) is NULL\n");
1324 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1325 "parameter(callback) is NULL\n");
1326 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1327 TETHERING_ERROR_NOT_ENABLED,
1328 "tethering is not enabled\n");
1330 __tethering_h *th = (__tethering_h *)tethering;
1331 DBusGProxy *proxy = th->client_bus_proxy;
1333 th->data_usage_cb = callback;
1334 th->data_usage_user_data = user_data;
1336 org_tizen_tethering_get_data_packet_usage_async(proxy,
1337 __get_data_usage_cb, (gpointer)th);
1339 return TETHERING_ERROR_NONE;
1343 * @brief Gets the client which is connected by USB tethering.
1344 * @param[in] tethering The handle of tethering
1345 * @param[in] type The type of tethering
1346 * @param[in] callback The callback function to invoke
1347 * @param[in] user_data The user data to be passed to the callback function
1348 * @retval #TETHERING_ERROR_NONE Successful
1349 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1350 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1351 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1352 * @pre tethering must be enabled.
1353 * @see tethering_is_enabled()
1354 * @see tethering_enable()
1356 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
1358 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1359 "parameter(tethering) is NULL\n");
1360 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1361 "parameter(callback) is NULL\n");
1362 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1363 TETHERING_ERROR_NOT_ENABLED,
1364 "tethering is not enabled\n");
1366 __tethering_h *th = (__tethering_h *)tethering;
1367 __tethering_client_h client = {0, };
1370 GPtrArray *array = NULL;
1371 GValue value = {0, {{0}}};
1372 GError *error = NULL;
1374 int no_of_client = 0;
1375 guint interface = 0;
1378 gchar *hostname = NULL;
1380 org_tizen_tethering_get_station_info(th->client_bus_proxy, &event,
1382 if (error != NULL) {
1383 ERR("DBus fail : %s\n", error->message);
1384 g_error_free(error);
1385 return TETHERING_ERROR_OPERATION_FAILED;
1388 g_value_init(&value, DBUS_STRUCT_STATIONS);
1389 no_of_client = array->len;
1390 for (i = 0; i < no_of_client; i++) {
1391 g_value_set_boxed(&value, g_ptr_array_index(array, i));
1393 dbus_g_type_struct_get(&value, 0, &interface, 1, &ip,
1394 2, &mac, 3, &hostname, G_MAXUINT);
1396 if (interface == MOBILE_AP_TYPE_USB)
1397 client.interface = TETHERING_TYPE_USB;
1398 else if (interface == MOBILE_AP_TYPE_WIFI)
1399 client.interface = TETHERING_TYPE_WIFI;
1400 else if (interface == MOBILE_AP_TYPE_BT)
1401 client.interface = TETHERING_TYPE_BT;
1403 if (client.interface != type && TETHERING_TYPE_ALL != type)
1406 g_strlcpy(client.ip, ip, sizeof(client.ip));
1407 g_strlcpy(client.mac, mac, sizeof(client.mac));
1408 g_strlcpy(client.hostname, hostname, sizeof(client.hostname));
1410 if (callback((tethering_client_h)&client, user_data) == false) {
1411 DBG("iteration is stopped\n");
1412 return TETHERING_ERROR_NONE;
1417 g_ptr_array_free(array, TRUE);
1419 return TETHERING_ERROR_NONE;
1423 * @brief Registers the callback function called when tethering is enabled.
1424 * @param[in] tethering The handle of tethering
1425 * @param[in] type The type of tethering
1426 * @param[in] callback The callback function to invoke
1427 * @param[in] user_data The user data to be passed to the callback function
1428 * @retval #TETHERING_ERROR_NONE Successful
1429 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1430 * @see tethering_unset_enabled_cb()
1432 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
1434 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1435 "parameter(tethering) is NULL\n");
1436 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1437 "parameter(callback) is NULL\n");
1439 __tethering_h *th = (__tethering_h *)tethering;
1440 tethering_type_e ti;
1442 if (type != TETHERING_TYPE_ALL) {
1443 th->enabled_cb[type] = callback;
1444 th->enabled_user_data[type] = user_data;
1446 return TETHERING_ERROR_NONE;
1449 /* TETHERING_TYPE_ALL */
1450 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1451 th->enabled_cb[ti] = callback;
1452 th->enabled_user_data[ti] = user_data;
1455 return TETHERING_ERROR_NONE;
1459 * @brief Unregisters the callback function called when tethering is disabled.
1460 * @param[in] tethering The handle of tethering
1461 * @param[in] type The type of tethering
1462 * @retval #TETHERING_ERROR_NONE Successful
1463 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1464 * @see tethering_set_enabled_cb()
1466 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
1468 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1469 "parameter(tethering) is NULL\n");
1471 __tethering_h *th = (__tethering_h *)tethering;
1472 tethering_type_e ti;
1474 if (type != TETHERING_TYPE_ALL) {
1475 th->enabled_cb[type] = NULL;
1476 th->enabled_user_data[type] = NULL;
1478 return TETHERING_ERROR_NONE;
1481 /* TETHERING_TYPE_ALL */
1482 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1483 th->enabled_cb[ti] = NULL;
1484 th->enabled_user_data[ti] = NULL;
1487 return TETHERING_ERROR_NONE;
1491 * @brief Registers the callback function called when tethering is disabled.
1492 * @param[in] tethering The handle of tethering
1493 * @param[in] type The type of tethering
1494 * @param[in] callback The callback function to invoke
1495 * @param[in] user_data The user data to be passed to the callback function
1496 * @retval #TETHERING_ERROR_NONE Successful
1497 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1498 * @see tethering_unset_disabled_cb()
1500 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
1502 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1503 "parameter(tethering) is NULL\n");
1504 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1505 "parameter(callback) is NULL\n");
1507 __tethering_h *th = (__tethering_h *)tethering;
1508 tethering_type_e ti;
1510 if (type != TETHERING_TYPE_ALL) {
1511 th->disabled_cb[type] = callback;
1512 th->disabled_user_data[type] = user_data;
1514 return TETHERING_ERROR_NONE;
1517 /* TETHERING_TYPE_ALL */
1518 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1519 th->disabled_cb[ti] = callback;
1520 th->disabled_user_data[ti] = user_data;
1523 return TETHERING_ERROR_NONE;
1527 * @brief Unregisters the callback function called when tethering is disabled.
1528 * @param[in] tethering The handle of tethering
1529 * @param[in] type The type of tethering
1530 * @retval #TETHERING_ERROR_NONE Successful
1531 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1532 * @see tethering_set_disabled_cb()
1534 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
1536 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1537 "parameter(tethering) is NULL\n");
1539 __tethering_h *th = (__tethering_h *)tethering;
1540 tethering_type_e ti;
1542 if (type != TETHERING_TYPE_ALL) {
1543 th->disabled_cb[type] = NULL;
1544 th->disabled_user_data[type] = NULL;
1546 return TETHERING_ERROR_NONE;
1549 /* TETHERING_TYPE_ALL */
1550 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1551 th->disabled_cb[ti] = NULL;
1552 th->disabled_user_data[ti] = NULL;
1555 return TETHERING_ERROR_NONE;
1559 * @brief Registers the callback function called when the state of connection is changed.
1560 * @param[in] tethering The handle of tethering
1561 * @param[in] type The type of tethering
1562 * @param[in] callback The callback function to invoke
1563 * @param[in] user_data The user data to be passed to the callback function
1564 * @retval #TETHERING_ERROR_NONE Successful
1565 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1566 * @see tethering_unset_connection_state_changed_cb_cb()
1568 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
1570 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1571 "parameter(tethering) is NULL\n");
1572 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1573 "parameter(callback) is NULL\n");
1575 __tethering_h *th = (__tethering_h *)tethering;
1576 tethering_type_e ti;
1578 if (type != TETHERING_TYPE_ALL) {
1579 th->changed_cb[type] = callback;
1580 th->changed_user_data[type] = user_data;
1582 return TETHERING_ERROR_NONE;
1585 /* TETHERING_TYPE_ALL */
1586 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1587 th->changed_cb[ti] = callback;
1588 th->changed_user_data[ti] = user_data;
1591 return TETHERING_ERROR_NONE;
1595 * @brief Unregisters the callback function called when the state of connection is changed.
1596 * @param[in] tethering The handle of tethering
1597 * @param[in] type The type of tethering
1598 * @retval #TETHERING_ERROR_NONE Successful
1599 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1600 * @see tethering_set_connection_state_changed_cb()
1602 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
1604 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1605 "parameter(tethering) is NULL\n");
1607 __tethering_h *th = (__tethering_h *)tethering;
1608 tethering_type_e ti;
1610 if (type != TETHERING_TYPE_ALL) {
1611 th->changed_cb[type] = NULL;
1612 th->changed_user_data[type] = NULL;
1614 return TETHERING_ERROR_NONE;
1617 /* TETHERING_TYPE_ALL */
1618 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1619 th->changed_cb[ti] = NULL;
1620 th->changed_user_data[ti] = NULL;
1623 return TETHERING_ERROR_NONE;
1627 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
1628 * @param[in] tethering The handle of tethering
1629 * @param[in] callback The callback function to invoke
1630 * @param[in] user_data The user data to be passed to the callback function
1631 * @retval #TETHERING_ERROR_NONE Successful
1632 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1633 * @see tethering_wifi_unset_security_type_changed_cb()
1635 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
1637 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1638 "parameter(tethering) is NULL\n");
1639 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1640 "parameter(callback) is NULL\n");
1642 __tethering_h *th = (__tethering_h *)tethering;
1644 th->security_type_changed_cb = callback;
1645 th->security_type_user_data = user_data;
1647 return TETHERING_ERROR_NONE;
1652 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
1653 * @param[in] tethering The handle of tethering
1654 * @param[in] type The type of tethering
1655 * @retval #TETHERING_ERROR_NONE Successful
1656 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1657 * @see tethering_wifi_set_security_type_changed_cb()
1659 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
1661 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1662 "parameter(tethering) is NULL\n");
1664 __tethering_h *th = (__tethering_h *)tethering;
1666 th->security_type_changed_cb = NULL;
1667 th->security_type_user_data = NULL;
1669 return TETHERING_ERROR_NONE;
1673 * @brief Registers the callback function called when the visibility of SSID is changed.
1674 * @param[in] tethering The handle of tethering
1675 * @param[in] callback The callback function to invoke
1676 * @param[in] user_data The user data to be passed to the callback function
1677 * @retval #TETHERING_ERROR_NONE Successful
1678 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1679 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
1681 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
1683 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1684 "parameter(tethering) is NULL\n");
1685 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1686 "parameter(callback) is NULL\n");
1688 __tethering_h *th = (__tethering_h *)tethering;
1690 th->ssid_visibility_changed_cb = callback;
1691 th->ssid_visibility_user_data = user_data;
1693 return TETHERING_ERROR_NONE;
1697 * @brief Unregisters the callback function called when the visibility of SSID is changed.
1698 * @param[in] tethering The handle of tethering
1699 * @retval #TETHERING_ERROR_NONE Successful
1700 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1701 * @see tethering_wifi_set_ssid_visibility_changed_cb()
1703 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
1705 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1706 "parameter(tethering) is NULL\n");
1708 __tethering_h *th = (__tethering_h *)tethering;
1710 th->ssid_visibility_changed_cb = NULL;
1711 th->ssid_visibility_user_data = NULL;
1713 return TETHERING_ERROR_NONE;
1717 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
1718 * @param[in] tethering The handle of tethering
1719 * @param[in] callback The callback function to invoke
1720 * @param[in] user_data The user data to be passed to the callback function
1721 * @retval #TETHERING_ERROR_NONE Successful
1722 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1723 * @see tethering_wifi_unset_passphrase_changed_cb()
1725 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
1727 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1728 "parameter(tethering) is NULL\n");
1729 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1730 "parameter(callback) is NULL\n");
1732 __tethering_h *th = (__tethering_h *)tethering;
1734 th->passphrase_changed_cb = callback;
1735 th->passphrase_user_data = user_data;
1737 return TETHERING_ERROR_NONE;
1741 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
1742 * @param[in] tethering The handle of tethering
1743 * @retval #TETHERING_ERROR_NONE Successful
1744 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1745 * @see tethering_wifi_set_passphrase_changed_cb()
1747 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
1749 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1750 "parameter(tethering) is NULL\n");
1752 __tethering_h *th = (__tethering_h *)tethering;
1754 th->passphrase_changed_cb = NULL;
1755 th->passphrase_user_data = NULL;
1757 return TETHERING_ERROR_NONE;
1761 * @brief Sets the security type of Wi-Fi tethering.
1762 * @remarks You must set this value when Wi-Fi tethering is disabled.
1763 * @param[in] tethering The handle of tethering
1764 * @param[in] type The security type
1765 * @return 0 on success, otherwise negative error value.
1766 * @retval #TETHERING_ERROR_NONE Successful
1767 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1768 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1769 * @retval #TETHERING_ERROR_INVALID_OPERATION Invalid operation
1770 * @pre Wi-Fi tethering must be disabled.
1771 * @see tethering_is_enabled()
1772 * @see tethering_wifi_get_security_type()
1774 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
1776 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1777 "parameter(tethering) is NULL\n");
1780 __tethering_h *th = (__tethering_h *)tethering;
1781 DBusGProxy *proxy = th->client_bus_proxy;
1782 char *type_str = NULL;
1784 if (type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1785 type_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
1786 } else if (type == TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
1787 type_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
1789 ERR("Unsupported type\n");
1790 return TETHERING_ERROR_INVALID_PARAMETER;
1793 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SECURITY_TYPE_CHANGED,
1794 G_CALLBACK(__handle_security_type_changed),
1795 (gpointer)tethering);
1797 org_tizen_tethering_set_wifi_tethering_security_type_async(proxy, type_str,
1798 __wifi_set_security_type_cb, (gpointer)tethering);
1801 return TETHERING_ERROR_NONE;
1805 * @brief Gets the security type of Wi-Fi tethering.
1806 * @param[in] tethering The handle of tethering
1807 * @param[out] type The security type
1808 * @return 0 on success, otherwise negative error value.
1809 * @retval #TETHERING_ERROR_NONE Successful
1810 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1811 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1812 * @see tethering_wifi_set_security_type()
1814 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
1816 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1817 "parameter(tethering) is NULL\n");
1818 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1819 "parameter(type) is NULL\n");
1822 __tethering_h *th = (__tethering_h *)tethering;
1823 DBusGProxy *proxy = th->client_bus_proxy;
1824 GError *error = NULL;
1825 char *type_str = NULL;
1827 org_tizen_tethering_get_wifi_tethering_security_type(proxy, &type_str, &error);
1828 if (error != NULL) {
1829 ERR("DBus fail : %s\n", error->message);
1830 g_error_free(error);
1831 return TETHERING_ERROR_OPERATION_FAILED;
1834 if (type_str == NULL)
1835 return TETHERING_ERROR_OPERATION_FAILED;
1837 DBG("security type : %s\n", type_str);
1838 if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
1839 *type = TETHERING_WIFI_SECURITY_TYPE_NONE;
1840 else if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
1841 *type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1843 ERR("Unknown security type : %s\n", type_str);
1845 return TETHERING_ERROR_OPERATION_FAILED;
1851 return TETHERING_ERROR_NONE;
1855 * @brief Gets the SSID (service set identifier).
1856 * @remarks @a ssid must be released with free() by you.
1857 * @param[in] tethering The handle of tethering
1858 * @param[out] ssid The SSID
1859 * @return 0 on success, otherwise negative error value.
1860 * @retval #TETHERING_ERROR_NONE Successful
1861 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1862 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1863 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1865 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
1867 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1868 "parameter(tethering) is NULL\n");
1869 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1870 "parameter(ssid) is NULL\n");
1873 __tethering_h *th = (__tethering_h *)tethering;
1874 DBusGProxy *proxy = th->client_bus_proxy;
1875 GError *error = NULL;
1876 char *ssid_buf = NULL;
1878 org_tizen_tethering_get_wifi_tethering_ssid(proxy, &ssid_buf, &error);
1879 if (error != NULL) {
1880 ERR("dbus fail : %s\n", error->message);
1881 g_error_free(error);
1882 return TETHERING_ERROR_OPERATION_FAILED;
1885 if (ssid_buf == NULL)
1886 return TETHERING_ERROR_OPERATION_FAILED;
1888 *ssid = strdup(ssid_buf);
1889 if (*ssid == NULL) {
1890 ERR("Memory allocation failed\n");
1891 return TETHERING_ERROR_OUT_OF_MEMORY;
1897 return TETHERING_ERROR_NONE;
1901 * @brief Sets the visibility of SSID(service set identifier).
1902 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
1903 * @remarks You must set this value when Wi-Fi tethering is disabled.
1904 * @param[in] tethering The handle of tethering
1905 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
1906 * @return 0 on success, otherwise negative error value.
1907 * @retval #TETHERING_ERROR_NONE Successful
1908 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1909 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1910 * @retval #TETHERING_ERROR_INVALID_OPERATION Invalid operation
1911 * @pre Wi-Fi tethering must be disabled.
1912 * @see tethering_is_enabled()
1913 * @see tethering_wifi_get_ssid_visibility()
1915 int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
1917 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1918 "parameter(tethering) is NULL\n");
1921 __tethering_h *th = (__tethering_h *)tethering;
1922 DBusGProxy *proxy = th->client_bus_proxy;
1926 hide_mode = VCONFKEY_MOBILE_AP_HIDE_OFF;
1928 hide_mode = VCONFKEY_MOBILE_AP_HIDE_ON;
1930 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
1931 G_CALLBACK(__handle_ssid_visibility_changed),
1932 (gpointer)tethering);
1934 org_tizen_tethering_set_wifi_tethering_hide_mode_async(proxy, hide_mode,
1935 __wifi_set_ssid_visibility_cb, (gpointer)tethering);
1938 return TETHERING_ERROR_NONE;
1942 * @brief Gets the visibility of SSID(service set identifier).
1943 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
1944 * @param[in] tethering The handle of tethering
1945 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
1946 * @return 0 on success, otherwise negative error value.
1947 * @retval #TETHERING_ERROR_NONE Successful
1948 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1949 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1950 * @see tethering_wifi_set_ssid_visibility()
1952 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
1954 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1955 "parameter(tethering) is NULL\n");
1956 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1957 "parameter(visible) is NULL\n");
1960 __tethering_h *th = (__tethering_h *)tethering;
1961 DBusGProxy *proxy = th->client_bus_proxy;
1962 GError *error = NULL;
1965 org_tizen_tethering_get_wifi_tethering_hide_mode(proxy, &hide_mode, &error);
1966 if (error != NULL) {
1967 ERR("dbus fail : %s\n", error->message);
1968 g_error_free(error);
1969 return TETHERING_ERROR_OPERATION_FAILED;
1971 DBG("hide mode : %d\n", hide_mode);
1973 if (hide_mode == VCONFKEY_MOBILE_AP_HIDE_OFF)
1979 return TETHERING_ERROR_NONE;
1983 * @brief Sets the passphrase.
1984 * @remarks You must set this value when Wi-Fi tethering is disabled.
1985 * @param[in] tethering The handle of tethering
1986 * @param[in] passphrase The passphrase
1987 * @return 0 on success, otherwise negative error value.
1988 * @retval #TETHERING_ERROR_NONE Successful
1989 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1990 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1991 * @retval #TETHERING_ERROR_INVALID_OPERATION Invalid operation
1992 * @pre Wi-Fi tethering must be disabled.
1993 * @see tethering_is_enabled()
1994 * @see tethering_wifi_get_passphrase()
1996 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
1998 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1999 "parameter(tethering) is NULL\n");
2000 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2001 "parameter(passphrase) is NULL\n");
2004 __tethering_h *th = (__tethering_h *)tethering;
2005 DBusGProxy *proxy = th->client_bus_proxy;
2007 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED,
2008 G_CALLBACK(__handle_passphrase_changed),
2009 (gpointer)tethering);
2011 org_tizen_tethering_set_wifi_tethering_passphrase_async(proxy,
2012 passphrase, strlen(passphrase),
2013 __wifi_set_passphrase_cb, (gpointer)tethering);
2016 return TETHERING_ERROR_NONE;
2020 * @brief Gets the passphrase.
2021 * @remarks @a passphrase must be released with free() by you.
2022 * @param[in] tethering The handle of tethering
2023 * @param[out] passphrase The passphrase
2024 * @return 0 on success, otherwise negative error value.
2025 * @retval #TETHERING_ERROR_NONE Successful
2026 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2027 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2028 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2029 * @see tethering_wifi_set_passphrase()
2031 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2033 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2034 "parameter(tethering) is NULL\n");
2035 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2036 "parameter(passphrase) is NULL\n");
2039 __tethering_h *th = (__tethering_h *)tethering;
2040 DBusGProxy *proxy = th->client_bus_proxy;
2041 GError *error = NULL;
2042 char *passphrase_buf = NULL;
2043 unsigned int len = 0;
2045 org_tizen_tethering_get_wifi_tethering_passphrase(proxy,
2046 &passphrase_buf, &len, &error);
2047 if (error != NULL) {
2048 ERR("dbus fail : %s\n", error->message);
2049 g_error_free(error);
2050 return TETHERING_ERROR_OPERATION_FAILED;
2053 if (passphrase_buf == NULL)
2054 return TETHERING_ERROR_OPERATION_FAILED;
2056 *passphrase = strdup(passphrase_buf);
2057 if (*passphrase == NULL) {
2058 ERR("Memory allocation failed\n");
2059 return TETHERING_ERROR_OUT_OF_MEMORY;
2062 g_free(passphrase_buf);
2065 return TETHERING_ERROR_NONE;