Add Null Check to avoid potential crash
[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         if (profile == NULL)
486                 return false;
487
488         for (list = prof_handle_list; list; list = list->next)
489                 if (profile == list->data) return true;
490
491         for (;i < profile_iterator.count;i++)
492                 if (profile == &profile_iterator.profiles[i]) return true;
493
494         return false;
495 }
496
497 bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
498 {
499         struct _profile_cb_s *cb_info;
500         net_profile_info_t *profile_info = profile;
501
502         if (profile == NULL)
503                 return false;
504
505         cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName);
506         if (cb_info != NULL)
507                 return true;
508
509         return false;
510 }
511
512
513 int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
514 {
515         int rv;
516         net_wifi_state_t wlan_state;
517         net_profile_name_t profile_name;
518
519         rv = net_get_wifi_state(&wlan_state, &profile_name);
520         if (rv == NET_ERR_ACCESS_DENIED) {
521                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
522                 return CONNECTION_ERROR_PERMISSION_DENIED;
523         } else if (rv != NET_ERR_NONE) {
524                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv);
525                 return CONNECTION_ERROR_OPERATION_FAILED;
526         }
527
528         switch (wlan_state) {
529         case WIFI_OFF:
530                 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
531                 break;
532         case WIFI_ON:
533         case WIFI_CONNECTING:
534                 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
535                 break;
536         case WIFI_CONNECTED:
537         case WIFI_DISCONNECTING:
538                 *state = CONNECTION_WIFI_STATE_CONNECTED;
539                 break;
540         default :
541                 CONNECTION_LOG(CONNECTION_ERROR, "Error!! Unknown state\n");
542                 return CONNECTION_ERROR_INVALID_OPERATION;
543         }
544
545         return CONNECTION_ERROR_NONE;
546 }
547
548 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
549 {
550         int rv;
551         struct _profile_list_s ethernet_profiles = {0, 0, NULL};
552         rv = net_get_profile_list(NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
553         if (rv == NET_ERR_ACCESS_DENIED) {
554                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
555                 return CONNECTION_ERROR_PERMISSION_DENIED;
556         }
557
558         if (ethernet_profiles.count == 0) {
559                 state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
560                 return true;
561         }
562
563         switch (ethernet_profiles.profiles->ProfileState) {
564         case NET_STATE_TYPE_ONLINE:
565         case NET_STATE_TYPE_READY:
566                 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
567                 break;
568         case NET_STATE_TYPE_IDLE:
569         case NET_STATE_TYPE_FAILURE:
570         case NET_STATE_TYPE_ASSOCIATION:
571         case NET_STATE_TYPE_CONFIGURATION:
572         case NET_STATE_TYPE_DISCONNECT:
573                 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
574                 break;
575         default:
576                 return CONNECTION_ERROR_OPERATION_FAILED;
577         }
578
579         __libnet_clear_profile_list(&ethernet_profiles);
580
581         return CONNECTION_ERROR_NONE;
582 }
583
584 int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
585 {
586         int rv = 0;
587         int status = 0;
588
589         rv = net_get_ethernet_cable_state(&status);
590         if (rv == NET_ERR_ACCESS_DENIED) {
591                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
592                 return CONNECTION_ERROR_PERMISSION_DENIED;
593         } else if (rv != NET_ERR_NONE) {
594                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
595                 return CONNECTION_ERROR_OPERATION_FAILED;
596         }
597
598         if(status == 1)
599                 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
600         else
601                 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
602         return CONNECTION_ERROR_NONE;
603 }
604
605 int _connection_libnet_set_ethernet_cable_state_changed_cb(
606                 libnet_ethernet_cable_state_changed_cb callback)
607 {
608         __libnet_set_ethernet_cable_state_changed_cb(callback);
609
610         return CONNECTION_ERROR_NONE;
611 }
612
613 int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
614 {
615         int i = 0;
616         int rv = 0;
617         struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
618         rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
619         if (rv == NET_ERR_ACCESS_DENIED) {
620                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
621                 return CONNECTION_ERROR_PERMISSION_DENIED;
622         }
623
624         if (bluetooth_profiles.count == 0) {
625                 *state = CONNECTION_BT_STATE_DEACTIVATED;
626                 return CONNECTION_ERROR_NONE;
627         }
628
629         for (; i < bluetooth_profiles.count; i++) {
630                 switch (bluetooth_profiles.profiles[i].ProfileState) {
631                 case NET_STATE_TYPE_ONLINE:
632                 case NET_STATE_TYPE_READY:
633                         *state = CONNECTION_BT_STATE_CONNECTED;
634                         goto done;
635                 case NET_STATE_TYPE_IDLE:
636                 case NET_STATE_TYPE_FAILURE:
637                 case NET_STATE_TYPE_ASSOCIATION:
638                 case NET_STATE_TYPE_CONFIGURATION:
639                 case NET_STATE_TYPE_DISCONNECT:
640                         *state = CONNECTION_BT_STATE_DISCONNECTED;
641                         break;
642                 default:
643                         __libnet_clear_profile_list(&bluetooth_profiles);
644                         return CONNECTION_ERROR_OPERATION_FAILED;
645                 }
646         }
647
648 done:
649         __libnet_clear_profile_list(&bluetooth_profiles);
650
651         return CONNECTION_ERROR_NONE;
652 }
653
654 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
655 {
656         int count = 0;
657         int rv;
658         net_profile_info_t *profiles = NULL;
659
660         struct _profile_list_s all_profiles = {0, 0, NULL};
661
662         __libnet_clear_profile_list(&profile_iterator);
663
664         rv = net_get_profile_list(NET_DEVICE_MAX, &all_profiles.profiles, &all_profiles.count);
665
666         if (rv != NET_ERR_NONE) {
667                 if (rv == NET_ERR_NO_SERVICE) {
668                         *profile_iter_h = &profile_iterator;
669                         return CONNECTION_ERROR_NONE;
670                 } else
671                         return CONNECTION_ERROR_OPERATION_FAILED;
672         }
673
674         *profile_iter_h = &profile_iterator;
675
676         switch (type) {
677         case CONNECTION_ITERATOR_TYPE_REGISTERED:
678                 count = all_profiles.count;
679                 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d\n", count);
680
681                 if (count == 0)
682                         return CONNECTION_ERROR_NONE;
683
684                 profile_iterator.profiles = all_profiles.profiles;
685
686                 break;
687         case CONNECTION_ITERATOR_TYPE_CONNECTED:
688                 count = __libnet_get_connected_count(&all_profiles);
689                 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d\n", count);
690
691                 if (count == 0)
692                         return CONNECTION_ERROR_NONE;
693
694                 profiles = g_try_new0(net_profile_info_t, count);
695                 if (profiles == NULL) {
696                         __libnet_clear_profile_list(&all_profiles);
697                         return CONNECTION_ERROR_OUT_OF_MEMORY;
698                 break;
699         case CONNECTION_ITERATOR_TYPE_DEFAULT:
700                         /* To do : Not supported yet */
701                 break;
702                 }
703
704                 profile_iterator.profiles = profiles;
705
706                 __libnet_copy_connected_profile(&profiles, &all_profiles);
707
708                 __libnet_clear_profile_list(&all_profiles);
709         }
710
711         profile_iterator.count = count;
712
713         return CONNECTION_ERROR_NONE;
714 }
715
716 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
717 {
718         if (profile_iter_h != &profile_iterator)
719                 return CONNECTION_ERROR_INVALID_PARAMETER;
720
721         if (profile_iterator.count <= profile_iterator.next)
722                 return CONNECTION_ERROR_ITERATOR_END;
723
724         *profile = &profile_iterator.profiles[profile_iterator.next];
725         profile_iterator.next++;
726
727         return CONNECTION_ERROR_NONE;
728 }
729
730 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
731 {
732         if (profile_iter_h != &profile_iterator)
733                 return false;
734
735         if (profile_iterator.count <= profile_iterator.next)
736                 return false;
737
738         return true;
739 }
740
741 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
742 {
743         if (profile_iter_h != &profile_iterator)
744                 return CONNECTION_ERROR_INVALID_PARAMETER;
745
746         __libnet_clear_profile_list(&profile_iterator);
747
748         return CONNECTION_ERROR_NONE;
749 }
750
751 int _connection_libnet_get_current_profile(connection_profile_h *profile)
752 {
753         net_profile_info_t active_profile;
754         int rv;
755
756         rv = net_get_active_net_info(&active_profile);
757         if (rv == NET_ERR_NO_SERVICE)
758                 return CONNECTION_ERROR_NO_CONNECTION;
759         else if (rv == NET_ERR_ACCESS_DENIED) {
760                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
761                 return CONNECTION_ERROR_PERMISSION_DENIED;
762         } else if (rv != NET_ERR_NONE)
763                 return CONNECTION_ERROR_OPERATION_FAILED;
764
765         *profile = g_try_malloc0(sizeof(net_profile_info_t));
766         if (*profile == NULL)
767                 return CONNECTION_ERROR_OUT_OF_MEMORY;
768
769         memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
770         prof_handle_list = g_slist_append(prof_handle_list, *profile);
771
772         return CONNECTION_ERROR_NONE;
773 }
774
775 int _connection_libnet_reset_profile(connection_reset_option_e type,
776                 connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
777 {
778         int rv;
779
780         rv = net_reset_profile(type, id);
781         if (rv == NET_ERR_ACCESS_DENIED) {
782                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
783                 return CONNECTION_ERROR_PERMISSION_DENIED;
784         } else if (rv != NET_ERR_NONE) {
785                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
786                 return CONNECTION_ERROR_OPERATION_FAILED;
787         }
788
789         __libnet_set_reset_profile_cb(callback, user_data);
790
791         return CONNECTION_ERROR_NONE;
792 }
793
794 int _connection_libnet_open_profile(connection_profile_h profile, connection_opened_cb callback, void* user_data)
795 {
796         int rv;
797
798         if (!(_connection_libnet_check_profile_validity(profile))) {
799                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
800                 return CONNECTION_ERROR_INVALID_PARAMETER;
801         }
802
803         net_profile_info_t *profile_info = profile;
804
805         rv = net_open_connection_with_profile(profile_info->ProfileName);
806         if (rv == NET_ERR_ACCESS_DENIED) {
807                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
808                 return CONNECTION_ERROR_PERMISSION_DENIED;
809         } else if (rv != NET_ERR_NONE)
810                 return CONNECTION_ERROR_OPERATION_FAILED;
811
812         __libnet_set_opened_cb(callback, user_data);
813
814         return CONNECTION_ERROR_NONE;
815 }
816
817 int _connection_libnet_get_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h *profile)
818 {
819         int i = 0;
820         int j = 0;
821         int rv = NET_ERR_NONE;
822         net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
823
824         struct _profile_list_s cellular_profiles = {0, 0, NULL};
825
826         rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
827         if (rv == NET_ERR_ACCESS_DENIED) {
828                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
829                 return CONNECTION_ERROR_PERMISSION_DENIED;
830         } else if (rv != NET_ERR_NONE) {
831                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv);
832                 return CONNECTION_ERROR_OPERATION_FAILED;
833         }
834
835         for (;i < cellular_profiles.count;i++)
836                 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
837                         break;
838
839         if (i >= cellular_profiles.count)
840                 return CONNECTION_ERROR_OPERATION_FAILED;
841
842         *profile = g_try_malloc0(sizeof(net_profile_info_t));
843         if (*profile == NULL)
844                 return CONNECTION_ERROR_OUT_OF_MEMORY;
845
846         memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
847
848         if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
849                 goto done;
850
851         if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
852             type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
853                 goto done;
854
855         for (;j < cellular_profiles.count;j++) {
856                 if (i == j)
857                         continue;
858
859                 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
860                         continue;
861
862                 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
863                         memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
864                         goto done;
865                 }
866         }
867
868 done:
869         prof_handle_list = g_slist_append(prof_handle_list, *profile);
870
871         return CONNECTION_ERROR_NONE;
872 }
873
874 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
875 {
876         int rv;
877
878         if (!(_connection_libnet_check_profile_validity(profile))) {
879                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
880                 return CONNECTION_ERROR_INVALID_PARAMETER;
881         }
882
883         net_profile_info_t *profile_info = profile;
884         connection_cellular_service_type_e service_type;
885
886         service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
887
888         if (service_type != type)
889                 return CONNECTION_ERROR_INVALID_PARAMETER;
890
891         rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
892         if (rv == NET_ERR_ACCESS_DENIED) {
893                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
894                 return CONNECTION_ERROR_PERMISSION_DENIED;
895         } else if (rv != NET_ERR_NONE)
896                 return CONNECTION_ERROR_OPERATION_FAILED;
897
898         return CONNECTION_ERROR_NONE;
899 }
900
901 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
902                         connection_profile_h profile, connection_set_default_cb callback, void* user_data)
903 {
904         int rv;
905
906         if (!(_connection_libnet_check_profile_validity(profile))) {
907                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
908                 return CONNECTION_ERROR_INVALID_PARAMETER;
909         }
910
911         net_profile_info_t *profile_info = profile;
912         connection_cellular_service_type_e service_type;
913
914         service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
915
916         if (service_type != type)
917                 return CONNECTION_ERROR_INVALID_PARAMETER;
918
919         rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
920         if (rv == NET_ERR_ACCESS_DENIED) {
921                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
922                 return CONNECTION_ERROR_PERMISSION_DENIED;
923         } else if (rv != NET_ERR_NONE)
924                 return CONNECTION_ERROR_OPERATION_FAILED;
925
926         __libnet_set_default_cb(callback, user_data);
927
928         return CONNECTION_ERROR_NONE;
929 }
930
931 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
932 {
933         int rv;
934
935         if (!(_connection_libnet_check_profile_validity(profile))) {
936                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
937                 return CONNECTION_ERROR_INVALID_PARAMETER;
938         }
939
940         net_profile_info_t *profile_info = profile;
941
942         rv = net_close_connection(profile_info->ProfileName);
943         if (rv == NET_ERR_ACCESS_DENIED) {
944                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
945                 return CONNECTION_ERROR_PERMISSION_DENIED;
946         } else if (rv != NET_ERR_NONE)
947                 return CONNECTION_ERROR_OPERATION_FAILED;
948
949         if (net_close_connection(profile_info->ProfileName) != NET_ERR_NONE)
950                 return CONNECTION_ERROR_OPERATION_FAILED;
951
952         __libnet_set_closed_cb(callback, user_data);
953
954         return CONNECTION_ERROR_NONE;
955 }
956
957 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
958 {
959         int rv;
960         char *endstr = NULL;
961         int address_family = 0;
962
963         if(__libnet_check_address_type(AF_INET, host_address))
964                 address_family = AF_INET;
965         else
966                 return CONNECTION_ERROR_INVALID_PARAMETER;
967
968         switch(address_family) {
969                 case AF_INET:
970                         endstr = strrchr(host_address, '.');
971                         if (endstr == NULL ||
972                                         strcmp(endstr, ".0") == 0 ||
973                                         strncmp(host_address, "0.", 2) == 0 ||
974                                         strstr(host_address, "255") != NULL) {
975                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
976                                 return CONNECTION_ERROR_INVALID_PARAMETER;
977                         }
978                         break;
979                 default:
980                         return CONNECTION_ERROR_OPERATION_FAILED;
981         }
982
983         rv = net_add_route(host_address, interface_name, address_family);
984         if (rv == NET_ERR_ACCESS_DENIED) {
985                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
986                 return CONNECTION_ERROR_PERMISSION_DENIED;
987         } else if (rv != NET_ERR_NONE)
988                 return CONNECTION_ERROR_OPERATION_FAILED;
989
990         return CONNECTION_ERROR_NONE;
991 }
992
993 int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
994 {
995         int rv;
996         char *endstr = strrchr(host_address, '.');
997         int address_family = 0;
998
999         if (__libnet_check_address_type(AF_INET, host_address))
1000                 address_family = AF_INET;
1001         else
1002                 return CONNECTION_ERROR_INVALID_PARAMETER;
1003
1004         switch(address_family) {
1005                 case AF_INET:
1006                         endstr = strrchr(host_address, '.');
1007                         if (endstr == NULL ||
1008                                 strcmp(endstr, ".0") == 0 ||
1009                                 strncmp(host_address, "0.", 2) == 0 ||
1010                                 strstr(host_address, ".0.") != NULL ||strstr(host_address, "255") != NULL) {
1011                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed");
1012                                 return CONNECTION_ERROR_INVALID_PARAMETER;
1013                         }
1014                         break;
1015                 default:
1016                         return CONNECTION_ERROR_OPERATION_FAILED;
1017         }
1018
1019         rv = net_remove_route(host_address, interface_name, address_family);
1020         if (rv == NET_ERR_ACCESS_DENIED) {
1021                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1022                 return CONNECTION_ERROR_PERMISSION_DENIED;
1023         } else if (rv != NET_ERR_NONE)
1024                 return CONNECTION_ERROR_OPERATION_FAILED;
1025
1026         return CONNECTION_ERROR_NONE;
1027 }
1028
1029 int _connection_libnet_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1030 {
1031         int rv;
1032         int address_family = 0;
1033
1034         address_family = AF_INET6;
1035 /*      if(__libnet_check_address_type(AF_INET6, host_address))
1036                 address_family = AF_INET6;
1037         else
1038                 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1039
1040         switch(address_family) {
1041                 case AF_INET6:
1042                         if (strncmp(host_address, "fe80:", 5) == 0 ||
1043                                 strncmp(host_address, "ff00:", 5) == 0 ||
1044                                 strncmp(host_address, "::", 2) == 0) {
1045                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1046                                 return CONNECTION_ERROR_INVALID_PARAMETER;
1047                         }
1048                         break;
1049                 default:
1050                         return CONNECTION_ERROR_OPERATION_FAILED;
1051         }
1052
1053         rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
1054         if (rv == NET_ERR_ACCESS_DENIED) {
1055                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1056                 return CONNECTION_ERROR_PERMISSION_DENIED;
1057         } else if (rv != NET_ERR_NONE)
1058                 return CONNECTION_ERROR_OPERATION_FAILED;
1059
1060         return CONNECTION_ERROR_NONE;
1061 }
1062
1063 int _connection_libnet_remove_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1064 {
1065         int rv;
1066         int address_family = 0;
1067
1068         address_family = AF_INET6;
1069 /*      if (__libnet_check_address_type(AF_INET6, host_address))
1070                 address_family = AF_INET6;
1071         else
1072                 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1073
1074         switch(address_family) {
1075                 case AF_INET6:
1076                         if (strncmp(host_address, "fe80:", 5) == 0 ||
1077                                 strncmp(host_address, "ff00:", 5) == 0 ||
1078                                 strncmp(host_address, "::", 2) == 0) {
1079                                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1080                                 return CONNECTION_ERROR_INVALID_PARAMETER;
1081                         }
1082                         break;
1083                 default:
1084                         return CONNECTION_ERROR_OPERATION_FAILED;
1085         }
1086
1087         rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
1088         if (rv == NET_ERR_ACCESS_DENIED) {
1089                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1090                 return CONNECTION_ERROR_PERMISSION_DENIED;
1091         } else if (rv != NET_ERR_NONE)
1092                 return CONNECTION_ERROR_OPERATION_FAILED;
1093
1094         return CONNECTION_ERROR_NONE;
1095 }
1096
1097 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1098 {
1099         prof_handle_list = g_slist_append(prof_handle_list, profile);
1100 }
1101
1102 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1103 {
1104         prof_handle_list = g_slist_remove(prof_handle_list, profile);
1105         g_free(profile);
1106 }
1107
1108 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1109                 connection_profile_state_changed_cb callback, void *user_data)
1110 {
1111         net_profile_info_t *profile_info = profile;
1112         char *profile_name = g_strdup(profile_info->ProfileName);
1113
1114         struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1115         if (profile_cb_info == NULL) {
1116                 g_free(profile_name);
1117                 return false;
1118         }
1119
1120         profile_cb_info->callback = callback;
1121         profile_cb_info->user_data = user_data;
1122
1123         g_hash_table_insert(profile_cb_table, profile_name, profile_cb_info);
1124
1125         return true;
1126 }
1127
1128 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1129 {
1130         net_profile_info_t *profile_info = profile;
1131         if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1132                 return true;
1133
1134         return false;
1135 }
1136
1137 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
1138 {
1139         int rv;
1140         rv = net_set_statistics(device_type, statistics_type);
1141         if (rv == NET_ERR_ACCESS_DENIED) {
1142                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1143                 return CONNECTION_ERROR_PERMISSION_DENIED;
1144         } else if (rv != NET_ERR_NONE)
1145                 return CONNECTION_ERROR_OPERATION_FAILED;
1146
1147         return CONNECTION_ERROR_NONE;
1148 }
1149
1150 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
1151 {
1152         int rv;
1153         rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
1154         if (rv == NET_ERR_ACCESS_DENIED) {
1155                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1156                 return CONNECTION_ERROR_PERMISSION_DENIED;
1157         }else if (rv != NET_ERR_NONE)
1158                 return CONNECTION_ERROR_OPERATION_FAILED;
1159
1160         return CONNECTION_ERROR_NONE;
1161 }
1162
1163 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1164                 connection_cellular_subscriber_id_e sim_id)
1165 {
1166         char *modem_path = NULL;
1167         net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1168
1169         if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1170                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id);
1171                 return CONNECTION_ERROR_OPERATION_FAILED;
1172         }
1173
1174         if (!modem_path) {
1175                 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path");
1176                 return CONNECTION_ERROR_OPERATION_FAILED;
1177         }
1178
1179         g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1180                                 NET_PROFILE_NAME_LEN_MAX);
1181         g_free(modem_path);
1182
1183         return CONNECTION_ERROR_NONE;
1184 }
1185
1186 static void __connection_idle_destroy_cb(gpointer data)
1187 {
1188         if (!data)
1189                 return;
1190
1191         managed_idler_list = g_slist_remove(managed_idler_list, data);
1192         g_free(data);
1193 }
1194
1195 static gboolean __connection_idle_cb(gpointer user_data)
1196 {
1197         struct managed_idle_data *data = (struct managed_idle_data *)user_data;
1198
1199         if (!data)
1200                 return FALSE;
1201
1202         return data->func(data->user_data);
1203 }
1204
1205 guint _connection_callback_add(GSourceFunc func, gpointer user_data)
1206 {
1207         guint id;
1208         struct managed_idle_data *data;
1209
1210         if (!func)
1211                 return 0;
1212
1213         data = g_try_new0(struct managed_idle_data, 1);
1214         if (!data)
1215                 return 0;
1216
1217         data->func = func;
1218         data->user_data = user_data;
1219
1220         id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __connection_idle_cb, data,
1221                         __connection_idle_destroy_cb);
1222         if (!id) {
1223                 g_free(data);
1224                 return id;
1225         }
1226
1227         data->id = id;
1228
1229         managed_idler_list = g_slist_append(managed_idler_list, data);
1230
1231         return id;
1232 }
1233
1234 void _connection_callback_cleanup(void)
1235 {
1236         GSList *cur = managed_idler_list;
1237         GSource *src;
1238         struct managed_idle_data *data;
1239
1240         while (cur) {
1241                 GSList *next = cur->next;
1242                 data = (struct managed_idle_data *)cur->data;
1243
1244                 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
1245                 if (src) {
1246                         g_source_destroy(src);
1247                         cur = managed_idler_list;
1248                 } else
1249                         cur = next;
1250         }
1251
1252         g_slist_free(managed_idler_list);
1253         managed_idler_list = NULL;
1254 }
1255
1256 int _connection_libnet_check_get_privilege()
1257 {
1258         int rv;
1259
1260         rv = net_check_get_privilege();
1261         if (rv == NET_ERR_ACCESS_DENIED) {
1262                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1263                 return CONNECTION_ERROR_PERMISSION_DENIED;
1264         } else if (rv != NET_ERR_NONE)
1265                 return CONNECTION_ERROR_OPERATION_FAILED;
1266
1267         return CONNECTION_ERROR_NONE;
1268 }
1269
1270 int _connection_libnet_check_profile_privilege()
1271 {
1272         int rv;
1273
1274         rv = net_check_profile_privilege();
1275         if (rv == NET_ERR_ACCESS_DENIED) {
1276                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1277                 return CONNECTION_ERROR_PERMISSION_DENIED;
1278         } else if (rv != NET_ERR_NONE)
1279                 return CONNECTION_ERROR_OPERATION_FAILED;
1280
1281         return CONNECTION_ERROR_NONE;
1282 }
1283
1284 bool _connection_libnet_get_is_check_enable_feature()
1285 {
1286         return is_check_enable_feature;
1287 }
1288
1289 bool _connection_libnet_get_enable_feature_state(enable_feature_type_e feature_type)
1290 {
1291         if(is_check_enable_feature){
1292                 switch(feature_type) {
1293                 case FEATURE_TYPE_TELEPHONY:
1294                         return enable_feature.telephony;
1295                 case FEATURE_TYPE_WIFI:
1296                         return enable_feature.wifi;
1297                 case FEATURE_TYPE_TETHERING_BLUETOOTH:
1298                         return enable_feature.tethering_bluetooth;
1299                 default:
1300                         CONNECTION_LOG(CONNECTION_ERROR, "Invalid feature type");
1301                         return false;
1302                 }
1303         }
1304         CONNECTION_LOG(CONNECTION_ERROR, "Not checked enable feature yet");
1305         return false;
1306 }