3.0 migration
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginConnManWrapper.cpp
1 /*
2  * Copyright (c) 2014 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 <errno.h>
18 #include <glib.h>
19 #include "MmsPluginConnManWrapper.h"
20 #include "MmsPluginDebug.h"
21 #include "MmsPluginHttp.h"
22 #include "net_connection.h"
23 #include "MmsPluginUtil.h"
24
25 #define MMS_CONTEXT_INVOKE_WAIT_TIME    30
26 #define MMS_CONNECTION_API_WAIT_TIME    420
27
28 static Mutex g_mx;
29 static CndVar g_cv;
30 static connection_h g_connection = NULL;
31 static connection_profile_h g_profile = NULL;
32
33 void __connection_profile_print(connection_profile_h profile)
34 {
35         int ret;
36         char *profile_id = NULL;
37         char *profile_name = NULL;
38         char *interface_name = NULL;
39         char *ip_address = NULL;
40         char *subnet_mask = NULL;
41         char *gateway_address = NULL;
42         char *dns_address = NULL;
43         char *proxy_address = NULL;
44         char *apn = NULL;
45         char *user_name = NULL;
46         char *password = NULL;
47         char *home_url = NULL;
48         bool is_roaming;
49
50         connection_profile_type_e profile_type;
51         connection_profile_state_e profile_state;
52         connection_ip_config_type_e ip_type = CONNECTION_IP_CONFIG_TYPE_NONE;
53         connection_proxy_type_e proxy_type;
54         connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
55         connection_cellular_auth_type_e auth_type = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
56
57         MSG_DEBUG("**************************************************************************************************");
58         ret = connection_profile_get_id(profile, &profile_id);
59         MSG_DEBUG("return value of connection_profile_get_id [%d]", ret);
60         MSG_SEC_INFO("Profile Id = [%s]", profile_id);
61
62         ret = connection_profile_get_name(profile, &profile_name);
63         MSG_SEC_INFO("Profile Name = [%s]", profile_name);
64
65         ret = connection_profile_get_type(profile, &profile_type);
66
67         if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
68                 MSG_SEC_INFO("Profile Type = [CELLULAR]");
69         } else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
70                 MSG_SEC_INFO("Profile Type = [WIFI]");
71         } else if (profile_type == CONNECTION_PROFILE_TYPE_ETHERNET) {
72                 MSG_SEC_INFO("Profile Type = [ETHERNET]");
73         } else if (profile_type == CONNECTION_PROFILE_TYPE_BT) {
74                 MSG_SEC_INFO("Profile Type = [BT]");
75         } else {
76                 MSG_SEC_INFO("Profile Type = Unknown [%d]", profile_type);
77         }
78
79         ret = connection_profile_get_network_interface_name(profile, &interface_name);
80         MSG_SEC_INFO("Profile Interface Name = [%s]", interface_name);
81
82         ret = connection_profile_get_state(profile, &profile_state);
83         if (profile_state == CONNECTION_PROFILE_STATE_DISCONNECTED) {
84                 MSG_SEC_INFO("Profile State = [DISCONNECTED]");
85         } else if (profile_state == CONNECTION_PROFILE_STATE_ASSOCIATION) {
86                 MSG_SEC_INFO("Profile State = [ASSOCIATION]");
87         } else if (profile_state == CONNECTION_PROFILE_STATE_CONFIGURATION) {
88                 MSG_SEC_INFO("Profile State = [CONFIGURATION]");
89         } else if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED) {
90                 MSG_SEC_INFO("Profile State = [CONNECTED]");
91         } else {
92                 MSG_SEC_INFO("Profile State = Unknown [%d]", profile_state);
93         }
94
95         ret = connection_profile_get_ip_config_type(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_type);
96         MSG_SEC_INFO("Profile Ip Config Type = [%d]", ip_type);
97
98         ret = connection_profile_get_ip_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_address);
99         MSG_SEC_INFO("Profile Ip Address = [%s]", ip_address);
100
101         ret = connection_profile_get_subnet_mask(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &subnet_mask);
102         MSG_SEC_INFO("Profile Subnet Mask = [%s]", subnet_mask);
103
104         ret = connection_profile_get_gateway_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &gateway_address);
105         MSG_SEC_INFO("Profile Gateway Address = [%s]", gateway_address);
106
107         ret = connection_profile_get_dns_address(profile, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &dns_address);
108         MSG_SEC_INFO("Profile Dns Address = [%s]", dns_address);
109
110         ret = connection_profile_get_proxy_type(profile, &proxy_type);
111         MSG_SEC_INFO("Profile Proxy Type = [%d]", proxy_type);
112
113         ret = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
114         MSG_SEC_INFO("Profile Proxy Address = [%s]", proxy_address);
115
116         ret = connection_profile_get_cellular_service_type(profile, &service_type);
117         if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) {
118                 MSG_SEC_INFO("Profile Service Type = [INTERNET]");
119         } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) {
120                 MSG_SEC_INFO("Profile Service Type = [MMS]");
121         } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET) {
122                 MSG_SEC_INFO("Profile Service Type = [PREPAID_INTERNET]");
123         } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS) {
124                 MSG_SEC_INFO("Profile Service Type = [PREPAID_MMS]");
125         } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING) {
126                 MSG_SEC_INFO("Profile Service Type = [TETHERING]");
127         } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION) {
128                 MSG_SEC_INFO("Profile Service Type = [APPLICATION]");
129         } else {
130                 MSG_SEC_INFO("Profile Service Type = [Unknown][%d]", service_type);
131         }
132
133         ret = connection_profile_get_cellular_apn(profile, &apn);
134         MSG_SEC_INFO("Profile Apn = [%s]", apn);
135
136         ret = connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password);
137         MSG_SEC_INFO("Profile Auth Type = [%d]", &auth_type);
138         MSG_SEC_INFO("Profile Auth Name = [%s]", &user_name);
139         MSG_SEC_INFO("Profile Auth Passward = [%s]", &password);
140
141         ret = connection_profile_get_cellular_home_url(profile, &home_url);
142         MSG_SEC_INFO("Profile Home Url = [%s]", home_url);
143
144         ret = connection_profile_is_cellular_roaming(profile, &is_roaming);
145         MSG_SEC_INFO("Profile Roaming = [%d]", is_roaming);
146         MSG_DEBUG("**************************************************************************************************");
147
148         MSG_FREE(profile_id);
149         MSG_FREE(profile_name);
150         MSG_FREE(interface_name);
151         MSG_FREE(ip_address);
152         MSG_FREE(subnet_mask);
153         MSG_FREE(gateway_address);
154         MSG_FREE(dns_address);
155         MSG_FREE(proxy_address);
156         MSG_FREE(apn);
157         MSG_FREE(user_name);
158         MSG_FREE(password);
159         MSG_FREE(home_url);
160 }
161
162 static void __connection_type_changed_cb(connection_type_e type, void* user_data)
163 {
164         MSG_INFO("Type changed callback, connection type : %d", type);
165 }
166
167 static void __connection_ip_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
168 {
169         MSG_INFO("IP changed callback, IPv4 address : %s, IPv6 address : %s",
170                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
171 }
172
173 static void __connection_proxy_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
174 {
175         MSG_INFO("Proxy changed callback, IPv4 address : %s, IPv6 address : %s",
176                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
177 }
178
179 static void __connection_profile_opened_cb(connection_error_e result, void* user_data)
180 {
181         if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS)
182                 MSG_INFO("Connection open Succeeded [%d]", result);
183         else
184                 MSG_ERR("Connection open Failed, err : %d", result);
185
186         MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
187
188         cmAgent->connection_profile_open_callback(result, user_data);
189 }
190
191 static void __connection_profile_closed_cb(connection_error_e result, void* user_data)
192 {
193         if (result ==  CONNECTION_ERROR_NONE)
194                 MSG_INFO("Connection close Succeeded");
195         else
196                 MSG_ERR("Connection close Failed, err : %d", result);
197
198         MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
199
200         cmAgent->connection_profile_close_callback(result, user_data);
201 }
202
203
204 void __connection_profile_state_changed_cb(connection_profile_state_e state, void* user_data)
205 {
206         MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
207
208         cmAgent->connection_profile_state_changed_cb(state, user_data);
209
210 }
211
212 static gboolean __connection_create(void *pVoid)
213 {
214         MSG_BEGIN();
215
216         bool ret = false;
217         bool *ret_val = (bool *)pVoid;
218
219         if (g_connection) {
220                 MSG_INFO("connection already exist");
221                 ret = true;
222         } else {
223                 int err = connection_create(&g_connection);
224
225                 if (CONNECTION_ERROR_NONE == err) {
226
227                         connection_cellular_state_e cellular_state;
228                         connection_type_e net_state;
229
230                         err = connection_get_cellular_state(g_connection, &cellular_state);
231
232                         err = connection_get_type(g_connection, &net_state);
233
234                         if (cellular_state == CONNECTION_CELLULAR_STATE_AVAILABLE
235                                 || cellular_state == CONNECTION_CELLULAR_STATE_CONNECTED) {
236
237                                 MSG_INFO("Client registration success [%p], cellular_state [%d], net_state [%d]", g_connection, cellular_state, net_state);
238
239                                 err = connection_set_type_changed_cb(g_connection, __connection_type_changed_cb, NULL);
240
241                                 err = connection_set_ip_address_changed_cb(g_connection, __connection_ip_changed_cb, NULL);
242
243                                 err = connection_set_proxy_address_changed_cb(g_connection, __connection_proxy_changed_cb, NULL);
244
245                                 ret = true;
246                         } else {
247
248                                 MSG_INFO("Client registration Failed,  cellular state [%d], net_state [%d]", cellular_state, net_state);
249                                 connection_destroy(g_connection);
250                                 g_connection = NULL;
251                         }
252
253                 } else {
254                         MSG_WARN("Client registration failed %d", err);
255                 }
256         }
257
258         if (ret_val) {
259                 *ret_val = ret;
260         }
261
262         MSG_END();
263         return FALSE;
264 }
265
266 static gboolean __connection_destroy(void *pVoid)
267 {
268         MSG_BEGIN();
269
270         int rv;
271
272         if (g_connection != NULL) {
273                 rv = connection_destroy(g_connection);
274                 g_connection = NULL;
275                 MSG_INFO("connection destory !!");
276         } else {
277                 MSG_ERR("Cannot connection destroy : Handle is NULL");
278                 rv = CONNECTION_ERROR_INVALID_OPERATION;
279         }
280
281         MSG_DEBUG("return value of connection destroy [%d]", rv);
282
283         MSG_END();
284         return FALSE;
285 }
286
287 static gboolean __connection_profile_open(void *pVoid)
288 {
289         MSG_BEGIN();
290
291         int netOpenResult = MSG_CM_ERR_NONE;
292         int *ret_val = (int *)pVoid;
293         int err;
294
295         if (g_profile) {
296                 MSG_WARN("connection profile Already exist!!, It will destroy");
297                 connection_profile_unset_state_changed_cb(g_profile);
298                 connection_profile_destroy(g_profile);
299                 g_profile = NULL;
300         }
301
302         err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &g_profile);
303
304         if (err != CONNECTION_ERROR_NONE) {
305                 MSG_ERR("connection_get_default_cellular_service_profile Failed!! [%d]", err);
306                 netOpenResult = MSG_CM_ERR_UNKNOWN;
307         } else {
308
309                 err = connection_profile_set_state_changed_cb(g_profile, __connection_profile_state_changed_cb, g_profile);
310
311                 if (connection_open_profile(g_connection, g_profile, __connection_profile_opened_cb, NULL) != CONNECTION_ERROR_NONE) {
312                         MSG_ERR("Connection open Failed!!");
313                         netOpenResult = MSG_CM_ERR_UNKNOWN;
314                 }
315
316
317         }
318
319         if (ret_val) {
320                 *ret_val = netOpenResult;
321                 MSG_DEBUG("[%d]", netOpenResult);
322         }
323
324         MSG_END();
325
326         return FALSE;
327 }
328
329 static gboolean __connection_profile_close(void *pVoid)
330 {
331         MSG_BEGIN();
332
333         int netOpenResult = MSG_CM_ERR_NONE;
334
335         int *ret_val = (int *)pVoid;
336
337         if (g_profile) {
338                 connection_profile_unset_state_changed_cb(g_profile);
339
340                 if (connection_close_profile(g_connection, g_profile, __connection_profile_closed_cb, NULL) != CONNECTION_ERROR_NONE) {
341                         MSG_ERR("Connection close Failed!!");
342                         netOpenResult = MSG_CM_ERR_UNKNOWN;
343                 }
344
345                 connection_profile_destroy(g_profile);
346                 g_profile = NULL;
347         }
348
349         if (ret_val) {
350                 *ret_val = netOpenResult;
351         }
352
353         MSG_END();
354
355         return FALSE;
356 }
357
358
359 void context_invoke_end_cb(gpointer data)
360 {
361         g_mx.lock();
362
363         MSG_INFO("@@ SIGNAL @@");
364
365         g_cv.signal();
366
367         g_mx.unlock();
368 }
369
370 /*
371  * Network api should run at g_main_loop to receive callback
372  * */
373 void context_invoke(GSourceFunc func, void *ret)
374 {
375         MSG_BEGIN();
376
377         int time_ret = 0;
378
379         g_mx.lock();
380
381         g_main_context_invoke_full(NULL, G_PRIORITY_DEFAULT, func, ret,  context_invoke_end_cb);
382
383         MSG_INFO("@@ WAIT @@");
384
385         time_ret = g_cv.timedwait(g_mx.pMutex(), MMS_CONTEXT_INVOKE_WAIT_TIME);
386
387         g_mx.unlock();
388
389         if (time_ret == ETIMEDOUT) {
390                 MSG_INFO("@@ WAKE by timeout@@");
391         } else {
392                 MSG_INFO("@@ WAKE by signal@@");
393         }
394
395         MSG_END();
396 }
397
398 MmsPluginCmAgent *MmsPluginCmAgent::pInstance = NULL;
399
400 MmsPluginCmAgent *MmsPluginCmAgent::instance()
401 {
402         if (!pInstance)
403                 pInstance = new MmsPluginCmAgent();
404
405         return pInstance;
406 }
407
408 MmsPluginCmAgent::MmsPluginCmAgent()
409 {
410         MSG_BEGIN();
411
412         isCmOpened = false;
413
414         home_url = NULL;
415         interface_name = NULL;
416         proxy_address = NULL;
417         MSG_END();
418 }
419
420 MmsPluginCmAgent::~MmsPluginCmAgent()
421 {
422         MSG_FREE(home_url);
423         MSG_FREE(interface_name);
424         MSG_FREE(proxy_address);
425 }
426
427 bool MmsPluginCmAgent::open()
428 {
429         MSG_BEGIN();
430
431         int netOpenResult = MSG_CM_ERR_NONE;
432         int bConnection = false;
433         int time_ret = 0;
434         lock();
435
436         //create connection
437         context_invoke(__connection_create, &bConnection);
438
439         if (bConnection == false || g_connection == NULL) {
440                 MSG_ERR("Failed __connection_create");
441                 goto __ERR_RETURN;
442         }
443
444         if (g_profile) {
445                 MSG_WARN("connection profile already exist");
446                 //TODO:: get data;
447                 //goto __RETURN;
448         }
449
450         waitProfileOpen = true;
451
452         context_invoke(__connection_profile_open, &netOpenResult);
453
454         if (netOpenResult != MSG_CM_ERR_NONE) {
455                 MSG_ERR("Failed __connection_profile_open. [%d]", netOpenResult);
456                 goto __ERR_RETURN;
457         }
458
459         MSG_INFO("## WAITING UNTIL __connection_profile_state CONNECT. ##");
460
461 //      cv.wait(mx.pMutex());
462 //      MSG_INFO("## WAKE by SIGNAL ##");
463
464         time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME); // isCmOpened will changed by processCBdatas
465
466         if (time_ret == ETIMEDOUT) {
467                 MSG_WARN("## WAKE by timeout ##");
468         } else {
469                 MSG_INFO("## WAKE by SIGNAL ##");
470         }
471
472         if(isCmOpened == false) {
473                 MSG_WARN("");
474                 goto __ERR_RETURN;
475         }
476
477 //__RETURN:
478         unlock();
479         MSG_END();
480         return isCmOpened;
481
482 __ERR_RETURN:
483         context_invoke(__connection_profile_close, NULL);
484         context_invoke( __connection_destroy, NULL);
485         unlock();
486         MSG_END();
487         return isCmOpened;
488 }
489
490
491 void MmsPluginCmAgent::close()
492 {
493         MSG_BEGIN();
494
495         lock();
496
497         int netOpenResult = MSG_CM_ERR_NONE;
498         int time_ret = 0;
499
500         isCmOpened = false;
501
502         if (g_profile == NULL) {
503                 MSG_INFO("connection profile is NULL");
504                 goto __RETURN;
505         }
506
507         context_invoke(__connection_profile_close, &netOpenResult);
508
509         if (netOpenResult != MSG_CM_ERR_NONE) {
510                 MSG_ERR("Failed __connection_profile_close. [%d]", netOpenResult);
511                 goto __RETURN;
512         }
513
514         MSG_INFO("## WAITING UNTIL connection_profile_close_callback ##");
515
516         time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME);
517
518         if (time_ret == ETIMEDOUT) {
519                 MSG_WARN("## WAKE by timeout ##");
520         } else {
521                 MSG_INFO("## WAKE by SIGNAL ##");
522         }
523
524
525 __RETURN:
526         if (g_connection)
527                 context_invoke(__connection_destroy, NULL);
528
529         g_profile = NULL;
530         g_connection = NULL;
531
532         MSG_FREE(this->home_url);
533         MSG_FREE(this->interface_name);
534         MSG_FREE(this->proxy_address);
535
536         unlock();
537
538         MSG_END();
539 }
540
541 //profile open callback
542 void MmsPluginCmAgent::connection_profile_open_callback(connection_error_e result, void* user_data)
543 {
544         lock();
545
546         connection_cellular_state_e state;
547         connection_profile_h profile = NULL;
548         connection_profile_state_e  profile_state;
549         int err = CONNECTION_ERROR_NONE;
550
551         if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS) {
552
553                 err = connection_get_cellular_state(g_connection, &state);
554
555                 MSG_INFO("connection_get_cellular_state ret [%d], state [%d]", err, state);
556
557                 err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
558                 if (err != CONNECTION_ERROR_NONE || profile == NULL) {
559
560                         MSG_ERR("Failed connection_get_default_cellular_service_profile. err [%d], profile [%p]", err, profile);
561                         goto __SIGNAL_RETURN;
562                 }
563
564                 err = connection_profile_get_state(profile, &profile_state);
565
566                 MSG_DEBUG("profile state [%d]", profile_state);
567
568                 if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED && waitProfileOpen == true) {
569
570                         __connection_profile_print(profile);
571
572                         MSG_FREE(this->home_url);
573                         MSG_FREE(this->interface_name);
574                         MSG_FREE(this->proxy_address);
575
576                         err = connection_profile_get_cellular_home_url(profile, &this->home_url);
577                         if (err != CONNECTION_ERROR_NONE) {
578                                 MSG_ERR("Failed connection_profile_get_cellular_home_url");
579                         }
580
581                         err = connection_profile_get_network_interface_name(profile, &this->interface_name);
582                         if (err != CONNECTION_ERROR_NONE) {
583                                 MSG_ERR("Failed connection_profile_get_cellular_home_url");
584                         }
585
586                         err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address);
587                         if (err != CONNECTION_ERROR_NONE) {
588                                 MSG_ERR("Failed connection_profile_get_cellular_home_url");
589                         }
590
591                         isCmOpened = true;
592
593                         goto __SIGNAL_RETURN; //open success
594
595                 } else {
596                         goto __NO_SIGNAL_RETURN; //Just open success
597                 }
598
599         } else {
600                 MSG_ERR("connection open profile Failed!! [%d]", result);
601                 isCmOpened = false;
602                 goto __SIGNAL_RETURN;
603
604         }
605
606 __NO_SIGNAL_RETURN: //Just Open
607         if (profile)
608                 connection_profile_destroy(profile);
609         unlock();
610         return;
611
612 __SIGNAL_RETURN: //Error or Already connected
613         if (profile)
614                 connection_profile_destroy(profile);
615
616         if (waitProfileOpen == true) {//open fail
617                 waitProfileOpen = false;
618                 MSG_INFO("## SIGNAL ##");
619                 signal();
620         }
621         unlock();
622         return;
623 }
624
625
626 void MmsPluginCmAgent::connection_profile_close_callback(connection_error_e result, void* user_data)
627 {
628         lock();
629         MSG_INFO("result [%d]", result);
630         MSG_INFO("## SIGNAL ##");
631         signal();
632
633         unlock();
634 }
635
636 void MmsPluginCmAgent::connection_profile_state_changed_cb(connection_profile_state_e state, void* user_data)
637 {
638         MSG_BEGIN();
639
640         lock();
641
642         int err;
643         connection_profile_h profile = NULL;
644
645         MSG_INFO("state [%d]", state);
646
647         if (state != CONNECTION_PROFILE_STATE_CONNECTED) {
648                 isCmOpened = false;
649                 goto __NO_SIGNAL_RETURN;
650         }
651
652         if (isCmOpened == true) {
653                 MSG_INFO("already opened");
654                 goto __SIGNAL_RETURN;
655         }
656
657         /* Should get profile to get latest profile info*/
658         err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
659         if (err != CONNECTION_ERROR_NONE || profile == NULL) {
660
661                 MSG_ERR("Failed connection_get_default_cellular_service_profile. err [%d], profile [%p]", err, profile);
662                 goto __SIGNAL_RETURN;
663         }
664
665         if (state == CONNECTION_PROFILE_STATE_CONNECTED ) {
666                 __connection_profile_print(profile);
667
668                 MSG_FREE(this->home_url);
669                 MSG_FREE(this->interface_name);
670                 MSG_FREE(this->proxy_address);
671
672                 err = connection_profile_get_cellular_home_url(profile, &this->home_url);
673                 if (err != CONNECTION_ERROR_NONE) {
674                         MSG_ERR("Failed connection_profile_get_cellular_home_url");
675                 }
676
677                 err = connection_profile_get_network_interface_name(profile, &this->interface_name);
678                 if (err != CONNECTION_ERROR_NONE) {
679                         MSG_ERR("Failed connection_profile_get_cellular_home_url");
680                 }
681
682                 err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address);
683                 if (err != CONNECTION_ERROR_NONE) {
684                         MSG_ERR("Failed connection_profile_get_cellular_home_url");
685                 }
686
687                 isCmOpened = true;
688                 goto __SIGNAL_RETURN;
689         }
690
691 __NO_SIGNAL_RETURN://Default
692         unlock();
693         return;
694
695 __SIGNAL_RETURN: //Error or connected
696         if (profile)
697                 connection_profile_destroy(profile);
698
699         if (waitProfileOpen == true) {
700                 waitProfileOpen = false;
701                 MSG_INFO("## SIGNAL ##");
702                 signal();
703         }
704         unlock();
705         return;
706 }
707
708 bool MmsPluginCmAgent::getInterfaceName(const char **deviceName)
709 {
710         if (!isCmOpened)
711                 return false;
712
713         if (deviceName == NULL)
714                 return false;
715
716         *deviceName = interface_name;
717
718         return true;
719 }
720
721 bool MmsPluginCmAgent::getHomeUrl(const char **homeURL)
722 {
723         if (!isCmOpened)
724                 return false;
725
726         if (homeURL == NULL)
727                 return false;
728
729         *homeURL = home_url;
730
731         return true;
732 }
733
734
735 bool MmsPluginCmAgent::getProxyAddr(const char **proxyAddr)
736 {
737         if (!isCmOpened)
738                 return false;
739
740         if (proxyAddr == NULL)
741                 return false;
742
743         *proxyAddr = proxy_address;
744
745         return true;
746 }