summaryrefslogtreecommitdiff
path: root/plugin/mms_plugin/MmsPluginConnManWrapper.cpp
blob: bb02aa645a772bcc4645fbb4483b202b8e1e9f78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

#include <errno.h>
#include <glib.h>
#include "MmsPluginConnManWrapper.h"
#include "MmsPluginDebug.h"
#include "MmsPluginHttp.h"
#include "net_connection.h"
#include "MmsPluginUtil.h"

#define MMS_CONTEXT_INVOKE_WAIT_TIME	30
#define MMS_CONNECTION_API_WAIT_TIME	420

static Mutex g_mx;
static CndVar g_cv;
static connection_h g_connection = NULL;
static connection_profile_h g_profile = NULL;

void __connection_profile_print(connection_profile_h profile)
{
	int ret;
	char *profile_id = NULL;
	char *profile_name = NULL;
	char *interface_name = NULL;
	char *ip_address = NULL;
	char *subnet_mask = NULL;
	char *gateway_address = NULL;
	char *dns_address = NULL;
	char *proxy_address = NULL;
	char *apn = NULL;
	char *user_name = NULL;
	char *password = NULL;
	char *home_url = NULL;
	bool is_roaming;

	connection_profile_type_e profile_type;
	connection_profile_state_e profile_state;
	connection_ip_config_type_e ip_type = CONNECTION_IP_CONFIG_TYPE_NONE;
	connection_proxy_type_e proxy_type;
	connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
	connection_cellular_auth_type_e auth_type = CONNECTION_CELLULAR_AUTH_TYPE_NONE;

	MSG_DEBUG("**************************************************************************************************");
	ret = connection_profile_get_id(profile, &profile_id);
	MSG_DEBUG("return value of connection_profile_get_id [%d]", ret);
	MSG_SEC_INFO("Profile Id = [%s]", profile_id);

	ret = connection_profile_get_name(profile, &profile_name);
	MSG_SEC_INFO("Profile Name = [%s]", profile_name);

	ret = connection_profile_get_type(profile, &profile_type);

	if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
		MSG_SEC_INFO("Profile Type = [CELLULAR]");
	} else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
		MSG_SEC_INFO("Profile Type = [WIFI]");
	} else if (profile_type == CONNECTION_PROFILE_TYPE_ETHERNET) {
		MSG_SEC_INFO("Profile Type = [ETHERNET]");
	} else if (profile_type == CONNECTION_PROFILE_TYPE_BT) {
		MSG_SEC_INFO("Profile Type = [BT]");
	} else {
		MSG_SEC_INFO("Profile Type = Unknown [%d]", profile_type);
	}

	ret = connection_profile_get_network_interface_name(profile, &interface_name);
	MSG_SEC_INFO("Profile Interface Name = [%s]", interface_name);

	ret = connection_profile_get_state(profile, &profile_state);
	if (profile_state == CONNECTION_PROFILE_STATE_DISCONNECTED) {
		MSG_SEC_INFO("Profile State = [DISCONNECTED]");
	} else if (profile_state == CONNECTION_PROFILE_STATE_ASSOCIATION) {
		MSG_SEC_INFO("Profile State = [ASSOCIATION]");
	} else if (profile_state == CONNECTION_PROFILE_STATE_CONFIGURATION) {
		MSG_SEC_INFO("Profile State = [CONFIGURATION]");
	} else if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED) {
		MSG_SEC_INFO("Profile State = [CONNECTED]");
	} else {
		MSG_SEC_INFO("Profile State = Unknown [%d]", profile_state);
	}

	ret = connection_profile_get_ip_config_type(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_type);
	MSG_SEC_INFO("Profile Ip Config Type = [%d]", ip_type);

	ret = connection_profile_get_ip_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_address);
	MSG_SEC_INFO("Profile Ip Address = [%s]", ip_address);

	ret = connection_profile_get_subnet_mask(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &subnet_mask);
	MSG_SEC_INFO("Profile Subnet Mask = [%s]", subnet_mask);

	ret = connection_profile_get_gateway_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &gateway_address);
	MSG_SEC_INFO("Profile Gateway Address = [%s]", gateway_address);

	ret = connection_profile_get_dns_address(profile, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &dns_address);
	MSG_SEC_INFO("Profile Dns Address = [%s]", dns_address);

	ret = connection_profile_get_proxy_type(profile, &proxy_type);
	MSG_SEC_INFO("Profile Proxy Type = [%d]", proxy_type);

	ret = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
	MSG_SEC_INFO("Profile Proxy Address = [%s]", proxy_address);

	ret = connection_profile_get_cellular_service_type(profile, &service_type);
	if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) {
		MSG_SEC_INFO("Profile Service Type = [INTERNET]");
	} else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) {
		MSG_SEC_INFO("Profile Service Type = [MMS]");
	} else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET) {
		MSG_SEC_INFO("Profile Service Type = [PREPAID_INTERNET]");
	} else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS) {
		MSG_SEC_INFO("Profile Service Type = [PREPAID_MMS]");
	} else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING) {
		MSG_SEC_INFO("Profile Service Type = [TETHERING]");
	} else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION) {
		MSG_SEC_INFO("Profile Service Type = [APPLICATION]");
	} else {
		MSG_SEC_INFO("Profile Service Type = [Unknown][%d]", service_type);
	}

	ret = connection_profile_get_cellular_apn(profile, &apn);
	MSG_SEC_INFO("Profile Apn = [%s]", apn);

	ret = connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password);
	MSG_SEC_INFO("Profile Auth Type = [%d]", &auth_type);
	MSG_SEC_INFO("Profile Auth Name = [%s]", &user_name);
	MSG_SEC_INFO("Profile Auth Passward = [%s]", &password);

	ret = connection_profile_get_cellular_home_url(profile, &home_url);
	MSG_SEC_INFO("Profile Home Url = [%s]", home_url);

	ret = connection_profile_is_cellular_roaming(profile, &is_roaming);
	MSG_SEC_INFO("Profile Roaming = [%d]", is_roaming);
	MSG_DEBUG("**************************************************************************************************");

	MSG_FREE(profile_id);
	MSG_FREE(profile_name);
	MSG_FREE(interface_name);
	MSG_FREE(ip_address);
	MSG_FREE(subnet_mask);
	MSG_FREE(gateway_address);
	MSG_FREE(dns_address);
	MSG_FREE(proxy_address);
	MSG_FREE(apn);
	MSG_FREE(user_name);
	MSG_FREE(password);
	MSG_FREE(home_url);
}

