53971c3294caf05d1071f1dfcd3802bfba4bd5ea
[platform/core/api/connection.git] / src / libnetwork.c
1 /*
2  * Copyright (c) 2011-2013 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 <string.h>
19 #include <glib.h>
20 #include <vconf/vconf.h>
21 #include <arpa/inet.h>
22
23 #include "net_connection_private.h"
24
25 static GSList *prof_handle_list = NULL;
26 static GHashTable *profile_cb_table = NULL;
27
28 struct _profile_cb_s {
29         connection_profile_state_changed_cb callback;
30         connection_profile_state_e state;
31         void *user_data;
32 };
33
34 struct _profile_list_s {
35         int count;
36         int next;
37         net_profile_info_t *profiles;
38 };
39
40 struct _libnet_s {
41         connection_opened_cb opened_cb;
42         connection_closed_cb closed_cb;
43         connection_set_default_cb set_default_cb;
44         connection_reset_cb reset_profile_cb;
45         libnet_ethernet_cable_state_changed_cb ethernet_cable_state_changed_cb;
46         void *opened_user_data;
47         void *closed_user_data;
48         void *set_default_user_data;
49         void *reset_profile_user_data;
50         bool registered;
51         bool is_created;
52 };
53
54 struct managed_idle_data {
55         GSourceFunc func;
56         gpointer user_data;
57         guint id;
58 };
59
60 struct feature_type {
61         bool telephony;
62         bool wifi;
63         bool tethering_bluetooth;
64 };
65
66 static struct _profile_list_s profile_iterator = {0, 0, NULL};
67 static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false};
68 static __thread GSList *managed_idler_list = NULL;
69 static __thread bool is_check_enable_feature = false;
70 static __thread struct feature_type enable_feature = {false, false, false};
71
72 bool _connection_is_created(void)
73 {
74         return libnet.is_created;
75 }
76
77 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
78 {
79         switch (err_type) {
80         case NET_ERR_NONE:
81                 return CONNECTION_ERROR_NONE;
82         case NET_ERR_APP_ALREADY_REGISTERED:
83                 return CONNECTION_ERROR_INVALID_OPERATION;
84         case NET_ERR_APP_NOT_REGISTERED:
85                 return CONNECTION_ERROR_INVALID_OPERATION;
86         case NET_ERR_NO_ACTIVE_CONNECTIONS:
87                 return CONNECTION_ERROR_NO_CONNECTION;
88         case NET_ERR_ACTIVE_CONNECTION_EXISTS:
89                 return CONNECTION_ERROR_ALREADY_EXISTS;
90         case NET_ERR_CONNECTION_DHCP_FAILED:
91                 return CONNECTION_ERROR_DHCP_FAILED;
92         case NET_ERR_CONNECTION_INVALID_KEY:
93                 return CONNECTION_ERROR_INVALID_KEY;
94         case NET_ERR_IN_PROGRESS:
95                 return CONNECTION_ERROR_NOW_IN_PROGRESS;
96         case NET_ERR_OPERATION_ABORTED:
97                 return CONNECTION_ERROR_OPERATION_ABORTED;
98         case NET_ERR_TIME_OUT:
99                 return CONNECTION_ERROR_NO_REPLY;
100         case NET_ERR_ACCESS_DENIED:
101                 return CONNECTION_ERROR_PERMISSION_DENIED;
102         default:
103                 return CONNECTION_ERROR_OPERATION_FAILED;
104         }
105 }
106
107 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
108 {
109         switch (err_type) {
110         case CONNECTION_ERROR_NONE:
111                 return "NONE";
112         case CONNECTION_ERROR_INVALID_PARAMETER:
113                 return "INVALID_PARAMETER";
114         case CONNECTION_ERROR_OUT_OF_MEMORY:
115                 return "OUT_OF_MEMORY";
116         case CONNECTION_ERROR_INVALID_OPERATION:
117                 return "INVALID_OPERATION";
118         case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
119                 return "ADDRESS_FAMILY_NOT_SUPPORTED";
120         case CONNECTION_ERROR_OPERATION_FAILED:
121                 return "OPERATION_FAILED";
122         case CONNECTION_ERROR_ITERATOR_END:
123                 return "ITERATOR_END";
124         case CONNECTION_ERROR_NO_CONNECTION:
125                 return "NO_CONNECTION";
126         case CONNECTION_ERROR_NOW_IN_PROGRESS:
127                 return "NOW_IN_PROGRESS";
128         case CONNECTION_ERROR_ALREADY_EXISTS:
129                 return "ALREADY_EXISTS";
130         case CONNECTION_ERROR_OPERATION_ABORTED:
131                 return "OPERATION_ABORTED";
132         case CONNECTION_ERROR_DHCP_FAILED:
133                 return "DHCP_FAILED";
134         case CONNECTION_ERROR_INVALID_KEY:
135                 return "INVALID_KEY";
136         case CONNECTION_ERROR_NO_REPLY:
137                 return "NO_REPLY";
138         case CONNECTION_ERROR_PERMISSION_DENIED:
139                 return "PERMISSION_DENIED";
140         case CONNECTION_ERROR_NOT_SUPPORTED:
141                 return "NOT_SUPPORTED";
142         }
143
144         return "UNKNOWN";
145 }
146
147 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
148 {
149         switch (state) {
150         case CONNECTION_PROFILE_STATE_DISCONNECTED:
151                 return "DISCONNECTED";
152         case CONNECTION_PROFILE_STATE_ASSOCIATION:
153                 return "ASSOCIATION";
154         case CONNECTION_PROFILE_STATE_CONFIGURATION:
155                 return "CONFIGURATION";
156         case CONNECTION_PROFILE_STATE_CONNECTED:
157                 return "CONNECTED";
158         default:
159                 return "UNKNOWN";
160         }
161 }
162
163 static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *user_data)
164 {
165         if (user_cb != NULL) {
166                 libnet.reset_profile_cb = user_cb;
167                 libnet.reset_profile_user_data = user_data;
168         }
169 }
170
171 static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
172 {
173         if (user_cb) {
174                 libnet.opened_cb = user_cb;
175                 libnet.opened_user_data = user_data;
176         }
177 }
178
179 static gboolean __libnet_reset_profile_cb_idle(gpointer data)
180 {
181         connection_error_e result = (connection_error_e)data;
182
183         if (libnet.reset_profile_cb != NULL)
184                 libnet.reset_profile_cb(result, libnet.reset_profile_user_data);
185
186         libnet.reset_profile_cb = NULL;
187         libnet.reset_profile_user_data = NULL;
188
189         return FALSE;
190 }
191
192 static void __libnet_reset_profile_cb(connection_error_e result)
193 {
194         if (_connection_is_created() != true) {
195                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
196                                 "If multi-threaded, thread integrity be broken.");
197                 return;
198         }
199
200         if (libnet.reset_profile_cb != NULL)
201                 _connection_callback_add(__libnet_reset_profile_cb_idle, (gpointer)result);
202 }
203
204 static void __libnet_opened_cb(connection_error_e result)
205 {
206         if (libnet.opened_cb)
207                 libnet.opened_cb(result, libnet.opened_user_data);
208
209         libnet.opened_cb = NULL;
210         libnet.opened_user_data = NULL;
211 }
212
213 static void __libnet_set_closed_cb(connection_closed_cb user_cb, void *user_data)
214 {
215         if (user_cb) {
216                 libnet.closed_cb = user_cb;
217                 libnet.closed_user_data = user_data;
218         }
219 }
220
221 static void __libnet_closed_cb(connection_error_e result)
222 {
223         if (libnet.closed_cb)
224                 libnet.closed_cb(result, libnet.closed_user_data);
225
226         libnet.closed_cb = NULL;
227         libnet.closed_user_data = NULL;
228 }
229
230 static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
231 {
232         if (user_cb) {
233                 libnet.set_default_cb = user_cb;
234                 libnet.set_default_user_data = user_data;
235         }
236 }
237
238 static void __libnet_default_cb(connection_error_e result)
239 {
240         if (libnet.set_default_cb)
241                 libnet.set_default_cb(result, libnet.set_default_user_data);
242
243         libnet.set_default_cb = NULL;
244         libnet.set_default_user_data = NULL;
245 }
246
247 static void __libnet_set_ethernet_cable_state_changed_cb(
248                 libnet_ethernet_cable_state_changed_cb user_cb)
249 {
250         libnet.ethernet_cable_state_changed_cb = user_cb;
251 }
252
253 static void __libnet_ethernet_cable_state_changed_cb(
254                 connection_ethernet_cable_state_e state)
255 {
256         if (libnet.ethernet_cable_state_changed_cb)
257                 libnet.ethernet_cable_state_changed_cb(state);
258 }
259
260 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
261 {
262         if (profile_name == NULL)
263                 return;
264
265         struct _profile_cb_s *cb_info;
266         cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
267
268         if (cb_info == NULL)
269                 return;
270
271         if (cb_info->state == state)
272                 return;
273
274         cb_info->state = state;
275
276         if (state >= 0 && cb_info->callback)
277                 cb_info->callback(state, cb_info->user_data);
278 }
279
280 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
281 {
282         if (profile_list->count > 0)
283                 g_free(profile_list->profiles);
284
285         profile_list->count = 0;
286         profile_list->next = 0;
287         profile_list->profiles = NULL;
288 }
289
290 static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
291 {
292         bool is_requested = false;
293         connection_error_e result = CONNECTION_ERROR_NONE;
294
295         switch (event_cb->Event) {
296         case NET_EVENT_OPEN_RSP:
297                 is_requested = true;
298                 /* fall through */
299         case NET_EVENT_OPEN_IND:
300                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
301                 CONNECTION_LOG(CONNECTION_INFO, "Got connection open %s : %s\n",
302                                         (is_requested) ? "RSP":"IND",
303                                         __libnet_convert_cp_error_type_to_string(result));
304
305                 if (is_requested)
306                         __libnet_opened_cb(result);
307
308                 switch (event_cb->Error) {
309                 case NET_ERR_NONE:
310                 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
311                         CONNECTION_LOG(CONNECTION_INFO, "'Open connection' succeeded\n");
312
313                         __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
314                         return;
315                 default:
316                         CONNECTION_LOG(CONNECTION_ERROR, "'Open connection' failed!! [%s]\n",
317                                                 __libnet_convert_cp_error_type_to_string(result));
318                 }
319
320                 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
321
322                 break;
323         case NET_EVENT_CLOSE_RSP:
324                 is_requested = true;
325                 /* fall through */
326         case NET_EVENT_CLOSE_IND:
327                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
328                 CONNECTION_LOG(CONNECTION_INFO, "Got connection close %s : %s\n",
329                                         (is_requested) ? "RSP":"IND",
330                                         __libnet_convert_cp_error_type_to_string(result));
331
332                 if (is_requested)
333                         __libnet_closed_cb(result);
334
335                 switch (event_cb->Error) {
336                 case NET_ERR_NONE:
337                         CONNECTION_LOG(CONNECTION_INFO, "'Close connection' succeeded!\n");
338
339                         __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
340                         return;
341                 default:
342                         CONNECTION_LOG(CONNECTION_ERROR, "'Close connection' failed!! [%s]\n",
343                                                 __libnet_convert_cp_error_type_to_string(result));
344                 }
345
346                 break;
347         case NET_EVENT_NET_STATE_IND:
348                 CONNECTION_LOG(CONNECTION_INFO, "Got State changed IND\n");
349
350                 if (event_cb->Datalength != sizeof(net_state_type_t))
351                         return;
352
353                 net_state_type_t *profile_state = (net_state_type_t*)event_cb->Data;
354                 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
355
356                 CONNECTION_LOG(CONNECTION_INFO,
357                                 "Profile State : %s, profile name : %s\n",
358                                 __libnet_convert_cp_state_to_string(cp_state),
359                                 event_cb->ProfileName);
360
361                 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
362
363                 break;
364         case NET_EVENT_WIFI_SCAN_IND:
365         case NET_EVENT_WIFI_SCAN_RSP:
366                 CONNECTION_LOG(CONNECTION_INFO, "Got wifi scan IND\n");
367                 break;
368         case NET_EVENT_WIFI_POWER_IND:
369         case NET_EVENT_WIFI_POWER_RSP:
370                 CONNECTION_LOG(CONNECTION_INFO, "Got wifi power IND\n");
371                 break;
372         case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
373                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
374                 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d\n", result);
375                 __libnet_default_cb(result);
376                 break;
377         case NET_EVENT_WIFI_WPS_RSP:
378                 CONNECTION_LOG(CONNECTION_INFO, "Got wifi WPS RSP\n");
379                 /* fall through */
380         case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
381                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
382                 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
383                 __libnet_reset_profile_cb(result);
384
385         case NET_EVENT_ETHERNET_CABLE_ATTACHED:
386                 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
387                 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_ATTACHED);
388                 break;
389         case NET_EVENT_ETHERNET_CABLE_DETACHED:
390                 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
391                 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_DETACHED);
392                 break;
393         default :
394                 CONNECTION_LOG(CONNECTION_ERROR, "Error! Unknown Event\n\n");
395                 break;
396         }
397 }
398
399 static int __libnet_check_address_type(int address_family, const char *address)
400 {
401         struct in6_addr buf;
402         int err = 0;
403
404         err = inet_pton(address_family, address, &buf);
405         if(err > 0)
406                 return 1;
407
408         return 0;
409 }
410
411 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
412 {
413         int count = 0;
414         int i = 0;
415
416         for (;i < profile_list->count;i++) {
417                 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
418                     profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
419                         count++;
420         }
421
422         return count;
423 }
424
425 void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
426 {
427         int i = 0;
428
429         for (;i < source->count;i++) {
430                 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
431                     source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
432                         memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
433                         (*dest)++;
434                 }
435         }
436 }
437
438 int _connection_libnet_init(void)
439 {
440         int rv;
441
442         if (!libnet.registered) {
443                 rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL);
444                 if (rv != NET_ERR_NONE)
445                         return false;
446
447                 libnet.registered = true;
448
449                 if (profile_cb_table == NULL)
450                         profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
451         }
452
453         return NET_ERR_NONE;
454 }
455
456 bool _connection_libnet_deinit(void)
457 {
458         if (libnet.registered) {
459                 if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE)
460                         return false;
461
462                 libnet.registered = false;
463
464                 if (profile_cb_table) {
465                         g_hash_table_destroy(profile_cb_table);
466                         profile_cb_table = NULL;
467                 }
468
469                 __libnet_clear_profile_list(&profile_iterator);
470
471                 if (prof_handle_list) {
472                         g_slist_free_full(prof_handle_list, g_free);
473                         prof_handle_list = NULL;
474                 }
475         }
476
477         return true;
478 }
479
480 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
481 {
482         GSList *list;
483         int i = 0;
484
485         for (list = prof_handle_list; list; list = list->next)
486                 if (profile == list->data) return true;
487
488         for (;i < profile_iterator.count;i++)
489                 if (profile == &profile_iterator.profiles[i]) return true;
490
491         return false;
492 }
493
494 bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
495 {
496         struct _profile_cb_s *cb_info;
497         net_profile_info_t *profile_info = profile;
498
499         if (profile == NULL)
500                 return false;
501
502         cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName);
503         if (cb_info != NULL)
504                 return true;
505
506         return false;
507 }
508
509
510 int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
511 {
512         int rv;
513         net_wifi_state_t wlan_state;
514         net_profile_name_t profile_name;
515
516         rv = net_get_wifi_state(&wlan_state, &profile_name);
517         if (rv == NET_ERR_ACCESS_DENIED) {
518                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
519                 return CONNECTION_ERROR_PERMISSION_DENIED;
520         } else if (rv != NET_ERR_NONE) {
521                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv);
522                 return CONNECTION_ERROR_OPERATION_FAILED;
523         }
524
525         switch (wlan_state) {
526         case WIFI_OFF:
527                 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
528                 break;
529         case WIFI_ON:
530         case WIFI_CONNECTING:
531                 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
532                 break;
533         case WIFI_CONNECTED:
534         case WIFI_DISCONNECTING:
535                 *state = CONNECTION_WIFI_STATE_CONNECTED;
536                 break;
537         default :
538                 CONNECTION_LOG(CONNECTION_ERROR, "Error!! Unknown state\n");
539                 return CONNECTION_ERROR_INVALID_OPERATION;
540         }
541
542         return CONNECTION_ERROR_NONE;
543 }
544
545 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
546 {
547         int rv;
548         struct _profile_list_s ethernet_profiles = {0, 0, NULL};
549         rv = net_get_profile_list(NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
550         if (rv == NET_ERR_ACCESS_DENIED) {
551                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
552                 return CONNECTION_ERROR_PERMISSION_DENIED;
553         }
554
555         switch (ethernet_profiles.profiles->ProfileState) {
556         case NET_STATE_TYPE_ONLINE:
557         case NET_STATE_TYPE_READY:
558                 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
559                 break;
560         case NET_STATE_TYPE_IDLE:
561         case NET_STATE_TYPE_FAILURE:
562         case NET_STATE_TYPE_ASSOCIATION:
563         case NET_STATE_TYPE_CONFIGURATION:
564         case NET_STATE_TYPE_DISCONNECT:
565                 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
566                 break;
567         default:
568                 return CONNECTION_ERROR_OPERATION_FAILED;
569         }
570
571         __libnet_clear_profile_list(&ethernet_profiles);
572
573         return CONNECTION_ERROR_NONE;
574 }
575
576 int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
577 {
578         int rv = 0;
579         int status = 0;
580
581         rv = net_get_ethernet_cable_state(&status);
582         if (rv == NET_ERR_ACCESS_DENIED) {
583                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
584                 return CONNECTION_ERROR_PERMISSION_DENIED;
585         } else if (rv != NET_ERR_NONE) {
586                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
587                 return CONNECTION_ERROR_OPERATION_FAILED;
588         }
589
590         if(status == 1)
591                 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
592         else
593                 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
594         return CONNECTION_ERROR_NONE;
595 }
596
597 int _connection_libnet_set_ethernet_cable_state_changed_cb(
598                 libnet_ethernet_cable_state_changed_cb callback)
599 {
600         __libnet_set_ethernet_cable_state_changed_cb(callback);
601
602         return CONNECTION_ERROR_NONE;
603 }
604
605 int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
606 {
607         int i = 0;
608         int rv = 0;
609         struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
610         rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
611         if (rv == NET_ERR_ACCESS_DENIED) {
612                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
613                 return CONNECTION_ERROR_PERMISSION_DENIED;
614         }
615
616         if (bluetooth_profiles.count == 0) {
617                 *state = CONNECTION_BT_STATE_DEACTIVATED;
618                 return CONNECTION_ERROR_NONE;
619         }
620
621         for (; i < bluetooth_profiles.count; i++) {
622                 switch (bluetooth_profiles.profiles[i].ProfileState) {
623                 case NET_STATE_TYPE_ONLINE:
624                 case NET_STATE_TYPE_READY:
625                         *state = CONNECTION_BT_STATE_CONNECTED;
626                         goto done;
627                 case NET_STATE_TYPE_IDLE:
628                 case NET_STATE_TYPE_FAILURE:
629                 case NET_STATE_TYPE_ASSOCIATION:
630                 case NET_STATE_TYPE_CONFIGURATION:
631                 case NET_STATE_TYPE_DISCONNECT:
632                         *state = CONNECTION_BT_STATE_DISCONNECTED;
633                         break;
634                 default:
635                         __libnet_clear_profile_list(&bluetooth_profiles);
636                         return CONNECTION_ERROR_OPERATION_FAILED;
637                 }
638         }
639
640 done:
641         __libnet_clear_profile_list(&bluetooth_profiles);
642
643         return CONNECTION_ERROR_NONE;
644 }
645
646 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
647 {
648         int count = 0;
649         int rv;
650         net_profile_info_t *profiles = NULL;
651
652         struct _profile_list_s all_profiles = {0, 0, NULL};
653
654         __libnet_clear_profile_list(&profile_iterator);
655
656         rv = net_get_profile_list(NET_DEVICE_MAX, &all_profiles.profiles, &all_profiles.count);
657
658         if (rv != NET_ERR_NONE) {
659                 if (rv == NET_ERR_NO_SERVICE) {
660                         *profile_iter_h = &profile_iterator;
661                         return CONNECTION_ERROR_NONE;
662                 } else
663                         return CONNECTION_ERROR_OPERATION_FAILED;
664         }
665
666         *profile_iter_h = &profile_iterator;
667
668         switch (type) {
669         case CONNECTION_ITERATOR_TYPE_REGISTERED:
670                 count = all_profiles.count;
671                 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d\n", count);
672
673                 if (count == 0)
674                         return CONNECTION_ERROR_NONE;
675
676                 profile_iterator.profiles = all_profiles.profiles;
677
678                 break;
679         case CONNECTION_ITERATOR_TYPE_CONNECTED:
680                 count = __libnet_get_connected_count(&all_profiles);
681                 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d\n", count);
682
683                 if (count == 0)
684                         return CONNECTION_ERROR_NONE;
685
686                 profiles = g_try_new0(net_profile_info_t, count);
687                 if (profiles == NULL) {
688                         __libnet_clear_profile_list(&all_profiles);
689                         return CONNECTION_ERROR_OUT_OF_MEMORY;
690                 break;
691         case CONNECTION_ITERATOR_TYPE_DEFAULT:
692                         /* To do : Not supported yet */
693                 break;
694                 }
695
696                 profile_iterator.profiles = profiles;
697
698                 __libnet_copy_connected_profile(&profiles, &all_profiles);
699
700                 __libnet_clear_profile_list(&all_profiles);
701         }
702
703         profile_iterator.count = count;
704
705         return CONNECTION_ERROR_NONE;
706 }
707
708 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
709 {
710         if (profile_iter_h != &profile_iterator)
711                 return CONNECTION_ERROR_INVALID_PARAMETER;
712
713         if (profile_iterator.count <= profile_iterator.next)
714                 return CONNECTION_ERROR_ITERATOR_END;
715
716         *profile = &profile_iterator.profiles[profile_iterator.next];
717         profile_iterator.next++;
718
719         return CONNECTION_ERROR_NONE;
720 }
721
722 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
723 {
724         if (profile_iter_h != &profile_iterator)
725                 return false;
726
727         if (profile_iterator.count <= profile_iterator.next)
728                 return false;
729
730         return true;
731 }
732
733 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
734 {
735         if (profile_iter_h != &profile_iterator)
736                 return CONNECTION_ERROR_INVALID_PARAMETER;
737
738         __libnet_clear_profile_list(&profile_iterator);
739
740         return CONNECTION_ERROR_NONE;
741 }
742
743 int _connection_libnet_get_current_profile(connection_profile_h *profile)
744 {
745         net_profile_info_t active_profile;
746         int rv;
747
748         rv = net_get_active_net_info(&active_profile);
749         if (rv == NET_ERR_NO_SERVICE)
750                 return CONNECTION_ERROR_NO_CONNECTION;
751         else if (rv == NET_ERR_ACCESS_DENIED) {
752                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
753                 return CONNECTION_ERROR_PERMISSION_DENIED;
754         } else if (rv != NET_ERR_NONE)
755                 return CONNECTION_ERROR_OPERATION_FAILED;
756
757         *profile = g_try_malloc0(sizeof(net_profile_info_t));
758         if (*profile == NULL)
759                 return CONNECTION_ERROR_OUT_OF_MEMORY;
760
761         memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
762         prof_handle_list = g_slist_append(prof_handle_list, *profile);
763
764         return CONNECTION_ERROR_NONE;
765 }
766
767 int _connection_libnet_reset_profile(connection_reset_option_e type,
768                 connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
769 {
770         int rv;
771
772         rv = net_reset_profile(type, id);
773         if (rv == NET_ERR_ACCESS_DENIED) {
774                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
775                 return CONNECTION_ERROR_PERMISSION_DENIED;
776         } else if (rv != NET_ERR_NONE) {
777                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
778                 return CONNECTION_ERROR_OPERATION_FAILED;
779         }
780
781         __libnet_set_reset_profile_cb(callback, user_data);
782
783         return CONNECTION_ERROR_NONE;
784 }
785
786 int _connection_libnet_open_profile(connection_profile_h profile, connection_opened_cb callback, void* user_data)
787 {
788         int rv;
789
790         if (!(_connection_libnet_check_profile_validity(profile))) {
791                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
792                 return CONNECTION_ERROR_INVALID_PARAMETER;
793         }
794
795         net_profile_info_t *profile_info = profile;
796
797         rv = net_open_connection_with_profile(profile_info->ProfileName);
798         if (rv == NET_ERR_ACCESS_DENIED) {
799                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
800                 return CONNECTION_ERROR_PERMISSION_DENIED;
801         } else if (rv != NET_ERR_NONE)
802                 return CONNECTION_ERROR_OPERATION_FAILED;
803
804         __libnet_set_opened_cb(callback, user_data);
805
806         return CONNECTION_ERROR_NONE;
807 }
808
809 int _connection_libnet_get_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h *profile)
810 {
811         int i = 0;
812         int j = 0;
813         int rv = NET_ERR_NONE;
814         net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
815
816         struct _profile_list_s cellular_profiles = {0, 0, NULL};
817
818         rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
819         if (rv == NET_ERR_ACCESS_DENIED) {
820                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
821                 return CONNECTION_ERROR_PERMISSION_DENIED;
822         } else if (rv != NET_ERR_NONE) {
823                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv);
824                 return CONNECTION_ERROR_OPERATION_FAILED;
825         }
826
827         for (;i < cellular_profiles.count;i++)
828                 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
829                         break;
830
831         if (i >= cellular_profiles.count)
832                 return CONNECTION_ERROR_OPERATION_FAILED;
833
834         *profile = g_try_malloc0(sizeof(net_profile_info_t));
835         if (*profile == NULL)
836                 return CONNECTION_ERROR_OUT_OF_MEMORY;
837
838         memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
839
840         if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
841                 goto done;
842
843         if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
844             type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
845                 goto done;
846
847         for (;j < cellular_profiles.count;j++) {
848                 if (i == j)
849                         continue;
850
851                 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
852                         continue;
853
854                 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
855                         memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
856                         goto done;
857                 }
858         }
859
860 done:
861         prof_handle_list = g_slist_append(prof_handle_list, *profile);
862
863         return CONNECTION_ERROR_NONE;
864 }
865
866 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
867 {
868         int rv;
869
870         if (!(_connection_libnet_check_profile_validity(profile))) {
871                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
872                 return CONNECTION_ERROR_INVALID_PARAMETER;
873         }
874
875         net_profile_info_t *profile_info = profile;
876         connection_cellular_service_type_e service_type;
877
878         service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
879
880         if (service_type != type)
881                 return CONNECTION_ERROR_INVALID_PARAMETER;
882
883         rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
884         if (rv == NET_ERR_ACCESS_DENIED) {
885                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
886                 return CONNECTION_ERROR_PERMISSION_DENIED;
887         } else if (rv != NET_ERR_NONE)
888                 return CONNECTION_ERROR_OPERATION_FAILED;
889
890         return CONNECTION_ERROR_NONE;
891 }
892
893 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
894                         connection_profile_h profile, connection_set_default_cb callback, void* user_data)
895 {
896         int rv;
897
898         if (!(_connection_libnet_check_profile_validity(profile))) {
899                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
900                 return CONNECTION_ERROR_INVALID_PARAMETER;
901         }
902
903         net_profile_info_t *profile_info = profile;
904         connection_cellular_service_type_e service_type;
905
906         service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
907
908         if (service_type != type)
909                 return CONNECTION_ERROR_INVALID_PARAMETER;
910
911         rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
912         if (rv == NET_ERR_ACCESS_DENIED) {
913                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
914                 return CONNECTION_ERROR_PERMISSION_DENIED;
915         } else if (rv != NET_ERR_NONE)
916                 return CONNECTION_ERROR_OPERATION_FAILED;
917
918         __libnet_set_default_cb(callback, user_data);
919
920         return CONNECTION_ERROR_NONE;
921 }
922
923 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
924 {
925         int rv;
926
927         if (!(_connection_libnet_check_profile_validity(profile))) {
928                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
929                 return CONNECTION_ERROR_INVALID_PARAMETER;
930         }
931
932         net_profile_info_t *profile_info = profile;
933
934         rv = net_close_connection(profile_info->ProfileName);
935         if (rv == NET_ERR_ACCESS_DENIED) {
936                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
937                 return CONNECTION_ERROR_PERMISSION_DENIED;
938         } else if (rv != NET_ERR_NONE)
939                 return CONNECTION_ERROR_OPERATION_FAILED;
940
941         if (net_close_connection(profile_info->ProfileName) != NET_ERR_NONE)
942                 return CONNECTION_ERROR_OPERATION_FAILED;
943
944         __libnet_set_closed_cb(callback, user_data);
945
946         return CONNECTION_ERROR_NONE;
947 }
948
949 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
950 {
951         int rv;
952         char *endstr = NULL;
953         int address_family = 0;
954
955         if(__libnet_check_address_type(AF_INET, host_address))
956                 address_family = AF_INET;
957         else
958                 return CONNECTION_ERROR_INVALID_PARAMETER;
959
960         switch(address_family) {
961                 case AF_INET:
962                         endstr = strrchr(host_address, '.');
963                         if (endstr == NULL ||
964                                         strcmp(endstr, ".0") == 0 ||
965                                         strncmp(host_address, "0.", 2) == 0 ||
966                                         strstr(host_address, "255") != NULL) {
967                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
968                                 return CONNECTION_ERROR_INVALID_PARAMETER;
969                         }
970                         break;
971                 default:
972                         return CONNECTION_ERROR_OPERATION_FAILED;
973         }
974
975         rv = net_add_route(host_address, interface_name, address_family);
976         if (rv == NET_ERR_ACCESS_DENIED) {
977                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
978                 return CONNECTION_ERROR_PERMISSION_DENIED;
979         } else if (rv != NET_ERR_NONE)
980                 return CONNECTION_ERROR_OPERATION_FAILED;
981
982         return CONNECTION_ERROR_NONE;
983 }
984
985 int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
986 {
987         int rv;
988         char *endstr = strrchr(host_address, '.');
989         int address_family = 0;
990
991         if (__libnet_check_address_type(AF_INET, host_address))
992                 address_family = AF_INET;
993         else
994                 return CONNECTION_ERROR_INVALID_PARAMETER;
995
996         switch(address_family) {
997                 case AF_INET:
998                         endstr = strrchr(host_address, '.');
999                         if (endstr == NULL ||
1000                                 strcmp(endstr, ".0") == 0 ||
1001                                 strncmp(host_address, "0.", 2) == 0 ||
1002                                 strstr(host_address, ".0.") != NULL ||strstr(host_address, "255") != NULL) {
1003                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed");
1004                                 return CONNECTION_ERROR_INVALID_PARAMETER;
1005                         }
1006                         break;
1007                 default:
1008                         return CONNECTION_ERROR_OPERATION_FAILED;
1009         }
1010
1011         rv = net_remove_route(host_address, interface_name, address_family);
1012         if (rv == NET_ERR_ACCESS_DENIED) {
1013                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1014                 return CONNECTION_ERROR_PERMISSION_DENIED;
1015         } else if (rv != NET_ERR_NONE)
1016                 return CONNECTION_ERROR_OPERATION_FAILED;
1017
1018         return CONNECTION_ERROR_NONE;
1019 }
1020
1021 int _connection_libnet_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1022 {
1023         int rv;
1024         int address_family = 0;
1025
1026         address_family = AF_INET6;
1027 /*      if(__libnet_check_address_type(AF_INET6, host_address))
1028                 address_family = AF_INET6;
1029         else
1030                 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1031
1032         switch(address_family) {
1033                 case AF_INET6:
1034                         if (strncmp(host_address, "fe80:", 5) == 0 ||
1035                                 strncmp(host_address, "ff00:", 5) == 0 ||
1036                                 strncmp(host_address, "::", 2) == 0) {
1037                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1038                                 return CONNECTION_ERROR_INVALID_PARAMETER;
1039                         }
1040                         break;
1041                 default:
1042                         return CONNECTION_ERROR_OPERATION_FAILED;
1043         }
1044
1045         rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
1046         if (rv == NET_ERR_ACCESS_DENIED) {
1047                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1048                 return CONNECTION_ERROR_PERMISSION_DENIED;
1049         } else if (rv != NET_ERR_NONE)
1050                 return CONNECTION_ERROR_OPERATION_FAILED;
1051
1052         return CONNECTION_ERROR_NONE;
1053 }
1054
1055 int _connection_libnet_remove_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1056 {
1057         int rv;
1058         int address_family = 0;
1059
1060         address_family = AF_INET6;
1061 /*      if (__libnet_check_address_type(AF_INET6, host_address))
1062                 address_family = AF_INET6;
1063         else
1064                 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1065
1066         switch(address_family) {
1067                 case AF_INET6:
1068                         if (strncmp(host_address, "fe80:", 5) == 0 ||
1069                                 strncmp(host_address, "ff00:", 5) == 0 ||
1070                                 strncmp(host_address, "::", 2) == 0) {
1071                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1072                                 return CONNECTION_ERROR_INVALID_PARAMETER;
1073                         }
1074                         break;
1075                 default:
1076                         return CONNECTION_ERROR_OPERATION_FAILED;
1077         }
1078
1079         rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
1080         if (rv == NET_ERR_ACCESS_DENIED) {
1081                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1082                 return CONNECTION_ERROR_PERMISSION_DENIED;
1083         } else if (rv != NET_ERR_NONE)
1084                 return CONNECTION_ERROR_OPERATION_FAILED;
1085
1086         return CONNECTION_ERROR_NONE;
1087 }
1088
1089 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1090 {
1091         prof_handle_list = g_slist_append(prof_handle_list, profile);
1092 }
1093
1094 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1095 {
1096         prof_handle_list = g_slist_remove(prof_handle_list, profile);
1097         g_free(profile);
1098 }
1099
1100 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1101                 connection_profile_state_changed_cb callback, void *user_data)
1102 {
1103         net_profile_info_t *profile_info = profile;
1104         char *profile_name = g_strdup(profile_info->ProfileName);
1105
1106         struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1107         if (profile_cb_info == NULL) {
1108                 g_free(profile_name);
1109                 return false;
1110         }
1111
1112         profile_cb_info->callback = callback;
1113         profile_cb_info->user_data = user_data;
1114
1115         g_hash_table_insert(profile_cb_table, profile_name, profile_cb_info);
1116
1117         return true;
1118 }
1119
1120 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1121 {
1122         net_profile_info_t *profile_info = profile;
1123         if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1124                 return true;
1125
1126         return false;
1127 }
1128
1129 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
1130 {
1131         int rv;
1132         rv = net_set_statistics(device_type, statistics_type);
1133         if (rv == NET_ERR_ACCESS_DENIED) {
1134                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1135                 return CONNECTION_ERROR_PERMISSION_DENIED;
1136         } else if (rv != NET_ERR_NONE)
1137                 return CONNECTION_ERROR_OPERATION_FAILED;
1138
1139         return CONNECTION_ERROR_NONE;
1140 }
1141
1142 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
1143 {
1144         int rv;
1145         rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
1146         if (rv == NET_ERR_ACCESS_DENIED) {
1147                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1148                 return CONNECTION_ERROR_PERMISSION_DENIED;
1149         }else if (rv != NET_ERR_NONE)
1150                 return CONNECTION_ERROR_OPERATION_FAILED;
1151
1152         return CONNECTION_ERROR_NONE;
1153 }
1154
1155 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1156                 connection_cellular_subscriber_id_e sim_id)
1157 {
1158         char *modem_path = NULL;
1159         net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1160
1161         if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1162                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id);
1163                 return CONNECTION_ERROR_OPERATION_FAILED;
1164         }
1165
1166         if (!modem_path) {
1167                 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path");
1168                 return CONNECTION_ERROR_OPERATION_FAILED;
1169         }
1170
1171         g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1172                                 NET_PROFILE_NAME_LEN_MAX);
1173         g_free(modem_path);
1174
1175         return CONNECTION_ERROR_NONE;
1176 }
1177
1178 static void __connection_idle_destroy_cb(gpointer data)
1179 {
1180         if (!data)
1181                 return;
1182
1183         managed_idler_list = g_slist_remove(managed_idler_list, data);
1184         g_free(data);
1185 }
1186
1187 static gboolean __connection_idle_cb(gpointer user_data)
1188 {
1189         struct managed_idle_data *data = (struct managed_idle_data *)user_data;
1190
1191         if (!data)
1192                 return FALSE;
1193
1194         return data->func(data->user_data);
1195 }
1196
1197 guint _connection_callback_add(GSourceFunc func, gpointer user_data)
1198 {
1199         guint id;
1200         struct managed_idle_data *data;
1201
1202         if (!func)
1203                 return 0;
1204
1205         data = g_try_new0(struct managed_idle_data, 1);
1206         if (!data)
1207                 return 0;
1208
1209         data->func = func;
1210         data->user_data = user_data;
1211
1212         id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __connection_idle_cb, data,
1213                         __connection_idle_destroy_cb);
1214         if (!id) {
1215                 g_free(data);
1216                 return id;
1217         }
1218
1219         data->id = id;
1220
1221         managed_idler_list = g_slist_append(managed_idler_list, data);
1222
1223         return id;
1224 }
1225
1226 void _connection_callback_cleanup(void)
1227 {
1228         GSList *cur = managed_idler_list;
1229         GSource *src;
1230         struct managed_idle_data *data;
1231
1232         while (cur) {
1233                 GSList *next = cur->next;
1234                 data = (struct managed_idle_data *)cur->data;
1235
1236                 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
1237                 if (src) {
1238                         g_source_destroy(src);
1239                         cur = managed_idler_list;
1240                 } else
1241                         cur = next;
1242         }
1243
1244         g_slist_free(managed_idler_list);
1245         managed_idler_list = NULL;
1246 }
1247
1248 int _connection_libnet_check_get_privilege()
1249 {
1250         int rv;
1251
1252         rv = net_check_get_privilege();
1253         if (rv == NET_ERR_ACCESS_DENIED) {
1254                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1255                 return CONNECTION_ERROR_PERMISSION_DENIED;
1256         } else if (rv != NET_ERR_NONE)
1257                 return CONNECTION_ERROR_OPERATION_FAILED;
1258
1259         return CONNECTION_ERROR_NONE;
1260 }
1261
1262 int _connection_libnet_check_profile_privilege()
1263 {
1264         int rv;
1265
1266         rv = net_check_profile_privilege();
1267         if (rv == NET_ERR_ACCESS_DENIED) {
1268                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1269                 return CONNECTION_ERROR_PERMISSION_DENIED;
1270         } else if (rv != NET_ERR_NONE)
1271                 return CONNECTION_ERROR_OPERATION_FAILED;
1272
1273         return CONNECTION_ERROR_NONE;
1274 }
1275
1276 bool _connection_libnet_get_is_check_enable_feature()
1277 {
1278         return is_check_enable_feature;
1279 }
1280
1281 bool _connection_libnet_get_enable_feature_state(enable_feature_type_e feature_type)
1282 {
1283         if(is_check_enable_feature){
1284                 switch(feature_type) {
1285                 case FEATURE_TYPE_TELEPHONY:
1286                         return enable_feature.telephony;
1287                 case FEATURE_TYPE_WIFI:
1288                         return enable_feature.wifi;
1289                 case FEATURE_TYPE_TETHERING_BLUETOOTH:
1290                         return enable_feature.tethering_bluetooth;
1291                 default:
1292                         CONNECTION_LOG(CONNECTION_ERROR, "Invalid feature type");
1293                         return false;
1294                 }
1295         }
1296         CONNECTION_LOG(CONNECTION_ERROR, "Not checked enable feature yet");
1297         return false;
1298 }