apply FSL(Flora Software License)
[framework/connectivity/libnet-client.git] / src / network-cm-intf.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif /* __cplusplus */
22
23
24 /*****************************************************************************
25  *      Standard headers
26  *****************************************************************************/
27 #include <stdio.h> 
28 #include <errno.h> 
29 #include <stdlib.h> 
30 #include <string.h>
31 #include <glib.h>
32
33 #include <dbus/dbus.h> 
34
35
36 /*****************************************************************************
37  *      Platform headers
38  *****************************************************************************/
39
40 #include "network-internal.h"
41 #include "network-signal-handler.h"
42 #include "network-dbus-request.h"
43
44 /*****************************************************************************
45  *      Macros and Typedefs
46  *****************************************************************************/
47
48 /*****************************************************************************
49  *      Local Functions Declaration
50  *****************************************************************************/
51
52 static int __net_get_default_profile(void *param, net_profile_info_t *active_profile_info);
53
54 /*****************************************************************************
55  *      Global Functions
56  *****************************************************************************/
57
58 /*****************************************************************************
59  *      Extern Variables
60  *****************************************************************************/
61
62 extern network_request_table_t request_table[NETWORK_REQUEST_TYPE_MAX];
63
64 /*****************************************************************************
65  *      Global Variables
66  *****************************************************************************/
67
68 network_info_t NetworkInfo = {0, };
69
70 /*****************************************************************************
71  *      Local Functions Definition
72  *****************************************************************************/
73
74 static int __net_get_default_profile(void *param, net_profile_info_t *active_profile_info)
75 {
76         __NETWORK_FUNC_ENTER__;
77
78         net_err_t Error = NET_ERR_NONE;
79
80         if (NetworkInfo.ClientEventCb == NULL) {
81                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
82                 __NETWORK_FUNC_EXIT__;
83                 return NET_ERR_APP_NOT_REGISTERED;
84         }
85
86         if (param == NULL) {
87                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid parameter\n");
88                 __NETWORK_FUNC_EXIT__;
89                 return NET_ERR_INVALID_PARAM;
90         }
91
92         Error = _net_get_default_profile_info(active_profile_info);
93
94         if (Error != NET_ERR_NONE) {
95                 NETWORK_LOG(NETWORK_ERROR,
96                                 "Error!!! _net_get_default_profile_info() failed. Error [%s]\n",
97                                 _net_print_error(Error));
98
99                 __NETWORK_FUNC_EXIT__;
100                 return Error;
101         }
102
103         __NETWORK_FUNC_EXIT__;
104         return NET_ERR_NONE;
105 }
106
107 /*****************************************************************************
108  *      ConnMan Client Common Interface API Definition
109  *****************************************************************************/
110
111 /**
112  * @fn  EXPORT_API int net_register_client(net_event_cb_t event_cb, void *user_data)
113  *
114  * This function registers callback with the network client
115  * This is Sync API.
116  *
117  * @return       int - NET_ERR_NONE on success, negative values for errors
118  * @param[in]    net_event_cb_t event_cb - Pointer to callback function
119  *               void* user_data - Pointer to user data 
120  * @param[out]   none 
121  */
122 EXPORT_API int net_register_client(net_event_cb_t event_cb, void *user_data)
123 {
124         __NETWORK_FUNC_ENTER__;
125
126         net_err_t Error = NET_ERR_NONE;
127
128         if (event_cb == NULL) {
129                  NETWORK_LOG(NETWORK_ASSERT, "Error!! Invalid EventCb parameter\n");
130                 __NETWORK_FUNC_EXIT__;
131                 return NET_ERR_INVALID_PARAM;
132         }
133         
134         if (NetworkInfo.ClientEventCb != NULL) {
135                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application Already registered\n");
136                 __NETWORK_FUNC_EXIT__;
137                 return NET_ERR_APP_ALREADY_REGISTERED;
138         }
139
140         if (_net_mutex_init() != NET_ERR_NONE) {
141                 __NETWORK_FUNC_EXIT__;
142                 return NET_ERR_UNKNOWN;
143         }
144
145         Error = _net_register_signal();
146         if (Error != NET_ERR_NONE) {
147                 NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_register_signal() failed. Error [%s]\n",
148                                 _net_print_error(Error));
149                 _net_mutex_destroy();
150                 __NETWORK_FUNC_EXIT__;
151                 return Error;
152         }
153
154         NetworkInfo.ClientEventCb = event_cb;
155         NetworkInfo.user_data = user_data;
156         NetworkInfo.wifi_state = _net_get_wifi_state();
157         _net_init_service_state_table();
158
159         NETWORK_LOG(NETWORK_HIGH, "Client Register Successfully\n");
160
161         __NETWORK_FUNC_EXIT__;  
162         return NET_ERR_NONE;
163 }
164
165
166 /**
167  * @fn  EXPORT_API int net_deregister_client(void)
168  *
169  * This function deregisters with network client 
170  * This is Sync API.
171  *
172  * @return       int - NET_ERR_NONE on success, negative values for errors
173  * @param[in]    none
174  * @param[out]   none
175  */
176
177 EXPORT_API int net_deregister_client(void)
178 {
179         __NETWORK_FUNC_ENTER__;
180
181         net_err_t Error = NET_ERR_NONE;
182         
183         if (NetworkInfo.ClientEventCb == NULL) {
184                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
185                 __NETWORK_FUNC_EXIT__;
186                 return NET_ERR_APP_NOT_REGISTERED;
187         }
188
189         Error = _net_deregister_signal();       
190         if (Error != NET_ERR_NONE) {
191                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Failed to deregister signal\n");
192                 __NETWORK_FUNC_EXIT__;
193                 return Error;
194         }
195
196         _net_mutex_destroy();
197         _net_clear_request_table();
198
199         NetworkInfo.ClientEventCb = NULL;
200         NetworkInfo.user_data = NULL;
201         
202         NETWORK_LOG(NETWORK_HIGH, "Client De-Register Successfull\n");
203         
204         __NETWORK_FUNC_EXIT__;  
205         return NET_ERR_NONE;
206 }
207
208 /**
209  * @fn  EXPORT_API int net_get_active_net_info(net_profile_info_t *active_profile_info)
210  *
211  * This API returns the information of active(default) network profile.
212  * This is Sync API.
213  *
214  * @return       int - NET_ERR_NONE on success, negative values for errors
215  * @param[in]    none
216  * @param[out]   active_profile_info    The information of active(default) network profile.
217  */
218 EXPORT_API int net_get_active_net_info(net_profile_info_t *active_profile_info)
219 {
220         __NETWORK_FUNC_ENTER__;
221
222         net_err_t Error = NET_ERR_NONE;
223
224         Error = __net_get_default_profile((void*)active_profile_info, active_profile_info);
225
226         __NETWORK_FUNC_EXIT__;
227         return Error;
228 }
229
230 /**
231  * @fn  EXPORT_API int net_get_active_ipaddress(net_addr_t *ip_address)
232  *
233  * This API returns a specific information of active(default) network profile.
234  * This is Sync API.
235  *
236  * @return       int - NET_ERR_NONE on success, negative values for errors
237  * @param[in]    none
238  * @param[out]   ip_address     Ip address of active(default) network profile.
239  */
240 EXPORT_API int net_get_active_ipaddress(net_addr_t *ip_address)
241 {
242         __NETWORK_FUNC_ENTER__;
243
244         net_err_t Error = NET_ERR_NONE;
245         net_profile_info_t active_profile_info;
246         net_dev_info_t *net_info = NULL;
247
248         Error = __net_get_default_profile((void*)ip_address, &active_profile_info);
249         if (Error != NET_ERR_NONE) {
250                 __NETWORK_FUNC_EXIT__;
251                 return Error;
252         }
253
254         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
255                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
256         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
257                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
258         else
259                 Error = NET_ERR_UNKNOWN;
260
261         if (net_info != NULL)
262                 memcpy(ip_address, &net_info->IpAddr, sizeof(net_addr_t));
263
264         __NETWORK_FUNC_EXIT__;
265         return Error;
266 }
267
268 /**
269  * @fn  EXPORT_API int net_get_active_netmask(net_addr_t *netmask)
270  *
271  * This API returns a specific information of active(default) network profile.
272  * This is Sync API.
273  *
274  * @return       int - NET_ERR_NONE on success, negative values for errors
275  * @param[in]    none
276  * @param[out]   netmask        Netmask of active(default) network profile.
277  */
278 EXPORT_API int net_get_active_netmask(net_addr_t *netmask)
279 {
280         __NETWORK_FUNC_ENTER__;
281
282         net_err_t Error = NET_ERR_NONE;
283         net_profile_info_t active_profile_info;
284         net_dev_info_t *net_info = NULL;
285
286         Error = __net_get_default_profile((void*)netmask, &active_profile_info);
287         if (Error != NET_ERR_NONE) {
288                 __NETWORK_FUNC_EXIT__;
289                 return Error;
290         }
291
292         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
293                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
294         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
295                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
296         else
297                 Error = NET_ERR_UNKNOWN;
298
299         if (net_info != NULL)
300                 memcpy(netmask, &net_info->SubnetMask, sizeof(net_addr_t));
301
302         __NETWORK_FUNC_EXIT__;
303         return Error;
304 }
305
306 /**
307  * @fn  EXPORT_API int net_get_active_gateway(net_addr_t *gateway)
308  *
309  * This API returns a specific information of active(default) network profile.
310  * This is Sync API.
311  *
312  * @return       int - NET_ERR_NONE on success, negative values for errors
313  * @param[in]    none
314  * @param[out]   gateway        Gateway address of active(default) network profile.
315  */
316 EXPORT_API int net_get_active_gateway(net_addr_t *gateway)
317 {
318         __NETWORK_FUNC_ENTER__;
319
320         net_err_t Error = NET_ERR_NONE;
321         net_profile_info_t active_profile_info;
322         net_dev_info_t *net_info = NULL;
323
324         Error = __net_get_default_profile((void*)gateway, &active_profile_info);
325         if (Error != NET_ERR_NONE) {
326                 __NETWORK_FUNC_EXIT__;
327                 return Error;
328         }
329
330         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
331                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
332         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
333                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
334         else
335                 Error = NET_ERR_UNKNOWN;
336
337         if (net_info != NULL)
338                 memcpy(gateway, &net_info->GatewayAddr, sizeof(net_addr_t));
339
340         __NETWORK_FUNC_EXIT__;
341         return Error;
342 }
343
344 /**
345  * @fn  EXPORT_API int net_get_active_dns(net_addr_t *dns)
346  *
347  * This API returns a specific information of active(default) network profile.
348  * This is Sync API.
349  *
350  * @return       int - NET_ERR_NONE on success, negative values for errors
351  * @param[in]    none
352  * @param[out]   dns    DNS address of active(default) network profile.
353  */
354 EXPORT_API int net_get_active_dns(net_addr_t *dns)
355 {
356         __NETWORK_FUNC_ENTER__;
357
358         net_err_t Error = NET_ERR_NONE;
359         net_profile_info_t active_profile_info;
360         net_dev_info_t *net_info = NULL;
361
362         Error = __net_get_default_profile((void*)dns, &active_profile_info);
363         if (Error != NET_ERR_NONE) {
364                 __NETWORK_FUNC_EXIT__;
365                 return Error;
366         }
367
368         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
369                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
370         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
371                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
372         else
373                 Error = NET_ERR_UNKNOWN;
374
375         if (net_info != NULL)
376                 memcpy(dns, &net_info->DnsAddr[0], sizeof(net_addr_t));
377
378         __NETWORK_FUNC_EXIT__;
379         return Error;
380 }
381
382 /**
383  * @fn  EXPORT_API int net_get_active_essid(net_essid_t *essid)
384  *
385  * This API returns a specific information of active(default) network profile.
386  * This is Sync API.
387  *
388  * @return       int - NET_ERR_NONE on success, negative values for errors
389  * @param[in]    none
390  * @param[out]   essid  ESSID of active(default) network profile.
391  */
392 EXPORT_API int net_get_active_essid(net_essid_t *essid)
393 {
394         __NETWORK_FUNC_ENTER__;
395
396         net_err_t Error = NET_ERR_NONE;
397         net_profile_info_t active_profile_info;
398         net_wifi_profile_info_t *wlan_info = NULL;
399
400         Error = __net_get_default_profile((void*)essid, &active_profile_info);
401         if (Error != NET_ERR_NONE) {
402                 __NETWORK_FUNC_EXIT__;
403                 return Error;
404         }
405
406         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR) {
407                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Active(default) network is cellular type.\n");
408                 Error = NET_ERR_NO_SERVICE;
409         } else if (active_profile_info.profile_type == NET_DEVICE_WIFI) {
410                 wlan_info = &active_profile_info.ProfileInfo.Wlan;
411                 memcpy(essid->essid, wlan_info->essid, NET_WLAN_ESSID_LEN+1);
412         } else
413                 Error = NET_ERR_UNKNOWN;
414
415         __NETWORK_FUNC_EXIT__;
416         return Error;
417 }
418
419 /**
420  * @fn  EXPORT_API int net_get_active_proxy(net_proxy_t *proxy)
421  *
422  * This API returns a specific information of active(default) network profile.
423  * This is Sync API.
424  *
425  * @return       int - NET_ERR_NONE on success, negative values for errors
426  * @param[in]    none
427  * @param[out]   proxy  Proxy of active(default) network profile.
428  */
429 EXPORT_API int net_get_active_proxy(net_proxy_t *proxy)
430 {
431         __NETWORK_FUNC_ENTER__;
432
433         net_err_t Error = NET_ERR_NONE;
434         net_profile_info_t active_profile_info;
435         net_dev_info_t *net_info = NULL;
436
437         Error = __net_get_default_profile((void*)proxy, &active_profile_info);
438         if (Error != NET_ERR_NONE) {
439                 __NETWORK_FUNC_EXIT__;
440                 return Error;
441         }
442
443         if (active_profile_info.profile_type == NET_DEVICE_CELLULAR)
444                 net_info = &active_profile_info.ProfileInfo.Pdp.net_info;
445         else if (active_profile_info.profile_type == NET_DEVICE_WIFI)
446                 net_info = &active_profile_info.ProfileInfo.Wlan.net_info;
447         else
448                 Error = NET_ERR_UNKNOWN;
449
450         if (net_info != NULL)
451                 memcpy(proxy->proxy_addr, net_info->ProxyAddr, NET_PROXY_LEN_MAX+1);
452
453         __NETWORK_FUNC_EXIT__;
454         return Error;
455 }
456
457 /**
458  * @fn  EXPORT_API int net_is_connected(void)
459  *
460  * This function check's whether connection manager is connected or not
461  * This is Sync API.
462  *
463  * @return       int - TRUE if connected, else FALSE
464  * @param[in]    none
465  * @param[out]   none
466  */
467 EXPORT_API int net_is_connected(void)
468 {
469         char state[CONNMAN_MAX_BUFLEN] = ""; /** Possible value are "online", "offline" and "connected" */
470         net_err_t Error = NET_ERR_NONE;
471
472         __NETWORK_FUNC_ENTER__;
473         
474         if (NetworkInfo.ClientEventCb == NULL) {
475                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
476                 __NETWORK_FUNC_EXIT__;
477                 return NET_ERR_APP_NOT_REGISTERED;
478         }
479
480         if ((Error = _net_dbus_get_state(state)) != NET_ERR_NONE) {
481                 NETWORK_LOG(NETWORK_ERROR, "Error!!! failed to get state. Error [%s]\n",
482                                 _net_print_error(Error));
483                 __NETWORK_FUNC_EXIT__;
484                 return FALSE;
485         }
486
487         if ((strcmp(state, "online") == 0) || (strcmp(state, "connected") == 0)) {
488                 NETWORK_LOG(NETWORK_HIGH, "State [%s]\n", state);
489                 __NETWORK_FUNC_EXIT__;
490                 return TRUE; 
491         }
492
493         __NETWORK_FUNC_EXIT__;  
494         return FALSE;
495 }
496
497
498 /**
499  * @fn   EXPORT_API int net_get_network_status(net_service_type_t network_type, net_cm_network_status_t* pNetworkStatus)
500  *
501  * This function requests wifi/pdp network status 
502  * This is Sync API.
503  *
504  * @return       int - NET_ERR_NONE on success, negative values for errors
505  * @param[in]    net_service_type_t network_type - Network type (wlan/pdp/default), of whose status to be checked. 
506  * @param[out]   net_cm_network_status_t* pNetworkStatus - Status of the requested network.
507  */
508
509 EXPORT_API int net_get_network_status(net_device_t device_type, net_cm_network_status_t* network_status)
510 {
511         net_err_t Error = NET_ERR_NONE;
512
513         __NETWORK_FUNC_ENTER__;
514
515         if(NetworkInfo.ClientEventCb == NULL)
516         {
517                 NETWORK_LOG( NETWORK_ERROR, "Error!!! Application was not registered\n");
518                 __NETWORK_FUNC_EXIT__;
519                 return NET_ERR_APP_NOT_REGISTERED;
520         }
521         
522         if((Error = _net_dbus_get_network_status(device_type, network_status)) != NET_ERR_NONE)
523         {
524                 NETWORK_LOG( NETWORK_ERROR, "Error!!! failed to get network status. Error [%s]\n",  
525                                 _net_print_error(Error));
526                 __NETWORK_FUNC_EXIT__;
527                 return Error;
528         }
529         
530         __NETWORK_FUNC_EXIT__;  
531         return NET_ERR_NONE;
532 }
533
534
535 /*****************************************************************************
536  *      ConnMan Wi-Fi Client Interface Async Function Definition
537  *****************************************************************************/
538
539
540 /**
541  * @fn   EXPORT_API int net_open_connection_with_profile(const char *profile_name)
542  *
543  * This function request open connection for the given profile name.
544  * This is Async API.
545  *
546  * @return       int - NET_ERR_NONE on success, negative values for errors
547  * @param[in]    char *ProfileName - Profile Name to be connected
548  * @param[out]   none
549  */
550
551 EXPORT_API int net_open_connection_with_profile(const char *profile_name)
552 {
553         __NETWORK_FUNC_ENTER__;
554
555         net_err_t Error = NET_ERR_NONE;
556                 
557         NETWORK_LOG(NETWORK_HIGH, "ProfileName [%s] passed\n", profile_name);
558
559         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
560                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid ProfileName passed\n");
561                 __NETWORK_FUNC_EXIT__;
562                 return NET_ERR_INVALID_PARAM;
563         }
564
565         if (NetworkInfo.ClientEventCb == NULL) {
566                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
567                 __NETWORK_FUNC_EXIT__;
568                 return NET_ERR_APP_NOT_REGISTERED;
569         }
570         
571         if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
572                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Request already in progress\n");
573                 __NETWORK_FUNC_EXIT__;
574                 return NET_ERR_INVALID_OPERATION;
575         }
576         
577         request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
578         snprintf(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName,
579                         NET_PROFILE_NAME_LEN_MAX+1, "%s", profile_name);
580
581         if ((Error = _net_dbus_open_connection(profile_name)) != NET_ERR_NONE) {
582                 NETWORK_LOG(NETWORK_ERROR,
583                                 "Error!! Failed to request open connection, Error [%s]\n", 
584                                 _net_print_error(Error));
585
586                 if(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE)
587                         memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION],
588                                         0, sizeof(network_request_table_t));
589
590                 __NETWORK_FUNC_EXIT__;
591                 return Error;
592         }
593
594         NETWORK_LOG(NETWORK_HIGH, "Connect Request Success for ProfileName[%s]\n", profile_name);
595         __NETWORK_FUNC_EXIT__;  
596         return NET_ERR_NONE;
597 }
598
599 /**
600  * @fn   EXPORT_API int net_open_connection_with_preference(net_service_type_t service_type)
601  *
602  * This function request open connection for the given service type.
603  * This is Async API.
604  *
605  * @return       int - NET_ERR_NONE on success, negative values for errors
606  * @param[in]    net_service_type_t service_type - Service type to be connected
607  * @param[out]   none
608  */
609 EXPORT_API int net_open_connection_with_preference(net_service_type_t service_type)
610 {
611         __NETWORK_FUNC_ENTER__;
612
613         net_err_t Error = NET_ERR_NONE;
614         net_profile_name_t profile_name;
615         memset(&profile_name, 0, sizeof(net_profile_name_t));
616
617         if (service_type != NET_SERVICE_INTERNET &&
618             service_type != NET_SERVICE_MMS &&
619             service_type != NET_SERVICE_WAP) {
620                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Service Type passed\n");
621                 __NETWORK_FUNC_EXIT__;
622                 return NET_ERR_INVALID_PARAM;
623         }
624
625         if (NetworkInfo.ClientEventCb == NULL) {
626                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
627                 __NETWORK_FUNC_EXIT__;
628                 return NET_ERR_APP_NOT_REGISTERED;
629         }
630
631         if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
632                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Request already in progress\n");
633                 __NETWORK_FUNC_EXIT__;
634                 return NET_ERR_INVALID_OPERATION;
635         }
636
637         Error = _net_get_service_profile(service_type, &profile_name);
638         if (Error != NET_ERR_NONE) {
639                 NETWORK_LOG(NETWORK_ASSERT, "Error!! Failed to find service\n");
640                 __NETWORK_FUNC_EXIT__;
641                 return Error;
642         }
643
644         request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
645         snprintf(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName,
646                         NET_PROFILE_NAME_LEN_MAX+1, "%s", profile_name.ProfileName);
647
648         if ((Error = _net_dbus_open_connection(profile_name.ProfileName)) != NET_ERR_NONE) {
649                 NETWORK_LOG(NETWORK_ERROR,
650                                 "Error!! Failed to request open connection, Error [%s]\n",
651                                 _net_print_error(Error));
652
653                 if(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE)
654                         memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION],
655                                         0, sizeof(network_request_table_t));
656
657                 __NETWORK_FUNC_EXIT__;
658                 return Error;
659         }
660
661         NETWORK_LOG(NETWORK_HIGH, "Connect Request Success for ProfileName[%s]\n",
662                         profile_name.ProfileName);
663         __NETWORK_FUNC_EXIT__;
664         return NET_ERR_NONE;
665 }
666
667 /**
668  * @fn   EXPORT_API int net_close_connection(const char *profile_name)
669  *
670  * This function requests close connection for the given profile name.
671  * This is Async API.
672  *
673  * @return       int - NET_ERR_NONE on success, negative values for errors
674  * @param[in]    char *profile_name - Connected profile Name
675  * @param[out]   none
676  */
677
678 EXPORT_API int net_close_connection(const char *profile_name)
679 {
680         __NETWORK_FUNC_ENTER__;
681         
682         net_err_t Error = NET_ERR_NONE;
683
684         NETWORK_LOG(NETWORK_HIGH, "ProfileName [%s] passed\n", profile_name);
685
686         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
687                  NETWORK_LOG(NETWORK_ERROR, "Error!! Invalid ProfileName parameter\n");
688                 __NETWORK_FUNC_EXIT__;
689                 return NET_ERR_INVALID_PARAM;
690         }
691
692         if (NetworkInfo.ClientEventCb == NULL) {
693                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
694                 __NETWORK_FUNC_EXIT__;
695                 return NET_ERR_APP_NOT_REGISTERED;
696         }
697         
698         if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE) {
699                 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Request already in progress\n");
700                 __NETWORK_FUNC_EXIT__;
701                 return NET_ERR_INVALID_OPERATION;
702         }
703         
704         request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag = TRUE;
705         snprintf(request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].ProfileName,
706                         NET_PROFILE_NAME_LEN_MAX+1, "%s", profile_name);
707
708         if ((Error = _net_dbus_close_connection(profile_name)) != NET_ERR_NONE) {
709                 NETWORK_LOG(NETWORK_ERROR,
710                                 "Error!! Failed to request close connection, Error [%s]\n", 
711                                 _net_print_error(Error));
712         
713                 if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE)
714                         memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION],
715                                         0, sizeof(network_request_table_t));
716
717                 __NETWORK_FUNC_EXIT__;
718                 return Error;
719         }
720         
721         __NETWORK_FUNC_EXIT__;  
722         return NET_ERR_NONE;
723 }
724
725 #ifdef __cplusplus
726 }
727 #endif /* __cplusplus */