static void __connection_type_changed_cb(connection_type_e type, void* user_data)
{
	MSG_INFO("Type changed callback, connection type : %d", type);
}

static void __connection_ip_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
{
	MSG_INFO("IP changed callback, IPv4 address : %s, IPv6 address : %s",
			ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
}

static void __connection_proxy_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
{
	MSG_INFO("Proxy changed callback, IPv4 address : %s, IPv6 address : %s",
			ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
}

static void __connection_profile_opened_cb(connection_error_e result, void* user_data)
{
	if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS)
		MSG_INFO("Connection open Succeeded [%d]", result);
	else
		MSG_ERR("Connection open Failed, err : %d", result);

	MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();

	cmAgent->connection_profile_open_callback(result, user_data);
}

static void __connection_profile_closed_cb(connection_error_e result, void* user_data)
{
	if (result ==  CONNECTION_ERROR_NONE)
		MSG_INFO("Connection close Succeeded");
	else
		MSG_ERR("Connection close Failed, err : %d", result);

	MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();

	cmAgent->connection_profile_close_callback(result, user_data);
}


void __connection_profile_state_changed_cb(connection_profile_state_e state, void* user_data)
{
	MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();

	cmAgent->connection_profile_state_changed_cb(state, user_data);

}

static gboolean __connection_create(void *pVoid)
{
	MSG_BEGIN();

	bool ret = false;
	bool *ret_val = (bool *)pVoid;

	if (g_connection) {
		MSG_INFO("connection already exist");
		ret = true;
	} else {
		int err = connection_create(&g_connection);

		if (CONNECTION_ERROR_NONE == err) {

			connection_cellular_state_e cellular_state;
			connection_type_e net_state;

			err = connection_get_cellular_state(g_connection, &cellular_state);

			err = connection_get_type(g_connection, &net_state);

			if (cellular_state == CONNECTION_CELLULAR_STATE_AVAILABLE
				|| cellular_state == CONNECTION_CELLULAR_STATE_CONNECTED) {

				MSG_INFO("Client registration success [%p], cellular_state [%d], net_state [%d]", g_connection, cellular_state, net_state);

				err = connection_set_type_changed_cb(g_connection, __connection_type_changed_cb, NULL);

				err = connection_set_ip_address_changed_cb(g_connection, __connection_ip_changed_cb, NULL);

				err = connection_set_proxy_address_changed_cb(g_connection, __connection_proxy_changed_cb, NULL);

				ret = true;
			} else {

				MSG_INFO("Client registration Failed,  cellular state [%d], net_state [%d]", cellular_state, net_state);
				connection_destroy(g_connection);
				g_connection = NULL;
			}

		} else {
			MSG_WARN("Client registration failed %d", err);
		}
	}

	if (ret_val) {
		*ret_val = ret;
	}

	MSG_END();
	return FALSE;
}

static gboolean __connection_destroy(void *pVoid)
{
	MSG_BEGIN();

	int rv;

	if (g_connection != NULL) {
		rv = connection_destroy(g_connection);
		g_connection = NULL;
		MSG_INFO("connection destory !!");
	} else {
		MSG_ERR("Cannot connection destroy : Handle is NULL");
		rv = CONNECTION_ERROR_INVALID_OPERATION;
	}

	MSG_DEBUG("return value of connection destroy [%d]", rv);

	MSG_END();
	return FALSE;
}

static gboolean __connection_profile_open(void *pVoid)
{
	MSG_BEGIN();

	int netOpenResult = MSG_CM_ERR_NONE;
	int *ret_val = (int *)pVoid;
	int err;

	if (g_profile) {
		MSG_WARN("connection profile Already exist!!, It will destroy");
		connection_profile_unset_state_changed_cb(g_profile);
		connection_profile_destroy(g_profile);
		g_profile = NULL;
	}

	err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &g_profile);

	if (err != CONNECTION_ERROR_NONE) {
		MSG_ERR("connection_get_default_cellular_service_profile Failed!! [%d]", err);
		netOpenResult = MSG_CM_ERR_UNKNOWN;
	} else {

		err = connection_profile_set_state_changed_cb(g_profile, __connection_profile_state_changed_cb, g_profile);

		if (connection_open_profile(g_connection, g_profile, __connection_profile_opened_cb, NULL) != CONNECTION_ERROR_NONE) {
			MSG_ERR("Connection open Failed!!");
			netOpenResult = MSG_CM_ERR_UNKNOWN;
		}


	}

	if (ret_val) {
		*ret_val = netOpenResult;
		MSG_DEBUG("[%d]", netOpenResult);
	}

	MSG_END();

	return FALSE;
}

