2 * tel-plugin-packetservice
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongHoo Park <donghoo.park@samsung.com>
7 * Arun Shukla <arun.shukla@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include "ps_common.h"
25 #include "generated-code.h"
27 #include <tzplatform_config.h>
32 #include <core_object.h>
34 #include <co_context.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
39 #include <iniparser.h>
41 #include <libxml/xmlmemory.h>
42 #include <libxml/parser.h>
43 #include <libxml/tree.h>
45 #define PROP_DEFAULT FALSE
46 #define PROP_DEFAULT_STR NULL
47 #define DATABASE_PATH_0 tzplatform_mkpath(TZ_SYS_DB, ".dnet.db")
48 #define DATABASE_PATH_1 tzplatform_mkpath(TZ_SYS_DB, ".dnet2.db")
49 #define DELAY_TO_SIGNAL_EMIT 1
54 enum co_context_type pdp_type;
55 enum co_context_role role;
56 const char *p_cscf_ipv4addr;
57 const char *p_cscf_ipv6addr;
60 #define FREE_AND_ASSIGN(ptr, value) do { \
63 ptr = g_strdup(value); \
66 static Storage *strg_db;
69 OperatorTable attach_apn_preference[] = {
70 {"45005", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "220.103.220.10", "2001:2d8:00e0:0220::10"},
71 {"45006", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "", ""},
72 {"45008", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "", ""},
75 static void __ps_context_emit_dedicated_bearer_info_signal(ps_context_t *context);
76 static void __ps_context_emit_property_changed_signal(ps_context_t *context);
77 static void _ps_context_setup_interface(PacketServiceContext *context, ps_context_t *context_data);
79 static gboolean __ps_context_create_storage_handle(gpointer plugin);
80 static gchar *__ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id, gchar *cp_name);
81 static gboolean __ps_context_profile_is_attach_apn(CoreObject *co_context, const gchar *mccmnc);
82 static gboolean __ps_context_create_co_context(gpointer context, GHashTable *property, gchar *cp_name);
83 static gboolean __ps_context_update_profile(ps_context_t *context, GHashTable *property);
84 static gboolean __ps_context_update_database(ps_context_t *context);
85 static gboolean __ps_context_update_default_internet_to_db(ps_context_t *context, gboolean enabled);
86 static gboolean __ps_context_remove_database(ps_context_t *context);
87 static int __ps_context_insert_network_id_to_database(gchar *mccmnc, gchar *cp_name);
88 static int __ps_context_load_network_id_from_database(gchar *mccmnc, gchar *cp_name);
89 static gchar *__ps_context_load_network_name_from_database(int network_id, gchar *cp_name);
90 static int __ps_context_load_profile_id_from_database(gchar *cp_name);
91 static int __ps_context_load_num_of_pdn_from_database(gchar *mccmnc, gchar *cp_name);
92 static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int index, gchar *cp_name);
93 static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id, gchar *cp_name);
94 static int __ps_context_get_network_id(gchar *mccmnc, gchar *cp_name);
95 GVariant *__ps_context_get_profile_properties(gpointer context, GVariantBuilder *properties);
96 static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled);
98 void __remove_context_handler(gpointer data)
100 ps_context_t *context = data;
105 dbg("Context is Null");
109 /*Need to UNexport and Unref the master Object */
110 g_object_unref(context->if_obj);
112 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context removed for the path [%s]", context->path);
114 g_free(context->path);
115 g_free(context->mccmnc);
122 static void __ps_context_emit_dedicated_bearer_info_signal(ps_context_t *context)
125 CoreObject *co_network = NULL, *co_context = NULL;
126 struct dedicated_bearer_info bearer_info;
127 GVariantBuilder properties;
129 char *num_dedicated_bearer, *primary_context_id;
130 char *secondary_context_id, *qci, *gbr_dl, *gbr_ul, *max_br_dl, *max_br_ul;
132 g_return_if_fail(context != NULL);
134 co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
135 co_context = _ps_context_ref_co_context(context);
136 tcore_context_get_bearer_info(co_context, &bearer_info);
138 if (bearer_info.num_dedicated_bearer == 0) {
139 ps_warn_ex_co(co_network, "No dedicated bearer information");
143 g_variant_builder_init(&properties, G_VARIANT_TYPE("a{ss}"));
145 primary_context_id = INT2STRING(tcore_context_get_id(co_context));
146 g_variant_builder_add(&properties, "{ss}", "primary_context_id", primary_context_id);
147 g_free(primary_context_id);
149 num_dedicated_bearer = CHAR2STRING(bearer_info.num_dedicated_bearer);
150 g_variant_builder_add(&properties, "{ss}", "num_dedicated_bearer", num_dedicated_bearer);
151 g_free(num_dedicated_bearer);
153 secondary_context_id = INT2STRING(bearer_info.secondary_context_id);
154 g_variant_builder_add(&properties, "{ss}", "secondary_context_id", secondary_context_id);
155 g_free(secondary_context_id);
157 for (i = 0; i < bearer_info.num_dedicated_bearer ; i++) {
159 buf = g_strdup_printf("%s_%d", "qci", i);
160 qci = CHAR2STRING(bearer_info.qos[i].qci);
161 g_variant_builder_add(&properties, "{ss}", buf, qci);
165 buf = g_strdup_printf("%s_%d", "gbr_dl", i);
166 gbr_dl = INT2STRING(bearer_info.qos[i].gbr_dl);
167 g_variant_builder_add(&properties, "{ss}", buf, gbr_dl);
171 buf = g_strdup_printf("%s_%d", "gbr_ul", i);
172 gbr_ul = INT2STRING(bearer_info.qos[i].gbr_ul);
173 g_variant_builder_add(&properties, "{ss}", buf, gbr_ul);
177 buf = g_strdup_printf("%s_%d", "max_br_dl", i);
178 max_br_dl = INT2STRING(bearer_info.qos[i].max_br_dl);
179 g_variant_builder_add(&properties, "{ss}", buf, max_br_dl);
183 buf = g_strdup_printf("%s_%d", "max_br_ul", i);
184 max_br_ul = INT2STRING(bearer_info.qos[i].max_br_ul);
185 g_variant_builder_add(&properties, "{ss}", buf, max_br_ul);
189 gv = g_variant_builder_end(&properties);
191 packet_service_context_emit_dedicated_bearer_info(context->if_obj, gv);
192 ps_warn_ex_co(co_network, "context (%p) emit the dedicated bearer infomation signal", context);
195 static void __ps_context_emit_property_changed_signal(ps_context_t *context)
198 GVariantBuilder property;
199 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
201 ps_dbg_ex_co(co_network, "get context Properties");
203 gv = _ps_context_get_properties(context, &property);
204 packet_service_context_emit_property_changed(context->if_obj, gv);
206 ps_dbg_ex_co(co_network, "context (%p) emit the context property changed signal", context);
210 /* Funtion : _ps_context_remove_context
211 * Description : removes and unregister the interface for the context
213 gboolean _ps_context_remove_context(gpointer context)
215 ps_context_t *pscontext = context;
216 ps_service_t *service = _ps_context_ref_service(pscontext);
218 g_return_val_if_fail(pscontext != NULL, FALSE);
219 g_return_val_if_fail(service != NULL, FALSE);
220 g_return_val_if_fail(pscontext->path != NULL, FALSE);
222 ps_dbg_ex_co(_ps_service_ref_co_network(service),
223 "remove context (%s)", pscontext->path);
225 /*Removing the context from the static list */
226 _ps_service_reset_connection_timer(context);
227 _ps_context_set_connected(context, FALSE);
229 /* Unexport object */
230 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(pscontext->if_obj));
232 /* remove context from the list (modem, service) */
233 tcore_ps_remove_context(service->co_ps,
234 (CoreObject *)_ps_context_ref_co_context(context));
235 tcore_context_free(pscontext->co_context);
237 /* free allocated resources for context. */
238 g_free(pscontext->mccmnc);
239 g_free(pscontext->path);
246 static gboolean __ps_context_create_storage_handle(gpointer plugin)
248 TcorePlugin *p = plugin;
250 strg_db = tcore_server_find_storage(tcore_plugin_ref_server(p), "database");
251 dbg("Storage: (%p)", strg_db);
256 static gchar *__ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id, gchar *cp_name)
258 gchar *path = NULL, *in_path = NULL;
259 int str_len = 0, context_index = 0;
262 dbg("profile_name is null");
266 str_len = strlen(profile_name);
267 in_path = g_strdup_printf("/%s%s", cp_name, "/context/");
269 for (context_index = 0; context_index < str_len; context_index++) {
270 gchar *buf = NULL, *tmp = NULL;
271 buf = g_strdup_printf("%02x", profile_name[context_index]);
272 tmp = g_strconcat(in_path, buf, NULL);
277 in_path = g_strdup(tmp);
281 dbg("converted name(%s) path(%s)", profile_name, in_path);
283 path = g_strdup_printf("%s_%d_%d", in_path, profile_id, svc_ctg_id);
284 dbg("path (%s)", path);
290 static gboolean __ps_context_profile_is_attach_apn(CoreObject *co_context, const gchar *mccmnc)
292 gboolean attach_apn = FALSE, default_conn = FALSE;
295 if (co_context == NULL)
298 default_conn = tcore_context_get_default_profile(co_context);
299 role = tcore_context_get_role(co_context);
302 * TODO: Read CSC Configuration routine.
303 * By default, default Ineternet profile will be used for PS attach.
304 * CSC will define APN for PS attach according to operator requirement.
308 gboolean matched = FALSE;
310 count = sizeof(attach_apn_preference) / sizeof(attach_apn_preference[0]);
311 for (i = 0; i < count ; i++) {
312 if (g_strcmp0(attach_apn_preference[i].mccmnc, mccmnc) == 0) {
313 if (attach_apn_preference[i].role == role) {
314 dbg("index[%d], attach_apn_preference[%d].role: %d, role: %d, apn: %s",
315 i, i, attach_apn_preference[i].role, role, attach_apn_preference[i].apn);
323 if (role == CONTEXT_ROLE_INTERNET)
328 dbg("role(%d), attach_apn (%d)", role, attach_apn);
332 static gboolean __ps_context_create_co_context(gpointer object, GHashTable *property, gchar *cp_name)
336 ps_context_t *context = NULL;
337 CoreObject *co_context = NULL;
341 gchar *profile_name = NULL;
343 gchar *auth_id = NULL, *auth_pwd = NULL, *home_url = NULL, *proxy_addr = NULL;
344 int auth_type = 0, svc_ctg_id = 0, pdp_type = 0;
345 gboolean hidden = FALSE, editable = FALSE, default_conn = FALSE, user_defined = FALSE, is_roaming_apn = FALSE, profile_enable = TRUE;
347 g_hash_table_iter_init(&iter, (GHashTable *) property);
348 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
349 if (g_str_equal(key, "3") == TRUE) { /*Profile ID*/
351 profile_id = atoi((const char *) value);
352 dbg("profile id (%d)", profile_id);
354 } else if (g_str_equal(key, "4") == TRUE) {
355 g_free(profile_name);
356 profile_name = g_strdup((const char *) value);
357 dbg("profile name (%s)", profile_name);
358 } else if (g_str_equal(key, "5") == TRUE) {
360 apn = g_strdup((const char *) value);
361 dbg("APN (%s)", apn);
362 } else if (g_str_equal(key, "6") == TRUE) {
364 auth_type = atoi((const char *) value);
365 dbg("auth type (%d)", auth_type);
367 } else if (g_str_equal(key, "7") == TRUE) {
369 auth_id = g_strdup((const char *) value);
370 dbg("auth id (%s)", auth_id);
371 } else if (g_str_equal(key, "8") == TRUE) {
373 auth_pwd = g_strdup((const char *) value);
374 dbg("auth pwd (%s)", auth_pwd);
375 } else if (g_str_equal(key, "9") == TRUE) {
376 if (!value || g_strcmp0((const gchar *) value, "") == 0) {
378 proxy_addr = g_strdup((const char *) value);
380 gboolean b_regex = FALSE;
381 b_regex = g_regex_match_simple("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+:[0-9]*", (const gchar *) value, 0, 0);
385 gchar **tmp_proxy = NULL;
387 tmp_proxy = g_strsplit_set((const gchar *) value, ".:", -1);
388 port_num = atoi(tmp_proxy[4]);
392 proxy_addr = g_strdup_printf("%d.%d.%d.%d",
393 atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]));
396 proxy_addr = g_strdup_printf("%d.%d.%d.%d:%d",
397 atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]), port_num);
399 g_strfreev(tmp_proxy);
402 proxy_addr = g_strdup((const char *) value);
403 } /* not in regular experssion */
406 dbg("proxy addr (%s)", proxy_addr);
407 } else if (g_str_equal(key, "10") == TRUE) {
409 home_url = g_strdup((const char *) value);
410 dbg("home url (%s)", home_url);
411 } else if (g_str_equal(key, "11") == TRUE) {
413 pdp_type = atoi((const char *) value);
414 dbg("pdp type (%d)", pdp_type);
416 } else if (g_str_equal(key, "19") == TRUE) {
418 svc_ctg_id = atoi((const char *) value);
419 dbg("context category type (%d)", svc_ctg_id);
421 } else if (g_str_equal(key, "20") == TRUE) {
423 hidden = atoi((const char *) value);
424 dbg("hidden profile (%d)", hidden);
426 } else if (g_str_equal(key, "21") == TRUE) {
428 editable = atoi((const char *) value);
429 dbg("editable profile (%d)", editable);
431 } else if (g_str_equal(key, "22") == TRUE) {
433 default_conn = atoi((const char*) value);
434 dbg("default connection profile (%d)", default_conn);
436 } else if (g_str_equal(key, "23") == TRUE) {
438 user_defined = atoi((const char*) value);
439 dbg("user defined profile (%d)", user_defined);
441 } else if (g_str_equal(key, "24") == TRUE) {
443 is_roaming_apn = atoi((const char*) value);
444 dbg("roaming APN profile (%d)", is_roaming_apn);
446 } else if (g_str_equal(key, "25") == TRUE) {
448 profile_enable = atoi((const char*) value);
449 dbg("profile enable (%d)", profile_enable);
454 path = __ps_context_create_path(profile_name, profile_id, svc_ctg_id, cp_name);
456 context = (ps_context_t *)object;
457 co_context = tcore_context_new(context->plg, path, NULL);
458 #ifdef TIZEN_PS_IPV4_ONLY
459 dbg("pdp type has been changed (%d)", CONTEXT_TYPE_IP);
460 tcore_context_set_type(co_context, CONTEXT_TYPE_IP);
462 tcore_context_set_type(co_context, pdp_type);
464 tcore_context_set_state(co_context, CONTEXT_STATE_DEACTIVATED);
465 tcore_context_set_role(co_context, svc_ctg_id);
466 tcore_context_set_apn(co_context, apn);
467 tcore_context_set_auth(co_context, auth_type);
468 tcore_context_set_username(co_context, auth_id);
469 tcore_context_set_password(co_context, auth_pwd);
470 tcore_context_set_proxy(co_context, proxy_addr);
471 tcore_context_set_mmsurl(co_context, home_url);
472 tcore_context_set_profile_name(co_context, profile_name);
473 tcore_context_set_default_profile(co_context, default_conn);
474 tcore_context_set_attach_apn(co_context, __ps_context_profile_is_attach_apn(co_context, context->mccmnc));
475 tcore_context_set_roaming_apn(co_context, is_roaming_apn);
477 context->profile_id = profile_id;
478 context->hidden = hidden;
479 context->editable = editable;
480 context->is_default = default_conn;
481 _ps_context_set_profile_enable(context, profile_enable);
482 context->path = path;
483 context->co_context = co_context;
485 g_free(profile_name);
495 static gpointer __ps_context_create_context(GDBusConnection *conn, TcorePlugin *p,
496 gchar *mccmnc, GHashTable *property, gchar *cp_name)
498 PacketServiceContext *context;
499 GError *error = NULL;
500 ps_context_t *new_context;
505 /*Initializing the master list for internal referencing*/
506 new_context = g_try_malloc0(sizeof(ps_context_t));
507 if (NULL == new_context) {
508 err("Unable to allocate memory for context");
511 dbg("creating the skeleton object");
512 context = packet_service_context_skeleton_new();
513 if (NULL == context) {
518 dbg("Assigning the memory location for the internal data");
519 new_context->conn = conn;
520 new_context->plg = p;
521 new_context->if_obj = context;
522 new_context->mccmnc = g_strdup(mccmnc);
524 __ps_context_create_co_context(new_context, property , cp_name);
525 _ps_context_set_alwayson_enable(new_context, TRUE);
526 path = _ps_context_ref_path(new_context);
527 _ps_context_setup_interface(context, new_context);
529 dbg("registering the interface object");
531 dbg("exporting the interface object to the dbus connection");
532 /*exporting the interface object to the path mention for master*/
533 g_dbus_interface_skeleton_export((G_DBUS_INTERFACE_SKELETON(context)),
538 g_assert_no_error(error);
540 dbg("Successfully new object created for the interface for path [%s]", path);
544 /*To do : handle failure */
545 dbg("Unable to allocate memory for the new object");
549 static gboolean __ps_context_update_profile(ps_context_t *context, GHashTable *property)
551 CoreObject *co_context = NULL;
555 co_context = context->co_context;
559 g_hash_table_iter_init(&iter, property);
560 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
561 if (g_str_equal(key, "apn") == TRUE) {
562 tcore_context_set_apn(co_context, (const char *) value);
563 } else if (g_str_equal(key, "profile_name") == TRUE) {
564 tcore_context_set_profile_name(co_context, (const char *) value);
565 } else if (g_str_equal(key, "auth_type") == TRUE) {
568 i_tmp = atoi((const char *) value);
569 tcore_context_set_auth(co_context, i_tmp);
571 } else if (g_str_equal(key, "auth_id") == TRUE) {
572 tcore_context_set_username(co_context, (const char *) value);
573 } else if (g_str_equal(key, "auth_pwd") == TRUE) {
574 tcore_context_set_password(co_context, (const char *) value);
575 } else if (g_str_equal(key, "pdp_protocol") == TRUE) {
578 i_tmp = atoi((const char *) value);
579 tcore_context_set_type(co_context, i_tmp);
581 } else if (g_str_equal(key, "proxy_addr") == TRUE) {
582 tcore_context_set_proxy(co_context, (const char *) value);
583 } else if (g_str_equal(key, "home_url") == TRUE) {
584 tcore_context_set_mmsurl(co_context, (const char *) value);
585 } else if (g_str_equal(key, "profile_enable") == TRUE) {
588 if (g_str_equal(value, "FALSE") == TRUE)
590 _ps_context_set_profile_enable(context, tmp);
595 return __ps_context_update_database(context);
598 static gboolean __ps_context_update_default_internet_to_db(ps_context_t *context, gboolean enabled)
601 GHashTable *in_param;
604 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
605 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
607 g_return_val_if_fail(context != NULL, FALSE);
609 /* Initialize Storage */
610 if (g_str_has_suffix(cp_name, "1"))
611 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
613 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
614 if (handle == NULL) {
615 ps_err_ex_co(co_network, "Failed to get Storage handle");
619 /* Initialize parameters */
620 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
621 g_hash_table_insert(in_param, "1",
622 g_strdup_printf("%d", enabled)); /* Profile enabled/disabled */
623 g_hash_table_insert(in_param, "2",
624 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
627 memset(szQuery, 0x0, sizeof(szQuery));
628 snprintf(szQuery, sizeof(szQuery), "%s",
629 " update pdp_profile set \
630 default_internet_con = ? \
631 where profile_id = ?");
633 rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
634 ps_dbg_ex_co(co_network, "Update Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
637 g_hash_table_destroy(in_param);
639 /* De-initialize Storage */
640 tcore_storage_remove_handle(strg_db, handle);
645 static gboolean __ps_context_update_database(ps_context_t *context)
648 GHashTable *in_param;
651 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
652 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
654 g_return_val_if_fail(context != NULL, FALSE);
656 /* Initialize Storage */
657 if (g_str_has_suffix(cp_name, "1"))
658 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
660 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
661 if (handle == NULL) {
662 ps_err_ex_co(co_network, "Failed to get Storage handle");
666 /* Initialize parameters */
667 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
668 g_hash_table_insert(in_param, "1",
669 tcore_context_get_apn(context->co_context)); /* APN */
670 g_hash_table_insert(in_param, "2",
671 g_strdup_printf("%d", tcore_context_get_auth(context->co_context))); /* Auth Type */
672 g_hash_table_insert(in_param, "3",
673 tcore_context_get_username(context->co_context)); /* Username */
674 g_hash_table_insert(in_param, "4",
675 tcore_context_get_password(context->co_context)); /* Password */
676 g_hash_table_insert(in_param, "5",
677 tcore_context_get_proxy(context->co_context)); /* Proxy */
678 g_hash_table_insert(in_param, "6",
679 tcore_context_get_mmsurl(context->co_context)); /* MMS URL */
680 g_hash_table_insert(in_param, "7",
681 tcore_context_get_profile_name(context->co_context)); /* Profile Name */
682 g_hash_table_insert(in_param, "8",
683 g_strdup_printf("%d", tcore_context_get_type(context->co_context))); /* PDP protocol */
684 g_hash_table_insert(in_param, "9",
685 g_strdup_printf("%d", _ps_context_get_profile_enable(context))); /* Profile Enable */
686 g_hash_table_insert(in_param, "10",
687 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
690 memset(szQuery, 0x0, sizeof(szQuery));
691 snprintf(szQuery, sizeof(szQuery), "%s",
692 " update pdp_profile set \
693 apn = ?, auth_type = ?, auth_id = ?, auth_pwd = ?, \
694 proxy_ip_addr = ?, home_url = ?, profile_name = ?, \
695 pdp_protocol = ?, profile_enable = ? where profile_id = ?");
697 rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
698 ps_dbg_ex_co(co_network, "Update Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
701 g_hash_table_destroy(in_param);
703 /* De-initialize Storage */
704 tcore_storage_remove_handle(strg_db, handle);
709 static gboolean __ps_context_remove_database(ps_context_t *context)
712 GHashTable *in_param;
715 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
716 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
718 g_return_val_if_fail(context != NULL, FALSE);
720 /* Initialize Storage */
721 if (g_str_has_suffix(cp_name, "1"))
722 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
724 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
725 if (handle == NULL) {
726 ps_err_ex_co(co_network, "Failed to get Storage handle");
730 /* Initialize parameters */
731 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
732 g_hash_table_insert(in_param, "1",
733 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
736 memset(szQuery, 0x0, sizeof(szQuery));
737 snprintf(szQuery, sizeof(szQuery), "%s",
738 " delete from pdp_profile where profile_id = ? ");
740 rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, in_param);
741 ps_dbg_ex_co(co_network, "Remove from Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
744 g_hash_table_destroy(in_param);
746 /* De-initialize Storage */
747 tcore_storage_remove_handle(strg_db, handle);
752 static int __ps_context_insert_network_id_to_database(gchar *mccmnc, gchar *cp_name)
755 GHashTable *in_param, *out_param;
763 /* Initialize Storage */
764 if (g_str_has_suffix(cp_name, "1"))
765 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
767 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
768 if (handle == NULL) {
769 err("Failed to get Storage handle");
774 * Check the maximum Network ID that exists in database,
775 * if NONE exists, then 'Network ID' would be equal to 1
776 * else if there exists a valid maximum entry; 'Network ID' would be incremented value.
778 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
779 (GDestroyNotify) g_hash_table_destroy);
782 memset(szQuery, 0x0, sizeof(szQuery));
783 snprintf(szQuery, sizeof(szQuery), "%s",
784 "select max(network_info_id) as network_id from network_info");
786 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
787 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
789 g_hash_table_iter_init(&iter, out_param);
790 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
791 GHashTableIter iter2;
792 gpointer key2, value2;
795 g_hash_table_iter_init(&iter2, (GHashTable *)value);
796 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
797 dbg("key2(%s) value2(%s)", key2, value2);
798 if (g_str_equal(key2, "0") == TRUE) {
799 if (!value2 || g_strcmp0((const char *)value2, "") == 0)
802 network_id = atoi((const char *)value2);
804 /* TODO - Check this logic */
812 g_hash_table_destroy(out_param);
814 /* Increment Network ID */
818 memset(szQuery, 0x0, sizeof(szQuery));
819 snprintf(szQuery, sizeof(szQuery), "%s",
820 " insert into network_info(network_info_id, network_name, mccmnc) values(?, ?, ?) ");
822 /* Initialize parameters */
823 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
824 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_id)); /* Network ID */
825 g_hash_table_insert(in_param, "2", g_strdup_printf("PLMN_%s", mccmnc));
826 g_hash_table_insert(in_param, "3", g_strdup(mccmnc));
828 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
830 err("Failed to insert query to Storage");
835 g_hash_table_destroy(in_param);
837 /* De-initialize Storage */
838 tcore_storage_remove_handle(strg_db, handle);
843 static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id, gchar *cp_name)
846 GHashTable *in_param;
854 gchar *profile_name = NULL, *apn = NULL, *auth_type = NULL;
855 gchar *auth_id = NULL, *auth_pwd = NULL, *proxy_addr = NULL;
856 gchar *home_url = NULL, *svc_id = NULL, *pdp_protocol = NULL;
858 /* Initialize Storage */
859 if (g_str_has_suffix(cp_name, "1"))
860 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
862 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
863 if (handle == NULL) {
864 err("Failed to get Storage handle");
868 profile_id = __ps_context_load_profile_id_from_database(cp_name);
869 if (profile_id < 0) {
870 dbg("Failed to get last Profile ID");
876 /* Increment Profile ID */
879 g_hash_table_iter_init(&iter, property);
880 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
881 if (g_str_equal(key, "profile_name") == TRUE) { /* Profile Name */
883 FREE_AND_ASSIGN(profile_name, value);
886 g_free(profile_name);
888 profile_name = __ps_context_load_network_name_from_database(network_id, cp_name);
890 } else if (g_str_equal(key, "apn") == TRUE) { /* APN */
891 FREE_AND_ASSIGN(apn, value);
892 } else if (g_str_equal(key, "auth_type") == TRUE) { /* Auth Type */
893 FREE_AND_ASSIGN(auth_type, value);
894 } else if (g_str_equal(key, "auth_id") == TRUE) { /* Auth ID */
895 FREE_AND_ASSIGN(auth_id, value);
896 } else if (g_str_equal(key, "auth_pwd") == TRUE) { /* Auth Password */
897 FREE_AND_ASSIGN(auth_pwd, value);
898 } else if (g_str_equal(key, "proxy_addr") == TRUE) { /* Proxy Address */
899 FREE_AND_ASSIGN(proxy_addr, value);
900 } else if (g_str_equal(key, "home_url") == TRUE) { /* Home URL */
901 FREE_AND_ASSIGN(home_url, value);
902 } else if (g_str_equal(key, "svc_ctg_id") == TRUE) { /* Service ID */
903 FREE_AND_ASSIGN(svc_id, value);
904 } else if (g_str_equal(key, "pdp_protocol") == TRUE) { /* PDP protocol */
905 FREE_AND_ASSIGN(pdp_protocol, value);
909 /* Set default PDP protocol */
910 if (pdp_protocol == NULL) {
911 dbg("default pdp_protocol = IPv4");
912 pdp_protocol = g_strdup_printf("%d", CONTEXT_TYPE_IP);
915 /* Initialize parameters */
916 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
918 g_hash_table_insert(in_param, "1",
919 g_strdup_printf("%d", profile_id)); /* Profile ID */
920 g_hash_table_insert(in_param, "2", profile_name); /* Profile Name */
921 g_hash_table_insert(in_param, "3", apn); /* APN */
922 g_hash_table_insert(in_param, "4", auth_type); /* Auth Type */
923 g_hash_table_insert(in_param, "5", auth_id); /* Auth ID */
924 g_hash_table_insert(in_param, "6", auth_pwd); /* Auth Password */
925 g_hash_table_insert(in_param, "7", pdp_protocol); /* PDP Protocol */
926 g_hash_table_insert(in_param, "8", proxy_addr); /* Proxy Address */
927 g_hash_table_insert(in_param, "9", home_url); /* Home URL */
928 g_hash_table_insert(in_param, "10",
929 g_strdup_printf("%d", network_id)); /* Network ID */
930 g_hash_table_insert(in_param, "11", svc_id); /* Service ID */
932 dbg("Profile ID: [%d] Profile name: [%s] APN :[%s] Auth Type [%s] Auth ID: [%s] "
933 "Auth Password: [%s] PDP Protocol: [%s] Proxy Address: [%s] Home URL: [%s] Service ID: [%s]",
934 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, pdp_protocol, proxy_addr, home_url, svc_id);
937 memset(szQuery, 0x0, sizeof(szQuery));
938 snprintf(szQuery, sizeof(szQuery), "%s",
939 " insert into pdp_profile(\
940 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, \
941 pdp_protocol, proxy_ip_addr, home_url, linger_time, \
942 network_info_id, svc_category_id, hidden, editable, \
943 default_internet_con, user_defined, is_roaming_apn, profile_enable) values(\
946 ?, ?, 0, 1, 0, 1, 0, 1)");
948 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
950 err("Failed to insert to Storage");
955 g_hash_table_destroy(in_param);
958 /* De-initialize Storage */
959 tcore_storage_remove_handle(strg_db, handle);
964 static int __ps_context_load_network_id_from_database(gchar *mccmnc, gchar *cp_name)
967 GHashTable *in_param, *out_param;
976 /* Initialize Storage */
977 if (g_str_has_suffix(cp_name, "1"))
978 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
980 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
981 if (handle == NULL) {
982 err("Failed to get Storage handle");
986 /* Initialize parameters */
987 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
988 g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
990 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
991 (GDestroyNotify) g_hash_table_destroy);
994 memset(szQuery, 0x0, sizeof(szQuery));
995 snprintf(szQuery, sizeof(szQuery), "%s",
996 "select network_info_id from network_info where mccmnc = ? ");
998 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
999 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1001 g_hash_table_iter_init(&iter, out_param);
1002 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1003 GHashTableIter iter2;
1004 gpointer key2, value2;
1007 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1008 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1009 if (g_str_equal(key2, "0") == TRUE) {
1010 if (!value2 || (g_strcmp0((const char *)value2, "") == 0))
1013 network_id = atoi((const char *)value2);
1015 /* TODO - Check this out */
1022 /* Free resources */
1023 g_hash_table_destroy(in_param);
1024 g_hash_table_destroy(out_param);
1026 /* De-initialize Storage */
1027 tcore_storage_remove_handle(strg_db, handle);
1032 static gchar *__ps_context_load_network_name_from_database(int network_id, gchar *cp_name)
1035 GHashTable *in_param, *out_param;
1037 gboolean rv = FALSE;
1039 GHashTableIter iter;
1040 gpointer key, value;
1042 gchar *network_name = NULL;
1044 /* Initialize Storage */
1045 if (g_str_has_suffix(cp_name, "1"))
1046 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1048 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1049 if (handle == NULL) {
1050 err("Failed to get Storage handle");
1054 /* Initialize parameters */
1055 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1056 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_id));
1058 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1059 (GDestroyNotify)g_hash_table_destroy);
1062 memset(szQuery, 0x0, sizeof(szQuery));
1063 snprintf(szQuery, sizeof(szQuery), "%s",
1064 "select network_name from network_info where network_info_id = ? ");
1066 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1067 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1069 g_hash_table_iter_init(&iter, out_param);
1070 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1071 GHashTableIter iter2;
1072 gpointer key2, value2;
1075 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1076 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1077 if (g_str_equal(key2, "0") == TRUE) {
1078 g_free(network_name);
1079 network_name = g_strdup(value2);
1081 /* TODO - Check this logic */
1088 /* Free resources */
1089 g_hash_table_destroy(in_param);
1090 g_hash_table_destroy(out_param);
1092 /* De-initialize Storage */
1093 tcore_storage_remove_handle(strg_db, handle);
1095 return network_name;
1098 static int __ps_context_load_profile_id_from_database(gchar *cp_name)
1101 GHashTable *out_param;
1103 gboolean rv = FALSE;
1105 GHashTableIter iter;
1106 gpointer key, value;
1108 int profile_id = -1;
1110 /* Initialize Storage */
1111 if (g_str_has_suffix(cp_name, "1"))
1112 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1114 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1115 if (handle == NULL) {
1116 err("Failed to get Storage handle");
1120 /* Initialize parameters */
1121 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1122 (GDestroyNotify) g_hash_table_destroy);
1125 memset(szQuery, 0x0, sizeof(szQuery));
1126 snprintf(szQuery, sizeof(szQuery), "%s",
1127 "select max(profile_id) as last_profile from pdp_profile");
1129 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
1130 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1132 g_hash_table_iter_init(&iter, out_param);
1133 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1134 GHashTableIter iter2;
1135 gpointer key2, value2;
1138 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1139 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1140 if (g_str_equal(key2, "0") == TRUE) {
1141 if (!value2 || (g_strcmp0((const char *)value2, "") == 0))
1144 profile_id = atoi((const char *)value2);
1146 /* TODO - Check this logic */
1153 /* Free resources */
1154 g_hash_table_destroy(out_param);
1156 /* De-initialize Storage */
1157 tcore_storage_remove_handle(strg_db, handle);
1162 static int __ps_context_load_num_of_pdn_from_database(gchar *mccmnc, gchar *cp_name)
1165 GHashTable *in_param, *out_param;
1167 gboolean rv = FALSE;
1169 GHashTableIter iter;
1170 gpointer key, value;
1174 /* Initialize Storage */
1175 if (g_str_has_suffix(cp_name, "1"))
1176 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1178 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1179 if (handle == NULL) {
1180 err("Failed to get Storage handle");
1184 /* Initialize parameters */
1185 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1186 g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
1188 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1189 (GDestroyNotify) g_hash_table_destroy);
1192 memset(szQuery, 0x0, sizeof(szQuery));
1193 snprintf(szQuery, sizeof(szQuery), "%s",
1194 "select a.max_pdp_3g from max_pdp a, network_info b \
1195 where a.network_info_id = b.network_info_id and b.mccmnc = ? ");
1197 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1198 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1200 g_hash_table_iter_init(&iter, out_param);
1201 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1202 GHashTableIter iter2;
1203 gpointer key2, value2;
1206 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1207 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1208 if (g_str_equal(key2, "0") == TRUE) {
1209 if (!value2 || (g_strcmp0((const char *)value2, "") == 0)) {
1211 dbg("There is NO value... Using 'default'");
1213 num_of_pdn = atoi((const char *) value2);
1214 dbg("value (%d)", num_of_pdn);
1217 /* TODO - Check this logic */
1224 if (num_of_pdn <= 0) {
1225 dbg("Loaded value is wrong... restoring to 'default'");
1226 num_of_pdn = PS_MAX_CID;
1227 } else if (num_of_pdn > PS_MAX_CID) {
1228 dbg("Loaded value is gretaer than 3... restoring to 'default'");
1229 num_of_pdn = PS_MAX_CID;
1232 /* Free resources */
1233 g_hash_table_destroy(in_param);
1234 g_hash_table_destroy(out_param);
1236 /* De-initialize Storage */
1237 tcore_storage_remove_handle(strg_db, handle);
1242 static gboolean __ps_context_remove_profile_tuple(dictionary *dic, int profile_index, gchar *cp_name)
1245 gboolean rv = FALSE;
1246 GHashTable *in_param;
1247 gchar *network_info_id;
1248 gchar *section_key = NULL;
1251 /* Initialize Storage */
1252 if (g_str_has_suffix(cp_name, "1"))
1253 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1255 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1256 if (handle == NULL) {
1257 err("Failed to get Storage handle");
1261 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1263 /* network info id */
1264 section_key = g_strdup_printf("connection:network_info_id_%d", profile_index);
1265 network_info_id = iniparser_getstring(dic, section_key, NULL);
1266 g_hash_table_insert(in_param, "1", g_strdup(network_info_id));
1267 g_free(section_key);
1270 memset(szQuery, 0x0, sizeof(szQuery));
1271 snprintf(szQuery, sizeof(szQuery), "%s",
1272 " delete from pdp_profile where network_info_id = ?");
1274 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
1275 dbg("delete from pdp_profile where network_info_id = %s, result(%d)", network_info_id, rv);
1276 /* Free resources */
1277 g_hash_table_destroy(in_param);
1279 /* De-initialize Storage */
1280 tcore_storage_remove_handle(strg_db, handle);
1285 static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int profile_index, gchar *cp_name)
1288 GHashTable *in_param;
1289 gboolean rv = FALSE;
1291 /* Initialize Storage */
1292 if (g_str_has_suffix(cp_name, "1"))
1293 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1295 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1296 if (handle == NULL) {
1297 err("Failed to get Storage handle");
1301 /* Initialize parameters */
1302 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1306 gchar *item_key = NULL;
1307 item_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1308 profile_id = iniparser_getstring(dic, item_key, NULL);
1309 if (profile_id == NULL) {
1313 g_hash_table_insert(in_param, "1", g_strdup(profile_id));
1318 gchar *profile_name;
1319 gchar *item_key = NULL;
1320 item_key = g_strdup_printf("connection:profile_name_%d", profile_index);
1321 profile_name = iniparser_getstring(dic, item_key, NULL);
1322 if (profile_name == NULL) {
1326 g_hash_table_insert(in_param, "2", g_strdup(profile_name));
1332 gchar *item_key = NULL;
1333 item_key = g_strdup_printf("connection:apn_%d", profile_index);
1334 apn = iniparser_getstring(dic, item_key, NULL);
1339 g_hash_table_insert(in_param, "3", g_strdup(apn));
1345 gchar *item_key = NULL;
1346 item_key = g_strdup_printf("connection:auth_type_%d", profile_index);
1347 auth_type = iniparser_getstring(dic, item_key, NULL);
1348 if (auth_type == NULL)
1349 g_hash_table_insert(in_param, "4", g_strdup_printf("%d", CONTEXT_AUTH_NONE));
1351 g_hash_table_insert(in_param, "4", g_strdup(auth_type));
1357 gchar *item_key = NULL;
1358 item_key = g_strdup_printf("connection:auth_id_%d", profile_index);
1359 auth_id = iniparser_getstring(dic, item_key, NULL);
1360 g_hash_table_insert(in_param, "5", g_strdup(auth_id));
1366 gchar *item_key = NULL;
1367 item_key = g_strdup_printf("connection:auth_pwd_%d", profile_index);
1368 auth_pwd = iniparser_getstring(dic, item_key, NULL);
1369 g_hash_table_insert(in_param, "6", g_strdup(auth_pwd));
1374 gchar *pdp_protocol;
1375 gchar *item_key = NULL;
1376 item_key = g_strdup_printf("connection:pdp_protocol_%d", profile_index);
1377 pdp_protocol = iniparser_getstring(dic, item_key, NULL);
1378 if (pdp_protocol == NULL)
1379 g_hash_table_insert(in_param, "7", g_strdup_printf("%d", CONTEXT_TYPE_IP));
1381 g_hash_table_insert(in_param, "7", g_strdup(pdp_protocol));
1386 gchar *proxy_ip_addr;
1387 gchar *section_key = NULL;
1388 section_key = g_strdup_printf("connection:proxy_ip_addr_%d", profile_index);
1389 proxy_ip_addr = iniparser_getstring(dic, section_key, NULL);
1390 g_hash_table_insert(in_param, "8", g_strdup(proxy_ip_addr));
1391 g_free(section_key);
1396 gchar *section_key = NULL;
1397 section_key = g_strdup_printf("connection:home_url_%d", profile_index);
1398 home_url = iniparser_getstring(dic, section_key, NULL);
1399 g_hash_table_insert(in_param, "9", g_strdup(home_url));
1400 g_free(section_key);
1405 gchar *section_key = NULL;
1406 section_key = g_strdup_printf("connection:linger_time_%d", profile_index);
1407 linger_time = iniparser_getstring(dic, section_key, NULL);
1408 g_hash_table_insert(in_param, "10", g_strdup(linger_time));
1409 g_free(section_key);
1412 {/* traffic class */
1413 gchar *traffic_class;
1414 gchar *section_key = NULL;
1415 section_key = g_strdup_printf("connection:traffic_class_%d", profile_index);
1416 traffic_class = iniparser_getstring(dic, section_key, NULL);
1417 g_hash_table_insert(in_param, "11", g_strdup(traffic_class));
1418 g_free(section_key);
1421 {/* is static ip address */
1422 gchar *is_static_ip_addr;
1423 gchar *section_key = NULL;
1424 section_key = g_strdup_printf("connection:is_static_ip_addr_%d", profile_index);
1425 is_static_ip_addr = iniparser_getstring(dic, section_key, NULL);
1426 g_hash_table_insert(in_param, "12", g_strdup(is_static_ip_addr));
1427 g_free(section_key);
1430 {/* ip address if static ip is true */
1432 gchar *section_key = NULL;
1433 section_key = g_strdup_printf("connection:ip_addr_%d", profile_index);
1434 ip_addr = iniparser_getstring(dic, section_key, NULL);
1435 g_hash_table_insert(in_param, "13", g_strdup(ip_addr));
1436 g_free(section_key);
1439 {/* is static dns address */
1440 gchar *is_static_dns_addr;
1441 gchar *section_key = NULL;
1442 section_key = g_strdup_printf("connection:is_static_dns_addr_%d", profile_index);
1443 is_static_dns_addr = iniparser_getstring(dic, section_key, NULL);
1444 g_hash_table_insert(in_param, "14", g_strdup(is_static_dns_addr));
1445 g_free(section_key);
1448 {/* dns address 1 */
1450 gchar *section_key = NULL;
1451 section_key = g_strdup_printf("connection:dns_addr1_%d", profile_index);
1452 dns_addr1 = iniparser_getstring(dic, section_key, NULL);
1453 g_hash_table_insert(in_param, "15", g_strdup(dns_addr1));
1454 g_free(section_key);
1457 {/* dns address 2 */
1459 gchar *section_key = NULL;
1460 section_key = g_strdup_printf("connection:dns_addr2_%d", profile_index);
1461 dns_addr2 = iniparser_getstring(dic, section_key, NULL);
1462 g_hash_table_insert(in_param, "16", g_strdup(dns_addr2));
1463 g_free(section_key);
1466 {/* network info id */
1467 gchar *network_info_id;
1468 gchar *section_key = NULL;
1469 section_key = g_strdup_printf("connection:network_info_id_%d", profile_index);
1470 network_info_id = iniparser_getstring(dic, section_key, NULL);
1471 g_hash_table_insert(in_param, "17", g_strdup(network_info_id));
1472 g_free(section_key);
1475 {/* service category id */
1476 gchar *svc_category_id;
1477 gchar *section_key = NULL;
1478 section_key = g_strdup_printf("connection:svc_category_id_%d", profile_index);
1479 svc_category_id = iniparser_getstring(dic, section_key, NULL);
1480 if (svc_category_id == NULL)
1481 g_hash_table_insert(in_param, "18", g_strdup_printf("%d", CONTEXT_ROLE_UNKNOWN));
1483 g_hash_table_insert(in_param, "18", g_strdup(svc_category_id));
1484 g_free(section_key);
1489 gchar *section_key = NULL;
1490 section_key = g_strdup_printf("connection:hidden_%d", profile_index);
1491 hidden = iniparser_getstring(dic, section_key, NULL);
1493 g_hash_table_insert(in_param, "19", g_strdup_printf("%d", FALSE));
1495 g_hash_table_insert(in_param, "19", g_strdup(hidden));
1496 g_free(section_key);
1501 gchar *section_key = NULL;
1502 section_key = g_strdup_printf("connection:editable_%d", profile_index);
1503 editable = iniparser_getstring(dic, section_key, NULL);
1504 if (editable == NULL)
1505 g_hash_table_insert(in_param, "20", g_strdup_printf("%d", TRUE));
1507 g_hash_table_insert(in_param, "20", g_strdup(editable));
1508 g_free(section_key);
1511 {/* default internet connection */
1512 gchar *default_internet_con;
1513 gchar *section_key = NULL;
1514 section_key = g_strdup_printf("connection:default_internet_con_%d", profile_index);
1515 default_internet_con = iniparser_getstring(dic, section_key, NULL);
1516 if (default_internet_con == NULL)
1517 g_hash_table_insert(in_param, "21", g_strdup_printf("%d", FALSE));
1519 g_hash_table_insert(in_param, "21", g_strdup(default_internet_con));
1520 g_free(section_key);
1523 {/* insert data into table */
1524 gchar *is_roaming_apn;
1525 gchar *section_key = NULL;
1526 section_key = g_strdup_printf("connection:is_roaming_apn_%d", profile_index);
1527 is_roaming_apn = iniparser_getstring(dic, section_key, NULL);
1528 if (is_roaming_apn == NULL)
1529 g_hash_table_insert(in_param, "22", g_strdup_printf("%d", FALSE));
1531 g_hash_table_insert(in_param, "22", g_strdup(is_roaming_apn));
1532 g_free(section_key);
1535 {/* insert data into table */
1539 memset(szQuery, 0x0, sizeof(szQuery));
1540 snprintf(szQuery, sizeof(szQuery), "%s",
1541 " insert into pdp_profile(\
1542 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, \
1543 pdp_protocol, proxy_ip_addr, home_url, linger_time, \
1544 traffic_class, is_static_ip_addr, ip_addr, is_static_dns_addr, dns_addr1, dns_addr2, \
1545 network_info_id, svc_category_id, hidden, editable, default_internet_con, \
1546 user_defined, is_roaming_apn, profile_enable) values(\
1550 ?, ?, ?, ?, ?, 0, ?, 1)");
1552 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
1553 dbg("Insert to Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1557 /* Free resources */
1558 g_hash_table_destroy(in_param);
1560 /* De-initialize Storage */
1561 tcore_storage_remove_handle(strg_db, handle);
1566 static int __ps_context_get_network_id(gchar *mccmnc, gchar *cp_name)
1570 network_id = __ps_context_load_network_id_from_database(mccmnc, cp_name);
1571 dbg("network id(%d)", network_id);
1575 network_id = __ps_context_insert_network_id_to_database(mccmnc, cp_name);
1576 if (network_id <= 0)
1582 GVariant *__ps_context_get_profile_properties(gpointer object, GVariantBuilder *properties)
1584 gchar *s_authtype = NULL, *s_role = NULL, *s_type = NULL;
1585 ps_context_t *context = NULL;
1586 char *apn, *username, *password, *proxy_addr, *home_url, *profile_name;
1588 g_return_val_if_fail(object != NULL, NULL);
1589 g_return_val_if_fail(properties != NULL, NULL);
1591 context = (ps_context_t *) object;
1592 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)),
1593 "get profile properties, path(%s)", _ps_context_ref_path(context));
1595 s_authtype = g_strdup_printf("%d", tcore_context_get_auth(context->co_context));
1596 s_role = g_strdup_printf("%d", tcore_context_get_role(context->co_context));
1597 s_type = g_strdup_printf("%d", tcore_context_get_type(context->co_context));
1599 apn = tcore_context_get_apn(context->co_context);
1600 username = tcore_context_get_username(context->co_context);
1601 password = tcore_context_get_password(context->co_context);
1602 proxy_addr = tcore_context_get_proxy(context->co_context);
1603 home_url = tcore_context_get_mmsurl(context->co_context);
1604 profile_name = tcore_context_get_profile_name(context->co_context);
1605 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
1607 g_variant_builder_add(properties, "{ss}", "path", context->path);
1609 g_variant_builder_add(properties, "{ss}", "apn", apn);
1612 g_variant_builder_add(properties, "{ss}", "auth_type", s_authtype);
1615 g_variant_builder_add(properties, "{ss}", "auth_id", username);
1618 g_variant_builder_add(properties, "{ss}", "auth_pwd", password);
1621 g_variant_builder_add(properties, "{ss}", "pdp_protocol", s_type);
1624 g_variant_builder_add(properties, "{ss}", "proxy_addr", proxy_addr);
1627 g_variant_builder_add(properties, "{ss}", "home_url", home_url);
1630 g_variant_builder_add(properties, "{ss}", "svc_ctg_id", s_role);
1632 g_variant_builder_add(properties, "{ss}", "profile_name", profile_name);
1633 g_variant_builder_add(properties, "{ss}", "hidden", BOOL2STRING(context->hidden));
1634 g_variant_builder_add(properties, "{ss}", "editable", BOOL2STRING(context->editable));
1635 g_variant_builder_add(properties, "{ss}", "default_internet_conn", BOOL2STRING(context->is_default));
1636 g_variant_builder_add(properties, "{ss}", "profile_enable", BOOL2STRING(context->profile_enable));
1638 /* Freeing locally allocated memory */
1647 g_free(profile_name);
1651 return g_variant_builder_end(properties);
1654 static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled)
1656 ps_context_t *context = object;
1658 g_return_val_if_fail(context != NULL, FALSE);
1660 context->is_default = enabled;
1664 static gpointer __ps_context_add_context(gpointer modem, gchar *mccmnc, int profile_id)
1667 GHashTable *in_param, *out_param;
1669 gboolean rv = FALSE;
1671 ps_modem_t *mdm = modem;
1672 CoreObject *co_modem = _ps_modem_ref_co_modem(mdm);
1673 GDBusConnection *conn = NULL;
1674 TcorePlugin *p = NULL;
1677 GHashTableIter iter;
1678 gpointer object = NULL;
1679 gpointer key, value;
1681 /* Initialize Storage */
1682 if (g_str_has_suffix(mdm->cp_name, "1"))
1683 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1685 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1686 if (handle == NULL) {
1687 ps_err_ex_co(co_modem, "Failed to get Storage handle");
1691 /* Initialize parameters */
1692 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1693 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", profile_id));
1695 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1696 (GDestroyNotify) g_hash_table_destroy);
1699 memset(szQuery, 0x0, sizeof(szQuery));
1700 snprintf(szQuery, sizeof(szQuery), "%s",
1702 a.network_info_id, a.network_name, a.mccmnc, \
1703 b.profile_id, b.profile_name, b.apn, \
1704 b.auth_type, b.auth_id, b.auth_pwd, \
1705 b.proxy_ip_addr, b.home_url, b.pdp_protocol, \
1706 b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr, \
1707 b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, \
1708 b.default_internet_con, b.user_defined, b.is_roaming_apn, b.profile_enable \
1709 from network_info a, pdp_profile b \
1710 where b.profile_id = ? and a.network_info_id = b.network_info_id ");
1712 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 26);
1713 ps_dbg_ex_co(co_modem, "Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1715 ps_dbg_ex_co(co_modem, "Create profile by Profile ID: [%d]", profile_id);
1716 conn = _ps_modem_ref_dbusconn(modem);
1717 p = _ps_modem_ref_plugin(modem);
1719 g_hash_table_iter_init(&iter, out_param);
1720 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1721 /* Create context */
1722 object = __ps_context_create_context(conn, p, mccmnc, (GHashTable *)value, mdm->cp_name);
1723 path = _ps_context_ref_path(object);
1725 /* Insert to contexts */
1726 mdm->contexts = g_slist_append(mdm->contexts, object);
1727 ps_dbg_ex_co(co_modem, "context (%p, %s) insert to hash", object, path);
1730 /* Free resources */
1731 g_hash_table_destroy(in_param);
1732 g_hash_table_destroy(out_param);
1734 /* De-initialize Storage */
1735 tcore_storage_remove_handle(strg_db, handle);
1740 gboolean _ps_context_check_is_roaming_apn_support(gchar* mccmnc, gchar* cp_name)
1743 GHashTable *in_param, *out_param;
1745 gboolean rv = FALSE, ret = FALSE;
1747 int network_info_id = -1;
1749 /* Initialize Storage */
1750 if (g_str_has_suffix(cp_name, "1"))
1751 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1753 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1754 if (handle == NULL) {
1755 err("Failed to get Storage handle");
1759 network_info_id = __ps_context_load_network_id_from_database(mccmnc, cp_name);
1760 if (network_info_id == -1)
1761 err("Failed to load network_info_id from mccmnc (%s)", mccmnc);
1763 /* Initialize parameters */
1764 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1765 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_info_id));
1767 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1768 (GDestroyNotify) g_hash_table_destroy);
1771 memset(szQuery, 0x0, sizeof(szQuery));
1772 snprintf(szQuery, sizeof(szQuery), "%s", "select profile_id from pdp_profile \
1773 where network_info_id = ? and is_roaming_apn = 1 ");
1775 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1776 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1778 profile_cnt = g_hash_table_size(out_param);
1779 if (profile_cnt > 0) {
1780 dbg("roaming profiles for (mccmnc: %s [%d]) exists: count[%d]", mccmnc, network_info_id, profile_cnt);
1783 /* Free resources */
1784 g_hash_table_destroy(in_param);
1785 g_hash_table_destroy(out_param);
1787 /* De-initialize Storage */
1788 tcore_storage_remove_handle(strg_db, handle);
1792 gboolean _ps_context_initialize(gpointer plugin)
1796 rv &= __ps_context_create_storage_handle(plugin);
1797 dbg("Global variable initialized: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1802 gboolean _ps_context_reset_profile_table(gchar *cp_name)
1806 gboolean rv = FALSE;
1808 /* Initialize Storage */
1809 if (g_str_has_suffix(cp_name, "1"))
1810 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1812 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1813 if (handle == NULL) {
1814 err("Failed to get Storage handle");
1819 memset(szQuery, 0x0, sizeof(szQuery));
1820 snprintf(szQuery, sizeof(szQuery), "%s", " delete from pdp_profile");
1822 rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, NULL);
1823 dbg("Reset profile table: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1825 /* De-initialize Storage */
1826 tcore_storage_remove_handle(strg_db, handle);
1831 gboolean _ps_context_fill_profile_table_from_ini_file(gchar *cp_name)
1833 int profile_index = 1;
1835 gchar *section_key = NULL;
1836 dictionary *dic = NULL;
1838 if (g_str_has_suffix(cp_name, "1"))
1839 dic = iniparser_load("/opt/system/csc-default/data/csc-default-data-connection-2.ini");
1841 dic = iniparser_load("/opt/system/csc-default/data/csc-default-data-connection.ini");
1844 dbg("fail to load the csc default file");
1850 section_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1851 dbg("section key (%s)", section_key);
1852 data_exist = iniparser_find_entry(dic, section_key);
1854 g_free(section_key);
1855 dbg("no more data in ini");
1858 __ps_context_remove_profile_tuple(dic, profile_index, cp_name);
1859 g_free(section_key);
1866 section_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1867 dbg("section key (%s)", section_key);
1868 data_exist = iniparser_find_entry(dic, section_key);
1870 g_free(section_key);
1871 iniparser_freedict(dic);
1872 dbg("no more data in ini");
1875 __ps_context_insert_profile_tuple(dic, profile_index, cp_name);
1876 g_free(section_key);
1883 GSList* _ps_context_create_hashtable(gpointer modem, gboolean roaming)
1886 GHashTable *in_param;
1887 GSList *out_param = NULL;
1889 gboolean rv = FALSE, roaming_apn = FALSE;
1893 ps_modem_t *mdm = modem;
1894 CoreObject *co_modem = _ps_modem_ref_co_modem(mdm);
1896 /* Initialize Storage */
1897 if (g_str_has_suffix(mdm->cp_name, "1"))
1898 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1900 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1901 if (handle == NULL) {
1902 ps_err_ex_co(co_modem, "Failed to get Storage handle");
1906 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1908 /* Check/Store roaming APN support at every SIM init complete. */
1909 roaming_apn = _ps_context_check_is_roaming_apn_support(mdm->operator, mdm->cp_name);
1910 _ps_modem_set_roaming_apn_support(modem, roaming_apn);
1913 /* Check roaming APN support first in the Roaming network. */
1914 ps_warn_ex_co(co_modem, "Roaming Network[%s], Roaming APN Support[%s]",
1915 roaming ? "TRUE" : "FALSE", roaming_apn ? "TRUE" : "FALSE");
1916 roaming = roaming_apn;
1918 ps_dbg_ex_co(co_modem, "create profile by mccmnc (%s)", mdm->operator);
1920 memset(szQuery, 0x0, sizeof(szQuery));
1921 snprintf(szQuery, sizeof(szQuery), "%s",
1923 a.network_info_id, a.network_name, a.mccmnc, \
1924 b.profile_id, b.profile_name, b.apn, \
1925 b.auth_type, b.auth_id, b.auth_pwd, \
1926 b.proxy_ip_addr, b.home_url, b.pdp_protocol, \
1927 b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr, \
1928 b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, \
1929 b.default_internet_con, b.user_defined, b.is_roaming_apn, b.profile_enable \
1930 from network_info a, pdp_profile b \
1931 where a.mccmnc = ? and b.is_roaming_apn = ? and a.network_info_id = b.network_info_id ");
1933 g_hash_table_insert(in_param, "1", g_strdup(mdm->operator));
1934 g_hash_table_insert(in_param, "2", g_strdup_printf("%d", roaming));
1936 for (retry = 0; retry < 5; retry++) {
1937 ps_dbg_ex_co(co_modem, "Reading database", mdm->operator);
1938 rv = tcore_storage_read_query_database_in_order(strg_db, handle, szQuery, in_param, &out_param, 26);
1942 ps_dbg_ex_co(co_modem, "Read Database: [%s], Retry[%d]", (rv == TRUE ? "SUCCESS" : "FAIL"), retry);
1944 for (index = 0; index < g_slist_length(out_param); index++) {
1946 gpointer object = NULL;
1947 GHashTable *value = NULL;
1949 value = g_slist_nth_data(out_param, index);
1952 /* Create new 'context' */
1953 object = __ps_context_create_context(mdm->conn, mdm->plg, mdm->operator, value, mdm->cp_name);
1954 path = _ps_context_ref_path(object);
1956 mdm->contexts = g_slist_append(mdm->contexts, object);
1957 ps_dbg_ex_co(co_modem, "context (%p, %s) insert to linked-list", object, path);
1960 g_hash_table_destroy(in_param);
1961 g_slist_free_full(out_param, (GDestroyNotify)g_hash_table_destroy);
1963 /* De-initialize Storage */
1964 tcore_storage_remove_handle(strg_db, handle);
1967 return mdm->contexts;
1970 gboolean _ps_context_add_context(gpointer modem, gchar *operator, GHashTable *property)
1972 GHashTable *services = NULL;
1973 gpointer context = NULL;
1974 ps_modem_t *mdm = modem;
1976 GHashTableIter iter;
1977 gpointer key, value;
1981 network_id = __ps_context_get_network_id(operator, mdm->cp_name);
1982 if (network_id <= 0) {
1983 dbg("fail to add network info");
1987 profile_id = __ps_context_insert_profile_to_database(property, network_id, mdm->cp_name);
1988 if (profile_id <= 0) {
1989 dbg("fail to insert profile info to database");
1993 context = __ps_context_add_context(modem, operator, profile_id);
1997 services = _ps_modem_ref_services(modem);
2001 g_hash_table_iter_init(&iter, services);
2002 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE)
2003 _ps_service_ref_context(value, context);
2008 gboolean _ps_context_get_properties_handler(gpointer object, GVariantBuilder *properties)
2010 int context_state = 0;
2011 gboolean active = FALSE;
2012 ps_context_t *context = object;
2013 char *dev_name = NULL;
2015 char *ipv4_address, *ipv4_gateway, *ipv4_dns1, *ipv4_dns2;
2016 char *ipv6_address, *ipv6_gateway, *ipv6_dns1, *ipv6_dns2;
2019 dbg("get context properties");
2020 g_return_val_if_fail(context != NULL, FALSE);
2021 g_return_val_if_fail(properties != NULL, FALSE);
2023 context_state = tcore_context_get_state(context->co_context);
2024 if (context_state == CONTEXT_STATE_ACTIVATED)
2028 ipv4_address = tcore_context_get_ipv4_addr(context->co_context);
2029 ipv4_gateway = tcore_context_get_ipv4_gw(context->co_context);
2030 ipv4_dns1 = tcore_context_get_ipv4_dns1(context->co_context);
2031 ipv4_dns2 = tcore_context_get_ipv4_dns2(context->co_context);
2034 ipv6_address = tcore_context_get_ipv6_addr(context->co_context);
2035 ipv6_gateway = tcore_context_get_ipv6_gw(context->co_context);
2036 ipv6_dns1 = tcore_context_get_ipv6_dns1(context->co_context);
2037 ipv6_dns2 = tcore_context_get_ipv6_dns2(context->co_context);
2039 proxy = tcore_context_get_proxy(context->co_context);
2040 dev_name = tcore_context_get_ipv4_devname(context->co_context);
2042 g_variant_builder_open(properties, G_VARIANT_TYPE("a{ss}"));
2044 g_variant_builder_add(properties, "{ss}", "path", (context->path));
2045 g_variant_builder_add(properties, "{ss}", "active", (BOOL2STRING(active)));
2047 /* Adding IPV4 data to builder */
2049 g_variant_builder_add(properties, "{ss}", "ipv4_address", ipv4_address);
2052 g_variant_builder_add(properties, "{ss}", "ipv4_gateway", ipv4_gateway);
2055 g_variant_builder_add(properties, "{ss}", "ipv4_dns1", ipv4_dns1);
2058 g_variant_builder_add(properties, "{ss}", "ipv4_dns2", ipv4_dns2);
2060 /* Adding IPV6 data to builder */
2061 g_variant_builder_add(properties, "{ss}", "ipv6_address",
2062 (ipv6_address == NULL ? "::" : ipv6_address));
2063 g_variant_builder_add(properties, "{ss}", "ipv6_gateway",
2064 (ipv6_gateway == NULL ? "::" : ipv6_gateway));
2065 g_variant_builder_add(properties, "{ss}", "ipv6_dns1",
2066 (ipv6_dns1 == NULL ? "::" : ipv6_dns1));
2067 g_variant_builder_add(properties, "{ss}", "ipv6_dns2",
2068 (ipv6_dns2 == NULL ? "::" : ipv6_dns2));
2071 g_variant_builder_add(properties, "{ss}", "proxy", proxy);
2074 g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
2076 g_variant_builder_add(properties, "{ss}", "default_internet_conn", (BOOL2STRING(context->is_default)));
2077 g_variant_builder_close(properties);
2079 /* Freeing local memory */
2080 g_free(ipv4_address);
2081 g_free(ipv4_gateway);
2084 g_free(ipv6_address);
2085 g_free(ipv6_gateway);
2096 GVariant *_ps_context_get_properties(gpointer object, GVariantBuilder *properties)
2098 int context_state = 0;
2099 gboolean active = FALSE;
2100 ps_context_t *context = object;
2101 char *dev_name = NULL;
2103 char *ipv4_address, *ipv4_gateway, *ipv4_dns1, *ipv4_dns2;
2104 char *ipv6_address, *ipv6_gateway, *ipv6_dns1, *ipv6_dns2;
2105 pcscf_addr *pcscf_ipv4, *pcscf_ipv6;
2108 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "get context properties");
2109 g_return_val_if_fail(context != NULL, NULL);
2110 g_return_val_if_fail(properties != NULL, NULL);
2112 context_state = tcore_context_get_state(context->co_context);
2113 if (context_state == CONTEXT_STATE_ACTIVATED)
2116 active &= context->b_active;
2119 ipv4_address = tcore_context_get_ipv4_addr(context->co_context);
2120 ipv4_gateway = tcore_context_get_ipv4_gw(context->co_context);
2121 ipv4_dns1 = tcore_context_get_ipv4_dns1(context->co_context);
2122 ipv4_dns2 = tcore_context_get_ipv4_dns2(context->co_context);
2125 ipv6_address = tcore_context_get_ipv6_addr(context->co_context);
2126 ipv6_gateway = tcore_context_get_ipv6_gw(context->co_context);
2127 ipv6_dns1 = tcore_context_get_ipv6_dns1(context->co_context);
2128 ipv6_dns2 = tcore_context_get_ipv6_dns2(context->co_context);
2131 pcscf_ipv4 = tcore_context_get_pcscf_ipv4_addr(context->co_context);
2132 pcscf_ipv6 = tcore_context_get_pcscf_ipv6_addr(context->co_context);
2134 proxy = tcore_context_get_proxy(context->co_context);
2135 dev_name = tcore_context_get_ipv4_devname(context->co_context);
2137 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
2139 g_variant_builder_add(properties, "{ss}", "path", (context->path));
2140 g_variant_builder_add(properties, "{ss}", "active", (BOOL2STRING(active)));
2141 g_variant_builder_add(properties, "{ss}", "routing_only", (BOOL2STRING(context->b_routing_only)));
2143 /* Adding IPV4 data to builder */
2145 g_variant_builder_add(properties, "{ss}", "ipv4_address", ipv4_address);
2148 g_variant_builder_add(properties, "{ss}", "ipv4_gateway", ipv4_gateway);
2151 g_variant_builder_add(properties, "{ss}", "ipv4_dns1", ipv4_dns1);
2154 g_variant_builder_add(properties, "{ss}", "ipv4_dns2", ipv4_dns2);
2156 /* Adding IPV6 data to builder */
2157 g_variant_builder_add(properties, "{ss}", "ipv6_address",
2158 (ipv6_address == NULL ? "::" : ipv6_address));
2159 g_variant_builder_add(properties, "{ss}", "ipv6_gateway",
2160 (ipv6_gateway == NULL ? "::" : ipv6_gateway));
2161 g_variant_builder_add(properties, "{ss}", "ipv6_dns1",
2162 (ipv6_dns1 == NULL ? "::" : ipv6_dns1));
2163 g_variant_builder_add(properties, "{ss}", "ipv6_dns2",
2164 (ipv6_dns2 == NULL ? "::" : ipv6_dns2));
2167 gboolean ipv6_link_only = FALSE;
2168 if (g_ascii_strncasecmp(ipv6_address, "fe80::", (gsize)6) == 0)
2169 ipv6_link_only = TRUE;
2170 g_variant_builder_add(properties, "{ss}", "ipv6_link_only", BOOL2STRING(ipv6_link_only));
2174 g_variant_builder_add(properties, "{ss}", "proxy", proxy);
2177 g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
2182 buf = g_strdup_printf("%d", pcscf_ipv4->count);
2183 g_variant_builder_add(properties, "{ss}", "pcscf_ipv4_count", buf);
2186 for (i = 0; i < pcscf_ipv4->count; i++) {
2187 buf = g_strdup_printf("%s_%d", "pcscf_ipv4_addr", i);
2188 g_variant_builder_add(properties, "{ss}", buf, pcscf_ipv4->addr[i]);
2192 /* Update pCSCF address (IPv4) count as '0' */
2193 g_variant_builder_add(properties, "{ss}", "pcscf_ipv4_count", "0");
2199 buf = g_strdup_printf("%d", pcscf_ipv6->count);
2200 g_variant_builder_add(properties, "{ss}", "pcscf_ipv6_count", buf);
2203 for (i = 0; i < pcscf_ipv6->count; i++) {
2204 buf = g_strdup_printf("%s_%d", "pcscf_ipv6_addr", i);
2205 g_variant_builder_add(properties, "{ss}", buf, pcscf_ipv6->addr[i]);
2209 /* Update pCSCF address (IPv6) count as '0' */
2210 g_variant_builder_add(properties, "{ss}", "pcscf_ipv6_count", "0");
2213 g_variant_builder_add(properties, "{ss}", "default_internet_conn", BOOL2STRING(context->is_default));
2215 /* Freeing local memory */
2217 for (i = 0; i < pcscf_ipv4->count; i++)
2218 g_free(pcscf_ipv4->addr[i]);
2222 for (i = 0; i < pcscf_ipv6->count; i++)
2223 g_free(pcscf_ipv6->addr[i]);
2226 g_free(ipv4_address);
2227 g_free(ipv4_gateway);
2230 g_free(ipv6_address);
2231 g_free(ipv6_gateway);
2238 return g_variant_builder_end(properties);
2241 gboolean _ps_context_set_alwayson_enable(gpointer object, gboolean enabled)
2243 ps_context_t *context = object;
2244 int role = CONTEXT_ROLE_UNKNOWN;
2245 g_return_val_if_fail(context != NULL, FALSE);
2247 role = tcore_context_get_role(context->co_context);
2249 if ((role == CONTEXT_ROLE_INTERNET) && context->is_default)
2250 context->alwayson = enabled;
2252 #ifdef PREPAID_SIM_APN_SUPPORT
2253 if ((role == CONTEXT_ROLE_PREPAID_INTERNET) && context->is_default)
2254 context->prepaid_alwayson = enabled;
2256 dbg("context (%p) alwayson (%d)", context, context->alwayson);
2260 gboolean _ps_context_get_default_context(gpointer object, int svc_cat_id)
2262 ps_context_t *context = object;
2263 int role = CONTEXT_ROLE_UNKNOWN;
2264 g_return_val_if_fail(context != NULL, FALSE);
2266 role = tcore_context_get_role(context->co_context);
2267 if (role == svc_cat_id && context->is_default)
2273 gboolean _ps_context_set_service(gpointer object, gpointer service)
2275 ps_context_t *context = object;
2276 g_return_val_if_fail(context != NULL, FALSE);
2278 context->p_service = service;
2282 gpointer _ps_context_ref_service(gpointer object)
2284 ps_context_t *context = object;
2285 g_return_val_if_fail(context != NULL, NULL);
2287 return context->p_service;
2290 gchar *_ps_context_ref_path(gpointer object)
2292 ps_context_t *context = object;
2293 g_return_val_if_fail(context != NULL, NULL);
2295 return context->path;
2298 gboolean _ps_context_get_alwayson_enable(gpointer object)
2300 ps_context_t *context = object;
2301 g_return_val_if_fail(context != NULL, FALSE);
2302 dbg("context (%p) alwayson (%d)", context, context->alwayson);
2303 return context->alwayson;
2306 #ifdef PREPAID_SIM_APN_SUPPORT
2307 gboolean _ps_context_get_prepaid_alwayson_enable(gpointer object)
2309 ps_context_t *context = object;
2310 g_return_val_if_fail(context != NULL, FALSE);
2311 dbg("prepaid context (%p) alwayson (%d)",
2312 context, context->prepaid_alwayson);
2313 return context->prepaid_alwayson;
2316 int _ps_context_get_profile_id(gpointer object)
2318 ps_context_t *context = object;
2319 g_return_val_if_fail(context != NULL, -1);
2320 dbg("profile_id[%d]", context->profile_id);
2321 return context->profile_id;
2325 gpointer _ps_context_ref_co_context(gpointer object)
2327 ps_context_t *context = object;
2328 g_return_val_if_fail(context != NULL, NULL);
2330 return context->co_context;
2333 gboolean _ps_context_set_connected(gpointer object, gboolean enabled)
2337 ps_context_t *context = object;
2338 Storage *strg_vconf = NULL;
2339 gpointer p_modem = NULL;
2341 gboolean b_roaming_checker = TRUE;
2342 gboolean data_allowed = FALSE;
2343 gboolean b_mms_checker = FALSE;
2344 gboolean b_ims_checker = TRUE;
2346 enum co_context_role role = CONTEXT_ROLE_UNKNOWN;
2348 dbg("Entry [enabled :%d]", enabled);
2350 g_return_val_if_fail(context != NULL, FALSE);
2352 strg_vconf = tcore_server_find_storage(tcore_plugin_ref_server(context->plg), "vconf");
2353 data_allowed = tcore_storage_get_bool(strg_vconf, STORAGE_KEY_3G_ENABLE);
2354 ipv4 = tcore_context_get_ipv4_addr(context->co_context);
2355 ipv6 = tcore_context_get_ipv6_addr(context->co_context);
2356 role = tcore_context_get_role(context->co_context);
2357 p_modem = _ps_service_ref_modem(context->p_service);
2359 if (role == CONTEXT_ROLE_MMS || role == CONTEXT_ROLE_PREPAID_MMS)
2360 b_mms_checker = TRUE;
2362 if (role == CONTEXT_ROLE_IMS || role == CONTEXT_ROLE_IMS_EMERGENCY)
2363 b_ims_checker = TRUE;
2365 #if !defined(TIZEN_SUPPORT_MMS_CONNECT_FORCE)
2366 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "csc runtime feature disabled");
2367 b_mms_checker = FALSE;
2370 context->b_active = enabled;
2371 if ((_ps_modem_get_roaming(p_modem)) && !(_ps_modem_get_data_roaming_allowed(p_modem))) {
2372 dbg("roaming network is not allowed");
2373 b_roaming_checker = FALSE;
2379 tcore_context_set_state(context->co_context, CONTEXT_STATE_ACTIVATED);
2381 if (context->deact_required == TRUE) {
2382 warn("Deactivation is required for context(%p)", context);
2383 _ps_service_deactivate_context(context->p_service, context);
2384 context->deact_required = FALSE;
2389 if ((g_str_equal(ipv4, "0.0.0.0") == TRUE) && (ipv6 == NULL)) {
2390 dbg("ip address is NULL");
2391 _ps_service_deactivate_context(context->p_service, context);
2395 _ps_service_reset_connection_timer(context);
2397 /* In case of PDP is disconnected by network in UPS mode.
2398 * default internet PDP could be activated if LCD was on at trigger time.
2400 ps_mode = _ps_modem_get_psmode(p_modem);
2401 warn("ps_mode: %d", ps_mode);
2402 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2403 gint pm_state = tcore_storage_get_int(strg_vconf, STORAGE_KEY_PM_STATE);
2404 if (pm_state == 3 && _ps_context_get_default_context(context, CONTEXT_ROLE_INTERNET)) {
2405 char *devname = tcore_context_get_ipv4_devname(context->co_context);
2406 if (TCORE_RETURN_SUCCESS != tcore_util_netif_down(devname))
2407 err("Failed to bring up interface");
2409 warn("[EXCEPTION] do not emit signal for PDP activation.");
2410 context->b_notify = TRUE;
2415 if (b_roaming_checker && (data_allowed || b_mms_checker || b_ims_checker))
2416 __ps_context_emit_property_changed_signal(context);
2419 tcore_context_set_state(context->co_context, CONTEXT_STATE_DEACTIVATED);
2420 tcore_context_reset_devinfo(context->co_context);
2421 __ps_context_emit_property_changed_signal(context);
2432 gboolean _ps_context_set_profile_enable(gpointer object, gboolean value)
2434 ps_context_t *context = object;
2435 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
2437 dbg("Entry [value :%d]", value);
2439 g_return_val_if_fail(context != NULL, FALSE);
2441 context->profile_enable = value;
2442 ps_dbg_ex_co(co_network, "context(%p) profile_enable(%d)", context, context->profile_enable);
2446 gboolean _ps_context_get_profile_enable(gpointer object)
2448 ps_context_t *context = object;
2450 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context(%p), profile_enable(%d)", context, context->profile_enable);
2452 return context->profile_enable;
2455 gboolean _ps_context_set_ps_defined(gpointer object, gboolean value)
2457 ps_context_t *context = (ps_context_t *)object;
2458 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
2460 dbg("Entry [value :%d]", value);
2462 g_return_val_if_fail(context != NULL, FALSE);
2464 context->ps_defined = value;
2465 ps_dbg_ex_co(co_network, "context(%p) ps_defined(%d)", context, context->ps_defined);
2469 gboolean _ps_context_get_ps_defined(gpointer object)
2471 ps_context_t *context = (ps_context_t *)object;
2473 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context(%p), ps_defined(%d)", context, context->ps_defined);
2475 return context->ps_defined;
2478 gboolean _ps_context_reset_user_data(gpointer object)
2480 ps_context_t *context = (ps_context_t *)object;
2482 g_return_val_if_fail(context != NULL, FALSE);
2483 context->user_data = NULL;
2488 gboolean _ps_context_set_bearer_info(gpointer object, struct tnoti_ps_dedicated_bearer_info *bearer_info)
2490 ps_context_t *context = (ps_context_t *)object;
2491 CoreObject *co_context = NULL;
2493 g_return_val_if_fail(context != NULL, FALSE);
2494 g_return_val_if_fail(bearer_info != NULL, FALSE);
2496 co_context = _ps_context_ref_co_context(object);
2498 if (bearer_info->dedicated_bearer.num_dedicated_bearer > 0) {
2499 warn("num_dedicated_bearer: %d", bearer_info->dedicated_bearer.num_dedicated_bearer);
2500 /* reset previous bearer info. */
2501 tcore_context_reset_bearer_info(co_context);
2502 tcore_context_set_bearer_info(co_context, bearer_info);
2503 __ps_context_emit_dedicated_bearer_info_signal(context);
2509 gpointer _ps_context_get_user_data(gpointer object)
2511 ps_context_t *context = (ps_context_t *)object;
2512 return context->user_data;
2515 TReturn _ps_connection_hdlr(gpointer object)
2517 int rv = TCORE_RETURN_FAILURE;
2518 ps_context_t *pscontext = object;
2519 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2521 _ps_context_set_alwayson_enable(pscontext, TRUE);
2522 rv = _ps_service_activate_context(pscontext->p_service, pscontext);
2523 if (rv != TCORE_RETURN_SUCCESS) {
2524 ps_dbg_ex_co(co_network, "fail to activate context connection");
2528 ps_dbg_ex_co(co_network, "success to activate context");
2532 gboolean _ps_context_create_cdma_profile(gchar *mccmnc, gchar *cp_name)
2535 gboolean rv = FALSE;
2536 GHashTable *in_param;
2539 /* Initialize Storage */
2540 if (g_str_has_suffix(cp_name, "1"))
2541 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
2543 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
2544 if (handle == NULL) {
2545 err("Failed to get Storage handle");
2549 /* Make default MMS profile for CDMA */
2550 memset(szQuery, 0, 5000);
2551 snprintf(szQuery, sizeof(szQuery), "%s",
2552 " update pdp_profile set \
2554 where profile_id = 1 and svc_category_id = 2 ");
2556 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
2558 g_hash_table_insert(in_param, "1", g_strdup("http://mms.vtext.com/servlets/mms")); /* home_url */
2560 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
2561 dbg("insert into pdp_profile result(%d)", rv);
2562 g_hash_table_destroy(in_param);
2564 /* De-initialize Storage */
2565 tcore_storage_remove_handle(strg_db, handle);
2570 void _ps_default_connection_hdlr(gpointer object)
2572 ps_context_t *pscontext = (ps_context_t *)object;
2573 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2575 __ps_context_update_default_internet_to_db(pscontext, TRUE);
2577 /* set request profile */
2578 tcore_context_set_default_profile(pscontext->co_context, TRUE);
2579 __ps_context_set_default_connection_enable(pscontext, TRUE);
2580 _ps_context_set_alwayson_enable(pscontext, TRUE);
2581 __ps_context_emit_property_changed_signal(pscontext);
2583 if (CONTEXT_ROLE_INTERNET == tcore_context_get_role(_ps_context_ref_co_context(object))) {
2584 int rv = TCORE_RETURN_FAILURE;
2585 ps_dbg_ex_co(co_network, "activation requeset in new ps (%p)", pscontext);
2586 /* request to connect */
2587 _ps_service_reset_connection_timer(pscontext);
2588 rv = _ps_service_connect_default_context(pscontext->p_service);
2589 if (rv == TCORE_RETURN_PS_NETWORK_NOT_READY) {
2590 unsigned char cid = -1;
2591 ps_service_t * p_service = (ps_service_t *)pscontext->p_service;
2593 ps_dbg_ex_co(co_network, "PS is not attached yet, release resources.");
2595 cid = tcore_context_get_id(pscontext->co_context);
2596 _ps_context_set_ps_defined((gpointer)pscontext, FALSE);
2597 tcore_ps_set_cid_active(p_service->co_ps, cid, FALSE);
2598 tcore_ps_clear_context_id(p_service->co_ps, pscontext->co_context);
2601 ps_dbg_ex_co(co_network, "complete to change the default connection");
2605 gint _ps_context_get_number_of_pdn(gchar *operator, gchar *cp_name)
2607 gint num_of_pdn = 0;
2609 num_of_pdn = __ps_context_load_num_of_pdn_from_database(operator, cp_name);
2610 dbg("loaded num_of_pdn (%d)", num_of_pdn);
2615 gboolean _ps_context_handle_ifaceup(gpointer user_data)
2617 ps_context_t *pscontext = user_data;
2618 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2619 int context_state = 0;
2621 context_state = tcore_context_get_state(pscontext->co_context);
2622 ps_warn_ex_co(co_network, "context_state: %d", context_state);
2623 if (context_state == CONTEXT_STATE_ACTIVATED) {
2624 char *devname = tcore_context_get_ipv4_devname(pscontext->co_context);
2625 gint ps_mode = _ps_modem_get_psmode(_ps_service_ref_modem(pscontext->p_service));
2626 if (TCORE_RETURN_SUCCESS != tcore_util_netif_up(devname))
2627 ps_err_ex_co(co_network, "Failed to bring up interface");
2629 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2630 /* If this flag is true, Connman won't update cellular service state. */
2631 if (pscontext->b_notify) {
2632 ps_warn_ex_co(co_network, "[EXCEPTION] notify status change to upper layer.");
2633 pscontext->b_routing_only = FALSE;
2635 pscontext->b_routing_only = TRUE;
2639 * 20131212, Deprecated: Fixed by HTTP stack.
2640 * ===============================================================================
2641 * 20130801, JIRA DCM-2221: HTTP communication behavior while bearer switching
2642 * Observations: When contiguous HTTP requests while ME handovers from wi-fi to 3G,
2643 * libcurl does not make Aborted event to application
2644 * even if libcurl receives socket closed event by SIOCKILLADDR.
2645 * So, we add work-around patch set here.
2646 * ===============================================================================
2648 if (pscontext->b_active == FALSE) {
2649 pscontext->b_active = TRUE;
2650 ps_dbg_ex_co(co_network, "Celluar profile: Emit property signal to provide IP configuration, devname(%s)", devname);
2651 __ps_context_emit_property_changed_signal(pscontext);
2653 pscontext->b_routing_only = FALSE;
2654 pscontext->b_notify = FALSE;
2656 } else if (context_state == CONTEXT_STATE_DEACTIVATED) {
2657 /* trigger PDP activation. */
2658 _ps_service_activate_context(pscontext->p_service, pscontext);
2663 gboolean _ps_context_handle_ifacedown(gpointer user_data)
2665 ps_context_t *pscontext = user_data;
2666 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2667 int context_state = 0;
2669 context_state = tcore_context_get_state(pscontext->co_context);
2670 ps_warn_ex_co(co_network, "context_state: %d", context_state);
2671 if (context_state == CONTEXT_STATE_ACTIVATED) {
2672 char *devname = tcore_context_get_ipv4_devname(pscontext->co_context);
2673 gint ps_mode = _ps_modem_get_psmode(_ps_service_ref_modem(pscontext->p_service));
2674 ps_dbg_ex_co(co_network, "Cellular profile: Do not send PDP deactivation request message to Modem.");
2675 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2676 /* If this flag is true, Connman won't update cellular service state. */
2677 pscontext->b_routing_only = TRUE;
2679 ps_warn_ex_co(co_network, "reset socket connections, devname(%s)", devname);
2680 if (TCORE_RETURN_SUCCESS != tcore_util_reset_ipv4_socket(devname, tcore_context_get_ipv4_addr(pscontext->co_context)))
2681 ps_err_ex_co(co_network, "Failed to reset socket.");
2684 if (TCORE_RETURN_SUCCESS != tcore_util_netif_down(devname))
2685 ps_err_ex_co(co_network, "Failed to bring down interface");
2686 if (pscontext->b_active == TRUE) {
2687 pscontext->b_active = FALSE;
2688 __ps_context_emit_property_changed_signal(pscontext);
2690 pscontext->b_routing_only = FALSE;
2696 static gboolean on_context_get_properties(PacketServiceContext *obj_context,
2697 GDBusMethodInvocation *invocation,
2700 GVariant *gv = NULL;
2701 GVariantBuilder property;
2704 gv = _ps_context_get_properties(user_data, &property);
2705 packet_service_context_complete_get_properties(obj_context, invocation, gv);
2709 static gboolean on_context_get_profile(PacketServiceContext *obj_context,
2710 GDBusMethodInvocation *invocation,
2713 GVariant *gv = NULL;
2714 GVariantBuilder profile;
2717 gv = __ps_context_get_profile_properties(user_data, &profile);
2718 packet_service_context_complete_get_profile(obj_context, invocation, gv);
2723 static gboolean on_context_handle_activate(PacketServiceContext *obj_context,
2724 GDBusMethodInvocation *invocation,
2727 gboolean rv = FALSE;
2728 TReturn result = TCORE_RETURN_FAILURE;
2731 int context_state = 0;
2732 unsigned int max_pdn = 0, num_of_active_cids = 0;
2733 gpointer p_service = NULL; gpointer co_ps = NULL;
2734 gpointer c_def_context = NULL; unsigned char cid_def = 0;
2735 GSList *active_cids = NULL;
2736 CoreObject *co_network;
2738 ps_context_t *pscontext = user_data;
2741 if (pscontext == NULL) {
2742 err("activation request object is NULL");
2743 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2747 p_service = pscontext->p_service;
2749 err("service object is null");
2750 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2754 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2755 co_ps = _ps_service_ref_co_ps(p_service);
2757 ps_err_ex_co(co_network, "core object is null");
2758 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2762 ps_dbg_ex_co(co_network, "activate context(%s)", _ps_context_ref_path(pscontext));
2764 apn = (gchar *)tcore_context_get_apn(pscontext->co_context);
2766 context_state = tcore_context_get_state(pscontext->co_context);
2767 if (context_state != CONTEXT_STATE_DEACTIVATED) {
2768 ps_warn_ex_co(co_network, "operation is in progress");
2769 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2773 ps_dbg_ex_co(co_network, "requested context(%p) co_context(%p) apn (%s)", pscontext, pscontext->co_context, apn);
2774 /* check apn is activated or not */
2775 rv = tcore_ps_is_active_apn(co_ps, (const char *)apn);
2777 ps_dbg_ex_co(co_network, "requested apn is already activated");
2779 result = _ps_connection_hdlr(pscontext);
2780 if (result != TCORE_RETURN_SUCCESS) {
2781 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2785 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2786 context_state = tcore_context_get_state(pscontext->co_context);
2787 if (context_state == CONTEXT_STATE_ACTIVATED) {
2788 ps_dbg_ex_co(co_network, "context is already connected");
2789 _ps_context_set_connected(pscontext, TRUE);
2792 ps_dbg_ex_co(co_network, "success to open connection request");
2796 active_cids = tcore_ps_get_active_cids(co_ps);
2797 num_of_active_cids = g_slist_length(active_cids);
2798 max_pdn = tcore_ps_get_num_of_pdn(co_ps);
2799 ps_dbg_ex_co(co_network, "activate cids(%d), max pdn(%d)", num_of_active_cids, max_pdn);
2800 if (num_of_active_cids < max_pdn) {
2801 ps_dbg_ex_co(co_network, "enough to active another pdn");
2802 result = _ps_connection_hdlr(pscontext);
2803 if (result != TCORE_RETURN_SUCCESS) {
2804 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2808 ps_dbg_ex_co(co_network, "success to open connection request");
2809 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2813 /* find the current default connection */
2814 c_def_context = _ps_service_return_default_context(p_service, CONTEXT_ROLE_INTERNET);
2815 if (c_def_context == NULL) {
2816 err("default context is NULL");
2817 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2820 cid_def = tcore_context_get_id(((ps_context_t *)c_def_context)->co_context);
2822 ps_err_ex_co(co_network, "it is not avaiable to open connection");
2823 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2827 /* check the status of def context */
2828 context_state = tcore_context_get_state(((ps_context_t *)c_def_context)->co_context);
2829 if (context_state != CONTEXT_STATE_ACTIVATED) {
2830 enum co_context_role context_role;
2831 context_role = tcore_context_get_role(pscontext->co_context);
2832 ps_err_ex_co(co_network, "default connection is in progress, new context_state[%d], role[%d]", context_state, context_role);
2833 if (context_state == CONTEXT_STATE_ACTIVATING &&
2834 (context_role == CONTEXT_ROLE_MMS ||context_role == CONTEXT_ROLE_PREPAID_MMS)) {
2835 ((ps_context_t *)c_def_context)->user_data = pscontext;
2836 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2839 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2843 _ps_service_reset_connection_timer(c_def_context);
2844 ((ps_context_t *)c_def_context)->user_data = pscontext;
2845 result = tcore_ps_deactivate_cid(co_ps, cid_def);
2846 if (result != TCORE_RETURN_SUCCESS) {
2847 ps_err_ex_co(co_network, "fail to deactivate exist network connection");
2848 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2852 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2857 static gboolean on_context_handle_deactiavte(PacketServiceContext *obj_context,
2858 GDBusMethodInvocation *invocation,
2861 gboolean rv = FALSE;
2862 CoreObject *co_network;
2863 int context_state = 0;
2864 ps_context_t *pscontext = user_data;
2867 if (pscontext == NULL) {
2868 err("deactivation request object is NULL");
2869 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2873 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2874 context_state = tcore_context_get_state(pscontext->co_context);
2875 ps_dbg_ex_co(co_network, "requested context(%p) co_context(%p), context_state %d", pscontext, pscontext->co_context, context_state);
2876 if (context_state != CONTEXT_STATE_ACTIVATED) {
2877 ps_err_ex_co(co_network, "operation is in progress");
2878 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2882 ps_dbg_ex_co(co_network, "deactivate context(%s)", _ps_context_ref_path(pscontext));
2884 _ps_service_reset_connection_timer(pscontext);
2885 _ps_context_set_alwayson_enable(pscontext, FALSE);
2887 rv = _ps_service_deactivate_context(pscontext->p_service, pscontext);
2888 if (rv != TCORE_RETURN_SUCCESS) {
2889 ps_err_ex_co(co_network, "fail to deactivate context connection");
2890 FAIL_RESPONSE(invocation, PS_ERR_TRASPORT);
2894 ps_dbg_ex_co(co_network, "success to deactivate context");
2895 packet_service_context_complete_deactivate(obj_context, invocation, pscontext->path);
2897 context_state = tcore_context_get_state(pscontext->co_context);
2898 if (context_state == CONTEXT_STATE_DEACTIVATED) {
2899 ps_dbg_ex_co(co_network, "context is already disconnected");
2900 pscontext->ps_defined = FALSE;
2901 _ps_context_set_connected(pscontext, FALSE);
2907 static gboolean on_context_set_default_connection(PacketServiceContext *obj_context,
2908 GDBusMethodInvocation *invocation,
2912 int role = CONTEXT_ROLE_UNKNOWN;
2913 gboolean is_default = FALSE;
2915 gpointer co_ps = NULL;
2916 gpointer service = NULL;
2917 gpointer cur_default_ctx = NULL;
2918 ps_context_t *pscontext = user_data;
2919 CoreObject *co_network;
2921 dbg("enter set default connection ps_context_t(%p)", pscontext);
2922 if (pscontext == NULL) {
2923 err("activation request object is NULL");
2924 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2928 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2929 ps_dbg_ex_co(co_network, "start default connection");
2930 role = tcore_context_get_role(pscontext->co_context);
2931 is_default = tcore_context_get_default_profile(pscontext->co_context);
2934 ps_err_ex_co(co_network, "already default profile for role (%d).", role);
2938 service = pscontext->p_service;
2939 cur_default_ctx = _ps_service_return_default_context(service, role);
2940 ps_dbg_ex_co(co_network, "current default connection (%p)", cur_default_ctx);
2942 if (!cur_default_ctx) {
2943 ps_err_ex_co(co_network, "No current default connection.");
2947 /* First, send deactivation request first. */
2948 rv = _ps_service_deactivate_context(((ps_context_t *)cur_default_ctx)->p_service, cur_default_ctx);
2949 if (rv == TCORE_RETURN_PS_ACTIVATING) {
2950 ps_dbg_ex_co(co_network, "fail to deactivate default connection, rv(%d)", rv);
2951 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2955 /* Normal deactivation case. */
2956 if (tcore_context_get_state(((ps_context_t *)cur_default_ctx)->co_context) == CONTEXT_STATE_DEACTIVATING) {
2957 ps_dbg_ex_co(co_network, "deactivation request in current ps (%p)", cur_default_ctx);
2958 ((ps_context_t *)cur_default_ctx)->user_data = pscontext;
2962 ps_dbg_ex_co(co_network, "[Not normal] deactivation request in current ps (%p)", cur_default_ctx);
2964 cid = tcore_context_get_id(((ps_context_t *)cur_default_ctx)->co_context);
2965 _ps_context_set_ps_defined(cur_default_ctx, FALSE);
2966 co_ps = _ps_service_ref_co_ps(service);
2967 tcore_ps_set_cid_active((CoreObject *)co_ps, cid, FALSE);
2968 tcore_ps_clear_context_id((CoreObject *)co_ps, ((ps_context_t *)cur_default_ctx)->co_context);
2971 /* unset default info of previous connection */
2972 _ps_context_set_alwayson_enable(cur_default_ctx, FALSE);
2973 __ps_context_set_default_connection_enable(cur_default_ctx, FALSE);
2974 tcore_context_set_default_profile(((ps_context_t *)cur_default_ctx)->co_context, FALSE);
2976 /* db update - release default connection */
2977 ps_dbg_ex_co(co_network, "context(%p): release default connection property.", cur_default_ctx);
2978 __ps_context_update_default_internet_to_db((ps_context_t *)cur_default_ctx, FALSE);
2979 /* Allow Connman to update profile information. */
2980 __ps_context_emit_property_changed_signal(cur_default_ctx);
2982 ps_dbg_ex_co(co_network, "activation requeset in new ps (%p)", pscontext);
2984 _ps_default_connection_hdlr(pscontext);
2985 packet_service_context_complete_set_default_connection(obj_context, invocation, TRUE);
2990 static gboolean on_context_modify_profile(PacketServiceContext *obj_context,
2991 GDBusMethodInvocation *invocation,
2995 GVariantIter g_iter;
2999 gboolean rv = FALSE;
3000 int context_state = 0;
3001 ps_context_t *context = user_data;
3002 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
3003 GHashTable *profile_property = NULL;
3005 ps_dbg_ex_co(co_network, "modify context's profile properties");
3007 context_state = tcore_context_get_state(context->co_context);
3008 if (context_state == CONTEXT_STATE_ACTIVATING) {
3009 ps_dbg_ex_co(co_network, "Modify profile in activating state, set deactivate flag.");
3010 context->deact_required = TRUE;
3013 /*Creating the profile property hash for for internal handling*/
3014 /*Create a hash table for the profile property as all fucntion already use ghash table */
3015 profile_property = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
3016 g_variant_iter_init(&g_iter, property);
3017 while (g_variant_iter_next(&g_iter, "{ss}", &g_key, &g_value)) {
3019 g_hash_table_insert(profile_property, g_strdup(g_key), g_strdup(g_value));
3020 /* must free data for ourselves */
3025 rv = __ps_context_update_profile(context, profile_property);
3027 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
3028 g_hash_table_destroy(profile_property);
3032 _ps_service_deactivate_context(context->p_service, context);
3033 if (context_state == CONTEXT_STATE_DEACTIVATED) {
3034 ps_dbg_ex_co(co_network, "context is already disconnected");
3035 _ps_context_set_connected(context, FALSE);
3038 packet_service_context_complete_modify_profile(obj_context, invocation, TRUE);
3039 g_hash_table_destroy(profile_property);
3043 static gboolean on_context_remove_profile(PacketServiceContext *obj_context,
3044 GDBusMethodInvocation *invocation, gpointer user_data)
3046 ps_context_t *context = user_data;
3047 ps_service_t *service = _ps_context_ref_service(context);
3048 CoreObject *co_network = _ps_service_ref_co_network(service);
3050 g_return_val_if_fail(service != NULL, FALSE);
3052 ps_dbg_ex_co(co_network, "Remove context.");
3054 __ps_context_remove_database(context);
3055 _ps_service_unref_context(service, context);
3056 service->contexts = g_slist_remove(service->contexts, context);
3057 _ps_context_remove_context(context);
3059 packet_service_context_complete_remove_profile(obj_context, invocation, TRUE);
3061 ps_dbg_ex_co(co_network, "Exit");
3065 static void _ps_context_setup_interface(PacketServiceContext *context, ps_context_t *context_data)
3068 g_signal_connect(context,
3069 "handle-get-properties",
3070 G_CALLBACK(on_context_get_properties),
3073 g_signal_connect(context,
3074 "handle-get-profile",
3075 G_CALLBACK(on_context_get_profile),
3078 g_signal_connect(context,
3080 G_CALLBACK(on_context_handle_activate),
3083 g_signal_connect(context,
3084 "handle-deactivate",
3085 G_CALLBACK(on_context_handle_deactiavte),
3088 g_signal_connect(context,
3089 "handle-set-default-connection",
3090 G_CALLBACK(on_context_set_default_connection),
3093 g_signal_connect(context,
3094 "handle-modify-profile",
3095 G_CALLBACK(on_context_modify_profile),
3098 g_signal_connect(context,
3099 "handle-remove-profile",
3100 G_CALLBACK(on_context_remove_profile),