51261f8d0cbb08bb99e62fc30bf7039ea3e1ee71
[platform/core/api/connection.git] / src / connection.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 <stdlib.h>
20 #include <string.h>
21 #include <vconf/vconf.h>
22 #include <system_info.h>
23
24 #include "net_connection_private.h"
25
26 static __thread GSList *conn_handle_list = NULL;
27 static int tv_profile = -1; // Unknown
28
29 //LCOV_EXCL_START
30 static int __connection_convert_net_state(int status)
31 {
32         switch (status) {
33         case VCONFKEY_NETWORK_CELLULAR:
34                 return CONNECTION_TYPE_CELLULAR;
35         case VCONFKEY_NETWORK_WIFI:
36                 return CONNECTION_TYPE_WIFI;
37         case VCONFKEY_NETWORK_ETHERNET:
38                 return CONNECTION_TYPE_ETHERNET;
39         case VCONFKEY_NETWORK_BLUETOOTH:
40                 return CONNECTION_TYPE_BT;
41         case VCONFKEY_NETWORK_DEFAULT_PROXY:
42                 return CONNECTION_TYPE_NET_PROXY;
43         default:
44                 return CONNECTION_TYPE_DISCONNECTED;
45         }
46 }
47
48 static int __connection_convert_cellular_state(int status)
49 {
50         switch (status) {
51         case VCONFKEY_NETWORK_CELLULAR_ON:
52                 return CONNECTION_CELLULAR_STATE_AVAILABLE;
53         case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
54                 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
55         case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
56                 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
57         case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
58                 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
59         default:
60                 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
61         }
62 }
63
64 static bool __connection_check_handle_validity(connection_h connection)
65 {
66         bool ret = false;
67
68         if (connection == NULL)
69                 return false;
70
71         if (g_slist_find(conn_handle_list, connection) != NULL)
72                 ret = true;
73
74         return ret;
75 }
76
77 bool _connection_check_handle_validity(connection_h connection)
78 {
79         return __connection_check_handle_validity(connection);
80 }
81
82 static connection_type_changed_cb
83 __connection_get_type_changed_callback(connection_handle_s *local_handle)
84 {
85         return local_handle->type_changed_callback;
86 }
87
88 static void *__connection_get_type_changed_userdata(
89                                                         connection_handle_s *local_handle)
90 {
91         return local_handle->type_changed_user_data;
92 }
93
94 static void __connection_cb_type_change_cb(int type)
95 {
96         GSList *list;
97         connection_h handle;
98         void *data;
99         connection_type_changed_cb callback;
100         int state;
101
102         if (_connection_is_created() != true) {
103                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
104                                 "If multi-threaded, thread integrity be broken.");
105                 return;
106         }
107
108         state = __connection_convert_net_state(type);
109
110         for (list = conn_handle_list; list; list = list->next) {
111                 handle = (connection_h)list->data;
112
113                 callback = __connection_get_type_changed_callback(handle);
114                 data = __connection_get_type_changed_userdata(handle);
115                 if (callback)
116                         callback(state, data);
117         }
118 }
119
120 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
121 {
122         CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
123
124         GSList *list;
125
126         for (list = conn_handle_list; list; list = list->next) {
127                 connection_handle_s *local_handle = (connection_handle_s *)list->data;
128                 if (local_handle->ethernet_cable_state_changed_callback)
129                         local_handle->ethernet_cable_state_changed_callback(state,
130                                         local_handle->ethernet_cable_state_changed_user_data);
131         }
132 }
133
134 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
135 {
136         GSList *list;
137         int count = 0;
138
139         for (list = conn_handle_list; list; list = list->next) {
140                 connection_handle_s *local_handle = (connection_handle_s *)list->data;
141                 if (local_handle->ethernet_cable_state_changed_callback) count++;
142         }
143
144         return count;
145 }
146
147 static int __connection_set_type_changed_callback(connection_h connection,
148                                                         void *callback, void *user_data)
149 {
150         static __thread gint refcount = 0;
151         connection_handle_s *local_handle;
152
153         local_handle = (connection_handle_s *)connection;
154
155         if (callback) {
156                 if (refcount == 0)
157                         _connection_libnet_set_type_changed_cb(
158                                                            __connection_cb_type_change_cb);
159
160                 refcount++;
161                 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
162                                            refcount);
163         } else {
164                 if (refcount > 0 &&
165                                 __connection_get_type_changed_callback(local_handle) != NULL) {
166                         if (--refcount == 0) {
167                                 _connection_libnet_set_type_changed_cb(NULL);
168                                 CONNECTION_LOG(CONNECTION_INFO,
169                                                 "Successfully de-registered(%d)", refcount);
170                         }
171                 }
172         }
173
174         local_handle->type_changed_user_data = user_data;
175         local_handle->type_changed_callback = callback;
176
177         return CONNECTION_ERROR_NONE;
178 }
179
180 static connection_address_changed_cb
181 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
182 {
183         return local_handle->ip_changed_callback;
184 }
185
186 static void *__connection_get_ip_changed_userdata(
187                                                         connection_handle_s *local_handle)
188 {
189         return local_handle->ip_changed_user_data;
190 }
191
192 static void __connection_cb_ip_change_cb(
193                          connection_address_family_e addr_family, char *ip_addr)
194 {
195         GSList *list;
196         connection_h handle;
197         char *ip4_addr = NULL;
198         char *ip6_addr = NULL;
199         void *data;
200         connection_address_changed_cb callback;
201
202         if (_connection_is_created() != true) {
203                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
204                                 "If multi-threaded, thread integrity be broken.");
205                 return;
206         }
207
208         switch (addr_family) {
209         case CONNECTION_ADDRESS_FAMILY_IPV4:
210                 ip4_addr = g_strdup(ip_addr);
211
212                 ip6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
213                 if (ip6_addr == NULL)
214                         CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
215                                                    "vconf_get_str(VCONFKEY_NETWORK_IP6) failed");
216                 break;
217         case CONNECTION_ADDRESS_FAMILY_IPV6:
218                 ip6_addr = g_strdup(ip_addr);
219
220                 ip4_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
221                 if (ip4_addr == NULL)
222                         CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
223                                                    "vconf_get_str(VCONFKEY_NETWORK_IP) failed");
224                 break;
225         default:
226                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Address Type");
227                 return;
228         }
229
230         for (list = conn_handle_list; list; list = list->next) {
231                 handle = (connection_h)list->data;
232
233                 callback = __connection_get_ip_changed_callback(handle);
234                 data = __connection_get_ip_changed_userdata(handle);
235
236                 if (callback)
237                         callback(ip4_addr, ip6_addr, data);
238         }
239
240         g_free(ip4_addr);
241         g_free(ip6_addr);
242 }
243
244 static int __connection_set_ip_changed_callback(connection_h connection,
245                                                         void *callback, void *user_data)
246 {
247         static __thread gint refcount = 0;
248         connection_handle_s *local_handle;
249
250         local_handle = (connection_handle_s *)connection;
251
252         if (callback) {
253                 if (refcount == 0)
254                         _connection_libnet_set_ip_changed_cb(
255                                                            __connection_cb_ip_change_cb);
256
257                 refcount++;
258                 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
259                                            refcount);
260         } else {
261                 if (refcount > 0 &&
262                                 __connection_get_ip_changed_callback(local_handle) != NULL) {
263                         if (--refcount == 0) {
264                                 _connection_libnet_set_ip_changed_cb(NULL);
265                                 CONNECTION_LOG(CONNECTION_INFO,
266                                                            "Successfully de-registered(%d)", refcount);
267                         }
268                 }
269         }
270
271         local_handle->ip_changed_user_data = user_data;
272         local_handle->ip_changed_callback = callback;
273
274         return CONNECTION_ERROR_NONE;
275 }
276
277 static connection_address_changed_cb
278 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
279 {
280         return local_handle->proxy_changed_callback;
281 }
282
283 static void *__connection_get_proxy_changed_userdata(
284                                                         connection_handle_s *local_handle)
285 {
286         return local_handle->proxy_changed_user_data;
287 }
288
289 static void __connection_cb_proxy_change_cb(char *proxy_addr)
290 {
291         GSList *list;
292         connection_h handle;
293         void *data;
294         connection_address_changed_cb callback;
295
296         if (_connection_is_created() != true) {
297                 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
298                                 "If multi-threaded, thread integrity be broken.");
299                 return;
300         }
301
302         for (list = conn_handle_list; list; list = list->next) {
303                 handle = (connection_h)list->data;
304
305                 callback = __connection_get_proxy_changed_callback(handle);
306                 data = __connection_get_proxy_changed_userdata(handle);
307                 /* TODO: IPv6 should be supported */
308                 if (callback)
309                         callback(proxy_addr, NULL, data);
310         }
311 }
312
313 static int __connection_set_proxy_changed_callback(connection_h connection,
314                                                         void *callback, void *user_data)
315 {
316         static __thread gint refcount = 0;
317         connection_handle_s *local_handle;
318
319         local_handle = (connection_handle_s *)connection;
320
321         if (callback) {
322                 if (refcount == 0)
323                         _connection_libnet_set_proxy_changed_cb(
324                                 __connection_cb_proxy_change_cb);
325
326                 refcount++;
327                 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
328                                            refcount);
329         } else {
330                 if (refcount > 0 &&
331                                 __connection_get_proxy_changed_callback(local_handle) != NULL) {
332                         if (--refcount == 0) {
333                                 _connection_libnet_set_proxy_changed_cb(NULL);
334                                 CONNECTION_LOG(CONNECTION_INFO,
335                                                 "Successfully de-registered(%d)", refcount);
336                         }
337                 }
338         }
339
340         local_handle->proxy_changed_user_data = user_data;
341         local_handle->proxy_changed_callback = callback;
342
343         return CONNECTION_ERROR_NONE;
344 }
345
346 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
347                 connection_ethernet_cable_state_changed_cb callback, void *user_data)
348 {
349         connection_handle_s *local_handle = (connection_handle_s *)connection;
350
351         if (callback) {
352                 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
353                         _connection_libnet_set_ethernet_cable_state_changed_cb(
354                                         __connection_cb_ethernet_cable_state_changed_cb);
355
356         } else {
357                 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1 &&
358                                   local_handle->ethernet_cable_state_changed_callback)
359                         _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
360         }
361
362         local_handle->ethernet_cable_state_changed_callback = callback;
363         local_handle->ethernet_cable_state_changed_user_data = user_data;
364         return CONNECTION_ERROR_NONE;
365 }
366 //LCOV_EXCL_STOP
367
368 static int __connection_get_handle_count(void)
369 {
370         return ((int)g_slist_length(conn_handle_list));
371 }
372
373 /* Connection Manager ********************************************************/
374 EXPORT_API int connection_create(connection_h *connection)
375 {
376         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
377
378         if (connection == NULL || __connection_check_handle_validity(*connection)) {
379                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
380                 return CONNECTION_ERROR_INVALID_PARAMETER;
381         }
382
383         int rv = _connection_libnet_init();
384         if (rv == NET_ERR_ACCESS_DENIED) {
385                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
386                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
387         } else if (rv != NET_ERR_NONE) {
388                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
389                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
390         }
391
392         *connection = g_try_malloc0(sizeof(connection_handle_s));
393         if (*connection != NULL)
394                 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
395         else
396                 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
397
398         conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
399
400         return CONNECTION_ERROR_NONE;
401 }
402
403 EXPORT_API int connection_destroy(connection_h connection)
404 {
405         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
406
407         if (!(__connection_check_handle_validity(connection))) {
408                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
409                 return CONNECTION_ERROR_INVALID_PARAMETER;
410         }
411
412         CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
413
414         __connection_set_type_changed_callback(connection, NULL, NULL);
415         __connection_set_ip_changed_callback(connection, NULL, NULL);
416         __connection_set_proxy_changed_callback(connection, NULL, NULL);
417         __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
418
419         conn_handle_list = g_slist_remove(conn_handle_list, connection);
420
421         g_free(connection);
422         connection = NULL;
423
424         if (__connection_get_handle_count() == 0) {
425                 _connection_libnet_deinit();
426                 _connection_callback_cleanup();
427         }
428
429         return CONNECTION_ERROR_NONE;
430 }
431
432 EXPORT_API int connection_create_cs(int tid, connection_h *connection)
433 {
434         int rv;
435
436         rv = connection_create(connection);
437
438         if (rv == CONNECTION_ERROR_NONE)
439                 _connection_set_cs_tid(tid);
440
441         return rv;
442 }
443
444 EXPORT_API int connection_destroy_cs(int tid, connection_h connection)
445 {
446         int rv;
447
448         _connection_unset_cs_tid(tid);
449         rv = connection_destroy(connection);
450
451         return rv;
452 }
453
454 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
455 {
456         int rv = 0;
457         int status = 0;
458
459         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
460
461         if (type == NULL || !(__connection_check_handle_validity(connection))) {
462                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
463                 return CONNECTION_ERROR_INVALID_PARAMETER;
464         }
465
466         rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
467         if (rv != VCONF_OK) {
468                 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
469                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
470         }
471
472         CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
473
474         *type = __connection_convert_net_state(status);
475
476         return CONNECTION_ERROR_NONE;
477 }
478
479 EXPORT_API int connection_get_ip_address(connection_h connection,
480                                 connection_address_family_e address_family, char** ip_address)
481 {
482         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
483
484         if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
485                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
486                 return CONNECTION_ERROR_INVALID_PARAMETER;
487         }
488
489         switch (address_family) {
490         case CONNECTION_ADDRESS_FAMILY_IPV4:
491                 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
492                 break;
493         case CONNECTION_ADDRESS_FAMILY_IPV6:
494                 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
495                 break;
496         default:
497                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
498                 return CONNECTION_ERROR_INVALID_PARAMETER;
499         }
500
501         if (*ip_address == NULL) {
502                 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
503                 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
504         }
505
506         return CONNECTION_ERROR_NONE;
507 }
508
509 EXPORT_API int connection_get_proxy(connection_h connection,
510                                 connection_address_family_e address_family, char** proxy)
511 {
512         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
513
514         if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
515                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
516                 return CONNECTION_ERROR_INVALID_PARAMETER;
517         }
518
519         switch (address_family) {
520         case CONNECTION_ADDRESS_FAMILY_IPV4:
521         case CONNECTION_ADDRESS_FAMILY_IPV6:
522                 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
523                 break;
524         default:
525                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
526                 return CONNECTION_ERROR_INVALID_PARAMETER;
527         }
528
529         if (*proxy == NULL) {
530                 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
531                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
532         }
533
534         return CONNECTION_ERROR_NONE;
535 }
536
537 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
538 {
539         FILE *fp;
540         char buf[CONNECTION_MAC_INFO_LENGTH + 1];
541
542         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
543
544         if (type == CONNECTION_TYPE_WIFI)
545                 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
546         else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
547                 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
548
549         if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
550                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
551                 return CONNECTION_ERROR_INVALID_PARAMETER;
552         }
553
554         switch (type) {
555         case CONNECTION_TYPE_WIFI:
556                 if (__builtin_expect(tv_profile == -1, 0)) {
557                         char *profileName;
558                         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
559                         if (*profileName == 't' || *profileName == 'T')
560                                 tv_profile = 1;
561                         else
562                                 tv_profile = 0;
563                         free(profileName);
564                 }
565                 if (tv_profile == 1) {
566                         fp = fopen(WIFI_MAC_INFO_FILE, "r");
567                         if (fp == NULL) {
568                                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
569                                 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
570                         }
571
572                         if (fgets(buf, sizeof(buf), fp) == NULL) {
573                                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
574                                 fclose(fp); //LCOV_EXCL_LINE
575                                 return CONNECTION_ERROR_OPERATION_FAILED;
576                         }
577
578                         CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
579
580                         *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
581                         if (*mac_addr == NULL) {
582                                 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
583                                 fclose(fp); //LCOV_EXCL_LINE
584                                 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
585                         }
586                         g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
587                         fclose(fp);
588                 } else {
589                         *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
590
591                         if (*mac_addr == NULL) {
592                                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
593                                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
594                         }
595                 }
596                 break;
597         //LCOV_EXCL_START
598         case CONNECTION_TYPE_ETHERNET:
599                 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
600                 if (fp == NULL) {
601                         CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
602                         return CONNECTION_ERROR_OUT_OF_MEMORY;
603                 }
604
605                 if (fgets(buf, sizeof(buf), fp) == NULL) {
606                         CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
607                         fclose(fp);
608                         return CONNECTION_ERROR_OPERATION_FAILED;
609                 }
610
611                 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
612
613                 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
614                 if (*mac_addr == NULL) {
615                         CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
616                         fclose(fp);
617                         return CONNECTION_ERROR_OUT_OF_MEMORY;
618                 }
619
620                 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
621                 fclose(fp);
622
623                 break;
624         //LCOV_EXCL_STOP
625         default:
626                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
627                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
628         }
629
630         /* Checking Invalid MAC Address */
631         if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
632                         (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
633                 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
634                 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
635         }
636
637         CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
638
639         return CONNECTION_ERROR_NONE;
640 }
641
642
643 EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
644 {
645         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
646
647         if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
648                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
649                 return CONNECTION_ERROR_INVALID_PARAMETER;
650         }
651
652         int rv = _connection_libnet_get_metered_state(is_metered);
653         if (rv != CONNECTION_ERROR_NONE) {
654                 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
655                 return rv; //LCOV_EXCL_LINE
656         }
657
658         CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
659         return CONNECTION_ERROR_NONE;
660 }
661
662
663 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
664 {
665         int rv = 0;
666         int status = 0;
667         int cellular_state = 0;
668 #if defined TIZEN_DUALSIM_ENABLE
669         int sim_id = 0;
670 #endif
671
672         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
673
674         if (state == NULL || !(__connection_check_handle_validity(connection))) {
675                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
676                 return CONNECTION_ERROR_INVALID_PARAMETER;
677         }
678
679         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
680         if (rv != VCONF_OK) {
681                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
682                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
683         }
684
685         CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
686         *state = __connection_convert_cellular_state(status);
687
688         if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
689 #if defined TIZEN_DUALSIM_ENABLE
690                 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
691                 if (rv != VCONF_OK) {
692                         CONNECTION_LOG(CONNECTION_ERROR,
693                                         "Failed to get default subscriber id", sim_id);
694                         return CONNECTION_ERROR_OPERATION_FAILED;
695                 }
696
697                 switch (sim_id) {
698                 case CONNECTION_CELLULAR_SUBSCRIBER_1:
699 #endif
700                         rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
701 #if defined TIZEN_DUALSIM_ENABLE
702                         break;
703
704                 case CONNECTION_CELLULAR_SUBSCRIBER_2:
705                         rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
706                         break;
707
708                 default:
709                         CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
710                         return CONNECTION_ERROR_OPERATION_FAILED;
711                 }
712 #endif
713                 if (rv != VCONF_OK) {
714                         CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
715                         return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
716                 }
717         }
718
719         CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
720
721         if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
722                         cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
723                         cellular_state == VCONFKEY_DNET_TRANSFER)
724                 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
725
726         return CONNECTION_ERROR_NONE;
727 }
728
729 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
730 {
731         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
732
733         if (state == NULL || !(__connection_check_handle_validity(connection))) {
734                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
735                 return CONNECTION_ERROR_INVALID_PARAMETER;
736         }
737
738         int rv = _connection_libnet_get_wifi_state(state);
739         if (rv != CONNECTION_ERROR_NONE) {
740                 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
741                 return rv; //LCOV_EXCL_LINE
742         }
743
744         CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
745
746         return CONNECTION_ERROR_NONE;
747 }
748
749 //LCOV_EXCL_START
750 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
751 {
752         CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
753
754         if (state == NULL || !(__connection_check_handle_validity(connection))) {
755                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
756                 return CONNECTION_ERROR_INVALID_PARAMETER;
757         }
758
759         return _connection_libnet_get_ethernet_state(state);
760 }
761
762 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
763 {
764         CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
765
766         if (state == NULL || !(__connection_check_handle_validity(connection))) {
767                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
768                 return CONNECTION_ERROR_INVALID_PARAMETER;
769         }
770
771         return _connection_libnet_get_ethernet_cable_state(state);
772 }
773
774 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
775                           connection_ethernet_cable_state_chaged_cb callback, void *user_data)
776 {
777         DEPRECATED_LOG(__FUNCTION__, "connection_set_ethernet_cable_state_changed_cb");
778         CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
779
780         if (callback == NULL || !(__connection_check_handle_validity(connection))) {
781                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
782                 return CONNECTION_ERROR_INVALID_PARAMETER;
783         }
784
785         DEPRECATED_LOG("connection_ethernet_cable_state_chaged_cb",
786                         "connection_ethernet_cable_state_changed_cb");
787
788         return __connection_set_ethernet_cable_state_changed_cb(connection,
789                         (connection_ethernet_cable_state_changed_cb)callback, user_data);
790 }
791
792 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
793 {
794         DEPRECATED_LOG(__FUNCTION__, "connection_unset_ethernet_cable_state_changed_cb");
795         CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
796
797         if (!(__connection_check_handle_validity(connection))) {
798                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
799                 return CONNECTION_ERROR_INVALID_PARAMETER;
800         }
801
802         return __connection_set_ethernet_cable_state_changed_cb(connection,
803                                                         NULL, NULL);
804 }
805
806 EXPORT_API int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
807                           connection_ethernet_cable_state_changed_cb callback, void *user_data)
808 {
809         CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
810
811         if (callback == NULL || !(__connection_check_handle_validity(connection))) {
812                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
813                 return CONNECTION_ERROR_INVALID_PARAMETER;
814         }
815
816         return __connection_set_ethernet_cable_state_changed_cb(connection,
817                                                         callback, user_data);
818 }
819
820 EXPORT_API int connection_unset_ethernet_cable_state_changed_cb(connection_h connection)
821 {
822         CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
823
824         if (!(__connection_check_handle_validity(connection))) {
825                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
826                 return CONNECTION_ERROR_INVALID_PARAMETER;
827         }
828
829         return __connection_set_ethernet_cable_state_changed_cb(connection,
830                                                         NULL, NULL);
831 }
832 //LCOV_EXCL_STOP
833
834 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
835 {
836         CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
837
838         if (state == NULL || !(__connection_check_handle_validity(connection))) {
839                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
840                 return CONNECTION_ERROR_INVALID_PARAMETER;
841         }
842
843         return _connection_libnet_get_bluetooth_state(state);
844 }
845
846 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
847                                         connection_type_changed_cb callback, void* user_data)
848 {
849         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
850
851         if (callback == NULL || !(__connection_check_handle_validity(connection))) {
852                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
853                 return CONNECTION_ERROR_INVALID_PARAMETER;
854         }
855
856         return __connection_set_type_changed_callback(connection, callback, user_data);
857 }
858
859 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
860 {
861         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
862
863         if (!(__connection_check_handle_validity(connection))) {
864                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
865                 return CONNECTION_ERROR_INVALID_PARAMETER;
866         }
867
868         return __connection_set_type_changed_callback(connection, NULL, NULL);
869 }
870
871 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
872                                 connection_address_changed_cb callback, void* user_data)
873 {
874         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
875
876         if (callback == NULL || !(__connection_check_handle_validity(connection))) {
877                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
878                 return CONNECTION_ERROR_INVALID_PARAMETER;
879         }
880
881         return __connection_set_ip_changed_callback(connection, callback, user_data);
882 }
883
884 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
885 {
886         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
887
888         if (!(__connection_check_handle_validity(connection))) {
889                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
890                 return CONNECTION_ERROR_INVALID_PARAMETER;
891         }
892
893         return __connection_set_ip_changed_callback(connection, NULL, NULL);
894 }
895
896 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
897                                 connection_address_changed_cb callback, void* user_data)
898 {
899         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
900
901         if (callback == NULL || !(__connection_check_handle_validity(connection))) {
902                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
903                 return CONNECTION_ERROR_INVALID_PARAMETER;
904         }
905
906         return __connection_set_proxy_changed_callback(connection, callback, user_data);
907 }
908
909 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
910 {
911         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
912
913         if (!(__connection_check_handle_validity(connection))) {
914                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
915                 return CONNECTION_ERROR_INVALID_PARAMETER;
916         }
917
918         return __connection_set_proxy_changed_callback(connection, NULL, NULL);
919 }
920
921 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
922 {
923         int rv = 0;
924         net_profile_info_t *profile_info = profile;
925
926         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
927
928         if (!(__connection_check_handle_validity(connection)) ||
929             !(_connection_libnet_check_profile_validity(profile))) {
930                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
931                 return CONNECTION_ERROR_INVALID_PARAMETER;
932         }
933
934         if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
935                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
936                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
937         }
938
939         if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
940                         strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
941                 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
942                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
943         }
944
945         rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
946                                                         (net_profile_info_t*)profile);
947         if (rv == NET_ERR_ACCESS_DENIED) {
948                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
949                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
950         } else if (rv != NET_ERR_NONE) {
951                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
952                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
953         }
954
955         return CONNECTION_ERROR_NONE;
956 }
957
958 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
959 {
960         int rv = 0;
961         net_profile_info_t *profile_info = profile;
962
963         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
964
965         if (!(__connection_check_handle_validity(connection)) ||
966                         !(_connection_libnet_check_profile_validity(profile))) {
967                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
968                 return CONNECTION_ERROR_INVALID_PARAMETER;
969         }
970
971         if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
972             profile_info->profile_type != NET_DEVICE_WIFI) {
973                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
974                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
975         }
976
977         rv = net_delete_profile(profile_info->ProfileName);
978         if (rv == NET_ERR_ACCESS_DENIED) {
979                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
980                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
981         } else if (rv != NET_ERR_NONE) {
982                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
983                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
984         }
985
986         return CONNECTION_ERROR_NONE;
987 }
988
989 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
990 {
991         int rv = 0;
992         net_profile_info_t *profile_info = profile;
993
994         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
995
996         if (!(__connection_check_handle_validity(connection)) ||
997             !(_connection_libnet_check_profile_validity(profile))) {
998                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
999                 return CONNECTION_ERROR_INVALID_PARAMETER;
1000         }
1001
1002         rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
1003         if (rv == NET_ERR_ACCESS_DENIED) {
1004                 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1005                 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1006         } else if (rv != NET_ERR_NONE) {
1007                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
1008                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1009         }
1010
1011         return CONNECTION_ERROR_NONE;
1012 }
1013
1014 EXPORT_API int connection_get_profile_iterator(connection_h connection,
1015                 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
1016 {
1017         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1018
1019         if (!(__connection_check_handle_validity(connection)) ||
1020             (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
1021              type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
1022              type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
1023                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1024                 return CONNECTION_ERROR_INVALID_PARAMETER;
1025         }
1026
1027         return _connection_libnet_get_profile_iterator(type, profile_iterator);
1028 }
1029
1030 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1031                                                         connection_profile_h* profile)
1032 {
1033         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1034
1035         return _connection_libnet_get_iterator_next(profile_iterator, profile);
1036 }
1037
1038 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1039 {
1040         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1041
1042         return _connection_libnet_iterator_has_next(profile_iterator);
1043 }
1044
1045 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1046 {
1047         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1048
1049         return _connection_libnet_destroy_iterator(profile_iterator);
1050 }
1051
1052 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1053 {
1054         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1055
1056         if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1057                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1058                 return CONNECTION_ERROR_INVALID_PARAMETER;
1059         }
1060
1061         return _connection_libnet_get_current_profile(profile);
1062 }
1063
1064 EXPORT_API int connection_get_default_cellular_service_profile(
1065                 connection_h connection, connection_cellular_service_type_e type,
1066                 connection_profile_h *profile)
1067 {
1068         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1069
1070         if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1071                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1072                 return CONNECTION_ERROR_INVALID_PARAMETER;
1073         }
1074
1075         return _connection_libnet_get_cellular_service_profile(type, profile);
1076 }
1077
1078 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1079                 connection_cellular_service_type_e type, connection_profile_h profile)
1080 {
1081         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1082
1083         if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1084                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1085                 return CONNECTION_ERROR_INVALID_PARAMETER;
1086         }
1087
1088         return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1089 }
1090
1091 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1092                 connection_cellular_service_type_e type, connection_profile_h profile,
1093                 connection_set_default_cb callback, void* user_data)
1094 {
1095         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1096
1097         if (!(__connection_check_handle_validity(connection)) ||
1098             profile == NULL || callback == NULL) {
1099                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1100                 return CONNECTION_ERROR_INVALID_PARAMETER;
1101         }
1102
1103         return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1104 }
1105
1106 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1107                                         connection_opened_cb callback, void* user_data)
1108 {
1109         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1110
1111         if (!(__connection_check_handle_validity(connection)) ||
1112             profile == NULL || callback == NULL) {
1113                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1114                 return CONNECTION_ERROR_INVALID_PARAMETER;
1115         }
1116
1117         return _connection_libnet_open_profile(profile, callback, user_data);
1118 }
1119
1120 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1121                                         connection_closed_cb callback, void* user_data)
1122 {
1123         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1124
1125         if (!(__connection_check_handle_validity(connection)) ||
1126             profile == NULL || callback == NULL) {
1127                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1128                 return CONNECTION_ERROR_INVALID_PARAMETER;
1129         }
1130
1131         return _connection_libnet_close_profile(profile, callback, user_data);
1132 }
1133
1134 EXPORT_API int connection_reset_profile(connection_h connection,
1135                                 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1136 {
1137         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1138
1139         if (!(__connection_check_handle_validity(connection))) {
1140                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1141                 return CONNECTION_ERROR_INVALID_PARAMETER;
1142         }
1143
1144         if (id < 0 || id > 1) {
1145                 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1146                 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1147         }
1148
1149         return _connection_libnet_reset_profile(type, id, callback, user_data);
1150 }
1151
1152 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1153 {
1154         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1155
1156         if (!(__connection_check_handle_validity(connection)) ||
1157             interface_name == NULL || host_address == NULL) {
1158                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1159                 return CONNECTION_ERROR_INVALID_PARAMETER;
1160         }
1161
1162         return _connection_libnet_add_route(interface_name, host_address);
1163 }
1164
1165 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1166 {
1167         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1168
1169         if (!(__connection_check_handle_validity(connection)) ||
1170             interface_name == NULL || host_address == NULL) {
1171                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1172                 return CONNECTION_ERROR_INVALID_PARAMETER;
1173         }
1174
1175         return _connection_libnet_remove_route(interface_name, host_address);
1176 }
1177
1178 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1179 {
1180         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1181
1182         if (!(__connection_check_handle_validity(connection)) ||
1183             interface_name == NULL || host_address == NULL) {
1184                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1185                 return CONNECTION_ERROR_INVALID_PARAMETER;
1186         }
1187
1188         return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1189 }
1190
1191 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1192 {
1193         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1194
1195         if (!(__connection_check_handle_validity(connection)) ||
1196             interface_name == NULL || host_address == NULL) {
1197                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1198                 return CONNECTION_ERROR_INVALID_PARAMETER;
1199         }
1200
1201         return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1202 }
1203
1204 EXPORT_API int connection_add_route_entry(connection_h connection,
1205                 connection_address_family_e address_family,     const char *interface_name,
1206                 const char *host_address, const char *gateway)
1207 {
1208         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1209
1210         if (!(__connection_check_handle_validity(connection)) ||
1211                 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1212              address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1213             interface_name == NULL || host_address == NULL) {
1214                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1215                 return CONNECTION_ERROR_INVALID_PARAMETER;
1216         }
1217
1218         if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1219                 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1220                                                                 interface_name, host_address, gateway);
1221         else
1222                 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1223                                                                 interface_name, host_address, gateway);
1224
1225         return CONNECTION_ERROR_NONE;
1226 }
1227
1228 EXPORT_API int connection_remove_route_entry(connection_h connection,
1229                 connection_address_family_e address_family,     const char *interface_name,
1230                 const char *host_address, const char *gateway)
1231 {
1232         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1233
1234         if (!(__connection_check_handle_validity(connection)) ||
1235                 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1236              address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1237             interface_name == NULL || host_address == NULL) {
1238                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1239                 return CONNECTION_ERROR_INVALID_PARAMETER;
1240         }
1241
1242         if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1243                 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1244                                                                 interface_name, host_address, gateway);
1245         else
1246                 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1247                                                                 interface_name, host_address, gateway);
1248
1249         return CONNECTION_ERROR_NONE;
1250 }
1251
1252 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1253 {
1254         int rv = VCONF_OK, rv1 = VCONF_OK;
1255         int last_size = 0, size = 0;
1256 #if defined TIZEN_DUALSIM_ENABLE
1257         int sim_id = 0;
1258 #endif
1259
1260         if (llsize == NULL) {
1261                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1262                 return CONNECTION_ERROR_INVALID_PARAMETER;
1263         }
1264
1265         switch (statistics_type) {
1266         case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1267         case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1268         case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1269         case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1270                 break;
1271         default:
1272                 return CONNECTION_ERROR_INVALID_PARAMETER;
1273         }
1274
1275 #if defined TIZEN_DUALSIM_ENABLE
1276         rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1277         if (rv != VCONF_OK) {
1278                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1279                 *llsize = 0;
1280                 return CONNECTION_ERROR_OPERATION_FAILED;
1281         }
1282
1283         switch (sim_id) {
1284         case 0:
1285 #endif
1286                 switch (statistics_type) {
1287                 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1288                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1289                         break;
1290                 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1291                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1292                         break;
1293                 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1294                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1295                         rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1296                         break;
1297                 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1298                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1299                         rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1300                         break;
1301                 }
1302 #if defined TIZEN_DUALSIM_ENABLE
1303                 break;
1304         case 1:
1305                 switch (statistics_type) {
1306                 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1307                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1308                         break;
1309                 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1310                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1311                         break;
1312                 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1313                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1314                         rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1315                         break;
1316                 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1317                         rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1318                         rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1319                         break;
1320                 }
1321                 break;
1322         default:
1323                 *llsize = 0;
1324                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1325                 return CONNECTION_ERROR_OPERATION_FAILED;
1326         }
1327 #endif
1328
1329         if (rv != VCONF_OK || rv1 != VCONF_OK) {
1330                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1331                 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1332         }
1333
1334         *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1335         CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1336
1337         return CONNECTION_ERROR_NONE;
1338 }
1339
1340 static int __get_statistic(connection_type_e connection_type,
1341                 connection_statistics_type_e statistics_type, long long *llsize)
1342 {
1343         int rv, stat_type;
1344         unsigned long long ull_size;
1345
1346         if (llsize == NULL) {
1347                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1348                 return CONNECTION_ERROR_INVALID_PARAMETER;
1349         }
1350
1351         rv  = _connection_libnet_check_get_privilege();
1352         if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1353                 return rv;
1354         else if (rv != CONNECTION_ERROR_NONE) {
1355                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1356                 return CONNECTION_ERROR_OPERATION_FAILED;
1357         }
1358
1359         if (connection_type == CONNECTION_TYPE_CELLULAR)
1360                 return __get_cellular_statistic(statistics_type, llsize);
1361         else if (connection_type == CONNECTION_TYPE_WIFI) {
1362                 switch (statistics_type) {
1363                 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1364                         stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1365                         break;
1366                 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1367                         stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1368                         break;
1369                 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1370                         stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1371                         break;
1372                 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1373                         stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1374                         break;
1375                 default:
1376                         return CONNECTION_ERROR_INVALID_PARAMETER;
1377                 }
1378
1379                 rv  = _connection_libnet_get_statistics(stat_type, &ull_size);
1380                 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1381                         return rv;
1382                 else if (rv != CONNECTION_ERROR_NONE) {
1383                         CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1384                         *llsize = 0; //LCOV_EXCL_LINE
1385                         return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1386                 }
1387
1388                 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1389                 *llsize = (long long)ull_size;
1390         } else
1391                 return CONNECTION_ERROR_INVALID_PARAMETER;
1392
1393         return CONNECTION_ERROR_NONE;
1394 }
1395
1396 static int __reset_statistic(connection_type_e connection_type,
1397                 connection_statistics_type_e statistics_type)
1398 {
1399         int conn_type;
1400         int stat_type;
1401         int rv;
1402
1403         if (connection_type == CONNECTION_TYPE_CELLULAR)
1404                 conn_type = NET_DEVICE_CELLULAR;
1405         else if (connection_type == CONNECTION_TYPE_WIFI)
1406                 conn_type = NET_DEVICE_WIFI;
1407         else
1408                 return CONNECTION_ERROR_INVALID_PARAMETER;
1409
1410         switch (statistics_type) {
1411         case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1412                 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1413                 break;
1414         case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1415                 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1416                 break;
1417         case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1418                 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1419                 break;
1420         case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1421                 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1422                 break;
1423         default:
1424                 return CONNECTION_ERROR_INVALID_PARAMETER;
1425         }
1426
1427         rv = _connection_libnet_set_statistics(conn_type, stat_type);
1428         if (rv != CONNECTION_ERROR_NONE)
1429                 return rv;
1430
1431         CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1432
1433         return CONNECTION_ERROR_NONE;
1434 }
1435
1436 EXPORT_API int connection_get_statistics(connection_h connection,
1437                                 connection_type_e connection_type,
1438                                 connection_statistics_type_e statistics_type, long long* size)
1439 {
1440         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1441
1442         if (connection_type == CONNECTION_TYPE_CELLULAR)
1443                 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1444         else if (connection_type == CONNECTION_TYPE_WIFI)
1445                 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1446
1447         if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1448                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1449                 return CONNECTION_ERROR_INVALID_PARAMETER;
1450         }
1451
1452         return __get_statistic(connection_type, statistics_type, size);
1453 }
1454
1455 EXPORT_API int connection_reset_statistics(connection_h connection,
1456                                 connection_type_e connection_type,
1457                                 connection_statistics_type_e statistics_type)
1458 {
1459         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1460
1461         if (connection_type == CONNECTION_TYPE_CELLULAR)
1462                 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1463         else if (connection_type == CONNECTION_TYPE_WIFI)
1464                 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1465
1466         if (!__connection_check_handle_validity(connection)) {
1467                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1468                 return CONNECTION_ERROR_INVALID_PARAMETER;
1469         }
1470
1471         return __reset_statistic(connection_type, statistics_type);
1472 }
1473
1474 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1475                 connection_type_e connection_type, connection_ipv6_address_cb callback,
1476                 void *user_data)
1477 {
1478         CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1479                         TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1480
1481         GSList *ipv6_address_list = NULL;
1482
1483         if (!(__connection_check_handle_validity(connection))) {
1484                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1485                 return CONNECTION_ERROR_INVALID_PARAMETER;
1486         }
1487
1488         int rv = CONNECTION_ERROR_NONE;
1489
1490         switch (connection_type) {
1491         case CONNECTION_TYPE_WIFI:
1492                 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1493                                 &ipv6_address_list);
1494                 break;
1495         case CONNECTION_TYPE_CELLULAR:
1496                 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1497                                 &ipv6_address_list);
1498                 break;
1499         case CONNECTION_TYPE_ETHERNET:
1500                 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1501                                 &ipv6_address_list);
1502                 break;
1503         case CONNECTION_TYPE_BT:
1504                 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1505                                 &ipv6_address_list);
1506                 break;
1507         default:
1508                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1509                 return CONNECTION_ERROR_INVALID_PARAMETER;
1510         }
1511
1512         if (rv != NET_ERR_NONE) {
1513                 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address"
1514                                 " Failed = %d\n", rv);
1515                 return CONNECTION_ERROR_OPERATION_FAILED;
1516         }
1517
1518         GSList *list;
1519         for (list = ipv6_address_list; list; list = list->next) {
1520                 rv = callback((char *)list->data, user_data);
1521                 if (rv == false)
1522                         break;
1523         }
1524
1525         g_slist_free_full(ipv6_address_list, g_free);
1526         ipv6_address_list = NULL;
1527
1528         return CONNECTION_ERROR_NONE;
1529 }
1530
1531 EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
1532 {
1533         int ret = 0;
1534
1535         if (!(__connection_check_handle_validity(connection))) {
1536                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1537                 return CONNECTION_ERROR_INVALID_PARAMETER;
1538         }
1539
1540         ret = _connection_libnet_start_tcpdump();
1541         if (ret != CONNECTION_ERROR_NONE) {
1542                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret);
1543                 return ret;
1544         }
1545
1546         return CONNECTION_ERROR_NONE;
1547 }
1548
1549 EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
1550 {
1551         int ret = 0;
1552
1553         if (!(__connection_check_handle_validity(connection))) {
1554                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1555                 return CONNECTION_ERROR_INVALID_PARAMETER;
1556         }
1557
1558         ret = _connection_libnet_stop_tcpdump();
1559         if (ret != CONNECTION_ERROR_NONE) {
1560                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret);
1561                 return ret;
1562         }
1563
1564         return CONNECTION_ERROR_NONE;
1565 }
1566
1567 EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
1568 {
1569         int ret = 0;
1570
1571         if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
1572                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1573                 return CONNECTION_ERROR_INVALID_PARAMETER;
1574         }
1575
1576         ret = _connection_libnet_get_tcpdump_state(tcpdump_state);
1577         if (ret != CONNECTION_ERROR_NONE) {
1578                 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret);
1579                 return ret;
1580         }
1581
1582         return CONNECTION_ERROR_NONE;
1583 }