static gboolean __connection_profile_close(void *pVoid)
{
	MSG_BEGIN();

	int netOpenResult = MSG_CM_ERR_NONE;

	int *ret_val = (int *)pVoid;

	if (g_profile) {
		connection_profile_unset_state_changed_cb(g_profile);

		if (connection_close_profile(g_connection, g_profile, __connection_profile_closed_cb, NULL) != CONNECTION_ERROR_NONE) {
			MSG_ERR("Connection close Failed!!");
			netOpenResult = MSG_CM_ERR_UNKNOWN;
		}

		connection_profile_destroy(g_profile);
		g_profile = NULL;
	}

	if (ret_val) {
		*ret_val = netOpenResult;
	}

	MSG_END();

	return FALSE;
}


void context_invoke_end_cb(gpointer data)
{
	g_mx.lock();

	MSG_INFO("@@ SIGNAL @@");

	g_cv.signal();

	g_mx.unlock();
}

/*
 * Network api should run at g_main_loop to receive callback
 * */
void context_invoke(GSourceFunc func, void *ret)
{
	MSG_BEGIN();

	int time_ret = 0;

	g_mx.lock();

	g_main_context_invoke_full(NULL, G_PRIORITY_DEFAULT, func, ret,  context_invoke_end_cb);

	MSG_INFO("@@ WAIT @@");

	time_ret = g_cv.timedwait(g_mx.pMutex(), MMS_CONTEXT_INVOKE_WAIT_TIME);

	g_mx.unlock();

	if (time_ret == ETIMEDOUT) {
		MSG_INFO("@@ WAKE by timeout@@");
	} else {
		MSG_INFO("@@ WAKE by signal@@");
	}

	MSG_END();
}

MmsPluginCmAgent *MmsPluginCmAgent::pInstance = NULL;

MmsPluginCmAgent *MmsPluginCmAgent::instance()
{
	if (!pInstance)
		pInstance = new MmsPluginCmAgent();

	return pInstance;
}

