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