Merge "Added APIs get the tcp dump and network state" into tizen
[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 <glib.h>
18 #include <stdio.h>
19 #include <stdarg.h>
20 #include <string.h>
21 #include <vconf/vconf.h>
22 #include <system_info.h>
23 #include <arpa/inet.h>
24
25 #include "net_connection_private.h"
26
27 static __thread GSList *prof_handle_list = NULL;
28 static __thread GHashTable *profile_cb_table = NULL;
29
30 struct _profile_cb_s {
31         connection_profile_state_changed_cb callback;
32         connection_profile_state_e state;
33         void *user_data;
34 };
35
36 struct _profile_list_s {
37         int count;
38         int next;
39         net_profile_info_t *profiles;
40 };
41
42 struct _libnet_s {
43         connection_opened_cb opened_cb;
44         connection_closed_cb closed_cb;
45         connection_set_default_cb set_default_cb;
46         connection_reset_cb reset_profile_cb;
47         libnet_ethernet_cable_state_changed_cb ethernet_cable_state_changed_cb;
48         void *opened_user_data;
49         void *closed_user_data;
50         void *set_default_user_data;
51         void *reset_profile_user_data;
52         bool is_created;
53 };
54
55 struct _state_notify {
56         connection_profile_state_changed_cb callback;
57         connection_profile_state_e state;
58         void *user_data;
59 };
60
61 struct managed_idle_data {
62         GSourceFunc func;
63         gpointer user_data;
64         guint id;
65 };
66
67 static __thread struct _profile_list_s profile_iterator = {0, 0, NULL};
68 static __thread struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL,
69                                         NULL, NULL, NULL, NULL, false};
70 static __thread GSList *managed_idler_list = NULL;
71 static __thread bool connection_is_feature_checked[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
72 static __thread bool connection_feature_supported[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
73
74 bool _connection_is_created(void)
75 {
76         return libnet.is_created;
77 }
78
79 static void __connection_set_created(bool tag)
80 {
81         libnet.is_created = tag;
82 }
83
84 //LCOV_EXCL_START
85 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
86 {
87         switch (err_type) {
88         case NET_ERR_NONE:
89                 return CONNECTION_ERROR_NONE;
90         case NET_ERR_APP_ALREADY_REGISTERED:
91                 return CONNECTION_ERROR_INVALID_OPERATION;
92         case NET_ERR_APP_NOT_REGISTERED:
93                 return CONNECTION_ERROR_INVALID_OPERATION;
94         case NET_ERR_NO_ACTIVE_CONNECTIONS:
95                 return CONNECTION_ERROR_NO_CONNECTION;
96         case NET_ERR_ACTIVE_CONNECTION_EXISTS:
97                 return CONNECTION_ERROR_ALREADY_EXISTS;
98         case NET_ERR_CONNECTION_DHCP_FAILED:
99                 return CONNECTION_ERROR_DHCP_FAILED;
100         case NET_ERR_CONNECTION_INVALID_KEY:
101                 return CONNECTION_ERROR_INVALID_KEY;
102         case NET_ERR_IN_PROGRESS:
103                 return CONNECTION_ERROR_NOW_IN_PROGRESS;
104         case NET_ERR_OPERATION_ABORTED:
105                 return CONNECTION_ERROR_OPERATION_ABORTED;
106         case NET_ERR_TIME_OUT:
107                 return CONNECTION_ERROR_NO_REPLY;
108         case NET_ERR_ACCESS_DENIED:
109                 return CONNECTION_ERROR_PERMISSION_DENIED;
110         default:
111                 return CONNECTION_ERROR_OPERATION_FAILED;
112         }
113 }
114
115 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
116 {
117         switch (err_type) {
118         case CONNECTION_ERROR_NONE:
119                 return "NONE";
120         case CONNECTION_ERROR_INVALID_PARAMETER:
121                 return "INVALID_PARAMETER";
122         case CONNECTION_ERROR_OUT_OF_MEMORY:
123                 return "OUT_OF_MEMORY";
124         case CONNECTION_ERROR_INVALID_OPERATION:
125                 return "INVALID_OPERATION";
126         case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
127                 return "ADDRESS_FAMILY_NOT_SUPPORTED";
128         case CONNECTION_ERROR_OPERATION_FAILED:
129                 return "OPERATION_FAILED";
130         case CONNECTION_ERROR_ITERATOR_END:
131                 return "ITERATOR_END";
132         case CONNECTION_ERROR_NO_CONNECTION:
133                 return "NO_CONNECTION";
134         case CONNECTION_ERROR_NOW_IN_PROGRESS:
135                 return "NOW_IN_PROGRESS";
136         case CONNECTION_ERROR_ALREADY_EXISTS:
137                 return "ALREADY_EXISTS";
138         case CONNECTION_ERROR_OPERATION_ABORTED:
139                 return "OPERATION_ABORTED";
140         case CONNECTION_ERROR_DHCP_FAILED:
141                 return "DHCP_FAILED";
142         case CONNECTION_ERROR_INVALID_KEY:
143                 return "INVALID_KEY";
144         case CONNECTION_ERROR_NO_REPLY:
145                 return "NO_REPLY";
146         case CONNECTION_ERROR_PERMISSION_DENIED:
147                 return "PERMISSION_DENIED";
148         case CONNECTION_ERROR_NOT_SUPPORTED:
149                 return "NOT_SUPPORTED";
150         }
151
152         return "UNKNOWN";
153 }
154
155 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
156 {
157         switch (state) {
158         case CONNECTION_PROFILE_STATE_DISCONNECTED:
159                 return "DISCONNECTED";
160         case CONNECTION_PROFILE_STATE_ASSOCIATION:
161                 return "ASSOCIATION";
162         case CONNECTION_PROFILE_STATE_CONFIGURATION:
163                 return "CONFIGURATION";
164         case CONNECTION_PROFILE_STATE_CONNECTED:
165                 return "CONNECTED";
166         default:
167                 return "UNKNOWN";
168         }
169 }
170
171 static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *user_data)
172 {
173         if (user_cb != NULL) {
174                 libnet.reset_profile_cb = user_cb;
175                 libnet.reset_profile_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_set_opened_cb(connection_opened_cb user_cb, void *user_data)
205 {
206         if (user_cb != NULL) {
207                 libnet.opened_cb = user_cb;
208                 libnet.opened_user_data = user_data;
209         }
210 }
211
212 static gboolean __libnet_opened_cb_idle(gpointer data)
213 {
214         connection_error_e result = (connection_error_e)data;
215
216         if (libnet.opened_cb != NULL)
217                 libnet.opened_cb(result, libnet.opened_user_data);
218
219         libnet.opened_cb = NULL;
220         libnet.opened_user_data = NULL;
221
222         return FALSE;
223 }
224
225 static void __libnet_opened_cb(connection_error_e result)
226 {
227         if (_connection_is_created() != true) {
228                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
229                                 "If multi-threaded, thread integrity be broken.");
230                 return;
231         }
232
233         if (libnet.opened_cb != NULL)
234                 _connection_callback_add(__libnet_opened_cb_idle, (gpointer)result);
235 }
236
237 static void __libnet_set_closed_cb(connection_closed_cb user_cb, void *user_data)
238 {
239         if (user_cb != NULL) {
240                 libnet.closed_cb = user_cb;
241                 libnet.closed_user_data = user_data;
242         }
243 }
244
245 static gboolean __libnet_closed_cb_idle(gpointer data)
246 {
247         connection_error_e result = (connection_error_e)data;
248
249         if (libnet.closed_cb != NULL)
250                 libnet.closed_cb(result, libnet.closed_user_data);
251
252         libnet.closed_cb = NULL;
253         libnet.closed_user_data = NULL;
254
255         return FALSE;
256 }
257
258 static void __libnet_closed_cb(connection_error_e result)
259 {
260         if (_connection_is_created() != true) {
261                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
262                                 "If multi-threaded, thread integrity be broken.");
263                 return;
264         }
265
266         if (libnet.closed_cb != NULL)
267                 _connection_callback_add(__libnet_closed_cb_idle, (gpointer)result);
268 }
269
270 static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
271 {
272         if (user_cb != NULL) {
273                 libnet.set_default_cb = user_cb;
274                 libnet.set_default_user_data = user_data;
275         }
276 }
277
278 static gboolean __libnet_default_cb_idle(gpointer data)
279 {
280         connection_error_e result = (connection_error_e)data;
281
282         if (libnet.set_default_cb != NULL)
283                 libnet.set_default_cb(result, libnet.set_default_user_data);
284
285         libnet.set_default_cb = NULL;
286         libnet.set_default_user_data = NULL;
287
288         return FALSE;
289 }
290
291 static void __libnet_default_cb(connection_error_e result)
292 {
293         if (_connection_is_created() != true) {
294                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
295                                 "If multi-threaded, thread integrity be broken.");
296                 return;
297         }
298
299         if (libnet.set_default_cb != NULL)
300                 _connection_callback_add(__libnet_default_cb_idle, (gpointer)result);
301 }
302
303 static void __libnet_set_ethernet_cable_state_changed_cb(
304                 libnet_ethernet_cable_state_changed_cb user_cb)
305 {
306         libnet.ethernet_cable_state_changed_cb = user_cb;
307 }
308
309 static void __libnet_ethernet_cable_state_changed_cb(
310                 connection_ethernet_cable_state_e state)
311 {
312         if (libnet.ethernet_cable_state_changed_cb)
313                 libnet.ethernet_cable_state_changed_cb(state);
314 }
315
316 static gboolean __libnet_state_changed_cb_idle(gpointer data)
317 {
318         struct _state_notify *notify = (struct _state_notify *)data;
319
320         if (notify == NULL)
321                 return FALSE;
322
323         if (notify->callback != NULL)
324                 notify->callback(notify->state, notify->user_data);
325
326         g_free(notify);
327
328         return FALSE;
329 }
330
331 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
332 {
333         guint id;
334         struct _state_notify *notify;
335         struct _profile_cb_s *cb_info;
336
337         if (_connection_is_created() != true) {
338                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
339                                 "If multi-threaded, thread integrity be broken.");
340                 return;
341         }
342
343         if (profile_name == NULL)
344                 return;
345
346         cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
347         if (cb_info == NULL)
348                 return;
349
350         if (cb_info->state == state)
351                 return;
352
353         cb_info->state = state;
354
355         if (state < 0 || cb_info->callback == NULL)
356                 return;
357
358         notify = g_try_new0(struct _state_notify, 1);
359         if (notify == NULL)
360                 return;
361
362         notify->callback = cb_info->callback;
363         notify->state = state;
364         notify->user_data = cb_info->user_data;
365
366         id = _connection_callback_add(__libnet_state_changed_cb_idle,
367                         (gpointer)notify);
368         if (!id)
369                 g_free(notify);
370 }
371
372 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
373 {
374         if (profile_list->count > 0)
375                 g_free(profile_list->profiles);
376
377         profile_list->count = 0;
378         profile_list->next = 0;
379         profile_list->profiles = NULL;
380 }
381
382 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
383 {
384         bool is_requested = false;
385         connection_error_e result = CONNECTION_ERROR_NONE;
386
387         switch (event_cb->Event) {
388         case NET_EVENT_OPEN_RSP:
389                 is_requested = true;
390                 /* fall through */
391         case NET_EVENT_OPEN_IND:
392                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
393                 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
394                                         (is_requested) ? "RSP" : "IND",
395                                         __libnet_convert_cp_error_type_to_string(result));
396
397                 if (is_requested)
398                         __libnet_opened_cb(result);
399
400                 switch (event_cb->Error) {
401                 case NET_ERR_NONE:
402                 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
403                         CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
404
405                         __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
406                         return;
407                 default:
408                         CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
409                                                 __libnet_convert_cp_error_type_to_string(result));
410                 }
411
412                 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
413
414                 break;
415         case NET_EVENT_CLOSE_RSP:
416                 is_requested = true;
417                 /* fall through */
418         case NET_EVENT_CLOSE_IND:
419                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
420                 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
421                                         (is_requested) ? "RSP" : "IND",
422                                         __libnet_convert_cp_error_type_to_string(result));
423
424                 if (is_requested)
425                         __libnet_closed_cb(result);
426
427                 switch (event_cb->Error) {
428                 case NET_ERR_NONE:
429                         CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
430
431                         __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
432                         return;
433                 default:
434                         CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
435                                                         __libnet_convert_cp_error_type_to_string(result));
436                 }
437
438                 break;
439         case NET_EVENT_NET_STATE_IND:
440                 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
441
442                 if (event_cb->Datalength != sizeof(net_state_type_t))
443                         return;
444
445                 net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
446                 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
447
448                 CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
449                 SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->ProfileName);
450
451                 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
452
453                 break;
454         case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
455                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
456                 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
457                 __libnet_default_cb(result);
458                 break;
459
460         case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
461                 result = __libnet_convert_to_cp_error_type(event_cb->Error);
462                 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
463                 __libnet_reset_profile_cb(result);
464                 break;
465         case NET_EVENT_ETHERNET_CABLE_ATTACHED:
466                 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
467                 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_ATTACHED);
468                 break;
469         case NET_EVENT_ETHERNET_CABLE_DETACHED:
470                 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
471                 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_DETACHED);
472                 break;
473
474         default:
475                 break;
476         }
477 }
478 //LCOV_EXCL_STOP
479
480 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
481 {
482         int count = 0;
483         int i = 0;
484
485         for (; i < profile_list->count; i++) {
486                 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
487                     profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
488                         count++;
489         }
490
491         return count;
492 }
493
494 void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
495 {
496         int i = 0;
497
498         for (; i < source->count; i++) {
499                 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
500                     source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
501                         memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
502                         (*dest)++;
503                 }
504         }
505 }
506
507 //LCOV_EXCL_START
508 int __libnet_get_default_count(struct _profile_list_s *profile_list)
509 {
510         int count = 0;
511         int i = 0;
512
513         for (; i < profile_list->count; i++) {
514                 if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
515                         count++;
516         }
517
518         return count;
519 }
520
521 void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
522 {
523         int i = 0;
524
525         for (; i < source->count; i++) {
526                 if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
527                         memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
528                         (*dest)++;
529                 }
530         }
531 }
532 //LCOV_EXCL_STOP
533
534 int _connection_libnet_init(void)
535 {
536         int rv;
537
538         if (_connection_is_created() != true) {
539                 rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL);
540                 if (rv != NET_ERR_NONE)
541                         return rv;
542
543                 __connection_set_created(true);
544
545                 if (profile_cb_table == NULL)
546                         profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
547         }
548
549         return NET_ERR_NONE;
550 }
551
552 bool _connection_libnet_deinit(void)
553 {
554         if (_connection_is_created() == true) {
555                 if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE)
556                         return false;
557
558                 __connection_set_created(false);
559
560                 if (profile_cb_table) {
561                         g_hash_table_destroy(profile_cb_table);
562                         profile_cb_table = NULL;
563                 }
564
565                 __libnet_clear_profile_list(&profile_iterator);
566
567                 if (prof_handle_list) {
568                         g_slist_free_full(prof_handle_list, g_free);
569                         prof_handle_list = NULL;
570                 }
571         }
572
573         return true;
574 }
575
576 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
577 {
578         GSList *list;
579         int i = 0;
580
581         if (profile == NULL)
582                 return false;
583
584         for (list = prof_handle_list; list; list = list->next)
585                 if (profile == list->data) return true;
586
587         for (; i < profile_iterator.count; i++)
588                 if (profile == &profile_iterator.profiles[i]) return true;
589
590         return false;
591 }
592
593 //LCOV_EXCL_START
594 bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
595 {
596         struct _profile_cb_s *cb_info;
597         net_profile_info_t *profile_info = profile;
598
599         if (profile == NULL)
600                 return false;
601
602         cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName);
603         if (cb_info != NULL)
604                 return true;
605
606         return false;
607 }
608 //LCOV_EXCL_STOP
609
610 int _connection_libnet_get_metered_state(bool* is_metered)
611 {
612         int rv = 0;
613         int status = 0;
614
615         rv = net_get_metered_state(&status);
616         if (rv == NET_ERR_ACCESS_DENIED) {
617                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
618                 return CONNECTION_ERROR_PERMISSION_DENIED;
619         } else if (rv != NET_ERR_NONE) {
620                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get metered state[%d]", rv);
621                 return CONNECTION_ERROR_OPERATION_FAILED;
622         }
623
624         if (status == 1)
625                 *is_metered = true;
626         else
627                 *is_metered = false;
628         return CONNECTION_ERROR_NONE;
629 }
630
631 int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
632 {
633         int rv;
634         net_wifi_state_t wlan_state;
635
636         rv = net_get_wifi_state(&wlan_state);
637         if (rv == NET_ERR_ACCESS_DENIED) {
638                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
639                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
640         } else if (rv != NET_ERR_NONE) {
641                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
642                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
643         }
644
645         switch (wlan_state) {
646         case WIFI_OFF:
647                 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
648                 break;
649         case WIFI_ON:
650         case WIFI_ASSOCIATION:
651         case WIFI_CONFIGURATION:
652                 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
653                 break;
654         case WIFI_CONNECTED:
655         case WIFI_DISCONNECTING:
656                 *state = CONNECTION_WIFI_STATE_CONNECTED;
657                 break;
658         default:
659                 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state"); //LCOV_EXCL_LINE
660                 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
661         }
662
663         return CONNECTION_ERROR_NONE;
664 }
665
666 //LCOV_EXCL_START
667 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e *state)
668 {
669         int rv;
670         struct _profile_list_s ethernet_profiles = {0, 0, NULL};
671         rv = net_get_profile_list(NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
672         if (rv == NET_ERR_ACCESS_DENIED) {
673                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
674                 return CONNECTION_ERROR_PERMISSION_DENIED;
675         }
676
677         if (ethernet_profiles.count == 0) {
678                 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
679                 return CONNECTION_ERROR_NONE;
680         }
681
682         switch (ethernet_profiles.profiles->ProfileState) {
683         case NET_STATE_TYPE_ONLINE:
684         case NET_STATE_TYPE_READY:
685                 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
686                 break;
687         case NET_STATE_TYPE_IDLE:
688         case NET_STATE_TYPE_FAILURE:
689         case NET_STATE_TYPE_ASSOCIATION:
690         case NET_STATE_TYPE_CONFIGURATION:
691         case NET_STATE_TYPE_DISCONNECT:
692                 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
693                 break;
694         default:
695                 __libnet_clear_profile_list(&ethernet_profiles);
696                 return CONNECTION_ERROR_OPERATION_FAILED;
697         }
698
699         __libnet_clear_profile_list(&ethernet_profiles);
700
701         return CONNECTION_ERROR_NONE;
702 }
703
704 int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
705 {
706         int rv = 0;
707         int status = 0;
708
709         rv = net_get_ethernet_cable_state(&status);
710         if (rv == NET_ERR_ACCESS_DENIED) {
711                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
712                 return CONNECTION_ERROR_PERMISSION_DENIED;
713         } else if (rv != NET_ERR_NONE) {
714                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
715                 return CONNECTION_ERROR_OPERATION_FAILED;
716         }
717
718         if (status == 1)
719                 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
720         else
721                 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
722         return CONNECTION_ERROR_NONE;
723 }
724
725 int _connection_libnet_set_ethernet_cable_state_changed_cb(
726                 libnet_ethernet_cable_state_changed_cb callback)
727 {
728         __libnet_set_ethernet_cable_state_changed_cb(callback);
729
730         return CONNECTION_ERROR_NONE;
731 }
732 //LCOV_EXCL_STOP
733
734 int _connection_libnet_get_bluetooth_state(connection_bt_state_e *state)
735 {
736         int i = 0;
737         int rv = 0;
738         struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
739         rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
740         if (rv == NET_ERR_ACCESS_DENIED) {
741                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
742                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
743         }
744
745         if (bluetooth_profiles.count == 0) {
746                 *state = CONNECTION_BT_STATE_DEACTIVATED;
747                 return CONNECTION_ERROR_NONE;
748         }
749
750         //LCOV_EXCL_START
751         for (; i < bluetooth_profiles.count; i++) {
752                 switch (bluetooth_profiles.profiles[i].ProfileState) {
753                 case NET_STATE_TYPE_ONLINE:
754                 case NET_STATE_TYPE_READY:
755                         *state = CONNECTION_BT_STATE_CONNECTED;
756                         goto done;
757                 case NET_STATE_TYPE_IDLE:
758                 case NET_STATE_TYPE_FAILURE:
759                 case NET_STATE_TYPE_ASSOCIATION:
760                 case NET_STATE_TYPE_CONFIGURATION:
761                 case NET_STATE_TYPE_DISCONNECT:
762                         *state = CONNECTION_BT_STATE_DISCONNECTED;
763                         break;
764                 default:
765                         __libnet_clear_profile_list(&bluetooth_profiles);
766                         return CONNECTION_ERROR_OPERATION_FAILED;
767                 }
768         }
769         //LCOV_EXCL_STOP
770
771 done:
772         __libnet_clear_profile_list(&bluetooth_profiles);
773
774         return CONNECTION_ERROR_NONE;
775 }
776
777 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
778 {
779         int count = 0;
780         int rv1, rv2, rv3, rv4;
781         net_profile_info_t *profiles = NULL;
782
783         struct _profile_list_s wifi_profiles = {0, 0, NULL};
784         struct _profile_list_s cellular_profiles = {0, 0, NULL};
785         struct _profile_list_s ethernet_profiles = {0, 0, NULL};
786         struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
787
788         __libnet_clear_profile_list(&profile_iterator);
789
790         rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
791         if (rv1 == NET_ERR_ACCESS_DENIED) {
792                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
793                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
794         } else if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
795                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
796
797         CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi profile count: %d", wifi_profiles.count);
798
799         rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
800         if (rv2 == NET_ERR_ACCESS_DENIED) {
801                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
802                 __libnet_clear_profile_list(&wifi_profiles);
803                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
804         } else if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
805                 __libnet_clear_profile_list(&wifi_profiles);
806                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
807         }
808         CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count: %d", cellular_profiles.count);
809
810         rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
811         if (rv3 == NET_ERR_ACCESS_DENIED) {
812                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
813                 __libnet_clear_profile_list(&wifi_profiles);
814                 __libnet_clear_profile_list(&cellular_profiles);
815                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
816         } else if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
817                 __libnet_clear_profile_list(&wifi_profiles);
818                 __libnet_clear_profile_list(&cellular_profiles);
819                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
820         }
821         CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d", ethernet_profiles.count);
822
823         rv4 = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
824         if (rv4 == NET_ERR_ACCESS_DENIED) {
825                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
826                 __libnet_clear_profile_list(&wifi_profiles);
827                 __libnet_clear_profile_list(&cellular_profiles);
828                 __libnet_clear_profile_list(&ethernet_profiles);
829                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
830         } else if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
831                 __libnet_clear_profile_list(&wifi_profiles);
832                 __libnet_clear_profile_list(&cellular_profiles);
833                 __libnet_clear_profile_list(&ethernet_profiles);
834                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
835         }
836         CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
837
838         *profile_iter_h = &profile_iterator;
839
840         switch (type) {
841         case CONNECTION_ITERATOR_TYPE_REGISTERED:
842                 count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count;
843                 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
844                 if (count == 0)
845                         return CONNECTION_ERROR_NONE;
846
847                 profiles = g_try_new0(net_profile_info_t, count);
848                 if (profiles == NULL) {
849                         __libnet_clear_profile_list(&wifi_profiles);
850                         __libnet_clear_profile_list(&cellular_profiles);
851                         __libnet_clear_profile_list(&ethernet_profiles);
852                         __libnet_clear_profile_list(&bluetooth_profiles);
853                         return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
854                 }
855
856                 profile_iterator.profiles = profiles;
857
858                 if (wifi_profiles.count > 0) {
859                         memcpy(profiles, wifi_profiles.profiles,
860                                         sizeof(net_profile_info_t) * wifi_profiles.count);
861                         profiles += wifi_profiles.count;
862                 }
863
864                 if (cellular_profiles.count > 0) {
865                         memcpy(profiles, cellular_profiles.profiles,
866                                         sizeof(net_profile_info_t) * cellular_profiles.count);
867                         profiles += cellular_profiles.count;
868                 }
869
870                 if (ethernet_profiles.count > 0) {
871                         memcpy(profiles, ethernet_profiles.profiles,
872                                         sizeof(net_profile_info_t) * ethernet_profiles.count);
873                         profiles += ethernet_profiles.count;
874                 }
875
876                 if (bluetooth_profiles.count > 0)
877                         memcpy(profiles, bluetooth_profiles.profiles,
878                                         sizeof(net_profile_info_t) * bluetooth_profiles.count);
879
880                 break;
881         case CONNECTION_ITERATOR_TYPE_CONNECTED:
882                 count = __libnet_get_connected_count(&wifi_profiles);
883                 count += __libnet_get_connected_count(&cellular_profiles);
884                 count += __libnet_get_connected_count(&ethernet_profiles);
885                 count += __libnet_get_connected_count(&bluetooth_profiles);
886                 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
887                 if (count == 0)
888                         return CONNECTION_ERROR_NONE;
889
890                 profiles = g_try_new0(net_profile_info_t, count);
891                 if (profiles == NULL) {
892                         __libnet_clear_profile_list(&wifi_profiles);
893                         __libnet_clear_profile_list(&cellular_profiles);
894                         __libnet_clear_profile_list(&ethernet_profiles);
895                         __libnet_clear_profile_list(&bluetooth_profiles);
896                         return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
897                 }
898
899                 profile_iterator.profiles = profiles;
900
901                 if (wifi_profiles.count > 0)
902                         __libnet_copy_connected_profile(&profiles, &wifi_profiles);
903
904                 if (cellular_profiles.count > 0)
905                         __libnet_copy_connected_profile(&profiles, &cellular_profiles);
906
907                 if (ethernet_profiles.count > 0)
908                         __libnet_copy_connected_profile(&profiles, &ethernet_profiles);
909
910                 if (bluetooth_profiles.count > 0)
911                         __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
912
913                 break;
914         case CONNECTION_ITERATOR_TYPE_DEFAULT:
915                 count = __libnet_get_default_count(&cellular_profiles);
916                 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count); //LCOV_EXCL_LINE
917                 if (count == 0)
918                         return CONNECTION_ERROR_NONE;
919
920                 profiles = g_try_new0(net_profile_info_t, count);
921                 if (profiles == NULL) {
922                         __libnet_clear_profile_list(&wifi_profiles);
923                         __libnet_clear_profile_list(&cellular_profiles);
924                         __libnet_clear_profile_list(&ethernet_profiles);
925                         __libnet_clear_profile_list(&bluetooth_profiles);
926                         return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
927                 }
928
929                 profile_iterator.profiles = profiles;
930
931                 if (cellular_profiles.count > 0)
932                         __libnet_copy_default_profile(&profiles, &cellular_profiles);
933                 break;
934         }
935
936         __libnet_clear_profile_list(&wifi_profiles);
937         __libnet_clear_profile_list(&cellular_profiles);
938         __libnet_clear_profile_list(&ethernet_profiles);
939         __libnet_clear_profile_list(&bluetooth_profiles);
940
941         profile_iterator.count = count;
942
943         return CONNECTION_ERROR_NONE;
944 }
945
946 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
947 {
948         if (profile_iter_h != &profile_iterator)
949                 return CONNECTION_ERROR_INVALID_PARAMETER;
950
951         if (profile_iterator.count <= profile_iterator.next)
952                 return CONNECTION_ERROR_ITERATOR_END;
953
954         *profile = &profile_iterator.profiles[profile_iterator.next];
955         profile_iterator.next++;
956
957         return CONNECTION_ERROR_NONE;
958 }
959
960 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
961 {
962         if (profile_iter_h != &profile_iterator)
963                 return false;
964
965         if (profile_iterator.count <= profile_iterator.next)
966                 return false;
967
968         return true;
969 }
970
971 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
972 {
973         if (profile_iter_h != &profile_iterator)
974                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
975
976         __libnet_clear_profile_list(&profile_iterator);
977
978         return CONNECTION_ERROR_NONE;
979 }
980
981 int _connection_libnet_get_current_profile(connection_profile_h *profile)
982 {
983         net_profile_info_t active_profile;
984         int rv;
985
986         rv = net_get_active_net_info(&active_profile);
987         if (rv == NET_ERR_NO_SERVICE)
988                 return CONNECTION_ERROR_NO_CONNECTION; //LCOV_EXCL_LINE
989         else if (rv == NET_ERR_ACCESS_DENIED) {
990                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
991                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
992         } else if (rv != NET_ERR_NONE)
993                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
994
995         *profile = g_try_malloc0(sizeof(net_profile_info_t));
996         if (*profile == NULL)
997                 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
998
999         memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
1000         prof_handle_list = g_slist_append(prof_handle_list, *profile);
1001
1002         return CONNECTION_ERROR_NONE;
1003 }
1004
1005 int _connection_libnet_reset_profile(connection_reset_option_e type,
1006                 connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
1007 {
1008         int rv;
1009
1010         rv = net_reset_profile(type, id);
1011         if (rv == NET_ERR_ACCESS_DENIED) {
1012                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1013                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1014         } else if (rv != NET_ERR_NONE) {
1015                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
1016                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1017         }
1018
1019         __libnet_set_reset_profile_cb(callback, user_data);
1020
1021         return CONNECTION_ERROR_NONE;
1022 }
1023
1024 int _connection_libnet_open_profile(connection_profile_h profile,
1025                 connection_opened_cb callback, void* user_data)
1026 {
1027         int rv;
1028
1029         if (!(_connection_libnet_check_profile_validity(profile))) {
1030                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1031                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1032         }
1033
1034         net_profile_info_t *profile_info = profile;
1035
1036         rv = net_open_connection_with_profile(profile_info->ProfileName);
1037         if (rv == NET_ERR_ACCESS_DENIED) {
1038                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1039                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1040         } else if (rv != NET_ERR_NONE)
1041                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1042
1043         __libnet_set_opened_cb(callback, user_data);
1044
1045         return CONNECTION_ERROR_NONE;
1046 }
1047
1048 int _connection_libnet_get_cellular_service_profile(
1049                 connection_cellular_service_type_e type, connection_profile_h *profile)
1050 {
1051         int i = 0, j = 0;
1052         int rv = NET_ERR_NONE;
1053 #if defined TIZEN_DUALSIM_ENABLE
1054         int default_subscriber_id = 0;
1055         char subscriber_id[3];
1056 #endif
1057
1058         struct _profile_list_s cellular_profiles = { 0, 0, NULL };
1059         net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
1060
1061         rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
1062         if (rv == NET_ERR_ACCESS_DENIED) {
1063                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1064                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1065         } else if (rv != NET_ERR_NONE) {
1066                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv); //LCOV_EXCL_LINE
1067                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1068         }
1069
1070 #if defined TIZEN_DUALSIM_ENABLE
1071         if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
1072                                                 &default_subscriber_id) != 0) {
1073                 CONNECTION_LOG(CONNECTION_ERROR,
1074                                                 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
1075                 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
1076                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1077         }
1078
1079         g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
1080 #endif
1081
1082         for (i = 0; i < cellular_profiles.count; i++)
1083                 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
1084 #if defined TIZEN_DUALSIM_ENABLE
1085                         if (g_str_has_suffix(
1086                                         cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
1087                                         subscriber_id) == TRUE)
1088 #endif
1089                                 break;
1090
1091         if (i >= cellular_profiles.count) {
1092                 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
1093                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1094         }
1095
1096         *profile = g_try_malloc0(sizeof(net_profile_info_t));
1097         if (*profile == NULL) {
1098                 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
1099                 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1100         }
1101
1102         memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
1103
1104         if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
1105                 goto done;
1106
1107         //LCOV_EXCL_START
1108         if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
1109             type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
1110                 goto done;
1111
1112         for (j = 0; j < cellular_profiles.count; j++) {
1113                 if (i == j)
1114                         continue;
1115
1116                 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
1117                         continue;
1118
1119                 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
1120                         memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
1121                         goto done;
1122                 }
1123         }
1124         //LCOV_EXCL_STOP
1125
1126 done:
1127         __libnet_clear_profile_list(&cellular_profiles);
1128         prof_handle_list = g_slist_append(prof_handle_list, *profile);
1129
1130         return CONNECTION_ERROR_NONE;
1131 }
1132
1133 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
1134 {
1135         int rv;
1136
1137         if (!(_connection_libnet_check_profile_validity(profile))) {
1138                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1139                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1140         }
1141
1142         net_profile_info_t *profile_info = profile;
1143         connection_cellular_service_type_e service_type;
1144
1145         service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1146
1147         if (service_type != type)
1148                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1149
1150         rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
1151         if (rv == NET_ERR_ACCESS_DENIED) {
1152                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1153                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1154         } else if (rv != NET_ERR_NONE)
1155                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1156
1157         return CONNECTION_ERROR_NONE;
1158 }
1159
1160 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
1161                         connection_profile_h profile, connection_set_default_cb callback, void* user_data)
1162 {
1163         int rv;
1164
1165         if (!(_connection_libnet_check_profile_validity(profile))) {
1166                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1167                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1168         }
1169
1170         net_profile_info_t *profile_info = profile;
1171         connection_cellular_service_type_e service_type;
1172
1173         service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1174
1175         if (service_type != type)
1176                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1177
1178         rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
1179         if (rv == NET_ERR_ACCESS_DENIED) {
1180                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1181                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1182         } else if (rv != NET_ERR_NONE)
1183                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1184
1185         __libnet_set_default_cb(callback, user_data);
1186
1187         return CONNECTION_ERROR_NONE;
1188 }
1189
1190 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
1191 {
1192         int rv;
1193
1194         if (!(_connection_libnet_check_profile_validity(profile))) {
1195                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1196                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1197         }
1198
1199         net_profile_info_t *profile_info = profile;
1200
1201         rv = net_close_connection(profile_info->ProfileName);
1202         if (rv == NET_ERR_ACCESS_DENIED) {
1203                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1204                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1205         } else if (rv != NET_ERR_NONE)
1206                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1207
1208         __libnet_set_closed_cb(callback, user_data);
1209
1210         return CONNECTION_ERROR_NONE;
1211 }
1212
1213 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
1214 {
1215         int rv;
1216         char *endstr = NULL;
1217         int address_family = 0;
1218
1219         address_family = AF_INET;
1220
1221         endstr = strrchr(host_address, '.');
1222         if (endstr == NULL ||
1223                         strcmp(endstr, ".0") == 0 ||
1224                         strncmp(host_address, "0.", 2) == 0 ||
1225                         strstr(host_address, "255") != NULL) {
1226                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1227                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1228         }
1229
1230         rv = net_add_route(host_address, interface_name, address_family);
1231         if (rv == NET_ERR_ACCESS_DENIED) {
1232                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1233                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1234         } else if (rv != NET_ERR_NONE)
1235                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1236
1237         return CONNECTION_ERROR_NONE;
1238 }
1239
1240 int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
1241 {
1242         int rv;
1243         char *endstr = strrchr(host_address, '.');
1244         int address_family = 0;
1245
1246         address_family = AF_INET;
1247
1248         endstr = strrchr(host_address, '.');
1249         if (endstr == NULL ||
1250                 strcmp(endstr, ".0") == 0 ||
1251                 strncmp(host_address, "0.", 2) == 0 ||
1252                 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1253                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1254                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1255         }
1256
1257         rv = net_remove_route(host_address, interface_name, address_family);
1258         if (rv == NET_ERR_ACCESS_DENIED) {
1259                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1260                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1261         } else if (rv != NET_ERR_NONE)
1262                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1263
1264         return CONNECTION_ERROR_NONE;
1265 }
1266
1267 int _connection_libnet_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1268 {
1269         int rv;
1270         int address_family = 0;
1271
1272         address_family = AF_INET6;
1273
1274         if (strncmp(host_address, "fe80:", 5) == 0 ||
1275                 strncmp(host_address, "ff00:", 5) == 0 ||
1276                 strncmp(host_address, "::", 2) == 0) {
1277                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1278                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1279         }
1280
1281         rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
1282         if (rv == NET_ERR_ACCESS_DENIED) {
1283                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1284                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1285         } else if (rv != NET_ERR_NONE)
1286                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1287
1288         return CONNECTION_ERROR_NONE;
1289 }
1290
1291 int _connection_libnet_remove_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1292 {
1293         int rv;
1294         int address_family = 0;
1295
1296         address_family = AF_INET6;
1297
1298         if (strncmp(host_address, "fe80:", 5) == 0 ||
1299                 strncmp(host_address, "ff00:", 5) == 0 ||
1300                 strncmp(host_address, "::", 2) == 0) {
1301                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1302                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1303         }
1304
1305         rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
1306         if (rv == NET_ERR_ACCESS_DENIED) {
1307                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1308                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1309         } else if (rv != NET_ERR_NONE)
1310                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1311
1312         return CONNECTION_ERROR_NONE;
1313 }
1314
1315 int _connection_libnet_add_route_entry(connection_address_family_e address_family,
1316                 const char *interface_name, const char *host_address, const char *gateway)
1317 {
1318         int rv;
1319         char *endstr = NULL;
1320         int address_family_type = 0;
1321
1322         if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1323                 address_family_type = AF_INET;
1324         else
1325                 address_family_type = AF_INET6;
1326
1327         if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1328
1329                 endstr = strrchr(host_address, '.');
1330                 if (endstr == NULL ||
1331                                 strcmp(endstr, ".0") == 0 ||
1332                                 strncmp(host_address, "0.", 2) == 0 ||
1333                                 strstr(host_address, "255") != NULL) {
1334                         CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1335                         return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1336                 }
1337
1338                 rv = net_add_route_entry(host_address, interface_name, address_family_type, gateway);
1339                 if (rv == NET_ERR_ACCESS_DENIED) {
1340                         CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1341                         return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1342                 } else if (rv != NET_ERR_NONE)
1343                         return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1344
1345         } else {
1346
1347                 if (strncmp(host_address, "fe80:", 5) == 0 ||
1348                         strncmp(host_address, "ff00:", 5) == 0 ||
1349                         strncmp(host_address, "::", 2) == 0) {
1350                         CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1351                         return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1352                 }
1353
1354                 rv = net_add_route_ipv6(host_address, interface_name, address_family_type, gateway);
1355                 if (rv == NET_ERR_ACCESS_DENIED) {
1356                         CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1357                         return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1358                 } else if (rv != NET_ERR_NONE)
1359                         return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1360         }
1361
1362         return CONNECTION_ERROR_NONE;
1363 }
1364
1365 int _connection_libnet_remove_route_entry(connection_address_family_e address_family,
1366                 const char *interface_name, const char *host_address, const char *gateway)
1367 {
1368         int rv;
1369         char *endstr = strrchr(host_address, '.');
1370         int address_family_type = 0;
1371
1372         if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1373                 address_family_type = AF_INET;
1374         else
1375                 address_family_type = AF_INET6;
1376
1377         if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1378                 endstr = strrchr(host_address, '.');
1379                 if (endstr == NULL ||
1380                         strcmp(endstr, ".0") == 0 ||
1381                         strncmp(host_address, "0.", 2) == 0 ||
1382                         strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1383                         CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1384                         return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1385                 }
1386
1387                 rv = net_remove_route_entry(host_address, interface_name, address_family_type, gateway);
1388                 if (rv == NET_ERR_ACCESS_DENIED) {
1389                         CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1390                         return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1391                 } else if (rv != NET_ERR_NONE)
1392                         return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1393
1394         } else {
1395
1396                 if (strncmp(host_address, "fe80:", 5) == 0 ||
1397                         strncmp(host_address, "ff00:", 5) == 0 ||
1398                         strncmp(host_address, "::", 2) == 0) {
1399                         CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1400                         return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1401                 }
1402
1403                 rv = net_remove_route_ipv6(host_address, interface_name, address_family_type, gateway);
1404                 if (rv == NET_ERR_ACCESS_DENIED) {
1405                         CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1406                         return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1407                 } else if (rv != NET_ERR_NONE)
1408                         return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1409         }
1410
1411         return CONNECTION_ERROR_NONE;
1412 }
1413
1414 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1415 {
1416         prof_handle_list = g_slist_append(prof_handle_list, profile);
1417 }
1418
1419 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1420 {
1421         prof_handle_list = g_slist_remove(prof_handle_list, profile);
1422         g_free(profile);
1423 }
1424
1425 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1426                 connection_profile_state_changed_cb callback, void *user_data)
1427 {
1428         net_profile_info_t *profile_info = profile;
1429         char *profile_name = g_strdup(profile_info->ProfileName);
1430
1431         struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1432         if (profile_cb_info == NULL) {
1433                 g_free(profile_name); //LCOV_EXCL_LINE
1434                 return false; //LCOV_EXCL_LINE
1435         }
1436
1437         profile_cb_info->callback = callback;
1438         profile_cb_info->user_data = user_data;
1439         profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1440
1441         g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1442
1443         return true;
1444 }
1445
1446 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1447 {
1448         net_profile_info_t *profile_info = profile;
1449
1450         if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1451                 return true;
1452
1453         return false; //LCOV_EXCL_LINE
1454 }
1455
1456 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
1457 {
1458         int rv;
1459         rv = net_set_statistics(device_type, statistics_type);
1460         if (rv == NET_ERR_ACCESS_DENIED) {
1461                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1462                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1463         } else if (rv != NET_ERR_NONE)
1464                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1465
1466         return CONNECTION_ERROR_NONE;
1467 }
1468
1469 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
1470 {
1471         int rv;
1472         rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
1473         if (rv == NET_ERR_ACCESS_DENIED) {
1474                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1475                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1476         } else if (rv != NET_ERR_NONE)
1477                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1478
1479         return CONNECTION_ERROR_NONE;
1480 }
1481
1482 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1483                 connection_cellular_subscriber_id_e sim_id)
1484 {
1485         char *modem_path = NULL;
1486         net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1487
1488         if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1489                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id); //LCOV_EXCL_LINE
1490                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1491         }
1492
1493         if (!modem_path) {
1494                 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path"); //LCOV_EXCL_LINE
1495                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1496         }
1497
1498         g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1499                                 NET_PROFILE_NAME_LEN_MAX);
1500         g_free(modem_path);
1501
1502         return CONNECTION_ERROR_NONE;
1503 }
1504
1505 static void __connection_idle_destroy_cb(gpointer data)
1506 {
1507         if (!data)
1508                 return;
1509
1510         managed_idler_list = g_slist_remove(managed_idler_list, data);
1511         g_free(data);
1512 }
1513
1514 static gboolean __connection_idle_cb(gpointer user_data)
1515 {
1516         struct managed_idle_data *data = (struct managed_idle_data *)user_data;
1517
1518         if (!data)
1519                 return FALSE;
1520
1521         return data->func(data->user_data);
1522 }
1523
1524 guint _connection_callback_add(GSourceFunc func, gpointer user_data)
1525 {
1526         guint id;
1527         struct managed_idle_data *data;
1528         GMainContext *context;
1529         GSource *src;
1530
1531         if (!func)
1532                 return 0;
1533
1534         data = g_try_new0(struct managed_idle_data, 1);
1535         if (!data)
1536                 return 0;
1537
1538         data->func = func;
1539         data->user_data = user_data;
1540
1541         context = g_main_context_get_thread_default();
1542         src = g_idle_source_new();
1543         g_source_set_callback(src, __connection_idle_cb, data,
1544                 __connection_idle_destroy_cb);
1545         id = g_source_attach(src, context);
1546         g_source_unref(src);
1547         if (!id) {
1548                 g_free(data);
1549                 return id;
1550         }
1551
1552         data->id = id;
1553
1554         managed_idler_list = g_slist_append(managed_idler_list, data);
1555
1556         return id;
1557 }
1558
1559 void _connection_callback_cleanup(void)
1560 {
1561         GSList *cur = managed_idler_list;
1562         GSource *src;
1563         struct managed_idle_data *data;
1564
1565         while (cur) {
1566                 //LCOV_EXCL_START
1567                 GSList *next = cur->next;
1568                 data = (struct managed_idle_data *)cur->data;
1569
1570                 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
1571                 if (src) {
1572                         g_source_destroy(src);
1573                         cur = managed_idler_list;
1574                 } else
1575                         cur = next;
1576                 //LCOV_EXCL_STOP
1577         }
1578
1579         g_slist_free(managed_idler_list);
1580         managed_idler_list = NULL;
1581 }
1582
1583 int _connection_libnet_check_get_privilege()
1584 {
1585         int rv;
1586
1587         rv = net_check_get_privilege();
1588         if (rv == NET_ERR_ACCESS_DENIED) {
1589                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1590                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1591         } else if (rv != NET_ERR_NONE)
1592                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1593
1594         return CONNECTION_ERROR_NONE;
1595 }
1596
1597 int _connection_libnet_check_profile_privilege()
1598 {
1599         int rv;
1600
1601         rv = net_check_profile_privilege();
1602         if (rv == NET_ERR_ACCESS_DENIED) {
1603                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1604                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1605         } else if (rv != NET_ERR_NONE)
1606                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1607
1608         return CONNECTION_ERROR_NONE;
1609 }
1610
1611 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1612 {
1613         if (!connection_is_feature_checked[feature]) {
1614                 if (system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1615                         CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); //LCOV_EXCL_LINE
1616                         set_last_result(CONNECTION_ERROR_OPERATION_FAILED); //LCOV_EXCL_LINE
1617                         return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1618                 }
1619                 connection_is_feature_checked[feature] = true;
1620         }
1621         return connection_feature_supported[feature];
1622 }
1623
1624 int _connection_check_feature_supported(const char *feature_name, ...)
1625 {
1626         va_list list;
1627         const char *key;
1628         bool value = false;
1629         bool feature_supported = false;
1630
1631         va_start(list, feature_name);
1632         key = feature_name;
1633         while (1) {
1634                 if (strcmp(key, TELEPHONY_FEATURE) == 0)
1635                         value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1636                 if (strcmp(key, WIFI_FEATURE) == 0)
1637                         value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1638                 if (strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)
1639                         value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1640                 if (strcmp(key, ETHERNET_FEATURE) == 0)
1641                         value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
1642
1643                 feature_supported |= value;
1644                 key = va_arg(list, const char *);
1645                 if (!key) break;
1646         }
1647         if (!feature_supported) {
1648                 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1649                 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1650                 va_end(list);
1651                 return CONNECTION_ERROR_NOT_SUPPORTED;
1652         }
1653
1654         va_end(list);
1655         set_last_result(CONNECTION_ERROR_NONE);
1656         return CONNECTION_ERROR_NONE;
1657 }
1658
1659 int _connection_libnet_start_tcpdump(void)
1660 {
1661         connection_error_e result = CONNECTION_ERROR_NONE;
1662         net_err_t ret = NET_ERR_NONE;
1663
1664         ret = net_start_tcpdump();
1665         result = __libnet_convert_to_cp_error_type(ret);
1666
1667         return result;
1668 }
1669
1670 int _connection_libnet_stop_tcpdump(void)
1671 {
1672         connection_error_e result = CONNECTION_ERROR_NONE;
1673         net_err_t ret = NET_ERR_NONE;
1674
1675         ret = net_stop_tcpdump();
1676         result = __libnet_convert_to_cp_error_type(ret);
1677
1678         return result;
1679 }
1680
1681 int _connection_libnet_get_tcpdump_state(gboolean *tcpdump_state)
1682 {
1683         connection_error_e result = CONNECTION_ERROR_NONE;
1684         net_err_t ret = NET_ERR_NONE;
1685
1686         ret = net_get_tcpdump_state(tcpdump_state);
1687         result = __libnet_convert_to_cp_error_type(ret);
1688
1689         return result;
1690 }