Release 2.0 beta
[framework/connectivity/libnet-client.git] / src / network-cm-intf.c
1 /*
2  *  Network Client Library
3  *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://www.tizenopensource.org/license
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17  *
18  */
19
20
21 #ifdef __cplusplus
22 extern "C"
23 {
24 #endif /* __cplusplus */
25
26
27 /*****************************************************************************
28  *      Standard headers
29  *****************************************************************************/
30 #include <stdio.h> 
31 #include <errno.h> 
32 #include <stdlib.h> 
33 #include <string.h>
34 #include <glib.h>
35
36 #include <dbus/dbus.h> 
37
38
39 /*****************************************************************************
40  *      Platform headers
41  *****************************************************************************/
42
43 #include "network-internal.h"
44 #include "network-signal-handler.h"
45 #include "network-dbus-request.h"
46
47 /*****************************************************************************
48  *      Macros and Typedefs
49  *****************************************************************************/
50
51 /*****************************************************************************
52  *      Local Functions Declaration
53  *****************************************************************************/
54
55 static int __net_get_default_profile(void *param, net_profile_info_t *active_profile_info);
56
57 /*****************************************************************************
58  *      Global Functions
59  *****************************************************************************/
60
61 /*****************************************************************************
62  *      Extern Variables
63  *****************************************************************************/
64
65 extern network_request_table_t request_table[NETWORK_REQUEST_TYPE_MAX];
66
67 /*****************************************************************************
68  *      Global Variables
69  *****************************************************************************/
70
71 network_info_t NetworkInfo = {0, };
72
73 /*****************************************************************************
74  *      Local Functions Definition
75  *****************************************************************************/
76
77 static int __net_get_default_profile(void *param, net_profile_info_t *active_profile_info)
78 {
79         __NETWORK_FUNC_ENTER__;
80
81         net_err_t Error = NET_ERR_NONE;
82
83         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
84                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
85                 __NETWORK_FUNC_EXIT__;
86                 return NET_ERR_APP_NOT_REGISTERED;
87         }
88
89         if (param == NULL) {
90                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid parameter\n");
91                 __NETWORK_FUNC_EXIT__;
92                 return NET_ERR_INVALID_PARAM;
93         }
94
95         Error = _net_get_default_profile_info(active_profile_info);
96
97         if (Error != NET_ERR_NONE) {
98                 NETWORK_LOG(NETWORK_ERROR,
99                                 "Error!!! _net_get_default_profile_info() failed. Error [%s]\n",
100                                 _net_print_error(Error));
101
102                 __NETWORK_FUNC_EXIT__;
103                 return Error;
104         }
105
106         __NETWORK_FUNC_EXIT__;
107         return NET_ERR_NONE;
108 }
109
110 /*****************************************************************************
111  *      ConnMan Client Common Interface API Definition
112  *****************************************************************************/
113
114 /**
115  * @fn  EXPORT_API int net_register_client(net_event_cb_t event_cb, void *user_data)
116  *
117  * This function registers callback with the network client
118  * This is Sync API.
119  *
120  * @return       int - NET_ERR_NONE on success, negative values for errors
121  * @param[in]    net_event_cb_t event_cb - Pointer to callback function
122  *               void* user_data - Pointer to user data 
123  * @param[out]   none 
124  */
125 EXPORT_API int net_register_client(net_event_cb_t event_cb, void *user_data)
126 {
127         __NETWORK_FUNC_ENTER__;
128
129         net_err_t Error = NET_ERR_NONE;
130
131         if (event_cb == NULL) {
132                  NETWORK_LOG(NETWORK_ASSERT, "Error!! Invalid EventCb parameter\n");
133                 __NETWORK_FUNC_EXIT__;
134                 return NET_ERR_INVALID_PARAM;
135         }
136
137         if (NetworkInfo.ClientEventCb != NULL) {
138                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application Already registered\n");
139                 __NETWORK_FUNC_EXIT__;
140                 return NET_ERR_APP_ALREADY_REGISTERED;
141         }
142
143         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
144                 if (_net_mutex_init() != NET_ERR_NONE) {
145                         __NETWORK_FUNC_EXIT__;
146                         return NET_ERR_UNKNOWN;
147                 }
148
149                 Error = _net_register_signal();
150                 if (Error != NET_ERR_NONE) {
151                         NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_register_signal() failed. Error [%s]\n",
152                                         _net_print_error(Error));
153                         _net_mutex_destroy();
154                         __NETWORK_FUNC_EXIT__;
155                         return Error;
156                 }
157
158                 NetworkInfo.wifi_state = _net_get_wifi_state();
159                 _net_init_service_state_table();
160         }
161
162         g_atomic_int_inc(&NetworkInfo.ref_count);
163
164         NetworkInfo.ClientEventCb = event_cb;
165         NetworkInfo.user_data = user_data;
166
167         NETWORK_LOG(NETWORK_HIGH, "Client Register Successfully\n");
168
169         __NETWORK_FUNC_EXIT__;
170         return NET_ERR_NONE;
171 }
172
173 int net_register_client_ext(net_event_cb_t event_cb, net_device_t client_type, void *user_data)
174 {
175         net_err_t Error = NET_ERR_NONE;
176
177         if (event_cb == NULL || (client_type != NET_DEVICE_DEFAULT && client_type != NET_DEVICE_WIFI)) {
178                  NETWORK_LOG(NETWORK_ASSERT, "Error!! Invalid EventCb parameter\n");
179                 return NET_ERR_INVALID_PARAM;
180         }
181
182         switch (client_type) {
183         case NET_DEVICE_DEFAULT:
184                 if (NetworkInfo.ClientEventCb_conn != NULL) {
185                         NETWORK_LOG(NETWORK_ERROR, "Error!!! Connection CAPI Already registered\n");
186                         return NET_ERR_APP_ALREADY_REGISTERED;
187                 }
188                 break;
189         case NET_DEVICE_WIFI:
190                 if (NetworkInfo.ClientEventCb_wifi != NULL) {
191                         NETWORK_LOG(NETWORK_ERROR, "Error!!! Wi-Fi CAPI Already registered\n");
192                         return NET_ERR_APP_ALREADY_REGISTERED;
193                 }
194         default:
195                 break;
196         }
197
198         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
199                 if (_net_mutex_init() != NET_ERR_NONE)
200                         return NET_ERR_UNKNOWN;
201
202                 Error = _net_register_signal();
203                 if (Error != NET_ERR_NONE) {
204                         NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_register_signal() failed. Error [%s]\n",
205                                         _net_print_error(Error));
206                         _net_mutex_destroy();
207                         return Error;
208                 }
209
210                 NetworkInfo.wifi_state = _net_get_wifi_state();
211                 _net_init_service_state_table();
212         }
213
214         g_atomic_int_inc(&NetworkInfo.ref_count);
215
216         switch (client_type) {
217         case NET_DEVICE_DEFAULT:
218                 NetworkInfo.ClientEventCb_conn = event_cb;
219                 NetworkInfo.user_data_conn = user_data;
220                 break;
221         case NET_DEVICE_WIFI:
222                 NetworkInfo.ClientEventCb_wifi = event_cb;
223                 NetworkInfo.user_data_wifi = user_data;
224         default:
225                 break;
226         }
227
228         NETWORK_LOG(NETWORK_HIGH, "Client Register Successfully\n");
229
230         return NET_ERR_NONE;
231 }
232
233 /**
234  * @fn  EXPORT_API int net_deregister_client(void)
235  *
236  * This function deregisters with network client 
237  * This is Sync API.
238  *
239  * @return       int - NET_ERR_NONE on success, negative values for errors
240  * @param[in]    none
241  * @param[out]   none
242  */
243
244 EXPORT_API int net_deregister_client(void)
245 {
246         __NETWORK_FUNC_ENTER__;
247
248         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0 ||
249             NetworkInfo.ClientEventCb == NULL) {
250                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
251                 __NETWORK_FUNC_EXIT__;
252                 return NET_ERR_APP_NOT_REGISTERED;
253         }
254
255         if (g_atomic_int_dec_and_test(&NetworkInfo.ref_count)) {
256                 _net_deregister_signal();
257                 _net_mutex_destroy();
258                 _net_clear_request_table();
259         }
260
261         NetworkInfo.ClientEventCb = NULL;
262         NetworkInfo.user_data = NULL;
263         NETWORK_LOG(NETWORK_HIGH, "Client De-Register Successfull\n");
264
265         __NETWORK_FUNC_EXIT__;
266         return NET_ERR_NONE;
267 }
268
269 int net_deregister_client_ext(net_device_t client_type)
270 {
271         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
272                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
273                 return NET_ERR_APP_NOT_REGISTERED;
274         }
275
276         switch (client_type) {
277         case NET_DEVICE_DEFAULT:
278                 if (NetworkInfo.ClientEventCb_conn == NULL) {
279                         NETWORK_LOG(NETWORK_ERROR, "Error!!! Connection CAPI was not registered\n");
280                         return NET_ERR_APP_NOT_REGISTERED;
281                 }
282                 NetworkInfo.ClientEventCb_conn = NULL;
283                 NetworkInfo.user_data_conn = NULL;
284                 break;
285         case NET_DEVICE_WIFI:
286                 if (NetworkInfo.ClientEventCb_wifi == NULL) {
287                         NETWORK_LOG(NETWORK_ERROR, "Error!!! Wi-Fi CAPI was not registered\n");
288                         return NET_ERR_APP_NOT_REGISTERED;
289                 }
290                 NetworkInfo.ClientEventCb_wifi = NULL;
291                 NetworkInfo.user_data_wifi = NULL;
292                 break;
293         default:
294                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid client_type parameter\n");
295                 return NET_ERR_INVALID_PARAM;
296         }
297
298         if (g_atomic_int_dec_and_test(&NetworkInfo.ref_count)) {
299                 _net_deregister_signal();
300                 _net_mutex_destroy();
301                 _net_clear_request_table();
302         }
303
304         NETWORK_LOG(NETWORK_HIGH, "Client De-Register Successfull\n");
305         return NET_ERR_NONE;
306 }
307
308 /**
309  * @fn  EXPORT_API int net_get_active_net_info(net_profile_info_t *active_profile_info)
310  *
311  * This API returns the information of active(default) network profile.
312  * This is Sync API.
313  *
314  * @return       int - NET_ERR_NONE on success, negative values for errors
315  * @param[in]    none
316  * @param[out]   active_profile_info    The information of active(default) network profile.
317  */
318 EXPORT_API int net_get_active_net_info(net_profile_info_t *active_profile_info)
319 {
320         __NETWORK_FUNC_ENTER__;
321
322         net_err_t Error = NET_ERR_NONE;
323
324         Error = __net_get_default_profile((void*)active_profile_info, active_profile_info);
325
326         __NETWORK_FUNC_EXIT__;
327         return Error;
328 }
329
330 /**
331  * @fn  EXPORT_API int net_get_active_ipaddress(net_addr_t *ip_address)
332  *
333  * This API returns a specific information of active(default) network profile.
334  * This is Sync API.
335  *
336  * @return       int - NET_ERR_NONE on success, negative values for errors
337  * @param[in]    none
338  * @param[out]   ip_address     Ip address of active(default) network profile.
339  */
340 EXPORT_API int net_get_active_ipaddress(net_addr_t *ip_address)
341 {
342         __NETWORK_FUNC_ENTER__;
343
344         net_err_t Error = NET_ERR_NONE;
345         net_profile_info_t active_profile_info;
346         net_dev_info_t *net_info = NULL;
347
348         Error = __net_get_default_profile((void*)ip_address, &active_profile_info);
349         if (Error != NET_ERR_NONE) {
350                 __NETWORK_FUNC_EXIT__;
351                 return Error;
352         }
353
354         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
355                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
356         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
357                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
358         else if (active_profile_info.profile_type == NET_DEVICE_ETHERNET)
359                 net_info = &active_profile_info.ProfileInfo.Ethernet.net_info;
360         else
361                 Error = NET_ERR_UNKNOWN;
362
363         if (net_info != NULL)
364                 memcpy(ip_address, &net_info->IpAddr, sizeof(net_addr_t));
365
366         __NETWORK_FUNC_EXIT__;
367         return Error;
368 }
369
370 /**
371  * @fn  EXPORT_API int net_get_active_netmask(net_addr_t *netmask)
372  *
373  * This API returns a specific information of active(default) network profile.
374  * This is Sync API.
375  *
376  * @return       int - NET_ERR_NONE on success, negative values for errors
377  * @param[in]    none
378  * @param[out]   netmask        Netmask of active(default) network profile.
379  */
380 EXPORT_API int net_get_active_netmask(net_addr_t *netmask)
381 {
382         __NETWORK_FUNC_ENTER__;
383
384         net_err_t Error = NET_ERR_NONE;
385         net_profile_info_t active_profile_info;
386         net_dev_info_t *net_info = NULL;
387
388         Error = __net_get_default_profile((void*)netmask, &active_profile_info);
389         if (Error != NET_ERR_NONE) {
390                 __NETWORK_FUNC_EXIT__;
391                 return Error;
392         }
393
394         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
395                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
396         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
397                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
398         else if (active_profile_info.profile_type == NET_DEVICE_ETHERNET)
399                 net_info = &active_profile_info.ProfileInfo.Ethernet.net_info;
400         else
401                 Error = NET_ERR_UNKNOWN;
402
403         if (net_info != NULL)
404                 memcpy(netmask, &net_info->SubnetMask, sizeof(net_addr_t));
405
406         __NETWORK_FUNC_EXIT__;
407         return Error;
408 }
409
410 /**
411  * @fn  EXPORT_API int net_get_active_gateway(net_addr_t *gateway)
412  *
413  * This API returns a specific information of active(default) network profile.
414  * This is Sync API.
415  *
416  * @return       int - NET_ERR_NONE on success, negative values for errors
417  * @param[in]    none
418  * @param[out]   gateway        Gateway address of active(default) network profile.
419  */
420 EXPORT_API int net_get_active_gateway(net_addr_t *gateway)
421 {
422         __NETWORK_FUNC_ENTER__;
423
424         net_err_t Error = NET_ERR_NONE;
425         net_profile_info_t active_profile_info;
426         net_dev_info_t *net_info = NULL;
427
428         Error = __net_get_default_profile((void*)gateway, &active_profile_info);
429         if (Error != NET_ERR_NONE) {
430                 __NETWORK_FUNC_EXIT__;
431                 return Error;
432         }
433
434         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
435                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
436         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
437                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
438         else if (active_profile_info.profile_type == NET_DEVICE_ETHERNET)
439                 net_info = &active_profile_info.ProfileInfo.Ethernet.net_info;
440         else
441                 Error = NET_ERR_UNKNOWN;
442
443         if (net_info != NULL)
444                 memcpy(gateway, &net_info->GatewayAddr, sizeof(net_addr_t));
445
446         __NETWORK_FUNC_EXIT__;
447         return Error;
448 }
449
450 /**
451  * @fn  EXPORT_API int net_get_active_dns(net_addr_t *dns)
452  *
453  * This API returns a specific information of active(default) network profile.
454  * This is Sync API.
455  *
456  * @return       int - NET_ERR_NONE on success, negative values for errors
457  * @param[in]    none
458  * @param[out]   dns    DNS address of active(default) network profile.
459  */
460 EXPORT_API int net_get_active_dns(net_addr_t *dns)
461 {
462         __NETWORK_FUNC_ENTER__;
463
464         net_err_t Error = NET_ERR_NONE;
465         net_profile_info_t active_profile_info;
466         net_dev_info_t *net_info = NULL;
467
468         Error = __net_get_default_profile((void*)dns, &active_profile_info);
469         if (Error != NET_ERR_NONE) {
470                 __NETWORK_FUNC_EXIT__;
471                 return Error;
472         }
473
474         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
475                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
476         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
477                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
478         else if (active_profile_info.profile_type == NET_DEVICE_ETHERNET)
479                 net_info = &active_profile_info.ProfileInfo.Ethernet.net_info;
480         else
481                 Error = NET_ERR_UNKNOWN;
482
483         if (net_info != NULL)
484                 memcpy(dns, &net_info->DnsAddr[0], sizeof(net_addr_t));
485
486         __NETWORK_FUNC_EXIT__;
487         return Error;
488 }
489
490 /**
491  * @fn  EXPORT_API int net_get_active_essid(net_essid_t *essid)
492  *
493  * This API returns a specific information of active(default) network profile.
494  * This is Sync API.
495  *
496  * @return       int - NET_ERR_NONE on success, negative values for errors
497  * @param[in]    none
498  * @param[out]   essid  ESSID of active(default) network profile.
499  */
500 EXPORT_API int net_get_active_essid(net_essid_t *essid)
501 {
502         __NETWORK_FUNC_ENTER__;
503
504         net_err_t Error = NET_ERR_NONE;
505         net_profile_info_t active_profile_info;
506         net_wifi_profile_info_t *wlan_info = NULL;
507
508         Error = __net_get_default_profile((void*)essid, &active_profile_info);
509         if (Error != NET_ERR_NONE) {
510                 __NETWORK_FUNC_EXIT__;
511                 return Error;
512         }
513
514         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR) {
515                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Active(default) network is cellular type.\n");
516                 Error = NET_ERR_NO_SERVICE;
517         } else if (active_profile_info.profile_type == NET_DEVICE_ETHERNET) {
518                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Active(default) network is ethernet type.\n");
519                 Error = NET_ERR_NO_SERVICE;
520         } else if (active_profile_info.profile_type == NET_DEVICE_WIFI) {
521                 wlan_info = &active_profile_info.ProfileInfo.Wlan;
522                 memcpy(essid->essid, wlan_info->essid, NET_WLAN_ESSID_LEN+1);
523         } else
524                 Error = NET_ERR_UNKNOWN;
525
526         __NETWORK_FUNC_EXIT__;
527         return Error;
528 }
529
530 /**
531  * @fn  EXPORT_API int net_get_active_proxy(net_proxy_t *proxy)
532  *
533  * This API returns a specific information of active(default) network profile.
534  * This is Sync API.
535  *
536  * @return       int - NET_ERR_NONE on success, negative values for errors
537  * @param[in]    none
538  * @param[out]   proxy  Proxy of active(default) network profile.
539  */
540 EXPORT_API int net_get_active_proxy(net_proxy_t *proxy)
541 {
542         __NETWORK_FUNC_ENTER__;
543
544         net_err_t Error = NET_ERR_NONE;
545         net_profile_info_t active_profile_info;
546         net_dev_info_t *net_info = NULL;
547
548         Error = __net_get_default_profile((void*)proxy, &active_profile_info);
549         if (Error != NET_ERR_NONE) {
550                 __NETWORK_FUNC_EXIT__;
551                 return Error;
552         }
553
554         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
555                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
556         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
557                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
558         else if (active_profile_info.profile_type == NET_DEVICE_ETHERNET)
559                 net_info = &active_profile_info.ProfileInfo.Ethernet.net_info;
560         else
561                 Error = NET_ERR_UNKNOWN;
562
563         if (net_info != NULL)
564                 memcpy(proxy->proxy_addr, net_info->ProxyAddr, NET_PROXY_LEN_MAX+1);
565
566         __NETWORK_FUNC_EXIT__;
567         return Error;
568 }
569
570 /**
571  * @fn  EXPORT_API int net_is_connected(void)
572  *
573  * This function check's whether connection manager is connected or not
574  * This is Sync API.
575  *
576  * @return       int - TRUE if connected, else FALSE
577  * @param[in]    none
578  * @param[out]   none
579  */
580 EXPORT_API int net_is_connected(void)
581 {
582         char state[CONNMAN_MAX_BUFLEN] = ""; /** Possible value are "online", "offline" and "connected" */
583         net_err_t Error = NET_ERR_NONE;
584
585         __NETWORK_FUNC_ENTER__;
586         
587         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
588                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
589                 __NETWORK_FUNC_EXIT__;
590                 return NET_ERR_APP_NOT_REGISTERED;
591         }
592
593         if ((Error = _net_dbus_get_state(state)) != NET_ERR_NONE) {
594                 NETWORK_LOG(NETWORK_ERROR, "Error!!! failed to get state. Error [%s]\n",
595                                 _net_print_error(Error));
596                 __NETWORK_FUNC_EXIT__;
597                 return FALSE;
598         }
599
600         if ((strcmp(state, "online") == 0) || (strcmp(state, "connected") == 0)) {
601                 NETWORK_LOG(NETWORK_HIGH, "State [%s]\n", state);
602                 __NETWORK_FUNC_EXIT__;
603                 return TRUE; 
604         }
605
606         __NETWORK_FUNC_EXIT__;  
607         return FALSE;
608 }
609
610
611 /**
612  * @fn   EXPORT_API int net_get_network_status(net_service_type_t network_type, net_cm_network_status_t* pNetworkStatus)
613  *
614  * This function requests wifi/pdp network status 
615  * This is Sync API.
616  *
617  * @return       int - NET_ERR_NONE on success, negative values for errors
618  * @param[in]    net_service_type_t network_type - Network type (wlan/pdp/default), of whose status to be checked. 
619  * @param[out]   net_cm_network_status_t* pNetworkStatus - Status of the requested network.
620  */
621
622 EXPORT_API int net_get_network_status(net_device_t device_type, net_cm_network_status_t* network_status)
623 {
624         net_err_t Error = NET_ERR_NONE;
625
626         __NETWORK_FUNC_ENTER__;
627
628         if(g_atomic_int_get(&NetworkInfo.ref_count) == 0)
629         {
630                 NETWORK_LOG( NETWORK_ERROR, "Error!!! Application was not registered\n");
631                 __NETWORK_FUNC_EXIT__;
632                 return NET_ERR_APP_NOT_REGISTERED;
633         }
634         
635         if((Error = _net_dbus_get_network_status(device_type, network_status)) != NET_ERR_NONE)
636         {
637                 NETWORK_LOG( NETWORK_ERROR, "Error!!! failed to get network status. Error [%s]\n",  
638                                 _net_print_error(Error));
639                 __NETWORK_FUNC_EXIT__;
640                 return Error;
641         }
642         
643         __NETWORK_FUNC_EXIT__;  
644         return NET_ERR_NONE;
645 }
646
647 EXPORT_API int net_get_statistics(net_device_t device_type, net_statistics_type_e statistics_type, unsigned long long *size)
648 {
649         net_err_t Error = NET_ERR_NONE;
650
651         if ((Error = _net_dbus_get_statistics(device_type, statistics_type, size)) != NET_ERR_NONE )
652                 NETWORK_LOG(NETWORK_ERROR,
653                         "Error!!! Failed to get statistics info. error : [%s]\n",
654                         _net_print_error(Error));
655
656         return Error;
657 }
658
659 EXPORT_API int net_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
660 {
661         net_err_t Error = NET_ERR_NONE;
662
663         if ((Error = _net_dbus_set_statistics(device_type, statistics_type)) != NET_ERR_NONE )
664                 NETWORK_LOG(NETWORK_ERROR,
665                         "Error!!! Failed to set statistics info. error : [%s]\n",
666                         _net_print_error(Error));
667
668         return Error;
669 }
670
671 /*****************************************************************************
672  *      ConnMan Wi-Fi Client Interface Async Function Definition
673  *****************************************************************************/
674
675
676 /**
677  * @fn   EXPORT_API int net_open_connection_with_profile(const char *profile_name)
678  *
679  * This function request open connection for the given profile name.
680  * This is Async API.
681  *
682  * @return       int - NET_ERR_NONE on success, negative values for errors
683  * @param[in]    char *ProfileName - Profile Name to be connected
684  * @param[out]   none
685  */
686
687 EXPORT_API int net_open_connection_with_profile(const char *profile_name)
688 {
689         __NETWORK_FUNC_ENTER__;
690
691         net_err_t Error = NET_ERR_NONE;
692                 
693         NETWORK_LOG(NETWORK_HIGH, "ProfileName [%s] passed\n", profile_name);
694
695         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
696                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid ProfileName passed\n");
697                 __NETWORK_FUNC_EXIT__;
698                 return NET_ERR_INVALID_PARAM;
699         }
700
701         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
702                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
703                 __NETWORK_FUNC_EXIT__;
704                 return NET_ERR_APP_NOT_REGISTERED;
705         }
706
707         if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
708                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Request already in progress\n");
709                 __NETWORK_FUNC_EXIT__;
710                 return NET_ERR_IN_PROGRESS;
711         }
712
713         if (_net_dbus_is_pending_call_used() == TRUE) {
714                 NETWORK_LOG(NETWORK_ASSERT, "Error!! pending call already in progress\n");
715                 __NETWORK_FUNC_EXIT__;
716                 return NET_ERR_IN_PROGRESS;
717         }
718
719         request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
720         snprintf(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName,
721                         NET_PROFILE_NAME_LEN_MAX+1, "%s", profile_name);
722
723         if ((Error = _net_dbus_open_connection(profile_name)) != NET_ERR_NONE) {
724                 NETWORK_LOG(NETWORK_ERROR,
725                                 "Error!! Failed to request open connection, Error [%s]\n", 
726                                 _net_print_error(Error));
727
728                 if(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE)
729                         memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION],
730                                         0, sizeof(network_request_table_t));
731
732                 __NETWORK_FUNC_EXIT__;
733                 return Error;
734         }
735
736         NETWORK_LOG(NETWORK_HIGH, "Connect Request Success for ProfileName[%s]\n", profile_name);
737         __NETWORK_FUNC_EXIT__;  
738         return NET_ERR_NONE;
739 }
740
741 /**
742  * @fn   EXPORT_API int net_open_connection_with_preference(net_service_type_t service_type)
743  *
744  * This function request open connection for the given service type.
745  * This is Async API.
746  *
747  * @return       int - NET_ERR_NONE on success, negative values for errors
748  * @param[in]    net_service_type_t service_type - Service type to be connected
749  * @param[out]   none
750  */
751 EXPORT_API int net_open_connection_with_preference(net_service_type_t service_type)
752 {
753         __NETWORK_FUNC_ENTER__;
754
755         net_err_t Error = NET_ERR_NONE;
756         net_profile_name_t profile_name;
757         memset(&profile_name, 0, sizeof(net_profile_name_t));
758
759         if (service_type != NET_SERVICE_INTERNET &&
760             service_type != NET_SERVICE_MMS &&
761             service_type != NET_SERVICE_WAP) {
762                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Service Type passed\n");
763                 __NETWORK_FUNC_EXIT__;
764                 return NET_ERR_INVALID_PARAM;
765         }
766
767         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
768                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
769                 __NETWORK_FUNC_EXIT__;
770                 return NET_ERR_APP_NOT_REGISTERED;
771         }
772
773         if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
774                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Request already in progress\n");
775                 __NETWORK_FUNC_EXIT__;
776                 return NET_ERR_IN_PROGRESS;
777         }
778
779         if (_net_dbus_is_pending_call_used() == TRUE) {
780                 NETWORK_LOG(NETWORK_ASSERT, "Error!! pending call already in progress\n");
781                 __NETWORK_FUNC_EXIT__;
782                 return NET_ERR_IN_PROGRESS;
783         }
784
785         Error = _net_get_service_profile(service_type, &profile_name);
786         if (Error != NET_ERR_NONE) {
787                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Failed to find service\n");
788                 __NETWORK_FUNC_EXIT__;
789                 return Error;
790         }
791
792         request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
793         snprintf(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName,
794                         NET_PROFILE_NAME_LEN_MAX+1, "%s", profile_name.ProfileName);
795
796         if ((Error = _net_dbus_open_connection(profile_name.ProfileName)) != NET_ERR_NONE) {
797                 NETWORK_LOG(NETWORK_ERROR,
798                                 "Error!! Failed to request open connection, Error [%s]\n",
799                                 _net_print_error(Error));
800
801                 if(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE)
802                         memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION],
803                                         0, sizeof(network_request_table_t));
804
805                 __NETWORK_FUNC_EXIT__;
806                 return Error;
807         }
808
809         NETWORK_LOG(NETWORK_HIGH, "Connect Request Success for ProfileName[%s]\n",
810                         profile_name.ProfileName);
811         __NETWORK_FUNC_EXIT__;
812         return NET_ERR_NONE;
813 }
814
815 int net_open_connection_with_preference_ext(net_service_type_t service_type, net_profile_name_t *prof_name)
816 {
817         net_err_t Error = NET_ERR_NONE;
818         net_profile_name_t profile_name;
819         memset(&profile_name, 0, sizeof(net_profile_name_t));
820
821         if (service_type != NET_SERVICE_INTERNET &&
822             service_type != NET_SERVICE_MMS &&
823             service_type != NET_SERVICE_WAP) {
824                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Service Type passed\n");
825                 return NET_ERR_INVALID_PARAM;
826         }
827
828         if (prof_name == NULL) {
829                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid profile name passed\n");
830                 return NET_ERR_INVALID_PARAM;
831         }
832
833         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
834                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
835                 return NET_ERR_APP_NOT_REGISTERED;
836         }
837
838         if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
839                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Request already in progress\n");
840                 return NET_ERR_IN_PROGRESS;
841         }
842
843         if (_net_dbus_is_pending_call_used() == TRUE) {
844                 NETWORK_LOG(NETWORK_ASSERT, "Error!! pending call already in progress\n");
845                 __NETWORK_FUNC_EXIT__;
846                 return NET_ERR_IN_PROGRESS;
847         }
848
849         Error = _net_get_service_profile(service_type, &profile_name);
850         if (Error != NET_ERR_NONE) {
851                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Failed to find service\n");
852                 return Error;
853         }
854
855         request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
856         snprintf(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName,
857                         NET_PROFILE_NAME_LEN_MAX+1, "%s", profile_name.ProfileName);
858
859         if ((Error = _net_dbus_open_connection(profile_name.ProfileName)) != NET_ERR_NONE) {
860                 NETWORK_LOG(NETWORK_ERROR,
861                                 "Error!! Failed to request open connection, Error [%s]\n",
862                                 _net_print_error(Error));
863
864                 if(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE)
865                         memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION],
866                                         0, sizeof(network_request_table_t));
867
868                 return Error;
869         }
870
871         NETWORK_LOG(NETWORK_HIGH, "Connect Request Success for ProfileName[%s]\n",
872                         profile_name.ProfileName);
873
874         memcpy(prof_name, &profile_name, sizeof(net_profile_name_t));
875         return NET_ERR_NONE;
876 }
877
878 /**
879  * @fn   EXPORT_API int net_close_connection(const char *profile_name)
880  *
881  * This function requests close connection for the given profile name.
882  * This is Async API.
883  *
884  * @return       int - NET_ERR_NONE on success, negative values for errors
885  * @param[in]    char *profile_name - Connected profile Name
886  * @param[out]   none
887  */
888
889 EXPORT_API int net_close_connection(const char *profile_name)
890 {
891         __NETWORK_FUNC_ENTER__;
892         
893         net_err_t Error = NET_ERR_NONE;
894
895         NETWORK_LOG(NETWORK_HIGH, "ProfileName [%s] passed\n", profile_name);
896
897         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
898                  NETWORK_LOG(NETWORK_ERROR, "Error!! Invalid ProfileName parameter\n");
899                 __NETWORK_FUNC_EXIT__;
900                 return NET_ERR_INVALID_PARAM;
901         }
902
903         if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) {
904                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
905                 __NETWORK_FUNC_EXIT__;
906                 return NET_ERR_APP_NOT_REGISTERED;
907         }
908
909         if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE) {
910                 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Request already in progress\n");
911                 __NETWORK_FUNC_EXIT__;
912                 return NET_ERR_IN_PROGRESS;
913         }
914
915         if (_net_dbus_is_pending_call_used() == TRUE) {
916                 if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
917                         _net_dbus_clear_pending_call();
918                         memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION],
919                                                         0, sizeof(network_request_table_t));
920
921                 } else if (request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE) {
922                         _net_dbus_clear_pending_call();
923                         memset(&request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS],
924                                                         0, sizeof(network_request_table_t));
925                 } else {
926                         NETWORK_LOG(NETWORK_ASSERT, "Error!! pending call already in progress\n");
927                         __NETWORK_FUNC_EXIT__;
928                         return NET_ERR_IN_PROGRESS;
929                 }
930         }
931
932         request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag = TRUE;
933         snprintf(request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].ProfileName,
934                         NET_PROFILE_NAME_LEN_MAX+1, "%s", profile_name);
935
936         if ((Error = _net_dbus_close_connection(profile_name)) != NET_ERR_NONE) {
937                 NETWORK_LOG(NETWORK_ERROR,
938                                 "Error!! Failed to request close connection, Error [%s]\n", 
939                                 _net_print_error(Error));
940         
941                 if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE)
942                         memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION],
943                                         0, sizeof(network_request_table_t));
944
945                 __NETWORK_FUNC_EXIT__;
946                 return Error;
947         }
948         
949         __NETWORK_FUNC_EXIT__;  
950         return NET_ERR_NONE;
951 }
952
953 #ifdef __cplusplus
954 }
955 #endif /* __cplusplus */