MmsPluginCmAgent::MmsPluginCmAgent()
{
	MSG_BEGIN();

	isCmOpened = false;
	waitProfileOpen = false;

	home_url = NULL;
	interface_name = NULL;
	proxy_address = NULL;
	MSG_END();
}

MmsPluginCmAgent::~MmsPluginCmAgent()
{
	MSG_FREE(home_url);
	MSG_FREE(interface_name);
	MSG_FREE(proxy_address);
}

bool MmsPluginCmAgent::open()
{
	MSG_BEGIN();

	int netOpenResult = MSG_CM_ERR_NONE;
	int bConnection = false;
	int time_ret = 0;
	lock();

	//create connection
	context_invoke(__connection_create, &bConnection);

	if (bConnection == false || g_connection == NULL) {
		MSG_ERR("Failed __connection_create");
		goto __ERR_RETURN;
	}

	if (g_profile) {
		MSG_WARN("connection profile already exist");
		//TODO:: get data;
		//goto __RETURN;
	}

	waitProfileOpen = true;

	context_invoke(__connection_profile_open, &netOpenResult);

	if (netOpenResult != MSG_CM_ERR_NONE) {
		MSG_ERR("Failed __connection_profile_open. [%d]", netOpenResult);
		goto __ERR_RETURN;
	}

	MSG_INFO("## WAITING UNTIL __connection_profile_state CONNECT. ##");

//	cv.wait(mx.pMutex());
//	MSG_INFO("## WAKE by SIGNAL ##");

	time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME); // isCmOpened will changed by processCBdatas

	if (time_ret == ETIMEDOUT) {
		MSG_WARN("## WAKE by timeout ##");
	} else {
		MSG_INFO("## WAKE by SIGNAL ##");
	}

	if(isCmOpened == false) {
		MSG_WARN("");
		goto __ERR_RETURN;
	}

//__RETURN:
	unlock();
	MSG_END();
	return isCmOpened;

__ERR_RETURN:
	context_invoke(__connection_profile_close, NULL);
	context_invoke( __connection_destroy, NULL);
	unlock();
	MSG_END();
	return isCmOpened;
}


void MmsPluginCmAgent::close()
{
	MSG_BEGIN();

	lock();

	int netOpenResult = MSG_CM_ERR_NONE;
	int time_ret = 0;

	isCmOpened = false;

	if (g_profile == NULL) {
		MSG_INFO("connection profile is NULL");
		goto __RETURN;
	}

	context_invoke(__connection_profile_close, &netOpenResult);

	if (netOpenResult != MSG_CM_ERR_NONE) {
		MSG_ERR("Failed __connection_profile_close. [%d]", netOpenResult);
		goto __RETURN;
	}

	MSG_INFO("## WAITING UNTIL connection_profile_close_callback ##");

	time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME);

	if (time_ret == ETIMEDOUT) {
		MSG_WARN("## WAKE by timeout ##");
	} else {
		MSG_INFO("## WAKE by SIGNAL ##");
	}


__RETURN:
	if (g_connection)
		context_invoke(__connection_destroy, NULL);

	g_profile = NULL;
	g_connection = NULL;

	MSG_FREE(this->home_url);
	MSG_FREE(this->interface_name);
	MSG_FREE(this->proxy_address);

	unlock();

	MSG_END();
}

//profile open callback
void MmsPluginCmAgent::connection_profile_open_callback(connection_error_e result, void* user_data)
{
	lock();

	connection_cellular_state_e state;
	connection_profile_h profile = NULL;
	connection_profile_state_e  profile_state;
	int err = CONNECTION_ERROR_NONE;

	if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS) {

		err = connection_get_cellular_state(g_connection, &state);

		MSG_INFO("connection_get_cellular_state ret [%d], state [%d]", err, state);

		err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
		if (err != CONNECTION_ERROR_NONE || profile == NULL) {

			MSG_ERR("Failed connection_get_default_cellular_service_profile. err [%d], profile [%p]", err, profile);
			goto __SIGNAL_RETURN;
		}

		err = connection_profile_get_state(profile, &profile_state);

		MSG_DEBUG("profile state [%d]", profile_state);

		if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED && waitProfileOpen == true) {

			__connection_profile_print(profile);

			MSG_FREE(this->home_url);
			MSG_FREE(this->interface_name);
			MSG_FREE(this->proxy_address);

			err = connection_profile_get_cellular_home_url(profile, &this->home_url);
			if (err != CONNECTION_ERROR_NONE) {
				MSG_ERR("Failed connection_profile_get_cellular_home_url");
			}

			err = connection_profile_get_network_interface_name(profile, &this->interface_name);
			if (err != CONNECTION_ERROR_NONE) {
				MSG_ERR("Failed connection_profile_get_cellular_home_url");
			}

			err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address);
			if (err != CONNECTION_ERROR_NONE) {
				MSG_ERR("Failed connection_profile_get_cellular_home_url");
			}

			isCmOpened = true;

			goto __SIGNAL_RETURN; //open success

		} else {
			goto __NO_SIGNAL_RETURN; //Just open success
		}

	} else {
		MSG_ERR("connection open profile Failed!! [%d]", result);
		isCmOpened = false;
		goto __SIGNAL_RETURN;

	}

