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_NOT_PERMITTED;
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, guint timestamp, 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));
175 client.tm = (time_t)timestamp;
177 ccb((tethering_client_h)&client, opened, data);
182 static void __handle_net_closed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
186 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
188 __tethering_h *th = (__tethering_h *)user_data;
189 tethering_type_e type = 0;
190 tethering_disabled_cb dcb = NULL;
192 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
194 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
195 dcb = th->disabled_cb[type];
198 data = th->disabled_user_data[type];
200 dcb(TETHERING_ERROR_NONE, type, code, data);
206 static void __handle_wifi_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data)
210 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
212 __tethering_h *th = (__tethering_h *)user_data;
213 tethering_type_e type = TETHERING_TYPE_WIFI;
214 bool is_requested = false;
215 tethering_enabled_cb ecb = NULL;
218 ecb = th->enabled_cb[type];
221 data = th->enabled_user_data[type];
223 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
226 static void __handle_wifi_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data)
230 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
232 __tethering_h *th = (__tethering_h *)user_data;
233 tethering_type_e type = TETHERING_TYPE_WIFI;
234 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
235 tethering_disabled_cb dcb = NULL;
238 dcb = th->disabled_cb[type];
241 data = th->disabled_user_data[type];
243 if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
244 code = TETHERING_DISABLED_BY_WIFI_ON;
245 else if (!g_strcmp0(value_name, SIGNAL_MSG_TIMEOUT))
246 code = TETHERING_DISABLED_BY_TIMEOUT;
248 dcb(TETHERING_ERROR_NONE, type, code, data);
253 static void __handle_usb_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data)
257 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
259 __tethering_h *th = (__tethering_h *)user_data;
260 tethering_type_e type = TETHERING_TYPE_USB;
261 bool is_requested = false;
262 tethering_enabled_cb ecb = NULL;
265 ecb = th->enabled_cb[type];
268 data = th->enabled_user_data[type];
270 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
273 static void __handle_usb_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data)
277 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
279 __tethering_h *th = (__tethering_h *)user_data;
280 tethering_type_e type = TETHERING_TYPE_USB;
281 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
282 tethering_disabled_cb dcb = NULL;
285 dcb = th->disabled_cb[type];
288 data = th->disabled_user_data[type];
290 if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
291 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
293 dcb(TETHERING_ERROR_NONE, type, code, data);
298 static void __handle_bt_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data)
302 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
304 __tethering_h *th = (__tethering_h *)user_data;
305 tethering_type_e type = TETHERING_TYPE_BT;
306 bool is_requested = false;
307 tethering_enabled_cb ecb = NULL;
310 ecb = th->enabled_cb[type];
313 data = th->enabled_user_data[type];
315 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
318 static void __handle_bt_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data)
322 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
324 __tethering_h *th = (__tethering_h *)user_data;
325 tethering_type_e type = TETHERING_TYPE_BT;
326 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
327 tethering_disabled_cb dcb = NULL;
330 dcb = th->disabled_cb[type];
333 data = th->disabled_user_data[type];
335 if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
336 code = TETHERING_DISABLED_BY_BT_OFF;
337 else if (!g_strcmp0(value_name, SIGNAL_MSG_TIMEOUT))
338 code = TETHERING_DISABLED_BY_TIMEOUT;
340 dcb(TETHERING_ERROR_NONE, type, code, data);
345 static void __handle_no_data_timeout(DBusGProxy *proxy, const char *value_name, gpointer user_data)
349 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
351 __tethering_h *th = (__tethering_h *)user_data;
352 tethering_type_e type = 0;
353 tethering_disabled_cb dcb = NULL;
355 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
357 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
358 dcb = th->disabled_cb[type];
361 data = th->disabled_user_data[type];
363 dcb(TETHERING_ERROR_NONE, type, code, data);
367 static void __handle_low_battery_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data)
371 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
373 __tethering_h *th = (__tethering_h *)user_data;
374 tethering_type_e type = 0;
375 tethering_disabled_cb dcb = NULL;
377 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
379 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
380 dcb = th->disabled_cb[type];
383 data = th->disabled_user_data[type];
385 dcb(TETHERING_ERROR_NONE, type, code, data);
389 static void __handle_flight_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data)
393 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
395 __tethering_h *th = (__tethering_h *)user_data;
396 tethering_type_e type = 0;
397 tethering_disabled_cb dcb = NULL;
399 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
401 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
402 dcb = th->disabled_cb[type];
405 data = th->disabled_user_data[type];
407 dcb(TETHERING_ERROR_NONE, type, code, data);
411 static void __handle_security_type_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
415 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
417 __tethering_h *th = (__tethering_h *)user_data;
418 tethering_wifi_security_type_changed_cb scb = NULL;
420 tethering_wifi_security_type_e security_type;
422 scb = th->security_type_changed_cb;
426 data = th->security_type_user_data;
427 if (g_strcmp0(value_name, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
428 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
429 else if (g_strcmp0(value_name, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
430 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
432 ERR("Unknown security type : %s\n", value_name);
436 scb(security_type, data);
441 static void __handle_ssid_visibility_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
445 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
447 __tethering_h *th = (__tethering_h *)user_data;
448 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
450 bool visible = false;
452 scb = th->ssid_visibility_changed_cb;
456 data = th->ssid_visibility_user_data;
457 if (g_strcmp0(value_name, SIGNAL_MSG_SSID_VISIBLE) == 0)
465 static void __handle_passphrase_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data)
469 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
471 __tethering_h *th = (__tethering_h *)user_data;
472 tethering_wifi_passphrase_changed_cb pcb = NULL;
475 pcb = th->passphrase_changed_cb;
479 data = th->passphrase_user_data;
486 static void __cfm_cb(DBusGProxy *remoteobj, guint event, guint info,
487 GError *g_error, gpointer user_data)
491 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
493 tethering_h tethering = (tethering_h)user_data;
494 __tethering_h *th = (__tethering_h *)tethering;
495 DBusGProxy *proxy = th->client_bus_proxy;
497 tethering_type_e type = 0;
498 tethering_error_e error = __get_error(info);
499 bool is_requested = true;
500 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
502 tethering_enabled_cb ecb = NULL;
503 tethering_disabled_cb dcb = NULL;
507 ERR("DBus error [%s]\n", g_error->message);
508 g_error_free(g_error);
512 DBG("cfm event : %d info : %d\n", event, info);
514 case MOBILE_AP_ENABLE_WIFI_TETHERING_CFM:
515 type = TETHERING_TYPE_WIFI;
516 ecb = th->enabled_cb[type];
517 data = th->enabled_user_data[type];
519 ecb(error, type, is_requested, data);
520 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
521 G_CALLBACK(__handle_wifi_tether_on),
522 (gpointer)tethering, NULL);
525 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
526 type = TETHERING_TYPE_WIFI;
527 dcb = th->disabled_cb[type];
528 data = th->disabled_user_data[type];
530 dcb(error, type, code, data);
531 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
532 G_CALLBACK(__handle_wifi_tether_off),
533 (gpointer)tethering, NULL);
536 case MOBILE_AP_ENABLE_BT_TETHERING_CFM:
537 type = TETHERING_TYPE_BT;
538 ecb = th->enabled_cb[type];
539 data = th->enabled_user_data[type];
541 ecb(error, type, is_requested, data);
542 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
543 G_CALLBACK(__handle_bt_tether_on),
544 (gpointer)tethering, NULL);
547 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
548 type = TETHERING_TYPE_BT;
549 dcb = th->disabled_cb[type];
550 data = th->disabled_user_data[type];
552 dcb(error, type, code, data);
553 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
554 G_CALLBACK(__handle_bt_tether_off),
555 (gpointer)tethering, NULL);
558 case MOBILE_AP_ENABLE_USB_TETHERING_CFM:
559 type = TETHERING_TYPE_USB;
560 ecb = th->enabled_cb[type];
561 data = th->enabled_user_data[type];
563 ecb(error, type, is_requested, data);
564 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
565 G_CALLBACK(__handle_usb_tether_on),
566 (gpointer)tethering, NULL);
569 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
570 type = TETHERING_TYPE_USB;
571 dcb = th->disabled_cb[type];
572 data = th->disabled_user_data[type];
574 dcb(error, type, code, data);
575 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
576 G_CALLBACK(__handle_usb_tether_off),
577 (gpointer)tethering, NULL);
580 case MOBILE_AP_DISABLE_CFM:
581 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
582 dcb = th->disabled_cb[type];
585 data = th->disabled_user_data[type];
587 dcb(error, type, code, data);
590 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
591 G_CALLBACK(__handle_usb_tether_off),
592 (gpointer)tethering, NULL);
593 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
594 G_CALLBACK(__handle_wifi_tether_off),
595 (gpointer)tethering, NULL);
596 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
597 G_CALLBACK(__handle_bt_tether_off),
598 (gpointer)tethering, NULL);
602 ERR("Invalid event\n");
609 static void __get_data_usage_cb(DBusGProxy *remoteobj, guint event,
610 guint64 tx_bytes, guint64 rx_bytes,
611 GError *error, gpointer user_data)
613 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
615 __tethering_h *th = (__tethering_h *)user_data;
617 if (th->data_usage_cb == NULL) {
618 ERR("There is no data_usage_cb\n");
622 if (error || event != MOBILE_AP_GET_DATA_PACKET_USAGE_CFM) {
624 ERR("DBus fail [%s]\n", error->message);
628 th->data_usage_cb(TETHERING_ERROR_OPERATION_FAILED,
629 0LL, 0LL, th->data_usage_user_data);
631 th->data_usage_cb = NULL;
632 th->data_usage_user_data = NULL;
637 th->data_usage_cb(TETHERING_ERROR_NONE,
638 rx_bytes, tx_bytes, th->data_usage_user_data);
640 th->data_usage_cb = NULL;
641 th->data_usage_user_data = NULL;
646 static void __ip_forward_cb(DBusGProxy *remoteobj, gint result,
647 GError *error, gpointer user_data)
649 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
652 ERR("DBus fail [%s]\n", error->message);
659 static void __connect_signals(tethering_h tethering)
661 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
663 __tethering_h *th = (__tethering_h *)tethering;
664 DBusGProxy *proxy = th->client_bus_proxy;
667 for (i = 0; sigs[i].cb != NULL; i++) {
668 dbus_g_proxy_add_signal(proxy, sigs[i].name,
669 G_TYPE_STRING, G_TYPE_INVALID);
670 dbus_g_proxy_connect_signal(proxy, sigs[i].name,
671 G_CALLBACK(sigs[i].cb), (gpointer)tethering, NULL);
674 dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_STRING_STRING_STRING_UINT,
675 G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING,
676 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
677 dbus_g_proxy_add_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
678 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING,
679 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
680 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
681 G_CALLBACK(__handle_dhcp), (gpointer)tethering, NULL);
686 static void __disconnect_signals(tethering_h tethering)
688 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
690 __tethering_h *th = (__tethering_h *)tethering;
691 DBusGProxy *proxy = th->client_bus_proxy;
695 for (i = 0; sigs[i].cb != NULL; i++) {
696 dbus_g_proxy_disconnect_signal(proxy, sigs[i].name,
697 G_CALLBACK(sigs[i].cb), (gpointer)tethering);
700 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
701 G_CALLBACK(__handle_dhcp), (gpointer)tethering);
706 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
708 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
711 case TETHERING_TYPE_USB:
712 g_strlcpy(buf, TETHERING_USB_IF, len);
715 case TETHERING_TYPE_WIFI:
716 g_strlcpy(buf, TETHERING_WIFI_IF, len);
719 case TETHERING_TYPE_BT:
720 g_strlcpy(buf, TETHERING_BT_IF, len);
724 ERR("Not supported type : %d\n", type);
731 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
733 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
736 case TETHERING_TYPE_USB:
737 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
740 case TETHERING_TYPE_WIFI:
741 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
744 case TETHERING_TYPE_BT:
745 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
749 ERR("Not supported type : %d\n", type);
756 static void __deinit_cb(DBusGProxy *remoteobj,
757 GError *error, gpointer user_data)
759 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
762 ERR("DBus fail [%s]\n", error->message);
769 static void __wifi_set_security_type_cb(DBusGProxy *remoteobj,
770 GError *error, gpointer user_data)
772 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
774 tethering_h tethering = (tethering_h)user_data;
775 __tethering_h *th = (__tethering_h *)tethering;
776 DBusGProxy *proxy = th->client_bus_proxy;
779 ERR("DBus fail [%s]\n", error->message);
783 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_SECURITY_TYPE_CHANGED,
784 G_CALLBACK(__handle_security_type_changed),
785 (gpointer)tethering, NULL);
790 static void __wifi_set_ssid_visibility_cb(DBusGProxy *remoteobj,
791 GError *error, gpointer user_data)
793 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
795 tethering_h tethering = (tethering_h)user_data;
796 __tethering_h *th = (__tethering_h *)tethering;
797 DBusGProxy *proxy = th->client_bus_proxy;
800 ERR("DBus fail [%s]\n", error->message);
804 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
805 G_CALLBACK(__handle_ssid_visibility_changed),
806 (gpointer)tethering, NULL);
811 static void __wifi_set_passphrase_cb(DBusGProxy *remoteobj,
812 GError *error, gpointer user_data)
814 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
816 tethering_h tethering = (tethering_h)user_data;
817 __tethering_h *th = (__tethering_h *)tethering;
818 DBusGProxy *proxy = th->client_bus_proxy;
821 ERR("DBus fail [%s]\n", error->message);
825 dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED,
826 G_CALLBACK(__handle_passphrase_changed),
827 (gpointer)tethering, NULL);
833 * @brief Creates the handle of tethering.
834 * @remarks The @a tethering must be released tethering_destroy() by you.
835 * @param[out] tethering A handle of a new mobile ap handle on success
836 * @return 0 on success, otherwise a negative error value.
837 * @retval #TETHERING_ERROR_NONE Successful
838 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
839 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
840 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
841 * @see tethering_destroy()
843 API int tethering_create(tethering_h *tethering)
845 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
846 "parameter(tethering) is NULL\n");
848 __tethering_h *th = NULL;
849 GError *error = NULL;
850 int retry = TETHERING_DBUS_MAX_RETRY_COUNT;
852 th = (__tethering_h *)malloc(sizeof(__tethering_h));
853 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
854 "malloc is failed\n");
855 memset(th, 0x00, sizeof(__tethering_h));
857 #if !GLIB_CHECK_VERSION(2,35,0)
860 th->client_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
862 ERR("Couldn't connect to the System bus[%s]", error->message);
865 return TETHERING_ERROR_OPERATION_FAILED;
868 th->client_bus_proxy = dbus_g_proxy_new_for_name(th->client_bus,
869 TETHERING_SERVICE_NAME,
870 TETHERING_SERVICE_OBJECT_PATH,
871 TETHERING_SERVICE_INTERFACE);
872 if (!th->client_bus_proxy) {
873 ERR("Couldn't create the proxy object");
874 dbus_g_connection_unref(th->client_bus);
876 return TETHERING_ERROR_OPERATION_FAILED;
880 org_tizen_tethering_init(th->client_bus_proxy, &error);
882 ERR("Couldn't connect to the System bus[%s]",
885 if (error->code == DBUS_GERROR_SERVICE_UNKNOWN) {
886 DBG("Tethering is not supported\n");
889 dbus_g_connection_unref(th->client_bus);
891 return TETHERING_ERROR_NOT_SUPPORT_API;
897 dbus_g_connection_unref(th->client_bus);
899 return TETHERING_ERROR_OPERATION_FAILED;
906 __connect_signals((tethering_h)th);
908 *tethering = (tethering_h)th;
909 DBG("Tethering Handle : 0x%X\n", th);
911 return TETHERING_ERROR_NONE;
915 * @brief Destroys the handle of tethering.
916 * @param[in] tethering The handle of tethering
917 * @return 0 on success, otherwise a negative error value.
918 * @retval #TETHERING_ERROR_NONE Successful
919 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
920 * @see tethering_create()
922 API int tethering_destroy(tethering_h tethering)
924 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
925 "parameter(tethering) is NULL\n");
927 __tethering_h *th = (__tethering_h *)tethering;
929 DBG("Tethering Handle : 0x%X\n", th);
930 __disconnect_signals(tethering);
932 org_tizen_tethering_deinit_async(th->client_bus_proxy, __deinit_cb,
933 (gpointer)tethering);
937 g_object_unref(th->client_bus_proxy);
938 dbus_g_connection_unref(th->client_bus);
939 memset(th, 0x00, sizeof(__tethering_h));
942 return TETHERING_ERROR_NONE;
946 * @brief Enables the tethering, asynchronously.
947 * @param[in] tethering The handle of tethering
948 * @param[in] type The type of tethering
949 * @return 0 on success, otherwise negative error value.
950 * @retval #TETHERING_ERROR_NONE Successful
951 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
952 * @post tethering_enabled_cb() will be invoked.
953 * @see tethering_is_enabled()
954 * @see tethering_disable()
956 API int tethering_enable(tethering_h tethering, tethering_type_e type)
960 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
961 "parameter(tethering) is NULL\n");
963 __tethering_h *th = (__tethering_h *)tethering;
964 DBusGProxy *proxy = th->client_bus_proxy;
967 case TETHERING_TYPE_USB:
968 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
969 G_CALLBACK(__handle_usb_tether_on),
970 (gpointer)tethering);
971 org_tizen_tethering_enable_usb_tethering_async(proxy,
972 __cfm_cb, (gpointer)tethering);
975 case TETHERING_TYPE_WIFI:
976 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
977 G_CALLBACK(__handle_wifi_tether_on),
978 (gpointer)tethering);
979 org_tizen_tethering_enable_wifi_tethering_async(proxy,
980 th->ssid ? th->ssid : "", "", false,
981 __cfm_cb, (gpointer)tethering);
984 case TETHERING_TYPE_BT:
985 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
986 G_CALLBACK(__handle_bt_tether_on),
987 (gpointer)tethering);
988 org_tizen_tethering_enable_bt_tethering_async(proxy,
989 __cfm_cb, (gpointer)tethering);
993 case TETHERING_TYPE_ALL:
994 /* TETHERING_TYPE_USB */
995 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON,
996 G_CALLBACK(__handle_usb_tether_on),
997 (gpointer)tethering);
998 org_tizen_tethering_enable_usb_tethering_async(proxy,
999 __cfm_cb, (gpointer)tethering);
1001 /* TETHERING_TYPE_WIFI */
1002 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON,
1003 G_CALLBACK(__handle_wifi_tether_on),
1004 (gpointer)tethering);
1005 org_tizen_tethering_enable_wifi_tethering_async(proxy,
1006 th->ssid ? th->ssid : "", "", false,
1007 __cfm_cb, (gpointer)tethering);
1009 /* TETHERING_TYPE_BT */
1010 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON,
1011 G_CALLBACK(__handle_bt_tether_on),
1012 (gpointer)tethering);
1013 org_tizen_tethering_enable_bt_tethering_async(proxy,
1014 __cfm_cb, (gpointer)tethering);
1018 ERR("Unknown type : %d\n", type);
1019 return TETHERING_ERROR_INVALID_PARAMETER;
1022 return TETHERING_ERROR_NONE;
1026 * @brief Disables the tethering, asynchronously.
1027 * @param[in] tethering The handle of tethering
1028 * @param[in] type The type of tethering
1029 * @return 0 on success, otherwise negative error value.
1030 * @retval #TETHERING_ERROR_NONE Successful
1031 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1032 * @post tethering_disabled_cb() will be invoked.
1033 * @see tethering_is_enabled()
1034 * @see tethering_enable()
1036 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1038 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1039 "parameter(tethering) is NULL\n");
1041 __tethering_h *th = (__tethering_h *)tethering;
1042 DBusGProxy *proxy = th->client_bus_proxy;
1045 case TETHERING_TYPE_USB:
1046 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
1047 G_CALLBACK(__handle_usb_tether_off),
1048 (gpointer)tethering);
1049 org_tizen_tethering_disable_usb_tethering_async(proxy,
1050 __cfm_cb, (gpointer)tethering);
1053 case TETHERING_TYPE_WIFI:
1054 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
1055 G_CALLBACK(__handle_wifi_tether_off),
1056 (gpointer)tethering);
1057 org_tizen_tethering_disable_wifi_tethering_async(proxy,
1058 __cfm_cb, (gpointer)tethering);
1060 case TETHERING_TYPE_BT:
1061 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
1062 G_CALLBACK(__handle_bt_tether_off),
1063 (gpointer)tethering);
1064 org_tizen_tethering_disable_bt_tethering_async(proxy,
1065 __cfm_cb, (gpointer)tethering);
1068 case TETHERING_TYPE_ALL:
1069 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF,
1070 G_CALLBACK(__handle_usb_tether_off),
1071 (gpointer)tethering);
1072 org_tizen_tethering_disable_usb_tethering_async(proxy,
1073 __cfm_cb, (gpointer)tethering);
1075 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF,
1076 G_CALLBACK(__handle_wifi_tether_off),
1077 (gpointer)tethering);
1078 org_tizen_tethering_disable_wifi_tethering_async(proxy,
1079 __cfm_cb, (gpointer)tethering);
1081 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF,
1082 G_CALLBACK(__handle_bt_tether_off),
1083 (gpointer)tethering);
1084 org_tizen_tethering_disable_bt_tethering_async(proxy,
1085 __cfm_cb, (gpointer)tethering);
1089 ERR("Not supported tethering type [%d]\n", type);
1090 return TETHERING_ERROR_INVALID_PARAMETER;
1094 return TETHERING_ERROR_NONE;
1098 * @brief Checks whetehr the tethering is enabled or not.
1099 * @param[in] tethering The handle of tethering
1100 * @param[in] type The type of tethering
1101 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1103 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1106 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1108 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) {
1113 case TETHERING_TYPE_USB:
1114 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1117 case TETHERING_TYPE_WIFI:
1118 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1121 case TETHERING_TYPE_BT:
1122 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1126 ERR("Not supported type : %d\n", type);
1130 return is_on & vconf_type ? true : false;
1134 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1135 * @remarks @a mac_address must be released with free() by you.
1136 * @param[in] tethering The handle of tethering
1137 * @param[in] type The type of tethering
1138 * @param[out] mac_address The MAC address
1139 * @return 0 on success, otherwise a negative error value.
1140 * @retval #TETHERING_ERROR_NONE Successful
1141 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1142 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1143 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1144 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1145 * @pre tethering must be enabled.
1146 * @see tethering_is_enabled()
1147 * @see tethering_enable()
1149 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1151 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1152 "parameter(tethering) is NULL\n");
1153 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1154 "parameter(mac_address) is NULL\n");
1155 _retvm_if(tethering_is_enabled(tethering, type) == false,
1156 TETHERING_ERROR_NOT_ENABLED,
1157 "tethering type[%d] is not enabled\n", type);
1161 char *macbuf = NULL;
1163 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1164 TETHERING_ERROR_OPERATION_FAILED,
1165 "getting interface name is failed\n");
1167 s = socket(AF_INET, SOCK_DGRAM, 0);
1168 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1169 "getting socket is failed\n");
1170 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1171 ERR("getting mac is failed\n");
1173 return TETHERING_ERROR_OPERATION_FAILED;
1177 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1178 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1179 "Not enough memory\n");
1180 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1181 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1182 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1183 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1184 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1185 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1186 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1188 *mac_address = macbuf;
1190 return TETHERING_ERROR_NONE;
1194 * @brief Gets the name of network interface. For example, usb0.
1195 * @remarks @a interface_name must be released with free() by you.
1196 * @param[in] tethering The handle of tethering
1197 * @param[in] type The type of tethering
1198 * @param[out] interface_name The name of network interface
1199 * @return 0 on success, otherwise negative error value.
1200 * @retval #TETHERING_ERROR_NONE Successful
1201 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1202 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1203 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1204 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1205 * @pre tethering must be enabled.
1206 * @see tethering_is_enabled()
1207 * @see tethering_enable()
1209 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1211 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1212 "parameter(tethering) is NULL\n");
1213 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1214 "parameter(interface_name) is NULL\n");
1215 _retvm_if(tethering_is_enabled(tethering, type) == false,
1216 TETHERING_ERROR_NOT_ENABLED,
1217 "tethering type[%d] is not enabled\n", type);
1219 char intf[TETHERING_STR_INFO_LEN] = {0, };
1221 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1222 TETHERING_ERROR_OPERATION_FAILED,
1223 "getting interface name is failed\n");
1224 *interface_name = strdup(intf);
1225 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1226 "Not enough memory\n");
1228 return TETHERING_ERROR_NONE;
1232 * @brief Gets the local IP address.
1233 * @remarks @a ip_address must be released with free() by you.
1234 * @param[in] tethering The handle of tethering
1235 * @param[in] type The type of tethering
1236 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1237 * @param[out] ip_address The local IP address
1238 * @return 0 on success, otherwise negative error value.
1239 * @retval #TETHERING_ERROR_NONE Successful
1240 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1241 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1242 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1243 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1244 * @pre tethering must be enabled.
1245 * @see tethering_is_enabled()
1246 * @see tethering_enable()
1248 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
1250 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1251 "parameter(tethering) is NULL\n");
1252 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1253 "parameter(ip_address) is NULL\n");
1254 _retvm_if(tethering_is_enabled(tethering, type) == false,
1255 TETHERING_ERROR_NOT_ENABLED,
1256 "tethering type[%d] is not enabled\n", type);
1262 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1263 TETHERING_ERROR_OPERATION_FAILED,
1264 "getting interface name is failed\n");
1266 s = socket(AF_INET, SOCK_DGRAM, 0);
1267 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1268 "getting socket is failed\n");
1269 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
1270 ERR("ioctl is failed\n");
1272 return TETHERING_ERROR_OPERATION_FAILED;
1276 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
1277 *ip_address = strdup(ipbuf);
1278 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1279 "Not enough memory\n");
1281 return TETHERING_ERROR_NONE;
1285 * @brief Gets the Gateway address.
1286 * @remarks @a gateway_address must be released with free() by you.
1287 * @param[in] tethering The handle of tethering
1288 * @param[in] type The type of tethering
1289 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1290 * @param[out] gateway_address The local IP address
1291 * @return 0 on success, otherwise negative error value.
1292 * @retval #TETHERING_ERROR_NONE Successful
1293 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1294 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1295 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1296 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1297 * @pre tethering must be enabled.
1298 * @see tethering_is_enabled()
1299 * @see tethering_enable()
1301 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
1303 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1304 "parameter(tethering) is NULL\n");
1305 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1306 "parameter(gateway_address) is NULL\n");
1307 _retvm_if(tethering_is_enabled(tethering, type) == false,
1308 TETHERING_ERROR_NOT_ENABLED,
1309 "tethering type[%d] is not enabled\n", type);
1311 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
1313 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
1314 TETHERING_ERROR_OPERATION_FAILED,
1315 "getting gateway address is failed\n");
1317 *gateway_address = strdup(gateway_buf);
1319 return TETHERING_ERROR_NONE;
1323 * @brief Gets the Subnet Mask.
1324 * @remarks @a subnet_mask must be released with free() by you.
1325 * @param[in] tethering The handle of tethering
1326 * @param[in] type The type of tethering
1327 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1328 * @param[out] subnet_mask The local IP address
1329 * @return 0 on success, otherwise negative error value.
1330 * @retval #TETHERING_ERROR_NONE Successful
1331 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1332 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1333 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1334 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1335 * @pre tethering must be enabled.
1336 * @see tethering_is_enabled()
1337 * @see tethering_enable()
1339 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
1341 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1342 "parameter(tethering) is NULL\n");
1343 _retvm_if(tethering_is_enabled(tethering, type) == false,
1344 TETHERING_ERROR_NOT_ENABLED,
1345 "tethering is not enabled\n");
1346 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1347 "parameter(subnet_mask) is NULL\n");
1349 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
1350 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1351 "Not enough memory\n");
1353 return TETHERING_ERROR_NONE;
1357 * @brief Gets the data usage.
1358 * @param[in] tethering The handle of tethering
1359 * @param[out] usage The data usage
1360 * @return 0 on success, otherwise negative error value.
1361 * @retval #TETHERING_ERROR_NONE Successful
1362 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1363 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1364 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1365 * @pre tethering must be enabled.
1366 * @see tethering_is_enabled()
1367 * @see tethering_enable()
1369 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
1371 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1372 "parameter(tethering) is NULL\n");
1373 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1374 "parameter(callback) is NULL\n");
1375 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1376 TETHERING_ERROR_NOT_ENABLED,
1377 "tethering is not enabled\n");
1379 __tethering_h *th = (__tethering_h *)tethering;
1380 DBusGProxy *proxy = th->client_bus_proxy;
1382 th->data_usage_cb = callback;
1383 th->data_usage_user_data = user_data;
1385 org_tizen_tethering_get_data_packet_usage_async(proxy,
1386 __get_data_usage_cb, (gpointer)th);
1388 return TETHERING_ERROR_NONE;
1392 * @brief Gets the client which is connected by USB tethering.
1393 * @param[in] tethering The handle of tethering
1394 * @param[in] type The type of tethering
1395 * @param[in] callback The callback function to invoke
1396 * @param[in] user_data The user data to be passed to the callback function
1397 * @retval #TETHERING_ERROR_NONE Successful
1398 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1399 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1400 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1401 * @pre tethering must be enabled.
1402 * @see tethering_is_enabled()
1403 * @see tethering_enable()
1405 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
1407 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1408 "parameter(tethering) is NULL\n");
1409 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1410 "parameter(callback) is NULL\n");
1411 _retvm_if(__any_tethering_is_enabled(tethering) == false,
1412 TETHERING_ERROR_NOT_ENABLED,
1413 "tethering is not enabled\n");
1415 __tethering_h *th = (__tethering_h *)tethering;
1416 __tethering_client_h client = {0, };
1419 GPtrArray *array = NULL;
1420 GValue value = {0, {{0}}};
1421 GError *error = NULL;
1423 int no_of_client = 0;
1424 guint interface = 0;
1427 gchar *hostname = NULL;
1428 guint timestamp = 0;
1430 org_tizen_tethering_get_station_info(th->client_bus_proxy, &event,
1432 if (error != NULL) {
1433 ERR("DBus fail : %s\n", error->message);
1434 g_error_free(error);
1435 return TETHERING_ERROR_OPERATION_FAILED;
1438 g_value_init(&value, DBUS_STRUCT_STATIONS);
1439 no_of_client = array->len;
1440 for (i = 0; i < no_of_client; i++) {
1441 g_value_set_boxed(&value, g_ptr_array_index(array, i));
1443 dbus_g_type_struct_get(&value, 0, &interface, 1, &ip,
1444 2, &mac, 3, &hostname, 4, ×tamp, G_MAXUINT);
1446 if (interface == MOBILE_AP_TYPE_USB)
1447 client.interface = TETHERING_TYPE_USB;
1448 else if (interface == MOBILE_AP_TYPE_WIFI)
1449 client.interface = TETHERING_TYPE_WIFI;
1450 else if (interface == MOBILE_AP_TYPE_BT)
1451 client.interface = TETHERING_TYPE_BT;
1453 if (client.interface != type && TETHERING_TYPE_ALL != type)
1456 g_strlcpy(client.ip, ip, sizeof(client.ip));
1457 g_strlcpy(client.mac, mac, sizeof(client.mac));
1458 g_strlcpy(client.hostname, hostname, sizeof(client.hostname));
1459 client.tm = (time_t)timestamp;
1461 if (callback((tethering_client_h)&client, user_data) == false) {
1462 DBG("iteration is stopped\n");
1463 return TETHERING_ERROR_NONE;
1468 g_ptr_array_free(array, TRUE);
1470 return TETHERING_ERROR_NONE;
1474 * @brief Set the ip forward status
1475 * @param[in] tethering The handle of tethering
1476 * @param[in] status The ip forward status: (@c true = enable, @c false = disable)
1477 * @retval #TETHERING_ERROR_NONE Successful
1478 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1479 * @see tethering_get_ip_forward_status()
1481 API int tethering_set_ip_forward_status(tethering_h tethering, bool status)
1483 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1484 "parameter(tethering) is NULL\n");
1486 __tethering_h *th = (__tethering_h *)tethering;
1487 DBusGProxy *proxy = th->client_bus_proxy;
1489 org_tizen_tethering_set_ip_forward_status_async(proxy, status,
1490 __ip_forward_cb, (gpointer)tethering);
1492 return TETHERING_ERROR_NONE;
1496 * @brief Get the ip forward status
1497 * @param[in] tethering The handle of tethering
1498 * @param[out] status The ip forward status: (@c true = enable, @c false = disable)
1499 * @retval #TETHERING_ERROR_NONE Successful
1500 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1501 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1502 * @see tethering_set_ip_forward_status()
1504 API int tethering_get_ip_forward_status(tethering_h tethering, bool *status)
1506 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1507 "parameter(tethering) is NULL\n");
1508 _retvm_if(status == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1509 "parameter(status) is NULL\n");
1511 __tethering_h *th = (__tethering_h *)tethering;
1512 DBusGProxy *proxy = th->client_bus_proxy;
1513 GError *error = NULL;
1514 int forward_mode = 0;
1516 org_tizen_tethering_get_ip_forward_status(proxy, &forward_mode, &error);
1517 if (error != NULL) {
1518 ERR("DBus fail : %s\n", error->message);
1519 g_error_free(error);
1520 return TETHERING_ERROR_OPERATION_FAILED;
1523 if (forward_mode == 1)
1528 return TETHERING_ERROR_NONE;
1533 * @brief Registers the callback function called when tethering is enabled.
1534 * @param[in] tethering The handle of tethering
1535 * @param[in] type The type of tethering
1536 * @param[in] callback The callback function to invoke
1537 * @param[in] user_data The user data to be passed to the callback function
1538 * @retval #TETHERING_ERROR_NONE Successful
1539 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1540 * @see tethering_unset_enabled_cb()
1542 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
1544 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1545 "parameter(tethering) is NULL\n");
1546 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1547 "parameter(callback) is NULL\n");
1549 __tethering_h *th = (__tethering_h *)tethering;
1550 tethering_type_e ti;
1552 if (type != TETHERING_TYPE_ALL) {
1553 th->enabled_cb[type] = callback;
1554 th->enabled_user_data[type] = user_data;
1556 return TETHERING_ERROR_NONE;
1559 /* TETHERING_TYPE_ALL */
1560 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1561 th->enabled_cb[ti] = callback;
1562 th->enabled_user_data[ti] = user_data;
1565 return TETHERING_ERROR_NONE;
1569 * @brief Unregisters the callback function called when tethering is disabled.
1570 * @param[in] tethering The handle of tethering
1571 * @param[in] type The type of tethering
1572 * @retval #TETHERING_ERROR_NONE Successful
1573 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1574 * @see tethering_set_enabled_cb()
1576 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
1578 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1579 "parameter(tethering) is NULL\n");
1581 __tethering_h *th = (__tethering_h *)tethering;
1582 tethering_type_e ti;
1584 if (type != TETHERING_TYPE_ALL) {
1585 th->enabled_cb[type] = NULL;
1586 th->enabled_user_data[type] = NULL;
1588 return TETHERING_ERROR_NONE;
1591 /* TETHERING_TYPE_ALL */
1592 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1593 th->enabled_cb[ti] = NULL;
1594 th->enabled_user_data[ti] = NULL;
1597 return TETHERING_ERROR_NONE;
1601 * @brief Registers the callback function called when tethering is disabled.
1602 * @param[in] tethering The handle of tethering
1603 * @param[in] type The type of tethering
1604 * @param[in] callback The callback function to invoke
1605 * @param[in] user_data The user data to be passed to the callback function
1606 * @retval #TETHERING_ERROR_NONE Successful
1607 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1608 * @see tethering_unset_disabled_cb()
1610 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
1612 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1613 "parameter(tethering) is NULL\n");
1614 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1615 "parameter(callback) is NULL\n");
1617 __tethering_h *th = (__tethering_h *)tethering;
1618 tethering_type_e ti;
1620 if (type != TETHERING_TYPE_ALL) {
1621 th->disabled_cb[type] = callback;
1622 th->disabled_user_data[type] = user_data;
1624 return TETHERING_ERROR_NONE;
1627 /* TETHERING_TYPE_ALL */
1628 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1629 th->disabled_cb[ti] = callback;
1630 th->disabled_user_data[ti] = user_data;
1633 return TETHERING_ERROR_NONE;
1637 * @brief Unregisters the callback function called when tethering is disabled.
1638 * @param[in] tethering The handle of tethering
1639 * @param[in] type The type of tethering
1640 * @retval #TETHERING_ERROR_NONE Successful
1641 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1642 * @see tethering_set_disabled_cb()
1644 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
1646 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1647 "parameter(tethering) is NULL\n");
1649 __tethering_h *th = (__tethering_h *)tethering;
1650 tethering_type_e ti;
1652 if (type != TETHERING_TYPE_ALL) {
1653 th->disabled_cb[type] = NULL;
1654 th->disabled_user_data[type] = NULL;
1656 return TETHERING_ERROR_NONE;
1659 /* TETHERING_TYPE_ALL */
1660 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1661 th->disabled_cb[ti] = NULL;
1662 th->disabled_user_data[ti] = NULL;
1665 return TETHERING_ERROR_NONE;
1669 * @brief Registers the callback function called when the state of connection is changed.
1670 * @param[in] tethering The handle of tethering
1671 * @param[in] type The type of tethering
1672 * @param[in] callback The callback function to invoke
1673 * @param[in] user_data The user data to be passed to the callback function
1674 * @retval #TETHERING_ERROR_NONE Successful
1675 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1676 * @see tethering_unset_connection_state_changed_cb_cb()
1678 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
1680 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1681 "parameter(tethering) is NULL\n");
1682 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1683 "parameter(callback) is NULL\n");
1685 __tethering_h *th = (__tethering_h *)tethering;
1686 tethering_type_e ti;
1688 if (type != TETHERING_TYPE_ALL) {
1689 th->changed_cb[type] = callback;
1690 th->changed_user_data[type] = user_data;
1692 return TETHERING_ERROR_NONE;
1695 /* TETHERING_TYPE_ALL */
1696 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1697 th->changed_cb[ti] = callback;
1698 th->changed_user_data[ti] = user_data;
1701 return TETHERING_ERROR_NONE;
1705 * @brief Unregisters the callback function called when the state of connection is changed.
1706 * @param[in] tethering The handle of tethering
1707 * @param[in] type The type of tethering
1708 * @retval #TETHERING_ERROR_NONE Successful
1709 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1710 * @see tethering_set_connection_state_changed_cb()
1712 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
1714 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1715 "parameter(tethering) is NULL\n");
1717 __tethering_h *th = (__tethering_h *)tethering;
1718 tethering_type_e ti;
1720 if (type != TETHERING_TYPE_ALL) {
1721 th->changed_cb[type] = NULL;
1722 th->changed_user_data[type] = NULL;
1724 return TETHERING_ERROR_NONE;
1727 /* TETHERING_TYPE_ALL */
1728 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
1729 th->changed_cb[ti] = NULL;
1730 th->changed_user_data[ti] = NULL;
1733 return TETHERING_ERROR_NONE;
1737 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
1738 * @param[in] tethering The handle of tethering
1739 * @param[in] callback The callback function to invoke
1740 * @param[in] user_data The user data to be passed to the callback function
1741 * @retval #TETHERING_ERROR_NONE Successful
1742 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1743 * @see tethering_wifi_unset_security_type_changed_cb()
1745 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
1747 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1748 "parameter(tethering) is NULL\n");
1749 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1750 "parameter(callback) is NULL\n");
1752 __tethering_h *th = (__tethering_h *)tethering;
1754 th->security_type_changed_cb = callback;
1755 th->security_type_user_data = user_data;
1757 return TETHERING_ERROR_NONE;
1762 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
1763 * @param[in] tethering The handle of tethering
1764 * @param[in] type The type of tethering
1765 * @retval #TETHERING_ERROR_NONE Successful
1766 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1767 * @see tethering_wifi_set_security_type_changed_cb()
1769 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
1771 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1772 "parameter(tethering) is NULL\n");
1774 __tethering_h *th = (__tethering_h *)tethering;
1776 th->security_type_changed_cb = NULL;
1777 th->security_type_user_data = NULL;
1779 return TETHERING_ERROR_NONE;
1783 * @brief Registers the callback function called when the visibility of SSID is changed.
1784 * @param[in] tethering The handle of tethering
1785 * @param[in] callback The callback function to invoke
1786 * @param[in] user_data The user data to be passed to the callback function
1787 * @retval #TETHERING_ERROR_NONE Successful
1788 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1789 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
1791 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
1793 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1794 "parameter(tethering) is NULL\n");
1795 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1796 "parameter(callback) is NULL\n");
1798 __tethering_h *th = (__tethering_h *)tethering;
1800 th->ssid_visibility_changed_cb = callback;
1801 th->ssid_visibility_user_data = user_data;
1803 return TETHERING_ERROR_NONE;
1807 * @brief Unregisters the callback function called when the visibility of SSID is changed.
1808 * @param[in] tethering The handle of tethering
1809 * @retval #TETHERING_ERROR_NONE Successful
1810 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1811 * @see tethering_wifi_set_ssid_visibility_changed_cb()
1813 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
1815 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1816 "parameter(tethering) is NULL\n");
1818 __tethering_h *th = (__tethering_h *)tethering;
1820 th->ssid_visibility_changed_cb = NULL;
1821 th->ssid_visibility_user_data = NULL;
1823 return TETHERING_ERROR_NONE;
1827 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
1828 * @param[in] tethering The handle of tethering
1829 * @param[in] callback The callback function to invoke
1830 * @param[in] user_data The user data to be passed to the callback function
1831 * @retval #TETHERING_ERROR_NONE Successful
1832 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1833 * @see tethering_wifi_unset_passphrase_changed_cb()
1835 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
1837 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1838 "parameter(tethering) is NULL\n");
1839 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1840 "parameter(callback) is NULL\n");
1842 __tethering_h *th = (__tethering_h *)tethering;
1844 th->passphrase_changed_cb = callback;
1845 th->passphrase_user_data = user_data;
1847 return TETHERING_ERROR_NONE;
1851 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
1852 * @param[in] tethering The handle of tethering
1853 * @retval #TETHERING_ERROR_NONE Successful
1854 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1855 * @see tethering_wifi_set_passphrase_changed_cb()
1857 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
1859 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1860 "parameter(tethering) is NULL\n");
1862 __tethering_h *th = (__tethering_h *)tethering;
1864 th->passphrase_changed_cb = NULL;
1865 th->passphrase_user_data = NULL;
1867 return TETHERING_ERROR_NONE;
1871 * @brief Sets the security type of Wi-Fi tethering.
1872 * @remarks This change is applied next time Wi-Fi tethering is enabled
1873 * @param[in] tethering The handle of tethering
1874 * @param[in] type The security type
1875 * @return 0 on success, otherwise negative error value.
1876 * @retval #TETHERING_ERROR_NONE Successful
1877 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1878 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1879 * @see tethering_wifi_get_security_type()
1881 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
1883 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1884 "parameter(tethering) is NULL\n");
1887 __tethering_h *th = (__tethering_h *)tethering;
1888 DBusGProxy *proxy = th->client_bus_proxy;
1889 char *type_str = NULL;
1891 if (type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1892 type_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
1893 } else if (type == TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
1894 type_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
1896 ERR("Unsupported type\n");
1897 return TETHERING_ERROR_INVALID_PARAMETER;
1900 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SECURITY_TYPE_CHANGED,
1901 G_CALLBACK(__handle_security_type_changed),
1902 (gpointer)tethering);
1904 org_tizen_tethering_set_wifi_tethering_security_type_async(proxy, type_str,
1905 __wifi_set_security_type_cb, (gpointer)tethering);
1908 return TETHERING_ERROR_NONE;
1912 * @brief Gets the security type of Wi-Fi tethering.
1913 * @param[in] tethering The handle of tethering
1914 * @param[out] type The security type
1915 * @return 0 on success, otherwise negative error value.
1916 * @retval #TETHERING_ERROR_NONE Successful
1917 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1918 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1919 * @see tethering_wifi_set_security_type()
1921 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
1923 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1924 "parameter(tethering) is NULL\n");
1925 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1926 "parameter(type) is NULL\n");
1929 __tethering_h *th = (__tethering_h *)tethering;
1930 DBusGProxy *proxy = th->client_bus_proxy;
1931 GError *error = NULL;
1932 char *type_str = NULL;
1934 org_tizen_tethering_get_wifi_tethering_security_type(proxy, &type_str, &error);
1935 if (error != NULL) {
1936 ERR("DBus fail : %s\n", error->message);
1937 g_error_free(error);
1938 return TETHERING_ERROR_OPERATION_FAILED;
1941 if (type_str == NULL)
1942 return TETHERING_ERROR_OPERATION_FAILED;
1944 DBG("security type : %s\n", type_str);
1945 if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
1946 *type = TETHERING_WIFI_SECURITY_TYPE_NONE;
1947 else if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
1948 *type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1950 ERR("Unknown security type : %s\n", type_str);
1952 return TETHERING_ERROR_OPERATION_FAILED;
1958 return TETHERING_ERROR_NONE;
1962 * @brief Sets the SSID (service set identifier).
1963 * @details If SSID is not set, Device name is used as SSID
1964 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
1965 * @param[in] tethering The handle of tethering
1966 * @param[out] ssid The SSID
1967 * @return 0 on success, otherwise negative error value.
1968 * @retval #TETHERING_ERROR_NONE Successful
1969 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1970 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1972 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
1974 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1975 "parameter(tethering) is NULL\n");
1976 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1977 "parameter(ssid) is NULL\n");
1979 __tethering_h *th = (__tethering_h *)tethering;
1983 ssid_len = strlen(ssid);
1984 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
1985 ERR("parameter(ssid) is too long");
1986 return TETHERING_ERROR_INVALID_PARAMETER;
1989 p_ssid = strdup(ssid);
1990 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1991 "strdup is failed\n");
1997 return TETHERING_ERROR_NONE;
2001 * @brief Gets the SSID (service set identifier).
2002 * @remarks @a ssid must be released with free() by you.
2003 * @param[in] tethering The handle of tethering
2004 * @param[out] ssid The SSID
2005 * @return 0 on success, otherwise negative error value.
2006 * @retval #TETHERING_ERROR_NONE Successful
2007 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2008 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2009 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2011 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2013 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2014 "parameter(tethering) is NULL\n");
2015 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2016 "parameter(ssid) is NULL\n");
2019 __tethering_h *th = (__tethering_h *)tethering;
2020 DBusGProxy *proxy = th->client_bus_proxy;
2021 GError *error = NULL;
2022 char *ssid_buf = NULL;
2024 if (tethering_is_enabled(NULL, TETHERING_TYPE_WIFI) == false &&
2026 DBG("Private SSID is set : %s\n", th->ssid);
2027 *ssid = strdup(th->ssid);
2028 if (*ssid == NULL) {
2029 ERR("Memory allocation failed\n");
2030 return TETHERING_ERROR_OUT_OF_MEMORY;
2033 return TETHERING_ERROR_NONE;
2036 org_tizen_tethering_get_wifi_tethering_ssid(proxy, &ssid_buf, &error);
2037 if (error != NULL) {
2038 ERR("dbus fail : %s\n", error->message);
2039 g_error_free(error);
2040 return TETHERING_ERROR_OPERATION_FAILED;
2043 if (ssid_buf == NULL)
2044 return TETHERING_ERROR_OPERATION_FAILED;
2046 *ssid = strdup(ssid_buf);
2047 if (*ssid == NULL) {
2048 ERR("Memory allocation failed\n");
2049 return TETHERING_ERROR_OUT_OF_MEMORY;
2055 return TETHERING_ERROR_NONE;
2059 * @brief Sets the visibility of SSID(service set identifier).
2060 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2061 * @remarks This change is applied next time Wi-Fi tethering is enabled
2062 * @param[in] tethering The handle of tethering
2063 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2064 * @return 0 on success, otherwise negative error value.
2065 * @retval #TETHERING_ERROR_NONE Successful
2066 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2067 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2068 * @see tethering_wifi_get_ssid_visibility()
2070 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2072 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2073 "parameter(tethering) is NULL\n");
2076 __tethering_h *th = (__tethering_h *)tethering;
2077 DBusGProxy *proxy = th->client_bus_proxy;
2081 hide_mode = VCONFKEY_MOBILE_AP_HIDE_OFF;
2083 hide_mode = VCONFKEY_MOBILE_AP_HIDE_ON;
2085 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2086 G_CALLBACK(__handle_ssid_visibility_changed),
2087 (gpointer)tethering);
2089 org_tizen_tethering_set_wifi_tethering_hide_mode_async(proxy, hide_mode,
2090 __wifi_set_ssid_visibility_cb, (gpointer)tethering);
2093 return TETHERING_ERROR_NONE;
2097 * @brief Gets the visibility of SSID(service set identifier).
2098 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2099 * @param[in] tethering The handle of tethering
2100 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2101 * @return 0 on success, otherwise negative error value.
2102 * @retval #TETHERING_ERROR_NONE Successful
2103 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2104 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2105 * @see tethering_wifi_set_ssid_visibility()
2107 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2109 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2110 "parameter(tethering) is NULL\n");
2111 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2112 "parameter(visible) is NULL\n");
2115 __tethering_h *th = (__tethering_h *)tethering;
2116 DBusGProxy *proxy = th->client_bus_proxy;
2117 GError *error = NULL;
2120 org_tizen_tethering_get_wifi_tethering_hide_mode(proxy, &hide_mode, &error);
2121 if (error != NULL) {
2122 ERR("dbus fail : %s\n", error->message);
2123 g_error_free(error);
2124 return TETHERING_ERROR_OPERATION_FAILED;
2126 DBG("hide mode : %d\n", hide_mode);
2128 if (hide_mode == VCONFKEY_MOBILE_AP_HIDE_OFF)
2134 return TETHERING_ERROR_NONE;
2138 * @brief Sets the passphrase.
2139 * @remarks This change is applied next time Wi-Fi tethering is enabled
2140 * @param[in] tethering The handle of tethering
2141 * @param[in] passphrase The passphrase
2142 * @return 0 on success, otherwise negative error value.
2143 * @retval #TETHERING_ERROR_NONE Successful
2144 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2145 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2146 * @see tethering_wifi_get_passphrase()
2148 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2150 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2151 "parameter(tethering) is NULL\n");
2152 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2153 "parameter(passphrase) is NULL\n");
2156 __tethering_h *th = (__tethering_h *)tethering;
2157 DBusGProxy *proxy = th->client_bus_proxy;
2160 passphrase_len = strlen(passphrase);
2161 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
2162 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
2163 ERR("parameter(passphrase) is too short or long\n");
2164 return TETHERING_ERROR_INVALID_PARAMETER;
2167 dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED,
2168 G_CALLBACK(__handle_passphrase_changed),
2169 (gpointer)tethering);
2171 org_tizen_tethering_set_wifi_tethering_passphrase_async(proxy,
2172 passphrase, passphrase_len,
2173 __wifi_set_passphrase_cb, (gpointer)tethering);
2176 return TETHERING_ERROR_NONE;
2180 * @brief Gets the passphrase.
2181 * @remarks @a passphrase must be released with free() by you.
2182 * @param[in] tethering The handle of tethering
2183 * @param[out] passphrase The passphrase
2184 * @return 0 on success, otherwise negative error value.
2185 * @retval #TETHERING_ERROR_NONE Successful
2186 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2187 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2188 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2189 * @see tethering_wifi_set_passphrase()
2191 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
2193 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2194 "parameter(tethering) is NULL\n");
2195 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2196 "parameter(passphrase) is NULL\n");
2199 __tethering_h *th = (__tethering_h *)tethering;
2200 DBusGProxy *proxy = th->client_bus_proxy;
2201 GError *error = NULL;
2202 char *passphrase_buf = NULL;
2203 unsigned int len = 0;
2205 org_tizen_tethering_get_wifi_tethering_passphrase(proxy,
2206 &passphrase_buf, &len, &error);
2207 if (error != NULL) {
2208 ERR("dbus fail : %s\n", error->message);
2209 g_error_free(error);
2210 return TETHERING_ERROR_OPERATION_FAILED;
2213 if (passphrase_buf == NULL)
2214 return TETHERING_ERROR_OPERATION_FAILED;
2216 *passphrase = strdup(passphrase_buf);
2217 if (*passphrase == NULL) {
2218 ERR("Memory allocation failed\n");
2219 return TETHERING_ERROR_OUT_OF_MEMORY;
2222 g_free(passphrase_buf);
2225 return TETHERING_ERROR_NONE;