Chage the GDBusProxyFlags to launch mobileap-agent on demand
[platform/core/api/tethering.git] / src / tethering.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <net/if.h>
24 #include <arpa/inet.h>
25 #include <unistd.h>
26 #include <dbus/dbus.h>
27 #include <gio/gio.h>
28 #include <vconf.h>
29 #include <openssl/evp.h>
30 #include <openssl/sha.h>
31 #include <ckmc/ckmc-manager.h>
32 #include "tethering_private.h"
33
34 #define ALLOWED_LIST    "/etc/hostapd.accept"
35 #define BLOCKED_LIST    "/etc/hostapd.deny"
36 #define TEMP_LIST       "/etc/hostapd_tmp"
37 #define MAC_ADDR_LEN    18
38 #define MAX_BUF_SIZE    80
39
40 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
41                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
42                         GVariant *parameters, gpointer user_data);
43
44 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
45                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
46                 GVariant *parameters, gpointer user_data);
47
48 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
49                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
50                 GVariant *parameters, gpointer user_data);
51
52 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
53                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
54                 GVariant *parameters, gpointer user_data);
55
56 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
57                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
58                 GVariant *parameters, gpointer user_data);
59
60 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
61                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
62                 GVariant *parameters, gpointer user_data);
63
64 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
65                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
66                 GVariant *parameters, gpointer user_data);
67
68 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
69                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
70                 GVariant *parameters, gpointer user_data);
71
72 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
73                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
74                 GVariant *parameters, gpointer user_data);
75
76 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
77                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
78                 GVariant *parameters, gpointer user_data);
79
80 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
81                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
82                 GVariant *parameters, gpointer user_data);
83
84 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
85                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
86                 GVariant *parameters, gpointer user_data);
87
88 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
89                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
90                 GVariant *parameters, gpointer user_data);
91
92 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
93                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
94                 GVariant *parameters, gpointer user_data);
95
96 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
97                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
98                 GVariant *parameters, gpointer user_data);
99
100 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
101                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
102                 GVariant *parameters, gpointer user_data);
103
104 static __tethering_sig_t sigs[] = {
105         {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
106         {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
107         {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
108         {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
109         {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
110         {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
111         {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
112         {0, SIGNAL_NAME_WIFI_AP_ON, __handle_wifi_ap_on},
113         {0, SIGNAL_NAME_WIFI_AP_OFF, __handle_wifi_ap_off},
114         {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
115         {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
116         {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
117         {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
118         {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
119         {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
120         {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
121         {0, "", NULL} };
122
123 static int retry = 0;
124
125 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
126 {
127         if (conn == NULL || signal_name == NULL)
128                 return;
129
130         GVariant *message = NULL;
131         GError *error = NULL;
132
133         if (arg)
134                 message = g_variant_new("(s)", arg);
135
136         g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
137                                         TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
138         if (error) {
139                 ERR("g_dbus_connection_emit_signal is failed because  %s\n", error->message);
140                 g_error_free(error);
141         }
142         g_variant_unref(message);
143 }
144
145 static bool __any_tethering_is_enabled(tethering_h tethering)
146 {
147         if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
148                         tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
149                         tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
150                         tethering_is_enabled(tethering, TETHERING_TYPE_RESERVED))
151                 return true;
152
153         return false;
154 }
155
156 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
157 {
158         if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
159                         security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
160                 ERR("Invalid param\n");
161                 return TETHERING_ERROR_INVALID_PARAMETER;
162         }
163
164         if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
165                 ERR("vconf_set_int is failed\n");
166                 return TETHERING_ERROR_OPERATION_FAILED;
167         }
168
169         return TETHERING_ERROR_NONE;
170 }
171
172 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
173 {
174         if (security_type == NULL) {
175                 ERR("Invalid param\n");
176                 return TETHERING_ERROR_INVALID_PARAMETER;
177         }
178
179         if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
180                                 (int *)security_type) < 0) {
181                 ERR("vconf_get_int is failed\n");
182                 return TETHERING_ERROR_OPERATION_FAILED;
183         }
184
185         return TETHERING_ERROR_NONE;
186 }
187
188 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
189 {
190         if (path == NULL || ssid == NULL || size == 0)
191                 return false;
192
193         char *ptr = NULL;
194         char *ptr_tmp = NULL;
195
196         ptr = vconf_get_str(path);
197         if (ptr == NULL)
198                 return false;
199
200         if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
201                 *ptr_tmp = '\0';
202
203         g_strlcpy(ssid, ptr, size);
204         free(ptr);
205
206         return true;
207 }
208
209 static tethering_error_e __set_visible(const bool visible)
210 {
211         if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
212                 ERR("vconf_set_int is failed\n");
213                 return TETHERING_ERROR_OPERATION_FAILED;
214         }
215
216         return TETHERING_ERROR_NONE;
217 }
218
219 static tethering_error_e __get_visible(bool *visible)
220 {
221         if (visible == NULL) {
222                 ERR("Invalid param\n");
223                 return TETHERING_ERROR_INVALID_PARAMETER;
224         }
225
226         int hide = 0;
227
228         if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
229                 ERR("vconf_get_int is failed\n");
230                 return TETHERING_ERROR_OPERATION_FAILED;
231         }
232
233         if (hide)
234                 *visible = false;
235         else
236                 *visible = true;
237         return TETHERING_ERROR_NONE;
238 }
239
240 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
241 {
242         if (passphrase == NULL ||
243                         size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
244                 return 0;
245
246         guint32 rand_int = 0;
247         int index = 0;
248
249         for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
250                 rand_int = g_random_int_range('a', 'z');
251                 passphrase[index] = rand_int;
252         }
253         passphrase[index] = '\0';
254
255         return index;
256 }
257
258 static tethering_error_e __get_error(int agent_error)
259 {
260         tethering_error_e err = TETHERING_ERROR_NONE;
261
262         switch (agent_error) {
263         case MOBILE_AP_ERROR_NONE:
264                 err = TETHERING_ERROR_NONE;
265                 break;
266
267         case MOBILE_AP_ERROR_RESOURCE:
268                 err = TETHERING_ERROR_OUT_OF_MEMORY;
269                 break;
270
271         case MOBILE_AP_ERROR_INTERNAL:
272                 err = TETHERING_ERROR_OPERATION_FAILED;
273                 break;
274
275         case MOBILE_AP_ERROR_INVALID_PARAM:
276                 err = TETHERING_ERROR_INVALID_PARAMETER;
277                 break;
278
279         case MOBILE_AP_ERROR_ALREADY_ENABLED:
280                 err = TETHERING_ERROR_OPERATION_FAILED;
281                 break;
282
283         case MOBILE_AP_ERROR_NOT_ENABLED:
284                 err = TETHERING_ERROR_NOT_ENABLED;
285                 break;
286
287         case MOBILE_AP_ERROR_NET_OPEN:
288                 err = TETHERING_ERROR_OPERATION_FAILED;
289                 break;
290
291         case MOBILE_AP_ERROR_NET_CLOSE:
292                 err = TETHERING_ERROR_OPERATION_FAILED;
293                 break;
294
295         case MOBILE_AP_ERROR_DHCP:
296                 err = TETHERING_ERROR_OPERATION_FAILED;
297                 break;
298
299         case MOBILE_AP_ERROR_IN_PROGRESS:
300                 err = TETHERING_ERROR_OPERATION_FAILED;
301                 break;
302
303         case MOBILE_AP_ERROR_NOT_PERMITTED:
304                 err = TETHERING_ERROR_NOT_PERMITTED;
305                 break;
306
307         case MOBILE_AP_ERROR_PERMISSION_DENIED:
308                 err = TETHERING_ERROR_PERMISSION_DENIED;
309                 break;
310
311         default:
312                 ERR("Not defined error : %d\n", agent_error);
313                 err = TETHERING_ERROR_OPERATION_FAILED;
314                 break;
315         }
316
317         return err;
318 }
319
320 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
321                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
322                 GVariant *parameters, gpointer user_data)
323 {
324         DBG("+\n");
325
326         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
327
328         __tethering_h *th = (__tethering_h *)user_data;
329         bool opened = false;
330         tethering_type_e type = 0;
331         mobile_ap_type_e ap_type = 0;
332         tethering_connection_state_changed_cb ccb = NULL;
333         __tethering_client_h client;
334         void *data = NULL;
335         char *buf = NULL;
336         char *name = NULL;
337         char *mac = NULL;
338         char *ip = NULL;
339         guint timestamp;
340
341         memset(&client, 0, sizeof(__tethering_client_h));
342         g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, &timestamp);
343
344         if (!g_strcmp0(buf, "DhcpConnected")) {
345                 opened = true;
346         } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
347                 opened = false;
348         } else {
349                 ERR("Unknown event [%s]\n", buf);
350                 goto DONE;
351         }
352
353         if (ap_type == MOBILE_AP_TYPE_USB)
354                 type = TETHERING_TYPE_USB;
355         else if (ap_type == MOBILE_AP_TYPE_WIFI)
356                 type = TETHERING_TYPE_WIFI;
357         else if (ap_type == MOBILE_AP_TYPE_BT)
358                 type = TETHERING_TYPE_BT;
359         else if (ap_type == MOBILE_AP_TYPE_WIFI_AP) {
360                 type = TETHERING_TYPE_RESERVED;
361         } else {
362                 ERR("Not supported tethering type [%d]\n", ap_type);
363                 goto DONE;
364         }
365
366         ccb = th->changed_cb[type];
367         if (ccb == NULL)
368                 goto DONE;
369         data = th->changed_user_data[type];
370
371         client.interface = type;
372         g_strlcpy(client.ip, ip, sizeof(client.ip));
373         g_strlcpy(client.mac, mac, sizeof(client.mac));
374         if (name != NULL)
375                 client.hostname = g_strdup(name);
376         client.tm = (time_t)timestamp;
377
378         ccb((tethering_client_h)&client, opened, data);
379         g_free(client.hostname);
380 DONE:
381         g_free(buf);
382         g_free(ip);
383         g_free(mac);
384         g_free(name);
385         DBG("-\n");
386 }
387
388 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
389                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
390                 GVariant *parameters, gpointer user_data)
391 {
392         DBG("+\n");
393
394         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
395
396         __tethering_h *th = (__tethering_h *)user_data;
397         tethering_type_e type = 0;
398         tethering_disabled_cb dcb = NULL;
399         void *data = NULL;
400         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
401
402         for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
403                 dcb = th->disabled_cb[type];
404                 if (dcb == NULL)
405                         continue;
406                 data = th->disabled_user_data[type];
407
408                 dcb(TETHERING_ERROR_NONE, type, code, data);
409         }
410
411         DBG("-\n");
412 }
413
414 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
415                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
416                         GVariant *parameters, gpointer user_data)
417 {
418         DBG("+\n");
419
420         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
421
422         __tethering_h *th = (__tethering_h *)user_data;
423         tethering_type_e type = TETHERING_TYPE_WIFI;
424         bool is_requested = false;
425         tethering_enabled_cb ecb = NULL;
426         void *data = NULL;
427
428         ecb = th->enabled_cb[type];
429         if (ecb == NULL)
430                 return;
431         data = th->enabled_user_data[type];
432
433         ecb(TETHERING_ERROR_NONE, type, is_requested, data);
434         DBG("-\n");
435 }
436
437 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
438                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
439                         GVariant *parameters, gpointer user_data)
440 {
441         DBG("+\n");
442
443         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
444
445         __tethering_h *th = (__tethering_h *)user_data;
446         tethering_type_e type = TETHERING_TYPE_WIFI;
447         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
448         tethering_disabled_cb dcb = NULL;
449         void *data = NULL;
450         char *buf = NULL;
451
452         dcb = th->disabled_cb[type];
453         if (dcb == NULL)
454                 return;
455         data = th->disabled_user_data[type];
456         g_variant_get(parameters, "(s)", &buf);
457         if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
458                 code = TETHERING_DISABLED_BY_WIFI_ON;
459         else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
460                 code = TETHERING_DISABLED_BY_TIMEOUT;
461
462         g_free(buf);
463         dcb(TETHERING_ERROR_NONE, type, code, data);
464
465         DBG("-\n");
466 }
467
468 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
469                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
470                         GVariant *parameters, gpointer user_data)
471 {
472         DBG("+\n");
473
474         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
475
476         __tethering_h *th = (__tethering_h *)user_data;
477         tethering_type_e type = TETHERING_TYPE_USB;
478         bool is_requested = false;
479         tethering_enabled_cb ecb = NULL;
480         void *data = NULL;
481
482         ecb = th->enabled_cb[type];
483         if (ecb == NULL)
484                 return;
485         data = th->enabled_user_data[type];
486
487         ecb(TETHERING_ERROR_NONE, type, is_requested, data);
488         DBG("-\n");
489 }
490
491 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
492                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
493                         GVariant *parameters, gpointer user_data)
494 {
495         DBG("+\n");
496
497         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
498
499         __tethering_h *th = (__tethering_h *)user_data;
500         tethering_type_e type = TETHERING_TYPE_USB;
501         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
502         tethering_disabled_cb dcb = NULL;
503         void *data = NULL;
504         char *buf = NULL;
505
506         dcb = th->disabled_cb[type];
507         if (dcb == NULL)
508                 return;
509         data = th->disabled_user_data[type];
510
511         g_variant_get(parameters, "(s)", &buf);
512         if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
513                 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
514
515         dcb(TETHERING_ERROR_NONE, type, code, data);
516         g_free(buf);
517         DBG("-\n");
518 }
519
520 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
521                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
522                         GVariant *parameters, gpointer user_data)
523 {
524         DBG("+\n");
525
526         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
527
528         __tethering_h *th = (__tethering_h *)user_data;
529         tethering_type_e type = TETHERING_TYPE_BT;
530         bool is_requested = false;
531         tethering_enabled_cb ecb = NULL;
532         void *data = NULL;
533
534         ecb = th->enabled_cb[type];
535         if (ecb == NULL)
536                 return;
537         data = th->enabled_user_data[type];
538
539         ecb(TETHERING_ERROR_NONE, type, is_requested, data);
540         DBG("-\n");
541 }
542
543 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
544                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
545                         GVariant *parameters, gpointer user_data)
546 {
547         DBG("+\n");
548
549         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
550
551         __tethering_h *th = (__tethering_h *)user_data;
552         tethering_type_e type = TETHERING_TYPE_BT;
553         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
554         tethering_disabled_cb dcb = NULL;
555         void *data = NULL;
556         char *buf = NULL;
557
558         dcb = th->disabled_cb[type];
559         if (dcb == NULL)
560                 return;
561         data = th->disabled_user_data[type];
562         g_variant_get(parameters, "(s)", &buf);
563         if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
564                 code = TETHERING_DISABLED_BY_BT_OFF;
565         else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
566                 code = TETHERING_DISABLED_BY_TIMEOUT;
567
568         dcb(TETHERING_ERROR_NONE, type, code, data);
569
570         g_free(buf);
571         DBG("-\n");
572 }
573
574 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
575                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
576                         GVariant *parameters, gpointer user_data)
577 {
578         DBG("+\n");
579
580         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
581
582         __tethering_h *th = (__tethering_h *)user_data;
583         tethering_type_e type = TETHERING_TYPE_RESERVED;
584         bool is_requested = false;
585         tethering_enabled_cb ecb = NULL;
586         void *data = NULL;
587
588         ecb = th->enabled_cb[type];
589         if (ecb == NULL)
590                 return;
591         data = th->enabled_user_data[type];
592
593         ecb(TETHERING_ERROR_NONE, type, is_requested, data);
594         DBG("-\n");
595 }
596
597 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
598                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
599                         GVariant *parameters, gpointer user_data)
600 {
601         DBG("+\n");
602
603         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
604
605         __tethering_h *th = (__tethering_h *)user_data;
606         tethering_type_e type = TETHERING_TYPE_RESERVED;
607         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
608         tethering_disabled_cb dcb = NULL;
609         void *data = NULL;
610         char *buf = NULL;
611
612         dcb = th->disabled_cb[type];
613         if (dcb == NULL)
614                 return;
615         data = th->disabled_user_data[type];
616         g_variant_get(parameters, "(s)", &buf);
617         if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
618                 code = TETHERING_DISABLED_BY_WIFI_ON;
619         else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
620                 code = TETHERING_DISABLED_BY_TIMEOUT;
621         g_free(buf);
622
623         dcb(TETHERING_ERROR_NONE, type, code, data);
624
625         DBG("-\n");
626 }
627
628 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
629                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
630                         GVariant *parameters, gpointer user_data)
631 {
632         DBG("+\n");
633
634         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
635
636         __tethering_h *th = (__tethering_h *)user_data;
637         tethering_type_e type = 0;
638         tethering_disabled_cb dcb = NULL;
639         void *data = NULL;
640         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
641
642         for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
643                 dcb = th->disabled_cb[type];
644                 if (dcb == NULL)
645                         continue;
646                 data = th->disabled_user_data[type];
647
648                 dcb(TETHERING_ERROR_NONE, type, code, data);
649         }
650         DBG("-\n");
651 }
652
653 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
654                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
655                         GVariant *parameters, gpointer user_data)
656 {
657         DBG("+\n");
658
659         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
660
661         __tethering_h *th = (__tethering_h *)user_data;
662         tethering_type_e type = 0;
663         tethering_disabled_cb dcb = NULL;
664         void *data = NULL;
665         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
666
667         for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
668                 dcb = th->disabled_cb[type];
669                 if (dcb == NULL)
670                         continue;
671                 data = th->disabled_user_data[type];
672
673                 dcb(TETHERING_ERROR_NONE, type, code, data);
674         }
675         DBG("-\n");
676 }
677
678 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
679                         const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
680                         GVariant *parameters, gpointer user_data)
681 {
682         DBG("+\n");
683
684         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
685
686         __tethering_h *th = (__tethering_h *)user_data;
687         tethering_type_e type = 0;
688         tethering_disabled_cb dcb = NULL;
689         void *data = NULL;
690         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
691
692         for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
693                 dcb = th->disabled_cb[type];
694                 if (dcb == NULL)
695                         continue;
696                 data = th->disabled_user_data[type];
697
698                 dcb(TETHERING_ERROR_NONE, type, code, data);
699         }
700         DBG("-\n");
701 }
702
703 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
704                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
705                 GVariant *parameters, gpointer user_data)
706
707 {
708         DBG("+\n");
709
710         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
711         __tethering_h *th = (__tethering_h *)user_data;
712
713         tethering_wifi_security_type_changed_cb scb = NULL;
714         void *data = NULL;
715         tethering_wifi_security_type_e security_type;
716         char *buf = NULL;
717
718         scb = th->security_type_changed_cb;
719         if (scb == NULL)
720                 return;
721
722         g_variant_get(parameters, "(s)", &buf);
723         data = th->security_type_user_data;
724         if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
725                 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
726         else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
727                 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
728         else {
729                 SERR("Unknown type : %s\n", buf);
730                 g_free(buf);
731                 return;
732         }
733         g_free(buf);
734         scb(security_type, data);
735
736         return;
737 }
738
739 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
740                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
741                 GVariant *parameters, gpointer user_data)
742 {
743         DBG("+\n");
744
745         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
746         __tethering_h *th = (__tethering_h *)user_data;
747
748         tethering_wifi_ssid_visibility_changed_cb scb = NULL;
749         void *data = NULL;
750         bool visible = false;
751         char *buf = NULL;
752
753         scb = th->ssid_visibility_changed_cb;
754         if (scb == NULL) {
755                 DBG("-\n");
756                 return;
757         }
758         g_variant_get(parameters, "(s)", &buf);
759         data = th->ssid_visibility_user_data;
760         if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
761                 visible = true;
762
763         scb(visible, data);
764         g_free(buf);
765         DBG("-\n");
766 }
767
768 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
769                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
770                 GVariant *parameters, gpointer user_data)
771 {
772         DBG("+\n");
773
774         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
775         __tethering_h *th = (__tethering_h *)user_data;
776
777         tethering_wifi_passphrase_changed_cb pcb = NULL;
778         void *data = NULL;
779
780         pcb = th->passphrase_changed_cb;
781         if (pcb == NULL)
782                 return;
783
784         data = th->passphrase_user_data;
785
786         pcb(data);
787         DBG("-\n");
788 }
789
790 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
791                 gpointer user_data)
792 {
793         DBG("+\n");
794
795         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
796         GError *g_error = NULL;
797         GVariant *g_var;
798         guint info;
799         tethering_error_e error;
800         __tethering_h *th = (__tethering_h *)user_data;
801         tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
802         void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
803
804         g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
805         if (g_error) {
806                 ERR("DBus error [%s]\n", g_error->message);
807                 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
808                                 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
809                         g_error_free(g_error);
810                         tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
811                         return;
812                 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
813                         error = TETHERING_ERROR_PERMISSION_DENIED;
814                 else
815                         error = TETHERING_ERROR_OPERATION_FAILED;
816                 g_error_free(g_error);
817         } else {
818                 g_variant_get(g_var, "(u)", &info);
819                 error = __get_error(info);
820         }
821         retry = 0;
822
823         sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
824                         NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
825                         TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
826                         sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
827
828         if (!ecb) {
829                 DBG("-\n");
830                 return;
831         }
832         ecb(error, TETHERING_TYPE_WIFI, true, data);
833         g_variant_unref(g_var);
834         DBG("-\n");
835 }
836
837 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
838                 gpointer user_data)
839 {
840         DBG("+\n");
841         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
842         GError *g_error = NULL;
843         GVariant *g_var;
844         guint info;
845         tethering_error_e error;
846
847         __tethering_h *th = (__tethering_h *)user_data;
848         tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
849         void *data = th->enabled_user_data[TETHERING_TYPE_BT];
850
851         g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
852         if (g_error) {
853                 ERR("DBus error [%s]\n", g_error->message);
854                 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
855                                 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
856                         g_error_free(g_error);
857                         tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
858                         DBG("-\n");
859                         return;
860                 }
861                 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
862                         error = TETHERING_ERROR_PERMISSION_DENIED;
863                 else
864                         error = TETHERING_ERROR_OPERATION_FAILED;
865                 g_error_free(g_error);
866         } else {
867                 g_variant_get(g_var, "(u)", &info);
868                 g_variant_unref(g_var);
869                 error = __get_error(info);
870         }
871         retry = 0;
872
873         sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
874                         NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
875                         TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
876                         sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
877
878         if (!ecb) {
879                 DBG("-\n");
880                 return;
881         }
882
883         ecb(error, TETHERING_TYPE_BT, true, data);
884         DBG("-\n");
885 }
886
887 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
888                                         gpointer user_data)
889 {
890         DBG("+\n");
891
892         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
893         __tethering_h *th = (__tethering_h *)user_data;
894         GError *g_error = NULL;
895         GVariant *g_var;
896         guint info;
897         tethering_error_e error;
898         tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
899         void *data = th->enabled_user_data[TETHERING_TYPE_USB];
900
901         g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
902         if (g_error) {
903                 ERR("DBus error [%s]\n", g_error->message);
904                 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
905                                 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
906                         g_error_free(g_error);
907                         tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
908                         DBG("-\n");
909                         return;
910                 }
911                 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
912                         error = TETHERING_ERROR_PERMISSION_DENIED;
913                 else
914                         error = TETHERING_ERROR_OPERATION_FAILED;
915                 g_error_free(g_error);
916         } else {
917                 g_variant_get(g_var, "(u)", &info);
918                 g_variant_unref(g_var);
919                 error = __get_error(info);
920         }
921         retry = 0;
922
923         sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
924                         NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
925                         TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
926                         sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
927
928         if (!ecb) {
929                 DBG("-\n");
930                 return;
931         }
932
933         ecb(error, TETHERING_TYPE_USB, true, data);
934         DBG("-\n");
935 }
936
937 static void __wifi_ap_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
938                 gpointer user_data)
939 {
940         DBG("+\n");
941
942         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
943         __tethering_h *th = (__tethering_h *)user_data;
944         GError *g_error = NULL;
945         GVariant *g_var;
946         guint info;
947         tethering_error_e error;
948         tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_RESERVED];
949         void *data = th->enabled_user_data[TETHERING_TYPE_RESERVED];
950
951         g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
952         if (g_error) {
953                 ERR("DBus error [%s]\n", g_error->message);
954                 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
955                                 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
956                         g_error_free(g_error);
957                         tethering_enable((tethering_h)th, TETHERING_TYPE_RESERVED);
958                         DBG("-\n");
959                         return;
960                 }
961                 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
962                         error = TETHERING_ERROR_PERMISSION_DENIED;
963                 else
964                         error = TETHERING_ERROR_OPERATION_FAILED;
965                 g_error_free(g_error);
966         } else {
967                 g_variant_get(g_var, "(u)", &info);
968                 g_variant_unref(g_var);
969                 error = __get_error(info);
970         }
971         retry = 0;
972
973         sigs[E_SIGNAL_WIFI_AP_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
974                         NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_ON].name,
975                         TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
976                         sigs[E_SIGNAL_WIFI_AP_ON].cb, (gpointer)th, NULL);
977
978         if (!ecb) {
979                 DBG("-\n");
980                 return;
981         }
982
983         ecb(error, TETHERING_TYPE_RESERVED, true, data);
984         DBG("-\n");
985 }
986
987 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
988                 gpointer user_data)
989 {
990         DBG("+\n");
991
992         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
993         GError *g_error = NULL;
994         GVariant *g_var;
995         guint info, event_type;
996         tethering_error_e error;
997         tethering_type_e type;
998         tethering_h tethering = (tethering_h)user_data;
999         __tethering_h *th = (__tethering_h *)tethering;
1000         tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
1001         tethering_disabled_cb dcb = NULL;
1002         void *data = NULL;
1003
1004         g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1005         if (g_error) {
1006                 ERR("DBus error [%s]\n", g_error->message);
1007                 g_error_free(g_error);
1008                 return;
1009         }
1010         g_variant_get(g_var, "(uu)", &event_type, &info);
1011         DBG("cfm event : %d info : %d\n", event_type, info);
1012         g_variant_unref(g_var);
1013         error = __get_error(info);
1014         DBG("cfm event : %d info : %d\n", event_type, error);
1015         switch (event_type) {
1016         case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1017                 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1018                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1019                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1020                                 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1021
1022                 type = TETHERING_TYPE_WIFI;
1023                 dcb = th->disabled_cb[type];
1024                 data = th->disabled_user_data[type];
1025                 if (dcb)
1026                         dcb(error, type, code, data);
1027                 break;
1028
1029         case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1030                 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1031                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1032                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1033                                 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1034
1035                 type = TETHERING_TYPE_BT;
1036                 dcb = th->disabled_cb[type];
1037                 data = th->disabled_user_data[type];
1038                 if (dcb)
1039                         dcb(error, type, code, data);
1040                 break;
1041
1042         case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1043                 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1044                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1045                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1046                                 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1047
1048                 type = TETHERING_TYPE_USB;
1049                 dcb = th->disabled_cb[type];
1050                 data = th->disabled_user_data[type];
1051                 if (dcb)
1052                         dcb(error, type, code, data);
1053                 break;
1054
1055         case MOBILE_AP_DISABLE_WIFI_AP_CFM:
1056                 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1057                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_OFF].name,
1058                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1059                                 sigs[E_SIGNAL_WIFI_AP_OFF].cb, (gpointer)th, NULL);
1060
1061                 type = TETHERING_TYPE_RESERVED;
1062                 dcb = th->disabled_cb[type];
1063                 data = th->disabled_user_data[type];
1064                 if (dcb)
1065                         dcb(error, type, code, data);
1066                 break;
1067
1068         case MOBILE_AP_DISABLE_CFM:
1069
1070                 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1071                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1072                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1073                                 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1074                 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1075                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1076                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1077                                 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1078                 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1079                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1080                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1081                                 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1082
1083                 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1084                         dcb = th->disabled_cb[type];
1085                         if (dcb == NULL)
1086                                 continue;
1087                         data = th->disabled_user_data[type];
1088
1089                         dcb(error, type, code, data);
1090                 }
1091                 break;
1092
1093         default:
1094                 ERR("Invalid event\n");
1095                 break;
1096         }
1097         DBG("-\n");
1098 }
1099
1100 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1101                                 gpointer user_data)
1102 {
1103         DBG("+\n");
1104
1105         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1106
1107         GError *g_error = NULL;
1108         GVariant *g_var;
1109         guint event_type;
1110         guint64 tx_bytes, rx_bytes;
1111         __tethering_h *th = (__tethering_h *)user_data;
1112         tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1113         bool flag = false;
1114
1115         g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1116         if (g_error) {
1117                 ERR("DBus fail [%s]\n", g_error->message);
1118                 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1119                         tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1120                 else
1121                         tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1122
1123                 flag = true;
1124         }
1125         if (th->data_usage_cb == NULL) {
1126                 ERR("There is no data_usage_cb\n");
1127                 return;
1128         }
1129         if (flag) {
1130                 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1131         } else {
1132                 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1133                 th->data_usage_cb(TETHERING_ERROR_NONE,
1134                         rx_bytes, tx_bytes, th->data_usage_user_data);
1135                 g_variant_unref(g_var);
1136         }
1137         th->data_usage_cb = NULL;
1138         th->data_usage_user_data = NULL;
1139
1140         DBG("-\n");
1141 }
1142
1143 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1144                 gpointer user_data)
1145 {
1146         DBG("+\n");
1147
1148         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1149         GError *g_error = NULL;
1150         GVariant *g_var;
1151         guint info;
1152         __tethering_h *th = (__tethering_h *)user_data;
1153         tethering_error_e tethering_error;
1154
1155         g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1156         if (g_error) {
1157                 ERR("DBus fail [%s]\n", g_error->message);
1158                 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1159                         tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1160                 else
1161                         tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1162                 g_error_free(g_error);
1163         }
1164         if (th->settings_reloaded_cb == NULL) {
1165                 DBG("There is no settings_reloaded_cb\n-\n");
1166                 return;
1167         }
1168         g_variant_get(g_var, "(u)", &info);
1169         tethering_error = __get_error(info);
1170         g_variant_unref(g_var);
1171
1172         th->settings_reloaded_cb(tethering_error,
1173                         th->settings_reloaded_user_data);
1174
1175         th->settings_reloaded_cb = NULL;
1176         th->settings_reloaded_user_data = NULL;
1177         DBG("-\n");
1178 }
1179
1180 static void __ap_settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1181                 gpointer user_data)
1182 {
1183         DBG("+\n");
1184
1185         _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1186         GError *g_error = NULL;
1187         GVariant *g_var;
1188         guint info;
1189         __tethering_h *th = (__tethering_h *)user_data;
1190         tethering_error_e tethering_error;
1191
1192         g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1193         if (g_error) {
1194                 ERR("DBus fail [%s]\n", g_error->message);
1195                 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1196                         tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1197                 else
1198                         tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1199                 g_error_free(g_error);
1200         }
1201         if (th->ap_settings_reloaded_cb == NULL) {
1202                 DBG("There is no settings_reloaded_cb\n-\n");
1203                 return;
1204         }
1205         g_variant_get(g_var, "(u)", &info);
1206         tethering_error = __get_error(info);
1207         g_variant_unref(g_var);
1208
1209         th->ap_settings_reloaded_cb(tethering_error,
1210                         th->ap_settings_reloaded_user_data);
1211
1212         th->ap_settings_reloaded_cb = NULL;
1213         th->ap_settings_reloaded_user_data = NULL;
1214         DBG("-\n");
1215 }
1216
1217 static void __connect_signals(tethering_h tethering)
1218 {
1219         DBG("+\n");
1220         _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1221
1222         __tethering_h *th = (__tethering_h *)tethering;
1223         GDBusConnection *connection = th->client_bus;
1224         int i = 0;
1225
1226         for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1227                 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1228                                 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1229                                 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1230                                 sigs[i].cb, tethering, NULL);
1231         }
1232         DBG("-\n");
1233 }
1234
1235 static void __disconnect_signals(tethering_h tethering)
1236 {
1237         DBG("+\n");
1238
1239         _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1240
1241         __tethering_h *th = (__tethering_h *)tethering;
1242         GDBusConnection *connection = th->client_bus;
1243
1244         int i = 0;
1245
1246         for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1247                 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1248         DBG("-\n");
1249 }
1250
1251
1252
1253 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1254 {
1255         _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1256
1257         switch (type) {
1258         case TETHERING_TYPE_USB:
1259                 g_strlcpy(buf, TETHERING_USB_IF, len);
1260                 break;
1261
1262         case TETHERING_TYPE_WIFI:
1263                 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1264                 break;
1265
1266         case TETHERING_TYPE_BT:
1267                 g_strlcpy(buf, TETHERING_BT_IF, len);
1268                 break;
1269
1270         case TETHERING_TYPE_RESERVED:
1271                 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1272                 break;
1273
1274         default:
1275                 ERR("Not supported type : %d\n", type);
1276                 return false;
1277         }
1278         return true;
1279 }
1280
1281 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1282 {
1283         _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1284
1285         switch (type) {
1286         case TETHERING_TYPE_USB:
1287                 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1288                 break;
1289
1290         case TETHERING_TYPE_WIFI:
1291                 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1292                 break;
1293
1294         case TETHERING_TYPE_BT:
1295                 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1296                 break;
1297
1298         case TETHERING_TYPE_RESERVED:
1299                 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1300                 break;
1301
1302         default:
1303                 ERR("Not supported type : %d\n", type);
1304                 return false;
1305         }
1306         return true;
1307 }
1308
1309 static int __get_common_ssid(char *ssid, unsigned int size)
1310 {
1311         if (ssid == NULL) {
1312                 ERR("ssid is null\n");
1313                 return TETHERING_ERROR_INVALID_PARAMETER;
1314         }
1315
1316         char *ptr = NULL;
1317         char *ptr_tmp = NULL;
1318
1319         ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1320         if (ptr == NULL) {
1321                 ERR("vconf_get_str is failed and set default ssid");
1322                 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1323         } else
1324                 g_strlcpy(ssid, ptr, size);
1325
1326         free(ptr);
1327
1328         if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1329                 *ptr_tmp = '\0';
1330
1331         return TETHERING_ERROR_NONE;
1332 }
1333
1334 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1335 {
1336         _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1337
1338         switch (type) {
1339         case TETHERING_WIFI_MODE_TYPE_B:
1340                 *buf = g_strdup("b");
1341                 break;
1342         case TETHERING_WIFI_MODE_TYPE_G:
1343                 *buf = g_strdup("g");
1344                 break;
1345         case TETHERING_WIFI_MODE_TYPE_A:
1346                 *buf = g_strdup("a");
1347                 break;
1348         case TETHERING_WIFI_MODE_TYPE_AD:
1349                 *buf = g_strdup("ad");
1350                 break;
1351         default:
1352                 ERR("Not supported type : %d\n", type);
1353                 return false;
1354         }
1355         return true;
1356 }
1357
1358 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1359 {
1360         DBG("+\n");
1361
1362         __tethering_h *th = (__tethering_h *)tethering;
1363         tethering_error_e ret = TETHERING_ERROR_NONE;
1364         char *ptr = NULL;
1365
1366         if (th == NULL || set == NULL) {
1367                 ERR("null parameter\n-\n");
1368                 return TETHERING_ERROR_INVALID_PARAMETER;
1369         }
1370
1371         if (th->ssid == NULL)
1372                 __get_common_ssid(set->ssid, sizeof(set->ssid));
1373         else
1374                 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1375
1376         ret = __get_security_type(&set->sec_type);
1377         if (ret != TETHERING_ERROR_NONE)
1378                 set->sec_type = th->sec_type;
1379
1380         ret = __get_visible(&set->visibility);
1381         if (ret != TETHERING_ERROR_NONE)
1382                 set->visibility = th->visibility;
1383
1384         set->mac_filter = th->mac_filter;
1385         set->channel = th->channel;
1386
1387         __get_wifi_mode_type(th->mode_type, &ptr);
1388         if (ptr == NULL) {
1389                 g_strlcpy(set->mode, "", sizeof(set->mode));
1390         } else {
1391                 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1392                 free(ptr);
1393         }
1394
1395         if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1396                 g_strlcpy(set->key, "", sizeof(set->key));
1397         } else {
1398                 GDBusProxy *proxy = th->client_bus_proxy;
1399                 GVariant *parameters;
1400                 GError *error = NULL;
1401                 char *passphrase = NULL;
1402                 unsigned int len = 0;
1403
1404                 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1405                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1406
1407                 if (error) {
1408                         ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
1409
1410                         if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1411                                 ret = TETHERING_ERROR_PERMISSION_DENIED;
1412                         else
1413                                 ret = TETHERING_ERROR_OPERATION_FAILED;
1414
1415                         g_error_free(error);
1416                         return ret;
1417                 }
1418
1419                 if (parameters != NULL) {
1420                         g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1421                         g_variant_unref(parameters);
1422                 }
1423
1424                 g_strlcpy(set->key, passphrase, sizeof(set->key));
1425         }
1426         DBG("-\n");
1427         return TETHERING_ERROR_NONE;
1428 }
1429
1430 static int __prepare_wifi_ap_settings(tethering_h tethering, _softap_settings_t *set)
1431 {
1432         DBG("+\n");
1433
1434         __tethering_h *th = (__tethering_h *)tethering;
1435
1436         if (th == NULL || set == NULL) {
1437                 ERR("null parameter\n");
1438                 return TETHERING_ERROR_INVALID_PARAMETER;
1439         }
1440
1441         g_strlcpy(set->ssid, th->ap_ssid, sizeof(set->ssid));
1442         set->sec_type = th->sec_type;
1443         set->visibility = th->visibility;
1444
1445         if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
1446                 g_strlcpy(set->key, "", sizeof(set->key));
1447         else
1448                 g_strlcpy(set->key, th->passphrase, sizeof(set->key));
1449
1450         DBG("-\n");
1451         return TETHERING_ERROR_NONE;
1452 }
1453
1454 static bool __check_precondition(tethering_type_e type)
1455 {
1456         int dnet_state = 0;
1457         int cellular_state = 0;
1458         int wifi_state = 0;
1459
1460         /* data network through cellular */
1461         vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1462         if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1463                 ERR("Data Network can be connected later");
1464                 return TRUE;
1465         }
1466
1467         vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1468         if (dnet_state > VCONFKEY_DNET_OFF) {
1469                 ERR("Data Network is connected");
1470                 return TRUE;
1471         }
1472
1473         /* data network through wifi */
1474         if (type != TETHERING_TYPE_WIFI) {
1475                 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1476                 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1477                         ERR("Wi-Fi is connected!");
1478                         return TRUE;
1479                 }
1480         }
1481
1482         ERR("Network is not available!");
1483         return FALSE;
1484 }
1485
1486 /**
1487  * @internal
1488  * @brief  Creates the handle of tethering.
1489  * @since_tizen 2.3
1490  * @privlevel platform
1491  * @privilege http://tizen.org/privilege/tethering.admin
1492  * @remarks  The @a tethering must be released tethering_destroy() by you.
1493  * @param[out]  tethering  A handle of a new mobile ap handle on success
1494  * @return  0 on success, otherwise a negative error value.
1495  * @retval  #TETHERING_ERROR_NONE  Successful
1496  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
1497  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
1498  * @retval  #TETHERING_ERROR_NOT_SUPPORT_API  API is not supported
1499  * @see  tethering_destroy()
1500  */
1501 API int tethering_create(tethering_h *tethering)
1502 {
1503         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1504         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1505                         "parameter(tethering) is NULL\n");
1506         DBG("+\n");
1507
1508         __tethering_h *th = NULL;
1509         GError *error = NULL;
1510         char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1511
1512         th = (__tethering_h *)malloc(sizeof(__tethering_h));
1513
1514         _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1515                         "malloc is failed\n");
1516         memset(th, 0x00, sizeof(__tethering_h));
1517         th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1518         th->visibility = true;
1519         th->mac_filter = false;
1520         th->channel = 6;
1521         th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1522
1523         if (__generate_initial_passphrase(th->passphrase,
1524                         sizeof(th->passphrase)) == 0) {
1525                 ERR("random passphrase generation failed\n");
1526                 free(th);
1527                 return TETHERING_ERROR_OPERATION_FAILED;
1528         }
1529
1530         if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1531                 ERR("common ssid get failed\n");
1532                 free(th);
1533                 return TETHERING_ERROR_OPERATION_FAILED;
1534         }
1535
1536         th->ap_ssid = g_strdup(ssid);
1537         if (th->ap_ssid == NULL) {
1538                 ERR("g_strdup failed\n");
1539                 free(th);
1540                 return TETHERING_ERROR_OPERATION_FAILED;
1541         }
1542
1543 #if !GLIB_CHECK_VERSION(2, 36, 0)
1544         g_type_init();
1545 #endif
1546         GCancellable *cancellable = g_cancellable_new();
1547         th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1548         if (error) {
1549                 ERR("Couldn't connect to the System bus[%s]", error->message);
1550                 g_error_free(error);
1551                 g_cancellable_cancel(cancellable);
1552                 g_object_unref(cancellable);
1553                 g_free(th->ap_ssid);
1554                 free(th);
1555                 return TETHERING_ERROR_OPERATION_FAILED;
1556         }
1557         th->cancellable = cancellable;
1558
1559         th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1560                         NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1561                         TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1562         if (!th->client_bus_proxy) {
1563                 if (error)
1564                         ERR("Couldn't create the proxy object because of %s\n", error->message);
1565                 g_cancellable_cancel(th->cancellable);
1566                 g_object_unref(th->cancellable);
1567                 g_object_unref(th->client_bus);
1568                 g_free(th->ap_ssid);
1569                 free(th);
1570                 return TETHERING_ERROR_OPERATION_FAILED;
1571         }
1572
1573         __connect_signals((tethering_h)th);
1574
1575         *tethering = (tethering_h)th;
1576         DBG("Tethering Handle : 0x%X\n", th);
1577         DBG("-\n");
1578         return TETHERING_ERROR_NONE;
1579 }
1580
1581 /**
1582  * @internal
1583  * @brief  Destroys the handle of tethering.
1584  * @since_tizen 2.3
1585  * @privlevel platform
1586  * @privilege http://tizen.org/privilege/tethering.admin
1587  * @param[in]  tethering  The handle of tethering
1588  * @return  0 on success, otherwise a negative error value.
1589  * @retval  #TETHERING_ERROR_NONE  Successful
1590  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
1591  * @see  tethering_create()
1592  */
1593 API int tethering_destroy(tethering_h tethering)
1594 {
1595         DBG("+\n");
1596         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1597         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1598                         "parameter(tethering) is NULL\n");
1599
1600         __tethering_h *th = (__tethering_h *)tethering;
1601
1602         DBG("Tethering Handle : 0x%X\n", th);
1603         __disconnect_signals(tethering);
1604
1605         if (th->ssid)
1606                 free(th->ssid);
1607         if (th->ap_ssid)
1608                 free(th->ap_ssid);
1609
1610         g_object_unref(th->cancellable);
1611         g_object_unref(th->client_bus_proxy);
1612         g_object_unref(th->client_bus);
1613         memset(th, 0x00, sizeof(__tethering_h));
1614         free(th);
1615
1616         DBG("-\n");
1617         return TETHERING_ERROR_NONE;
1618 }
1619
1620 /**
1621  * @internal
1622  * @brief Enables the tethering, asynchronously.
1623  * @since_tizen 2.3
1624  * @privlevel platform
1625  * @privilege http://tizen.org/privilege/tethering.admin
1626  * @param[in]  tethering  The handle of tethering
1627  * @param[in]  type  The type of tethering
1628  * @return 0 on success, otherwise negative error value.
1629  * @retval  #TETHERING_ERROR_NONE  Successful
1630  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
1631  * @post tethering_enabled_cb() will be invoked.
1632  * @see  tethering_is_enabled()
1633  * @see  tethering_disable()
1634  */
1635 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1636 {
1637         DBG("+ type :  %d\n", type);
1638         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1639         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1640         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1641         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1642
1643         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1644                         "parameter(tethering) is NULL\n");
1645
1646         tethering_error_e ret = TETHERING_ERROR_NONE;
1647         __tethering_h *th = (__tethering_h *)tethering;
1648         GDBusProxy *proxy = th->client_bus_proxy;
1649         GDBusConnection *connection = th->client_bus;
1650
1651         g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1652
1653         if (type != TETHERING_TYPE_RESERVED
1654                 && __check_precondition(type) == FALSE) {
1655                 DBG("-\n");
1656                 return TETHERING_ERROR_OPERATION_FAILED;
1657         }
1658
1659         switch (type) {
1660         case TETHERING_TYPE_USB:
1661                 g_dbus_connection_signal_unsubscribe(connection,
1662                                 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1663
1664                 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1665                                 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1666                                 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1667                 break;
1668
1669         case TETHERING_TYPE_WIFI: {
1670                 _softap_settings_t set = {"", "", "", 0, false};
1671
1672                 ret = __prepare_wifi_settings(tethering, &set);
1673                 if (ret != TETHERING_ERROR_NONE) {
1674                         ERR("softap settings initialization failed\n");
1675                         DBG("-\n");
1676                         return TETHERING_ERROR_OPERATION_FAILED;
1677                 }
1678                 g_dbus_connection_signal_unsubscribe(connection,
1679                                 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1680
1681                 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1682                                 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
1683                                 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1684                                 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1685                 break;
1686         }
1687
1688         case TETHERING_TYPE_BT:
1689                 g_dbus_connection_signal_unsubscribe(connection,
1690                                 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1691
1692                 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1693                                 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1694                                 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1695
1696                 break;
1697
1698         case TETHERING_TYPE_RESERVED: {
1699                 _softap_settings_t set = {"", "", "", 0, false};
1700
1701                 ret = __prepare_wifi_ap_settings(tethering, &set);
1702                 if (ret != TETHERING_ERROR_NONE) {
1703                         ERR("softap settings initialization failed\n");
1704                         return TETHERING_ERROR_OPERATION_FAILED;
1705                 }
1706
1707                 g_dbus_connection_signal_unsubscribe(connection,
1708                                 sigs[E_SIGNAL_WIFI_AP_ON].sig_id);
1709
1710                 g_dbus_proxy_call(proxy, "enable_wifi_ap",
1711                                 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1712                                 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_ap_enabled_cfm_cb, (gpointer)tethering);
1713                 break;
1714         }
1715         case TETHERING_TYPE_ALL: {
1716                 _softap_settings_t set = {"", "", "", 0, false};
1717
1718                 ret = __prepare_wifi_settings(tethering, &set);
1719                 if (ret != TETHERING_ERROR_NONE) {
1720                         ERR("softap settings initialization failed\n");
1721                         return TETHERING_ERROR_OPERATION_FAILED;
1722                 }
1723
1724                 /* TETHERING_TYPE_USB */
1725                 g_dbus_connection_signal_unsubscribe(connection,
1726                                 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1727
1728                 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1729                                 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1730                                 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1731
1732                 /* TETHERING_TYPE_WIFI */
1733                 g_dbus_connection_signal_unsubscribe(connection,
1734                                 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1735
1736                 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1737                                 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1738                                 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1739                                 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1740
1741                 /* TETHERING_TYPE_BT */
1742                 g_dbus_connection_signal_unsubscribe(connection,
1743                                 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1744
1745                 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1746                                 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1747                                 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1748                 break;
1749         }
1750         default:
1751                 ERR("Unknown type : %d\n", type);
1752
1753                 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1754
1755                 DBG("-\n");
1756                 return TETHERING_ERROR_INVALID_PARAMETER;
1757         }
1758
1759         g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1760         DBG("-\n");
1761         return TETHERING_ERROR_NONE;
1762 }
1763
1764 /**
1765  * @internal
1766  * @brief Disables the tethering, asynchronously.
1767  * @since_tizen 2.3
1768  * @privlevel platform
1769  * @privilege http://tizen.org/privilege/tethering.admin
1770  * @param[in]  tethering  The handle of tethering
1771  * @param[in]  type  The type of tethering
1772  * @return 0 on success, otherwise negative error value.
1773  * @retval  #TETHERING_ERROR_NONE  Successful
1774  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
1775  * @post tethering_disabled_cb() will be invoked.
1776  * @see  tethering_is_enabled()
1777  * @see  tethering_enable()
1778  */
1779 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1780 {
1781         DBG("+ type :  %d\n", type);
1782         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1783         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1784         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1785
1786         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1787                         "parameter(tethering) is NULL\n");
1788
1789         __tethering_h *th = (__tethering_h *)tethering;
1790         GDBusProxy *proxy = th->client_bus_proxy;
1791         GDBusConnection *connection = th->client_bus;
1792
1793         switch (type) {
1794         case TETHERING_TYPE_USB:
1795                 g_dbus_connection_signal_unsubscribe(connection,
1796                                 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1797
1798                 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1799                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1800                                 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1801
1802                 break;
1803
1804         case TETHERING_TYPE_WIFI:
1805
1806                 g_dbus_connection_signal_unsubscribe(connection,
1807                                 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1808
1809                 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1810                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1811                                 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1812                 break;
1813
1814         case TETHERING_TYPE_BT:
1815
1816                 g_dbus_connection_signal_unsubscribe(connection,
1817                                 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1818
1819                 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1820                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1821                                 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1822                 break;
1823
1824         case TETHERING_TYPE_RESERVED:
1825                 g_dbus_connection_signal_unsubscribe(connection,
1826                                 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id);
1827
1828                 g_dbus_proxy_call(proxy, "disable_wifi_ap",
1829                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1830                                 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1831                 break;
1832
1833         case TETHERING_TYPE_ALL:
1834                 g_dbus_connection_signal_unsubscribe(connection,
1835                                 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1836
1837                 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1838                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1839                                 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1840
1841                 g_dbus_connection_signal_unsubscribe(connection,
1842                                 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1843
1844                 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1845                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1846                                 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1847
1848                 g_dbus_connection_signal_unsubscribe(connection,
1849                                 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1850
1851                 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1852                                 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1853                                 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1854                 break;
1855
1856         default:
1857                 ERR("Not supported tethering type [%d]\n", type);
1858                 DBG("-\n");
1859                 return TETHERING_ERROR_INVALID_PARAMETER;
1860         }
1861         DBG("-\n");
1862         return TETHERING_ERROR_NONE;
1863 }
1864
1865 /**
1866  * @internal
1867  * @brief  Checks whetehr the tethering is enabled or not.
1868  * @since_tizen 2.3
1869  * @privlevel platform
1870  * @privilege http://tizen.org/privilege/tethering.admin
1871  * @param[in]  tethering  The handle of tethering
1872  * @param[in]  type  The type of tethering
1873  * @return  @c true if tethering is enabled, \n @c false if tethering is disabled.
1874  */
1875 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1876 {
1877         int is_on = 0;
1878         int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1879
1880         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1881
1882         if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1883                 return FALSE;
1884
1885         switch (type) {
1886         case TETHERING_TYPE_USB:
1887                 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1888                 break;
1889
1890         case TETHERING_TYPE_WIFI:
1891                 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1892                 break;
1893
1894         case TETHERING_TYPE_BT:
1895                 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1896                 break;
1897
1898         case TETHERING_TYPE_RESERVED:
1899                 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
1900                 break;
1901
1902         default:
1903                 ERR("Not supported type : %d\n", type);
1904                 break;
1905         }
1906         return is_on & vconf_type ? true : false;
1907 }
1908
1909 /**
1910  * @internal
1911  * @brief  Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1912  * @since_tizen 2.3
1913  * @privlevel platform
1914  * @privilege http://tizen.org/privilege/tethering.admin
1915  * @remarks @a mac_address must be released with free() by you.
1916  * @param[in]  tethering  The handle of tethering
1917  * @param[in]  type  The type of tethering
1918  * @param[out]  mac_address  The MAC address
1919  * @return  0 on success, otherwise a negative error value.
1920  * @retval  #TETHERING_ERROR_NONE  Successful
1921  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
1922  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
1923  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
1924  * @retval  #TETHERING_ERROR_NOT_ENABLED  Not enabled
1925  * @pre  tethering must be enabled.
1926  * @see  tethering_is_enabled()
1927  * @see  tethering_enable()
1928  */
1929 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1930 {
1931         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1932         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1933         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1934
1935         _retvm_if(tethering_is_enabled(tethering, type) == false,
1936                         TETHERING_ERROR_NOT_ENABLED,
1937                         "tethering type[%d] is not enabled\n", type);
1938         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1939                         "parameter(tethering) is NULL\n");
1940         _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1941                         "parameter(mac_address) is NULL\n");
1942
1943         struct ifreq ifr;
1944         int s = 0;
1945         char *macbuf = NULL;
1946
1947         _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1948                         TETHERING_ERROR_OPERATION_FAILED,
1949                         "getting interface name is failed\n");
1950
1951         s = socket(AF_INET, SOCK_DGRAM, 0);
1952         _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1953                         "getting socket is failed\n");
1954         if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1955                 ERR("getting mac is failed\n");
1956                 close(s);
1957                 return TETHERING_ERROR_OPERATION_FAILED;
1958         }
1959         close(s);
1960
1961         macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1962         _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1963                         "Not enough memory\n");
1964         snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1965                         (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1966                         (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1967                         (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1968                         (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1969                         (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1970                         (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1971
1972         *mac_address = macbuf;
1973
1974         return TETHERING_ERROR_NONE;
1975 }
1976
1977 /**
1978  * @internal
1979  * @brief Gets the name of network interface. For example, usb0.
1980  * @since_tizen 2.3
1981  * @privlevel platform
1982  * @privilege http://tizen.org/privilege/tethering.admin
1983  * @remarks @a interface_name must be released with free() by you.
1984  * @param[in]  tethering  The handle of tethering
1985  * @param[in]  type  The type of tethering
1986  * @param[out]  interface_name  The name of network interface
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_OUT_OF_MEMORY  Out of memory
1991  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
1992  * @retval  #TETHERING_ERROR_NOT_ENABLED  Not enabled
1993  * @pre  tethering must be enabled.
1994  * @see  tethering_is_enabled()
1995  * @see  tethering_enable()
1996  */
1997 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1998 {
1999         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2000         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2001         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2002
2003         _retvm_if(tethering_is_enabled(tethering, type) == false,
2004                         TETHERING_ERROR_NOT_ENABLED,
2005                         "tethering type[%d] is not enabled\n", type);
2006         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2007                         "parameter(tethering) is NULL\n");
2008         _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2009                         "parameter(interface_name) is NULL\n");
2010
2011         char intf[TETHERING_STR_INFO_LEN] = {0, };
2012
2013         _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2014                         TETHERING_ERROR_OPERATION_FAILED,
2015                         "getting interface name is failed\n");
2016         *interface_name = strdup(intf);
2017         _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2018                         "Not enough memory\n");
2019
2020         return TETHERING_ERROR_NONE;
2021 }
2022
2023 /**
2024  * @internal
2025  * @brief Gets the local IP address.
2026  * @since_tizen 2.3
2027  * @privlevel platform
2028  * @privilege http://tizen.org/privilege/tethering.admin
2029  * @remarks @a ip_address must be released with free() by you.
2030  * @param[in]  tethering  The handle of tethering
2031  * @param[in]  type  The type of tethering
2032  * @param[in]  address_family  The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2033  * @param[out]  ip_address  The local IP address
2034  * @return 0 on success, otherwise negative error value.
2035  * @retval  #TETHERING_ERROR_NONE  Successful
2036  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2037  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
2038  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2039  * @retval  #TETHERING_ERROR_NOT_ENABLED  Not enabled
2040  * @pre  tethering must be enabled.
2041  * @see  tethering_is_enabled()
2042  * @see  tethering_enable()
2043  */
2044 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2045 {
2046
2047         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2048         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2049         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2050
2051         _retvm_if(tethering_is_enabled(tethering, type) == false,
2052                         TETHERING_ERROR_NOT_ENABLED,
2053                         "tethering type[%d] is not enabled\n", type);
2054         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2055                         "parameter(tethering) is NULL\n");
2056         _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2057                         "parameter(ip_address) is NULL\n");
2058
2059         struct ifreq ifr;
2060         int s = 0;
2061         char *ipbuf = NULL;
2062
2063         _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2064                         TETHERING_ERROR_OPERATION_FAILED,
2065                         "getting interface name is failed\n");
2066
2067         s = socket(AF_INET, SOCK_DGRAM, 0);
2068         _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2069                         "getting socket is failed\n");
2070         if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2071                 ERR("ioctl is failed\n");
2072                 close(s);
2073                 return TETHERING_ERROR_OPERATION_FAILED;
2074         }
2075         close(s);
2076
2077         ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2078         *ip_address = strdup(ipbuf);
2079         _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2080                         "Not enough memory\n");
2081
2082         return TETHERING_ERROR_NONE;
2083 }
2084
2085 /**
2086  * @internal
2087  * @brief Gets the Gateway address.
2088  * @since_tizen 2.3
2089  * @privlevel platform
2090  * @privilege http://tizen.org/privilege/tethering.admin
2091  * @remarks @a gateway_address must be released with free() by you.
2092  * @param[in]  tethering  The handle of tethering
2093  * @param[in]  type  The type of tethering
2094  * @param[in]  address_family  The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2095  * @param[out]  gateway_address  The local IP address
2096  * @return 0 on success, otherwise negative error value.
2097  * @retval  #TETHERING_ERROR_NONE  Successful
2098  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2099  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
2100  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2101  * @retval  #TETHERING_ERROR_NOT_ENABLED  Not enabled
2102  * @pre  tethering must be enabled.
2103  * @see  tethering_is_enabled()
2104  * @see  tethering_enable()
2105  */
2106 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2107 {
2108
2109         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2110         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2111         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2112
2113         _retvm_if(tethering_is_enabled(tethering, type) == false,
2114                         TETHERING_ERROR_NOT_ENABLED,
2115                         "tethering type[%d] is not enabled\n", type);
2116         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2117                         "parameter(tethering) is NULL\n");
2118         _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2119                         "parameter(gateway_address) is NULL\n");
2120
2121         char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2122
2123         _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2124                         TETHERING_ERROR_OPERATION_FAILED,
2125                         "getting gateway address is failed\n");
2126
2127         *gateway_address = strdup(gateway_buf);
2128
2129         return TETHERING_ERROR_NONE;
2130 }
2131
2132 /**
2133  * @internal
2134  * @brief Gets the Subnet Mask.
2135  * @since_tizen 2.3
2136  * @privlevel platform
2137  * @privilege http://tizen.org/privilege/tethering.admin
2138  * @remarks @a subnet_mask must be released with free() by you.
2139  * @param[in]  tethering  The handle of tethering
2140  * @param[in]  type  The type of tethering
2141  * @param[in]  address_family  The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2142  * @param[out]  subnet_mask  The local IP address
2143  * @return 0 on success, otherwise negative error value.
2144  * @retval  #TETHERING_ERROR_NONE  Successful
2145  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2146  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
2147  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2148  * @retval  #TETHERING_ERROR_NOT_ENABLED  Not enabled
2149  * @pre  tethering must be enabled.
2150  * @see  tethering_is_enabled()
2151  * @see  tethering_enable()
2152  */
2153 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2154 {
2155         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2156         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2157         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2158
2159         _retvm_if(tethering_is_enabled(tethering, type) == false,
2160                         TETHERING_ERROR_NOT_ENABLED,
2161                         "tethering is not enabled\n");
2162         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2163                         "parameter(tethering) is NULL\n");
2164         _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2165                         "parameter(subnet_mask) is NULL\n");
2166
2167         *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2168         _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2169                         "Not enough memory\n");
2170
2171         return TETHERING_ERROR_NONE;
2172 }
2173
2174 /**
2175  * @internal
2176  * @brief Gets the data usage.
2177  * @since_tizen 2.3
2178  * @privlevel platform
2179  * @privilege http://tizen.org/privilege/tethering.admin
2180  * @param[in]  tethering  The handle of tethering
2181  * @param[out]  usage  The data usage
2182  * @return 0 on success, otherwise negative error value.
2183  * @retval  #TETHERING_ERROR_NONE  Successful
2184  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2185  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2186  * @retval  #TETHERING_ERROR_NOT_ENABLED  Not enabled
2187  * @pre  tethering must be enabled.
2188  * @see  tethering_is_enabled()
2189  * @see  tethering_enable()
2190  */
2191 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2192 {
2193         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2194
2195         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2196                         "parameter(tethering) is NULL\n");
2197         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2198                         "parameter(callback) is NULL\n");
2199         _retvm_if(__any_tethering_is_enabled(tethering) == false,
2200                         TETHERING_ERROR_NOT_ENABLED,
2201                         "tethering is not enabled\n");
2202
2203         __tethering_h *th = (__tethering_h *)tethering;
2204         GDBusProxy *proxy = th->client_bus_proxy;
2205
2206         th->data_usage_cb = callback;
2207         th->data_usage_user_data = user_data;
2208
2209         g_dbus_proxy_call(proxy, "get_data_packet_usage",
2210                         NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2211                         (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2212
2213         return TETHERING_ERROR_NONE;
2214 }
2215
2216 /**
2217  * @internal
2218  * @brief Gets the client which is connected by tethering "type".
2219  * @since_tizen 2.3
2220  * @privlevel platform
2221  * @privilege http://tizen.org/privilege/tethering.admin
2222  * @param[in]  tethering  The handle of tethering
2223  * @param[in]  type  The type of tethering
2224  * @param[in]  callback  The callback function to invoke
2225  * @param[in]  user_data  The user data to be passed to the callback function
2226  * @retval  #TETHERING_ERROR_NONE  Successful
2227  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2228  * @retval  #TETHERING_ERROR_NOT_ENABLED  Not enabled
2229  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2230  * @pre  tethering must be enabled.
2231  * @see  tethering_is_enabled()
2232  * @see  tethering_enable()
2233  */
2234 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2235 {
2236         DBG("+\n");
2237         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2238         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2239         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2240
2241         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2242                         "parameter(tethering) is NULL\n");
2243         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2244                         "parameter(callback) is NULL\n");
2245         _retvm_if(__any_tethering_is_enabled(tethering) == false,
2246                         TETHERING_ERROR_NOT_ENABLED,
2247                         "tethering is not enabled\n");
2248
2249         mobile_ap_type_e interface;
2250         __tethering_h *th = (__tethering_h *)tethering;
2251         __tethering_client_h client = {0, };
2252         gchar *ip = NULL;
2253         gchar *mac = NULL;
2254         gchar *hostname = NULL;
2255         guint timestamp = 0;
2256         GError *error = NULL;
2257         GVariant *result = NULL;
2258         GVariantIter *outer_iter = NULL;
2259         GVariantIter *inner_iter = NULL;
2260         GVariant *station = NULL;
2261         GVariant *value = NULL;
2262         gchar *key = NULL;
2263
2264         result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2265                         NULL, G_DBUS_CALL_FLAGS_NONE,
2266                         -1, th->cancellable, &error);
2267         if (error)
2268                 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2269         g_variant_get(result, "(a(a{sv}))", &outer_iter);
2270         while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2271                 g_variant_get(station, "a{sv}", &inner_iter);
2272                 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2273                         if (g_strcmp0(key, "Type") == 0) {
2274                                 interface = g_variant_get_int32(value);
2275                                 if (interface == MOBILE_AP_TYPE_USB)
2276                                         client.interface = TETHERING_TYPE_USB;
2277                                 else if (interface == MOBILE_AP_TYPE_WIFI)
2278                                         client.interface = TETHERING_TYPE_WIFI;
2279                                 else if (interface == MOBILE_AP_TYPE_BT)
2280                                         client.interface = TETHERING_TYPE_BT;
2281                                 else if (interface == MOBILE_AP_TYPE_WIFI_AP)
2282                                         client.interface = TETHERING_TYPE_RESERVED;
2283                                 else {
2284                                         ERR("Invalid interface\n");
2285                                         g_free(key);
2286                                         g_variant_unref(value);
2287                                         break;
2288                                 }
2289                                 DBG("interface is %d\n", client.interface);
2290                                 if (client.interface != type && (TETHERING_TYPE_ALL != type &&
2291                                                         client.interface != TETHERING_TYPE_RESERVED)) {
2292                                         g_free(key);
2293                                         g_variant_unref(value);
2294                                         break;
2295                                 }
2296                         } else if (g_strcmp0(key, "IP") == 0) {
2297                                 g_variant_get(value, "s", &ip);
2298                                 SDBG("ip is %s\n", ip);
2299                                 g_strlcpy(client.ip, ip, sizeof(client.ip));
2300                         } else if (g_strcmp0(key, "MAC") == 0) {
2301                                 g_variant_get(value, "s", &mac);
2302                                 SDBG("mac is %s\n", mac);
2303                                 g_strlcpy(client.mac, mac, sizeof(client.mac));
2304                         } else if (g_strcmp0(key, "Name") == 0) {
2305                                 g_variant_get(value, "s", &hostname);
2306                                 SDBG("hsotname is %s\n", hostname);
2307                                 if (hostname)
2308                                         client.hostname = g_strdup(hostname);
2309                         } else if (g_strcmp0(key, "Time") == 0) {
2310                                 timestamp = g_variant_get_int32(value);
2311                                 DBG("timestamp is %d\n", timestamp);
2312                                 client.tm = (time_t)timestamp;
2313                         } else {
2314                                 ERR("Key %s not required\n", key);
2315                         }
2316                 }
2317                 g_free(hostname);
2318                 g_free(ip);
2319                 g_free(mac);
2320                 g_variant_iter_free(inner_iter);
2321                 if (callback((tethering_client_h)&client, user_data) == false) {
2322                         DBG("iteration is stopped\n");
2323                         g_free(client.hostname);
2324                         g_variant_iter_free(outer_iter);
2325                         g_variant_unref(station);
2326                         g_variant_unref(result);
2327                         DBG("-\n");
2328                         return TETHERING_ERROR_OPERATION_FAILED;
2329                 }
2330                 g_free(client.hostname);
2331         }
2332         g_variant_iter_free(outer_iter);
2333         g_variant_unref(station);
2334         g_variant_unref(result);
2335         DBG("-\n");
2336         return TETHERING_ERROR_NONE;
2337 }
2338
2339 /**
2340  * @internal
2341  * @brief Registers the callback function called when tethering is enabled.
2342  * @since_tizen 2.3
2343  * @privlevel platform
2344  * @privilege http://tizen.org/privilege/tethering.admin
2345  * @param[in]  tethering  The handle of tethering
2346  * @param[in]  type  The type of tethering
2347  * @param[in]  callback  The callback function to invoke
2348  * @param[in]  user_data  The user data to be passed to the callback function
2349  * @retval  #TETHERING_ERROR_NONE  Successful
2350  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2351  * @see  tethering_unset_enabled_cb()
2352  */
2353 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2354 {
2355         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2356         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2357         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2358
2359         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2360                         "parameter(tethering) is NULL\n");
2361         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2362                         "parameter(callback) is NULL\n");
2363
2364         __tethering_h *th = (__tethering_h *)tethering;
2365         tethering_type_e ti;
2366
2367         if (type != TETHERING_TYPE_ALL) {
2368                 th->enabled_cb[type] = callback;
2369                 th->enabled_user_data[type] = user_data;
2370
2371                 return TETHERING_ERROR_NONE;
2372         }
2373
2374         /* TETHERING_TYPE_ALL */
2375         for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2376                 th->enabled_cb[ti] = callback;
2377                 th->enabled_user_data[ti] = user_data;
2378         }
2379
2380         return TETHERING_ERROR_NONE;
2381 }
2382
2383 /**
2384  * @internal
2385  * @brief Unregisters the callback function called when tethering is disabled.
2386  * @since_tizen 2.3
2387  * @privlevel platform
2388  * @privilege http://tizen.org/privilege/tethering.admin
2389  * @param[in]  tethering  The handle of tethering
2390  * @param[in]  type  The type of tethering
2391  * @retval  #TETHERING_ERROR_NONE  Successful
2392  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2393  * @see  tethering_set_enabled_cb()
2394  */
2395 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2396 {
2397         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2398         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2399         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2400
2401         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2402                         "parameter(tethering) is NULL\n");
2403
2404         __tethering_h *th = (__tethering_h *)tethering;
2405         tethering_type_e ti;
2406
2407         if (type != TETHERING_TYPE_ALL) {
2408                 th->enabled_cb[type] = NULL;
2409                 th->enabled_user_data[type] = NULL;
2410
2411                 return TETHERING_ERROR_NONE;
2412         }
2413
2414         /* TETHERING_TYPE_ALL */
2415         for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2416                 th->enabled_cb[ti] = NULL;
2417                 th->enabled_user_data[ti] = NULL;
2418         }
2419
2420         return TETHERING_ERROR_NONE;
2421 }
2422
2423 /**
2424  * @internal
2425  * @brief Registers the callback function called when tethering is disabled.
2426  * @since_tizen 2.3
2427  * @privlevel platform
2428  * @privilege http://tizen.org/privilege/tethering.admin
2429  * @param[in]  tethering  The handle of tethering
2430  * @param[in]  type  The type of tethering
2431  * @param[in]  callback  The callback function to invoke
2432  * @param[in]  user_data  The user data to be passed to the callback function
2433  * @retval  #TETHERING_ERROR_NONE  Successful
2434  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2435  * @see  tethering_unset_disabled_cb()
2436  */
2437 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2438 {
2439         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2440         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2441         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2442
2443         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2444                         "parameter(tethering) is NULL\n");
2445         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2446                         "parameter(callback) is NULL\n");
2447
2448         __tethering_h *th = (__tethering_h *)tethering;
2449         tethering_type_e ti;
2450
2451         if (type != TETHERING_TYPE_ALL) {
2452                 th->disabled_cb[type] = callback;
2453                 th->disabled_user_data[type] = user_data;
2454
2455                 return TETHERING_ERROR_NONE;
2456         }
2457
2458         /* TETHERING_TYPE_ALL */
2459         for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2460                 th->disabled_cb[ti] = callback;
2461                 th->disabled_user_data[ti] = user_data;
2462         }
2463
2464         return TETHERING_ERROR_NONE;
2465 }
2466
2467 /**
2468  * @internal
2469  * @brief Unregisters the callback function called when tethering is disabled.
2470  * @since_tizen 2.3
2471  * @privlevel platform
2472  * @privilege http://tizen.org/privilege/tethering.admin
2473  * @param[in]  tethering  The handle of tethering
2474  * @param[in]  type  The type of tethering
2475  * @retval  #TETHERING_ERROR_NONE  Successful
2476  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2477  * @see  tethering_set_disabled_cb()
2478  */
2479 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2480 {
2481         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2482         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2483         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2484
2485         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2486                         "parameter(tethering) is NULL\n");
2487
2488         __tethering_h *th = (__tethering_h *)tethering;
2489         tethering_type_e ti;
2490
2491         if (type != TETHERING_TYPE_ALL) {
2492                 th->disabled_cb[type] = NULL;
2493                 th->disabled_user_data[type] = NULL;
2494
2495                 return TETHERING_ERROR_NONE;
2496         }
2497
2498         /* TETHERING_TYPE_ALL */
2499         for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2500                 th->disabled_cb[ti] = NULL;
2501                 th->disabled_user_data[ti] = NULL;
2502         }
2503
2504         return TETHERING_ERROR_NONE;
2505 }
2506
2507 /**
2508  * @internal
2509  * @brief Registers the callback function called when the state of connection is changed.
2510  * @since_tizen 2.3
2511  * @privlevel platform
2512  * @privilege http://tizen.org/privilege/tethering.admin
2513  * @param[in]  tethering  The handle of tethering
2514  * @param[in]  type  The type of tethering
2515  * @param[in]  callback  The callback function to invoke
2516  * @param[in]  user_data  The user data to be passed to the callback function
2517  * @retval  #TETHERING_ERROR_NONE  Successful
2518  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2519  * @see  tethering_unset_connection_state_changed_cb_cb()
2520  */
2521 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2522 {
2523         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2524         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2525         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2526
2527         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2528                         "parameter(tethering) is NULL\n");
2529         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2530                         "parameter(callback) is NULL\n");
2531
2532         __tethering_h *th = (__tethering_h *)tethering;
2533         tethering_type_e ti;
2534
2535         if (type != TETHERING_TYPE_ALL) {
2536                 th->changed_cb[type] = callback;
2537                 th->changed_user_data[type] = user_data;
2538
2539                 return TETHERING_ERROR_NONE;
2540         }
2541
2542         /* TETHERING_TYPE_ALL */
2543         for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2544                 th->changed_cb[ti] = callback;
2545                 th->changed_user_data[ti] = user_data;
2546         }
2547
2548         return TETHERING_ERROR_NONE;
2549 }
2550
2551 /**
2552  * @internal
2553  * @brief Unregisters the callback function called when the state of connection is changed.
2554  * @since_tizen 2.3
2555  * @privlevel platform
2556  * @privilege http://tizen.org/privilege/tethering.admin
2557  * @param[in]  tethering  The handle of tethering
2558  * @param[in]  type  The type of tethering
2559  * @retval  #TETHERING_ERROR_NONE  Successful
2560  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2561  * @see  tethering_set_connection_state_changed_cb()
2562  */
2563 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2564 {
2565         if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2566         else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2567         else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2568
2569         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2570                         "parameter(tethering) is NULL\n");
2571
2572         __tethering_h *th = (__tethering_h *)tethering;
2573         tethering_type_e ti;
2574
2575         if (type != TETHERING_TYPE_ALL) {
2576                 th->changed_cb[type] = NULL;
2577                 th->changed_user_data[type] = NULL;
2578
2579                 return TETHERING_ERROR_NONE;
2580         }
2581
2582         /* TETHERING_TYPE_ALL */
2583         for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2584                 th->changed_cb[ti] = NULL;
2585                 th->changed_user_data[ti] = NULL;
2586         }
2587
2588         return TETHERING_ERROR_NONE;
2589 }
2590
2591 /**
2592  * @internal
2593  * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2594  * @since_tizen 2.3
2595  * @privlevel platform
2596  * @privilege http://tizen.org/privilege/tethering.admin
2597  * @param[in]  tethering  The handle of tethering
2598  * @param[in]  callback  The callback function to invoke
2599  * @param[in]  user_data  The user data to be passed to the callback function
2600  * @retval  #TETHERING_ERROR_NONE  Successful
2601  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2602  * @see  tethering_wifi_unset_security_type_changed_cb()
2603  */
2604 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2605 {
2606         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2607
2608         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2609                         "parameter(tethering) is NULL\n");
2610         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2611                         "parameter(callback) is NULL\n");
2612
2613         __tethering_h *th = (__tethering_h *)tethering;
2614
2615         th->security_type_changed_cb = callback;
2616         th->security_type_user_data = user_data;
2617
2618         return TETHERING_ERROR_NONE;
2619
2620 }
2621
2622 /**
2623  * @internal
2624  * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2625  * @since_tizen 2.3
2626  * @privlevel platform
2627  * @privilege http://tizen.org/privilege/tethering.admin
2628  * @param[in]  tethering  The handle of tethering
2629  * @param[in]  type  The type of tethering
2630  * @retval  #TETHERING_ERROR_NONE  Successful
2631  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2632  * @see  tethering_wifi_set_security_type_changed_cb()
2633  */
2634 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2635 {
2636         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2637
2638         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2639                         "parameter(tethering) is NULL\n");
2640
2641         __tethering_h *th = (__tethering_h *)tethering;
2642
2643         th->security_type_changed_cb = NULL;
2644         th->security_type_user_data = NULL;
2645
2646         return TETHERING_ERROR_NONE;
2647 }
2648
2649 /**
2650  * @internal
2651  * @brief Registers the callback function called when the visibility of SSID is changed.
2652  * @since_tizen 2.3
2653  * @privlevel platform
2654  * @privilege http://tizen.org/privilege/tethering.admin
2655  * @param[in]  tethering  The handle of tethering
2656  * @param[in]  callback  The callback function to invoke
2657  * @param[in]  user_data  The user data to be passed to the callback function
2658  * @retval  #TETHERING_ERROR_NONE  Successful
2659  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2660  * @see  tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2661  */
2662 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2663 {
2664         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2665
2666         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2667                         "parameter(tethering) is NULL\n");
2668         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2669                         "parameter(callback) is NULL\n");
2670
2671         __tethering_h *th = (__tethering_h *)tethering;
2672
2673         th->ssid_visibility_changed_cb = callback;
2674         th->ssid_visibility_user_data = user_data;
2675
2676         return TETHERING_ERROR_NONE;
2677 }
2678
2679 /**
2680  * @internal
2681  * @brief Unregisters the callback function called when the visibility of SSID is changed.
2682  * @since_tizen 2.3
2683  * @privlevel platform
2684  * @privilege http://tizen.org/privilege/tethering.admin
2685  * @param[in]  tethering  The handle of tethering
2686  * @retval  #TETHERING_ERROR_NONE  Successful
2687  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2688  * @see  tethering_wifi_set_ssid_visibility_changed_cb()
2689  */
2690 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2691 {
2692         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2693
2694         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2695                         "parameter(tethering) is NULL\n");
2696
2697         __tethering_h *th = (__tethering_h *)tethering;
2698
2699         th->ssid_visibility_changed_cb = NULL;
2700         th->ssid_visibility_user_data = NULL;
2701
2702         return TETHERING_ERROR_NONE;
2703 }
2704
2705 /**
2706  * @internal
2707  * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2708  * @since_tizen 2.3
2709  * @privlevel platform
2710  * @privilege http://tizen.org/privilege/tethering.admin
2711  * @param[in]  tethering  The handle of tethering
2712  * @param[in]  callback  The callback function to invoke
2713  * @param[in]  user_data  The user data to be passed to the callback function
2714  * @retval  #TETHERING_ERROR_NONE  Successful
2715  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2716  * @see  tethering_wifi_unset_passphrase_changed_cb()
2717  */
2718 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2719 {
2720         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2721
2722         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2723                         "parameter(tethering) is NULL\n");
2724         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2725                         "parameter(callback) is NULL\n");
2726
2727         __tethering_h *th = (__tethering_h *)tethering;
2728
2729         th->passphrase_changed_cb = callback;
2730         th->passphrase_user_data = user_data;
2731
2732         return TETHERING_ERROR_NONE;
2733 }
2734
2735 /**
2736  * @internal
2737  * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2738  * @since_tizen 2.3
2739  * @privlevel platform
2740  * @privilege http://tizen.org/privilege/tethering.admin
2741  * @param[in]  tethering  The handle of tethering
2742  * @retval  #TETHERING_ERROR_NONE  Successful
2743  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2744  * @see  tethering_wifi_set_passphrase_changed_cb()
2745  */
2746 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2747 {
2748         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2749
2750         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2751                         "parameter(tethering) is NULL\n");
2752
2753         __tethering_h *th = (__tethering_h *)tethering;
2754
2755         th->passphrase_changed_cb = NULL;
2756         th->passphrase_user_data = NULL;
2757
2758         return TETHERING_ERROR_NONE;
2759 }
2760
2761 /**
2762  * @internal
2763  * @brief Sets the security type of Wi-Fi tethering.
2764  * @since_tizen 2.3
2765  * @privlevel platform
2766  * @privilege http://tizen.org/privilege/tethering.admin
2767  * @remarks This change is applied next time Wi-Fi tethering is enabled
2768  * @param[in]  tethering  The handle of tethering
2769  * @param[in]  type  The security type
2770  * @return 0 on success, otherwise negative error value.
2771  * @retval  #TETHERING_ERROR_NONE  Successful
2772  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2773  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2774  * @see  tethering_wifi_get_security_type()
2775  */
2776 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2777 {
2778         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2779
2780         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2781                         "parameter(tethering) is NULL\n");
2782
2783         __tethering_h *th = (__tethering_h *)tethering;
2784         tethering_error_e ret = TETHERING_ERROR_NONE;
2785
2786         ret = __set_security_type(type);
2787         if (ret == TETHERING_ERROR_NONE) {
2788
2789                 __send_dbus_signal(th->client_bus,
2790                                 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2791                                 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2792                                 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2793                                 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2794         }
2795         return ret;
2796 }
2797
2798 /**
2799  * @internal
2800  * @brief Gets the security type of Wi-Fi tethering.
2801  * @since_tizen 2.3
2802  * @privlevel platform
2803  * @privilege http://tizen.org/privilege/tethering.admin
2804  * @param[in]  tethering  The handle of tethering
2805  * @param[out]  type  The security type
2806  * @return 0 on success, otherwise negative error value.
2807  * @retval  #TETHERING_ERROR_NONE  Successful
2808  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2809  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2810  * @see  tethering_wifi_set_security_type()
2811  */
2812 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2813 {
2814         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2815
2816         _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2817                         "parameter(type) is NULL\n");
2818
2819         return __get_security_type(type);
2820 }
2821
2822 /**
2823  * @internal
2824  * @brief Sets the SSID (service set identifier).
2825  * @since_tizen 2.3
2826  * @privlevel platform
2827  * @privilege http://tizen.org/privilege/tethering.admin
2828  * @details If SSID is not set, Device name is used as SSID
2829  * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2830  * @param[in]  tethering  The handle of tethering
2831  * @param[out]  ssid  The SSID
2832  * @return 0 on success, otherwise negative error value.
2833  * @retval  #TETHERING_ERROR_NONE  Successful
2834  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2835  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
2836  */
2837 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2838 {
2839         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2840
2841         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2842                         "parameter(tethering) is NULL\n");
2843         _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2844                         "parameter(ssid) is NULL\n");
2845
2846         __tethering_h *th = (__tethering_h *)tethering;
2847         char *p_ssid = NULL;
2848         int ssid_len = 0;
2849
2850         ssid_len = strlen(ssid);
2851         if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2852                 ERR("parameter(ssid) is too long");
2853                 return TETHERING_ERROR_INVALID_PARAMETER;
2854         }
2855
2856         p_ssid = strdup(ssid);
2857         _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2858                         "strdup is failed\n");
2859
2860         if (th->ssid)
2861                 free(th->ssid);
2862         th->ssid = p_ssid;
2863
2864         return TETHERING_ERROR_NONE;
2865 }
2866
2867 /**
2868  * @internal
2869  * @brief Gets the SSID (service set identifier).
2870  * @since_tizen 2.3
2871  * @privlevel platform
2872  * @privilege http://tizen.org/privilege/tethering.admin
2873  * @remarks @a ssid must be released with free() by you.
2874  * @param[in]  tethering  The handle of tethering
2875  * @param[out]  ssid  The SSID
2876  * @return 0 on success, otherwise negative error value.
2877  * @retval  #TETHERING_ERROR_NONE  Successful
2878  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2879  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
2880  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2881  */
2882 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2883 {
2884         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2885
2886         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2887                         "parameter(tethering) is NULL\n");
2888         _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2889                         "parameter(ssid) is NULL\n");
2890         DBG("+\n");
2891
2892         __tethering_h *th = (__tethering_h *)tethering;
2893         char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2894
2895         if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2896                 if (th->ssid != NULL) {
2897                         DBG("Private SSID is set\n");
2898                         *ssid = strdup(th->ssid);
2899                 } else {
2900                         if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2901                                                 val, sizeof(val)) == false) {
2902                                 return TETHERING_ERROR_OPERATION_FAILED;
2903                         }
2904                         *ssid = strdup(val);
2905                 }
2906         } else {
2907                 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2908                                         val, sizeof(val)) == false) {
2909                         return TETHERING_ERROR_OPERATION_FAILED;
2910                 }
2911                 *ssid = strdup(val);
2912         }
2913
2914         if (*ssid == NULL) {
2915                 ERR("strdup is failed\n");
2916                 return TETHERING_ERROR_OUT_OF_MEMORY;
2917         }
2918
2919         return TETHERING_ERROR_NONE;
2920 }
2921
2922 /**
2923  * @internal
2924  * @brief Sets the visibility of SSID(service set identifier).
2925  * @since_tizen 2.3
2926  * @privlevel platform
2927  * @privilege http://tizen.org/privilege/tethering.admin
2928  * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2929  * @remarks This change is applied next time Wi-Fi tethering is enabled
2930  * @param[in]  tethering  The handle of tethering
2931  * @param[in]  visible  The visibility of SSID: (@c true = visible, @c false = invisible)
2932  * @return 0 on success, otherwise negative error value.
2933  * @retval  #TETHERING_ERROR_NONE  Successful
2934  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2935  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2936  * @see  tethering_wifi_get_ssid_visibility()
2937  */
2938 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2939 {
2940         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2941
2942         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2943                         "parameter(tethering) is NULL\n");
2944
2945         __tethering_h *th = (__tethering_h *)tethering;
2946         tethering_error_e ret = TETHERING_ERROR_NONE;
2947
2948         ret = __set_visible(visible);
2949         if (ret == TETHERING_ERROR_NONE) {
2950
2951                 __send_dbus_signal(th->client_bus,
2952                                 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2953                                 visible ? SIGNAL_MSG_SSID_VISIBLE :
2954                                 SIGNAL_MSG_SSID_HIDE);
2955         }
2956         return ret;
2957 }
2958
2959 /**
2960  * @internal
2961  * @brief Gets the visibility of SSID(service set identifier).
2962  * @since_tizen 2.3
2963  * @privlevel platform
2964  * @privilege http://tizen.org/privilege/tethering.admin
2965  * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2966  * @param[in]  tethering  The handle of tethering
2967  * @param[out]  visible  The visibility of SSID: (@c true = visible, @c false = invisible)
2968  * @return 0 on success, otherwise negative error value.
2969  * @retval  #TETHERING_ERROR_NONE  Successful
2970  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2971  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2972  * @see  tethering_wifi_set_ssid_visibility()
2973  */
2974 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2975 {
2976         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2977
2978         _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2979                         "parameter(visible) is NULL\n");
2980
2981         return __get_visible(visible);
2982 }
2983
2984 /**
2985  * @internal
2986  * @brief Sets the passphrase.
2987  * @since_tizen 2.3
2988  * @privlevel platform
2989  * @privilege http://tizen.org/privilege/tethering.admin
2990  * @remarks This change is applied next time Wi-Fi tethering is enabled
2991  * @param[in]  tethering  The handle of tethering
2992  * @param[in]  passphrase  The passphrase
2993  * @return 0 on success, otherwise negative error value.
2994  * @retval  #TETHERING_ERROR_NONE  Successful
2995  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
2996  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
2997  * @see  tethering_wifi_get_passphrase()
2998  */
2999 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3000 {
3001         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3002
3003         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3004                         "parameter(tethering) is NULL\n");
3005         _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3006                         "parameter(passphrase) is NULL\n");
3007
3008         __tethering_h *th = (__tethering_h *)tethering;
3009         GDBusProxy *proxy = th->client_bus_proxy;
3010         GVariant *parameters;
3011         GError *error = NULL;
3012         int passphrase_len = 0;
3013         int ret = 0;
3014
3015         DBG("+");
3016         passphrase_len = strlen(passphrase);
3017         if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3018                         passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3019                 ERR("parameter(passphrase) is too short or long\n");
3020                 return TETHERING_ERROR_INVALID_PARAMETER;
3021         }
3022
3023         parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3024                         g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3025
3026         if (error) {
3027                 ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
3028
3029                 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3030                         ret = TETHERING_ERROR_PERMISSION_DENIED;
3031                 else
3032                         ret = TETHERING_ERROR_OPERATION_FAILED;
3033
3034                 g_error_free(error);
3035                 return ret;
3036         }
3037
3038         g_variant_get(parameters, "(u)", &ret);
3039         g_variant_unref(parameters);
3040
3041         if (ret == TETHERING_ERROR_NONE) {
3042                 __send_dbus_signal(th->client_bus,
3043                                 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3044         }
3045
3046         DBG("-");
3047         return ret;
3048 }
3049
3050 /**
3051  * @internal
3052  * @brief Gets the passphrase.
3053  * @since_tizen 2.3
3054  * @privlevel platform
3055  * @privilege http://tizen.org/privilege/tethering.admin
3056  * @remarks @a passphrase must be released with free() by you.
3057  * @param[in]  tethering  The handle of tethering
3058  * @param[out]  passphrase  The passphrase
3059  * @return 0 on success, otherwise negative error value.
3060  * @retval  #TETHERING_ERROR_NONE  Successful
3061  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3062  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
3063  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
3064  * @see  tethering_wifi_set_passphrase()
3065  */
3066 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3067 {
3068         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3069
3070         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3071                         "parameter(tethering) is NULL\n");
3072         _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3073                         "parameter(passphrase) is NULL\n");
3074
3075         __tethering_h *th = (__tethering_h *)tethering;
3076         GDBusProxy *proxy = th->client_bus_proxy;
3077         GVariant *parameters;
3078         GError *error = NULL;
3079         unsigned int len = 0;
3080         tethering_error_e ret = TETHERING_ERROR_NONE;
3081
3082         parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3083                         NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3084
3085         if (error) {
3086                 ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
3087
3088                 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3089                         ret = TETHERING_ERROR_PERMISSION_DENIED;
3090                 else
3091                         ret = TETHERING_ERROR_OPERATION_FAILED;
3092
3093                 g_error_free(error);
3094                 return ret;
3095         }
3096
3097         if (parameters != NULL) {
3098                 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3099                 g_variant_unref(parameters);
3100         }
3101
3102         return TETHERING_ERROR_NONE;
3103 }
3104
3105 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3106 {
3107         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3108         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3109                         "parameter(tethering) is NULL\n");
3110
3111         __tethering_h *th = (__tethering_h *)tethering;
3112         th->channel = channel;
3113
3114         return TETHERING_ERROR_NONE;
3115 }
3116
3117 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3118 {
3119         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3120         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3121                         "parameter(tethering) is NULL\n");
3122
3123         _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3124                         "parameter(channel) is NULL\n");
3125
3126         __tethering_h *th = (__tethering_h *)tethering;
3127         *channel = th->channel;
3128
3129         return TETHERING_ERROR_NONE;
3130 }
3131
3132 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3133 {
3134         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3135         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3136                         "parameter(tethering) is NULL\n");
3137
3138         __tethering_h *th = (__tethering_h *)tethering;
3139
3140         th->mode_type = type;
3141
3142         return TETHERING_ERROR_NONE;
3143 }
3144
3145 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3146 {
3147         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3148         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3149                         "parameter(tethering) is NULL\n");
3150         _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3151                         "parameter(type) is NULL\n");
3152
3153         __tethering_h *th = (__tethering_h *)tethering;
3154         *type = th->mode_type;
3155
3156         return TETHERING_ERROR_NONE;
3157 }
3158
3159
3160 /**
3161  * @internal
3162  * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3163  * @since_tizen 2.3
3164  * @privlevel platform
3165  * @privilege http://tizen.org/privilege/tethering.admin
3166  * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3167  * @param[in]  tethering  The handle of tethering
3168  * @param[in]  callback  The callback function to invoke
3169  * @param[in]  user_data  The user data to be passed to the callback function
3170  * @return 0 on success, otherwise negative error value.
3171  * @retval  #TETHERING_ERROR_NONE  Successful
3172  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3173  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
3174  */
3175 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3176
3177 {
3178         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3179
3180         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3181                         "parameter(tethering) is NULL\n");
3182         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3183                         "parameter(callback) is NULL\n");
3184
3185         __tethering_h *th = (__tethering_h *)tethering;
3186         _softap_settings_t set = {"", "", "", 0, false};
3187         GDBusProxy *proxy = th->client_bus_proxy;
3188         int ret = 0;
3189
3190         DBG("+\n");
3191
3192         if (th->settings_reloaded_cb) {
3193                 ERR("Operation in progress\n");
3194                 return TETHERING_ERROR_OPERATION_FAILED;
3195         }
3196
3197         ret = __prepare_wifi_settings(tethering, &set);
3198         if (ret != TETHERING_ERROR_NONE) {
3199                 ERR("softap settings initialization failed\n");
3200                 return TETHERING_ERROR_OPERATION_FAILED;
3201         }
3202
3203         th->settings_reloaded_cb = callback;
3204         th->settings_reloaded_user_data = user_data;
3205
3206         g_dbus_proxy_call(proxy, "reload_wifi_settings",
3207                         g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
3208                         G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3209                         (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3210
3211         return TETHERING_ERROR_NONE;
3212 }
3213
3214 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3215 {
3216         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3217
3218         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3219                         "parameter(tethering) is NULL\n");
3220
3221         __tethering_h *th = (__tethering_h *)tethering;
3222         th->mac_filter = mac_filter;
3223
3224         return TETHERING_ERROR_NONE;
3225 }
3226
3227 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3228 {
3229         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3230
3231         _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3232                         "parameter(mac_filter) is NULL\n");
3233
3234         __tethering_h *th = (__tethering_h *)tethering;
3235         *mac_filter = th->mac_filter;
3236
3237         return TETHERING_ERROR_NONE;
3238 }
3239
3240 static int __add_mac_to_file(const char *filepath, const char *mac)
3241 {
3242         FILE *fp = NULL;
3243         char line[MAX_BUF_SIZE] = "\0";
3244         bool mac_exist = false;
3245
3246         fp = fopen(filepath, "a+");
3247         if (!fp) {
3248                 ERR("fopen is failed\n");
3249                 return TETHERING_ERROR_OPERATION_FAILED;
3250         }
3251
3252         while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3253                 if (strncmp(mac, line, 17) == 0) {
3254                         DBG("MAC %s already exist in the list\n", mac);
3255                         mac_exist = true;
3256                         break;
3257                 }
3258         }
3259
3260         if (!mac_exist)
3261                 fprintf(fp, "%s\n", mac);
3262
3263         fclose(fp);
3264
3265         return TETHERING_ERROR_NONE;
3266 }
3267
3268 static int __remove_mac_from_file(const char *filepath, const char *mac)
3269 {
3270         FILE *fp = NULL;
3271         FILE *fp1 = NULL;
3272         char line[MAX_BUF_SIZE] = "\0";
3273
3274         fp = fopen(filepath, "r");
3275         if (!fp) {
3276                 ERR("fopen is failed\n");
3277                 return TETHERING_ERROR_OPERATION_FAILED;
3278         }
3279
3280         fp1 = fopen(TEMP_LIST, "w+");
3281         if (!fp1) {
3282                 fclose(fp);
3283                 ERR("fopen is failed\n");
3284                 return TETHERING_ERROR_OPERATION_FAILED;
3285         }
3286
3287         while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3288                 if (strncmp(mac, line, 17) == 0)
3289                         DBG("MAC %s found in the list\n", mac);
3290                 else
3291                         fprintf(fp1, "%s", line);
3292         }
3293
3294         fclose(fp);
3295         fclose(fp1);
3296
3297         if ((strcmp(filepath, ALLOWED_LIST) == 0))
3298                 rename(TEMP_LIST, ALLOWED_LIST);
3299         else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3300                 rename(TEMP_LIST, BLOCKED_LIST);
3301
3302         return TETHERING_ERROR_NONE;
3303 }
3304
3305 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3306 {
3307         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3308
3309         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3310                         "parameter(tethering) is NULL\n");
3311         _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3312                         "parameter(mac) is NULL\n");
3313
3314         return __add_mac_to_file(ALLOWED_LIST, mac);
3315 }
3316
3317 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3318 {
3319         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3320                         "parameter(tethering) is NULL\n");
3321         _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3322                         "parameter(mac) is NULL\n");
3323
3324         return __remove_mac_from_file(ALLOWED_LIST, mac);
3325 }
3326
3327 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3328 {
3329         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3330                         "parameter(tethering) is NULL\n");
3331         _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3332                         "parameter(mac) is NULL\n");
3333
3334         return __add_mac_to_file(BLOCKED_LIST, mac);
3335 }
3336
3337 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3338 {
3339         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3340                         "parameter(tethering) is NULL\n");
3341         _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3342                         "parameter(mac) is NULL\n");
3343
3344         return __remove_mac_from_file(BLOCKED_LIST, mac);
3345 }
3346
3347 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3348 {
3349         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3350
3351         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3352                         "parameter(tethering) is NULL\n");
3353
3354         GVariant *parameters;
3355         GError *error = NULL;
3356         guint result;
3357
3358         __tethering_h *th = (__tethering_h *)tethering;
3359
3360         GDBusProxy *proxy = th->client_bus_proxy;
3361
3362         parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3363                         g_variant_new("(b)", enable),
3364                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3365
3366         if (error) {
3367                 ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
3368                 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3369                         result = TETHERING_ERROR_PERMISSION_DENIED;
3370                 else
3371                         result = TETHERING_ERROR_OPERATION_FAILED;
3372
3373                 g_error_free(error);
3374                 th->dhcp_enabled = false;
3375
3376                 return result;
3377         }
3378
3379         g_variant_get(parameters, "(u)", &result);
3380         g_variant_unref(parameters);
3381
3382         if (enable)
3383                 th->dhcp_enabled = true;
3384         else
3385                 th->dhcp_enabled = false;
3386
3387         return TETHERING_ERROR_NONE;
3388 }
3389
3390 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3391 {
3392         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3393
3394         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3395                         "parameter(tethering) is NULL\n");
3396         _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3397                         "parameter(rangestart) is NULL\n");
3398         _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3399                         "parameter(rangestop) is NULL\n");
3400
3401         GVariant *parameters;
3402         GError *error = NULL;
3403         guint result;
3404
3405         __tethering_h *th = (__tethering_h *)tethering;
3406
3407         GDBusProxy *proxy = th->client_bus_proxy;
3408
3409         parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3410                         g_variant_new("(ss)", rangestart, rangestop),
3411                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3412         if (error) {
3413                 ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
3414
3415                 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3416                         result = TETHERING_ERROR_PERMISSION_DENIED;
3417                 else
3418                         result = TETHERING_ERROR_OPERATION_FAILED;
3419
3420                 g_error_free(error);
3421                 th->dhcp_enabled = false;
3422
3423                 return result;
3424         }
3425
3426         g_variant_get(parameters, "(u)", &result);
3427         g_variant_unref(parameters);
3428
3429         th->dhcp_enabled = true;
3430
3431         return TETHERING_ERROR_NONE;
3432 }
3433
3434 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3435 {
3436         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3437         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3438                         "parameter(tethering) is NULL\n");
3439         _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3440                         "parameter(dhcp_enabled) is NULL\n");
3441
3442         __tethering_h *th = (__tethering_h *)tethering;
3443         *dhcp_enabled = th->dhcp_enabled;
3444
3445         return TETHERING_ERROR_NONE;
3446 }
3447
3448 /**
3449  * @internal
3450  * @brief Sets the security type of Wi-Fi AP.
3451  * @since_tizen 2.3
3452  * @privlevel platform
3453  * @privilege http://tizen.org/privilege/tethering.admin
3454  * @details If security type is not set, WPA2_PSK is used
3455  * @param[in]  tethering  The handle of tethering
3456  * @param[in]  type  The security type
3457  * @return 0 on success, otherwise negative error value.
3458  * @retval  #TETHERING_ERROR_NONE  Successful
3459  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3460  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
3461  * @see  tethering_wifi_ap_get_security_type()
3462  */
3463 API int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
3464 {
3465         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3466
3467         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3468                 "parameter(tethering) is NULL\n");
3469
3470         __tethering_h *th = (__tethering_h *)tethering;
3471         th->sec_type = type;
3472         return TETHERING_ERROR_NONE;
3473 }
3474
3475 /**
3476  * @internal
3477  * @brief Gets the security type of Wi-Fi AP.
3478  * @since_tizen 2.3
3479  * @privlevel platform
3480  * @privilege http://tizen.org/privilege/tethering.admin
3481  * @details If security type is not set, WPA2_PSK is used
3482  * @param[in]  tethering  The handle of tethering
3483  * @param[out]  type  The security type
3484  * @return 0 on success, otherwise negative error value.
3485  * @retval  #TETHERING_ERROR_NONE  Successful
3486  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3487  * @see  tethering_wifi_ap_set_security_type()
3488  */
3489 API int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3490 {
3491         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3492
3493         _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3494                 "parameter(type) is NULL\n");
3495
3496         __tethering_h *th = (__tethering_h *)tethering;
3497
3498         *type = th->sec_type;
3499         return TETHERING_ERROR_NONE;
3500 }
3501
3502 /**
3503  * @internal
3504  * @brief Sets the SSID (service set identifier) for Wi-Fi AP. The SSID cannot exceed 32 bytes.
3505  * @since_tizen 2.3
3506  * @privlevel platform
3507  * @privilege http://tizen.org/privilege/tethering.admin
3508  * @details If SSID is not set, Device name is used as SSID
3509  * @param[in]  tethering  The handle of tethering
3510  * @param[in]  ssid  The SSID
3511  * @return 0 on success, otherwise negative error value.
3512  * @retval  #TETHERING_ERROR_NONE  Successful
3513  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3514  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
3515  */
3516 API int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid)
3517 {
3518         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3519
3520         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3521                         "parameter(tethering) is NULL\n");
3522         _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3523                         "parameter(ssid) is NULL\n");
3524
3525         __tethering_h *th = (__tethering_h *)tethering;
3526         char *p_ssid = NULL;
3527         int ssid_len = 0;
3528
3529         ssid_len = strlen(ssid);
3530         if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3531                 ERR("parameter(ssid) is too long");
3532                 return TETHERING_ERROR_INVALID_PARAMETER;
3533         }
3534
3535         p_ssid = strdup(ssid);
3536         if (p_ssid == NULL) {
3537                 ERR("strdup failed\n");
3538                 return TETHERING_ERROR_OUT_OF_MEMORY;
3539         }
3540
3541         if (th->ap_ssid)
3542                 g_free(th->ap_ssid);
3543         th->ap_ssid = p_ssid;
3544
3545         return TETHERING_ERROR_NONE;
3546 }
3547
3548 /**
3549  * @internal
3550  * @brief Gets the SSID (service set identifier) for Wi-Fi AP.
3551  * @since_tizen 2.3
3552  * @privlevel platform
3553  * @privilege http://tizen.org/privilege/tethering.admin
3554  * @details If SSID is not set, Device name is used as SSID
3555  * @remarks @a ssid must be released with free() by you.
3556  * @param[in]  tethering  The handle of tethering
3557  * @param[out]  ssid  The SSID
3558  * @return 0 on success, otherwise negative error value.
3559  * @retval  #TETHERING_ERROR_NONE  Successful
3560  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3561  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
3562  */
3563 API int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid)
3564 {
3565         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3566
3567         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3568                         "parameter(tethering) is NULL\n");
3569         _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3570                         "parameter(ssid) is NULL\n");
3571
3572         __tethering_h *th = (__tethering_h *)tethering;
3573
3574         *ssid = g_strdup(th->ap_ssid);
3575         if (*ssid == NULL) {
3576                 ERR("strdup failed\n");
3577                 return TETHERING_ERROR_OUT_OF_MEMORY;
3578         }
3579
3580         return TETHERING_ERROR_NONE;
3581 }
3582
3583 /**
3584  * @internal
3585  * @brief Sets the visibility of SSID(service set identifier) for Wi-Fi AP.
3586  * @since_tizen 2.3
3587  * @privlevel platform
3588  * @privilege http://tizen.org/privilege/tethering.admin
3589  * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3590  * @details by default visibility is set to true.
3591  * @remarks This change is applied next time Wi-Fi tethering is enabled
3592  * @param[in]  tethering  The handle of tethering
3593  * @param[in]  visible  The visibility of SSID: (@c true = visible, @c false = invisible)
3594  * @return 0 on success, otherwise negative error value.
3595  * @retval  #TETHERING_ERROR_NONE  Successful
3596  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3597  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
3598  * @see  tethering_wifi_ap_get_ssid_visibility()
3599  */
3600 API int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible)
3601 {
3602         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3603
3604         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3605                 "parameter(tethering) is NULL\n");
3606
3607         __tethering_h *th = (__tethering_h *)tethering;
3608         th->visibility = visible;
3609         return TETHERING_ERROR_NONE;
3610 }
3611
3612 /**
3613  * @internal
3614  * @brief Gets the visibility of SSID(service set identifier) for Wi-Fi AP.
3615  * @since_tizen 2.3
3616  * @privlevel platform
3617  * @privilege http://tizen.org/privilege/tethering.admin
3618  * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3619  * @details by default visibility is set to true.
3620  * @param[in]  tethering  The handle of tethering
3621  * @param[out]  visible  The visibility of SSID: (@c true = visible, @c false = invisible)
3622  * @return 0 on success, otherwise negative error value.
3623  * @retval  #TETHERING_ERROR_NONE  Successful
3624  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3625  * @see  tethering_wifi_ap_set_ssid_visibility()
3626  */
3627 API int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible)
3628 {
3629         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3630
3631         _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3632                         "parameter(visible) is NULL\n");
3633
3634         __tethering_h *th = (__tethering_h *)tethering;
3635
3636         *visible = th->visibility;
3637         return TETHERING_ERROR_NONE;
3638 }
3639
3640 /**
3641  * @internal
3642  * @brief Sets the passphrase for Wi-Fi AP.
3643  * @since_tizen 2.3
3644  * @privlevel platform
3645  * @privilege http://tizen.org/privilege/tethering.admin
3646  * @details If the passphrase is not set, random string of 8 alphabets will be used.
3647  * @param[in]  tethering  The handle of tethering
3648  * @param[in]  passphrase  The passphrase
3649  * @return 0 on success, otherwise negative error value.
3650  * @retval  #TETHERING_ERROR_NONE  Successful
3651  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3652  * @see  tethering_wifi_ap_get_passphrase()
3653  */
3654 API int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase)
3655 {
3656         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3657
3658         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3659                 "parameter(tethering) is NULL\n");
3660         _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3661                 "parameter(passphrase) is NULL\n");
3662
3663         __tethering_h *th = (__tethering_h *)tethering;
3664         int passphrase_len = 0;
3665
3666         passphrase_len = strlen(passphrase);
3667
3668         if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3669                         passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3670                 ERR("parameter(passphrase) is too short or long\n");
3671                 return TETHERING_ERROR_INVALID_PARAMETER;
3672         }
3673
3674         if (!g_strcmp0(passphrase, th->passphrase))
3675                 return TETHERING_ERROR_NONE;
3676
3677         g_strlcpy(th->passphrase, passphrase, sizeof(th->passphrase));
3678         return TETHERING_ERROR_NONE;
3679 }
3680
3681 /**
3682  * @internal
3683  * @brief Gets the passphrase for Wi-Fi AP.
3684  * @since_tizen 2.3
3685  * @privlevel platform
3686  * @privilege http://tizen.org/privilege/tethering.admin
3687  * @details If the passphrase is not set, random string of 8 alphabets will be used.
3688  * @remarks @a passphrase must be released with free() by you.
3689  * @param[in]  tethering  The handle of tethering
3690  * @param[out]  passphrase  The passphrase
3691  * @return 0 on success, otherwise negative error value.
3692  * @retval  #TETHERING_ERROR_NONE  Successful
3693  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3694  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
3695  * @see  tethering_wifi_ap_set_passphrase()
3696  */
3697 API int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase)
3698 {
3699         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3700
3701         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3702                         "parameter(tethering) is NULL\n");
3703         _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3704                         "parameter(passphrase) is NULL\n");
3705
3706         __tethering_h *th = (__tethering_h *)tethering;
3707
3708         *passphrase = g_strdup(th->passphrase);
3709         if (*passphrase == NULL) {
3710                 ERR("strdup is failed\n");
3711                 return TETHERING_ERROR_OUT_OF_MEMORY;
3712         }
3713
3714         return TETHERING_ERROR_NONE;
3715 }
3716
3717 /**
3718  * @internal
3719  * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP.
3720  * @since_tizen 2.3
3721  * @privlevel platform
3722  * @privilege http://tizen.org/privilege/tethering.admin
3723  * @remarks Connected devices via MobileAP will be disconnected when the settings are reloaded
3724  * @param[in]  tethering  The handle of tethering
3725  * @param[in]  callback  The callback function to invoke
3726  * @param[in]  user_data  The user data to be passed to the callback function
3727  * @return 0 on success, otherwise negative error value.
3728  * @retval  #TETHERING_ERROR_NONE  Successful
3729  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
3730  * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
3731  */
3732 API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data)
3733
3734 {
3735         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3736
3737         _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3738                         "parameter(tethering) is NULL\n");
3739         _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3740                         "parameter(callback) is NULL\n");
3741
3742         __tethering_h *th = (__tethering_h *)tethering;
3743         _softap_settings_t set = {"", "", "", 0, false};
3744         GDBusProxy *proxy = th->client_bus_proxy;
3745         int ret = 0;
3746
3747         DBG("+\n");
3748
3749         if (th->ap_settings_reloaded_cb) {
3750                 ERR("Operation in progress\n");
3751                 return TETHERING_ERROR_OPERATION_FAILED;
3752         }
3753
3754         ret = __prepare_wifi_ap_settings(tethering, &set);
3755         if (ret != TETHERING_ERROR_NONE) {
3756                 ERR("softap settings initialization failed\n");
3757                 return TETHERING_ERROR_OPERATION_FAILED;
3758         }
3759
3760         th->ap_settings_reloaded_cb = callback;
3761         th->ap_settings_reloaded_user_data = user_data;
3762
3763         g_dbus_proxy_call(proxy, "reload_wifi_ap_settings",
3764                         g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
3765                         G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3766                         (GAsyncReadyCallback) __ap_settings_reloaded_cb, (gpointer)tethering);
3767
3768         return TETHERING_ERROR_NONE;
3769 }