__NO_SIGNAL_RETURN: //Just Open
	if (profile)
		connection_profile_destroy(profile);
	unlock();
	return;

__SIGNAL_RETURN: //Error or Already connected
	if (profile)
		connection_profile_destroy(profile);

	if (waitProfileOpen == true) {//open fail
		waitProfileOpen = false;
		MSG_INFO("## SIGNAL ##");
		signal();
	}
	unlock();
	return;
}


void MmsPluginCmAgent::connection_profile_close_callback(connection_error_e result, void* user_data)
{
	lock();
	MSG_INFO("result [%d]", result);
	MSG_INFO("## SIGNAL ##");
	signal();

	unlock();
}

void MmsPluginCmAgent::connection_profile_state_changed_cb(connection_profile_state_e state, void* user_data)
{
	MSG_BEGIN();

	lock();

	int err;
	connection_profile_h profile = NULL;

	MSG_INFO("state [%d]", state);

	if (state != CONNECTION_PROFILE_STATE_CONNECTED) {
		isCmOpened = false;
		goto __NO_SIGNAL_RETURN;
	}

	if (isCmOpened == true) {
		MSG_INFO("already opened");
		goto __SIGNAL_RETURN;
	}

	/* Should get profile to get latest profile info*/
	err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
	if (err != CONNECTION_ERROR_NONE || profile == NULL) {

		MSG_ERR("Failed connection_get_default_cellular_service_profile. err [%d], profile [%p]", err, profile);
		goto __SIGNAL_RETURN;
	}

	if (state == CONNECTION_PROFILE_STATE_CONNECTED ) {
		__connection_profile_print(profile);

		MSG_FREE(this->home_url);
		MSG_FREE(this->interface_name);
		MSG_FREE(this->proxy_address);

		err = connection_profile_get_cellular_home_url(profile, &this->home_url);
		if (err != CONNECTION_ERROR_NONE) {
			MSG_ERR("Failed connection_profile_get_cellular_home_url");
		}

		err = connection_profile_get_network_interface_name(profile, &this->interface_name);
		if (err != CONNECTION_ERROR_NONE) {
			MSG_ERR("Failed connection_profile_get_cellular_home_url");
		}

		err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address);
		if (err != CONNECTION_ERROR_NONE) {
			MSG_ERR("Failed connection_profile_get_cellular_home_url");
		}

		isCmOpened = true;
		goto __SIGNAL_RETURN;
	}

__NO_SIGNAL_RETURN://Default
	unlock();
	return;

__SIGNAL_RETURN: //Error or connected
	if (profile)
		connection_profile_destroy(profile);

	if (waitProfileOpen == true) {
		waitProfileOpen = false;
		MSG_INFO("## SIGNAL ##");
		signal();
	}
	unlock();
	return;
}

bool MmsPluginCmAgent::getInterfaceName(const char **deviceName)
{
	if (!isCmOpened)
		return false;

	if (deviceName == NULL)
		return false;

	*deviceName = interface_name;

	return true;
}

bool MmsPluginCmAgent::getHomeUrl(const char **homeURL)
{
	if (!isCmOpened)
		return false;

	if (homeURL == NULL)
		return false;

	*homeURL = home_url;

	return true;
}


bool MmsPluginCmAgent::getProxyAddr(const char **proxyAddr)
{
	if (!isCmOpened)
		return false;

	if (proxyAddr == NULL)
		return false;

	*proxyAddr = proxy_address;

	return true;
}