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"
31 #include <core_object.h>
33 #include <co_context.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
38 #include <iniparser.h>
40 #include <libxml/xmlmemory.h>
41 #include <libxml/parser.h>
42 #include <libxml/tree.h>
44 #define PROP_DEFAULT FALSE
45 #define PROP_DEFAULT_STR NULL
46 #define DATABASE_PATH_0 "/opt/dbspace/.dnet.db"
47 #define DATABASE_PATH_1 "/opt/dbspace/.dnet2.db"
48 #define DELAY_TO_SIGNAL_EMIT 1
53 enum co_context_type pdp_type;
54 enum co_context_role role;
55 const char *p_cscf_ipv4addr;
56 const char *p_cscf_ipv6addr;
59 #define FREE_AND_ASSIGN(ptr, value) do { \
62 ptr = g_strdup(value); \
65 static Storage *strg_db;
68 OperatorTable attach_apn_preference[] = {
69 {"45005", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "220.103.220.10", "2001:2d8:00e0:0220::10"},
70 {"45006", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "", ""},
71 {"45008", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "", ""},
74 static void __ps_context_emit_dedicated_bearer_info_signal(ps_context_t *context);
75 static void __ps_context_emit_property_changed_signal(ps_context_t *context);
76 static void _ps_context_setup_interface(PacketServiceContext *context, ps_context_t *context_data);
78 static gboolean __ps_context_create_storage_handle(gpointer plugin);
79 static gchar *__ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id, gchar *cp_name);
80 static gboolean __ps_context_profile_is_attach_apn(CoreObject *co_context, const gchar *mccmnc);
81 static gboolean __ps_context_create_co_context(gpointer context, GHashTable *property, gchar *cp_name);
82 static gboolean __ps_context_update_profile(ps_context_t *context, GHashTable *property);
83 static gboolean __ps_context_update_database(ps_context_t *context);
84 static gboolean __ps_context_update_default_internet_to_db(ps_context_t *context, gboolean enabled);
85 static gboolean __ps_context_remove_database(ps_context_t *context);
86 static int __ps_context_insert_network_id_to_database(gchar *mccmnc, gchar *cp_name);
87 static int __ps_context_load_network_id_from_database(gchar *mccmnc, gchar *cp_name);
88 static gchar *__ps_context_load_network_name_from_database(int network_id, gchar *cp_name);
89 static int __ps_context_load_profile_id_from_database(gchar *cp_name);
90 static int __ps_context_load_num_of_pdn_from_database(gchar *mccmnc, gchar *cp_name);
91 static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int index, gchar *cp_name);
92 static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id, gchar *cp_name);
93 static int __ps_context_get_network_id(gchar *mccmnc, gchar *cp_name);
94 GVariant *__ps_context_get_profile_properties(gpointer context, GVariantBuilder *properties);
95 static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled);
97 void __remove_context_handler(gpointer data)
99 ps_context_t *context = data;
104 dbg("Context is Null");
108 /*Need to UNexport and Unref the master Object */
109 g_object_unref(context->if_obj);
111 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context removed for the path [%s]", context->path);
113 g_free(context->path);
114 g_free(context->mccmnc);
121 static void __ps_context_emit_dedicated_bearer_info_signal(ps_context_t *context)
124 CoreObject *co_network = NULL, *co_context = NULL;
125 struct dedicated_bearer_info bearer_info;
126 GVariantBuilder properties;
128 char *num_dedicated_bearer, *primary_context_id;
129 char *secondary_context_id, *qci, *gbr_dl, *gbr_ul, *max_br_dl, *max_br_ul;
131 g_return_if_fail(context != NULL);
133 co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
134 co_context = _ps_context_ref_co_context(context);
135 tcore_context_get_bearer_info(co_context, &bearer_info);
137 if (bearer_info.num_dedicated_bearer == 0) {
138 ps_warn_ex_co(co_network, "No dedicated bearer information");
142 g_variant_builder_init(&properties, G_VARIANT_TYPE("a{ss}"));
144 primary_context_id = INT2STRING(tcore_context_get_id(co_context));
145 g_variant_builder_add(&properties, "{ss}", "primary_context_id", primary_context_id);
146 g_free(primary_context_id);
148 num_dedicated_bearer = CHAR2STRING(bearer_info.num_dedicated_bearer);
149 g_variant_builder_add(&properties, "{ss}", "num_dedicated_bearer", num_dedicated_bearer);
150 g_free(num_dedicated_bearer);
152 secondary_context_id = INT2STRING(bearer_info.secondary_context_id);
153 g_variant_builder_add(&properties, "{ss}", "secondary_context_id", secondary_context_id);
154 g_free(secondary_context_id);
156 for (i = 0; i < bearer_info.num_dedicated_bearer ; i++) {
158 buf = g_strdup_printf("%s_%d", "qci", i);
159 qci = CHAR2STRING(bearer_info.qos[i].qci);
160 g_variant_builder_add(&properties, "{ss}", buf, qci);
164 buf = g_strdup_printf("%s_%d", "gbr_dl", i);
165 gbr_dl = INT2STRING(bearer_info.qos[i].gbr_dl);
166 g_variant_builder_add(&properties, "{ss}", buf, gbr_dl);
170 buf = g_strdup_printf("%s_%d", "gbr_ul", i);
171 gbr_ul = INT2STRING(bearer_info.qos[i].gbr_ul);
172 g_variant_builder_add(&properties, "{ss}", buf, gbr_ul);
176 buf = g_strdup_printf("%s_%d", "max_br_dl", i);
177 max_br_dl = INT2STRING(bearer_info.qos[i].max_br_dl);
178 g_variant_builder_add(&properties, "{ss}", buf, max_br_dl);
182 buf = g_strdup_printf("%s_%d", "max_br_ul", i);
183 max_br_ul = INT2STRING(bearer_info.qos[i].max_br_ul);
184 g_variant_builder_add(&properties, "{ss}", buf, max_br_ul);
188 gv = g_variant_builder_end(&properties);
190 packet_service_context_emit_dedicated_bearer_info(context->if_obj, gv);
191 ps_warn_ex_co(co_network, "context (%p) emit the dedicated bearer infomation signal", context);
194 static void __ps_context_emit_property_changed_signal(ps_context_t *context)
197 GVariantBuilder property;
198 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
200 ps_dbg_ex_co(co_network, "get context Properties");
202 gv = _ps_context_get_properties(context, &property);
203 packet_service_context_emit_property_changed(context->if_obj, gv);
205 ps_dbg_ex_co(co_network, "context (%p) emit the context property changed signal", context);
209 /* Funtion : _ps_context_remove_context
210 * Description : removes and unregister the interface for the context
212 gboolean _ps_context_remove_context(gpointer context)
214 ps_context_t *pscontext = context;
215 ps_service_t *service = _ps_context_ref_service(pscontext);
217 g_return_val_if_fail(pscontext != NULL, FALSE);
218 g_return_val_if_fail(service != NULL, FALSE);
219 g_return_val_if_fail(pscontext->path != NULL, FALSE);
221 ps_dbg_ex_co(_ps_service_ref_co_network(service),
222 "remove context (%s)", pscontext->path);
224 /*Removing the context from the static list */
225 _ps_service_reset_connection_timer(context);
226 _ps_context_set_connected(context, FALSE);
228 /* Unexport object */
229 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(pscontext->if_obj));
231 /* remove context from the list (modem, service) */
232 tcore_ps_remove_context(service->co_ps,
233 (CoreObject *)_ps_context_ref_co_context(context));
234 tcore_context_free(pscontext->co_context);
236 /* free allocated resources for context. */
237 g_free(pscontext->mccmnc);
238 g_free(pscontext->path);
245 static gboolean __ps_context_create_storage_handle(gpointer plugin)
247 TcorePlugin *p = plugin;
249 strg_db = tcore_server_find_storage(tcore_plugin_ref_server(p), "database");
250 dbg("Storage: (%p)", strg_db);
255 static gchar *__ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id, gchar *cp_name)
257 gchar *path = NULL, *in_path = NULL;
258 int str_len = 0, context_index = 0;
261 dbg("profile_name is null");
265 str_len = strlen(profile_name);
266 in_path = g_strdup_printf("/%s%s", cp_name, "/context/");
268 for (context_index = 0; context_index < str_len; context_index++) {
269 gchar *buf = NULL, *tmp = NULL;
270 buf = g_strdup_printf("%02x", profile_name[context_index]);
271 tmp = g_strconcat(in_path, buf, NULL);
276 in_path = g_strdup(tmp);
280 dbg("converted name(%s) path(%s)", profile_name, in_path);
282 path = g_strdup_printf("%s_%d_%d", in_path, profile_id, svc_ctg_id);
283 dbg("path (%s)", path);
289 static gboolean __ps_context_profile_is_attach_apn(CoreObject *co_context, const gchar *mccmnc)
291 gboolean attach_apn = FALSE, default_conn = FALSE;
294 if (co_context == NULL)
297 default_conn = tcore_context_get_default_profile(co_context);
298 role = tcore_context_get_role(co_context);
301 * TODO: Read CSC Configuration routine.
302 * By default, default Ineternet profile will be used for PS attach.
303 * CSC will define APN for PS attach according to operator requirement.
307 gboolean matched = FALSE;
309 count = sizeof(attach_apn_preference) / sizeof(attach_apn_preference[0]);
310 for (i = 0; i < count ; i++) {
311 if (g_strcmp0(attach_apn_preference[i].mccmnc, mccmnc) == 0) {
312 if (attach_apn_preference[i].role == role) {
313 dbg("index[%d], attach_apn_preference[%d].role: %d, role: %d, apn: %s",
314 i, i, attach_apn_preference[i].role, role, attach_apn_preference[i].apn);
322 if (role == CONTEXT_ROLE_INTERNET)
327 dbg("role(%d), attach_apn (%d)", role, attach_apn);
331 static gboolean __ps_context_create_co_context(gpointer object, GHashTable *property, gchar *cp_name)
335 ps_context_t *context = NULL;
336 CoreObject *co_context = NULL;
340 gchar *profile_name = NULL;
342 gchar *auth_id = NULL, *auth_pwd = NULL, *home_url = NULL, *proxy_addr = NULL;
343 int auth_type = 0, svc_ctg_id = 0, pdp_type = 0;
344 gboolean hidden = FALSE, editable = FALSE, default_conn = FALSE, user_defined = FALSE, is_roaming_apn = FALSE, profile_enable = TRUE;
346 g_hash_table_iter_init(&iter, (GHashTable *) property);
347 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
348 if (g_str_equal(key, "3") == TRUE) { /*Profile ID*/
350 profile_id = atoi((const char *) value);
351 dbg("profile id (%d)", profile_id);
353 } else if (g_str_equal(key, "4") == TRUE) {
354 g_free(profile_name);
355 profile_name = g_strdup((const char *) value);
356 dbg("profile name (%s)", profile_name);
357 } else if (g_str_equal(key, "5") == TRUE) {
359 apn = g_strdup((const char *) value);
360 dbg("APN (%s)", apn);
361 } else if (g_str_equal(key, "6") == TRUE) {
363 auth_type = atoi((const char *) value);
364 dbg("auth type (%d)", auth_type);
366 } else if (g_str_equal(key, "7") == TRUE) {
368 auth_id = g_strdup((const char *) value);
369 dbg("auth id (%s)", auth_id);
370 } else if (g_str_equal(key, "8") == TRUE) {
372 auth_pwd = g_strdup((const char *) value);
373 dbg("auth pwd (%s)", auth_pwd);
374 } else if (g_str_equal(key, "9") == TRUE) {
375 if (!value || g_strcmp0((const gchar *) value, "") == 0) {
377 proxy_addr = g_strdup((const char *) value);
379 gboolean b_regex = FALSE;
380 b_regex = g_regex_match_simple("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+:[0-9]*", (const gchar *) value, 0, 0);
384 gchar **tmp_proxy = NULL;
386 tmp_proxy = g_strsplit_set((const gchar *) value, ".:", -1);
387 port_num = atoi(tmp_proxy[4]);
391 proxy_addr = g_strdup_printf("%d.%d.%d.%d",
392 atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]));
395 proxy_addr = g_strdup_printf("%d.%d.%d.%d:%d",
396 atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]), port_num);
398 g_strfreev(tmp_proxy);
401 proxy_addr = g_strdup((const char *) value);
402 } /* not in regular experssion */
405 dbg("proxy addr (%s)", proxy_addr);
406 } else if (g_str_equal(key, "10") == TRUE) {
408 home_url = g_strdup((const char *) value);
409 dbg("home url (%s)", home_url);
410 } else if (g_str_equal(key, "11") == TRUE) {
412 pdp_type = atoi((const char *) value);
413 dbg("pdp type (%d)", pdp_type);
415 } else if (g_str_equal(key, "19") == TRUE) {
417 svc_ctg_id = atoi((const char *) value);
418 dbg("context category type (%d)", svc_ctg_id);
420 } else if (g_str_equal(key, "20") == TRUE) {
422 hidden = atoi((const char *) value);
423 dbg("hidden profile (%d)", hidden);
425 } else if (g_str_equal(key, "21") == TRUE) {
427 editable = atoi((const char *) value);
428 dbg("editable profile (%d)", editable);
430 } else if (g_str_equal(key, "22") == TRUE) {
432 default_conn = atoi((const char*) value);
433 dbg("default connection profile (%d)", default_conn);
435 } else if (g_str_equal(key, "23") == TRUE) {
437 user_defined = atoi((const char*) value);
438 dbg("user defined profile (%d)", user_defined);
440 } else if (g_str_equal(key, "24") == TRUE) {
442 is_roaming_apn = atoi((const char*) value);
443 dbg("roaming APN profile (%d)", is_roaming_apn);
445 } else if (g_str_equal(key, "25") == TRUE) {
447 profile_enable = atoi((const char*) value);
448 dbg("profile enable (%d)", profile_enable);
453 path = __ps_context_create_path(profile_name, profile_id, svc_ctg_id, cp_name);
455 context = (ps_context_t *)object;
456 co_context = tcore_context_new(context->plg, path, NULL);
457 #ifdef TIZEN_PS_IPV4_ONLY
458 dbg("pdp type has been changed (%d)", CONTEXT_TYPE_IP);
459 tcore_context_set_type(co_context, CONTEXT_TYPE_IP);
461 tcore_context_set_type(co_context, pdp_type);
463 tcore_context_set_state(co_context, CONTEXT_STATE_DEACTIVATED);
464 tcore_context_set_role(co_context, svc_ctg_id);
465 tcore_context_set_apn(co_context, apn);
466 tcore_context_set_auth(co_context, auth_type);
467 tcore_context_set_username(co_context, auth_id);
468 tcore_context_set_password(co_context, auth_pwd);
469 tcore_context_set_proxy(co_context, proxy_addr);
470 tcore_context_set_mmsurl(co_context, home_url);
471 tcore_context_set_profile_name(co_context, profile_name);
472 tcore_context_set_default_profile(co_context, default_conn);
473 tcore_context_set_attach_apn(co_context, __ps_context_profile_is_attach_apn(co_context, context->mccmnc));
474 tcore_context_set_roaming_apn(co_context, is_roaming_apn);
476 context->profile_id = profile_id;
477 context->hidden = hidden;
478 context->editable = editable;
479 context->is_default = default_conn;
480 _ps_context_set_profile_enable(context, profile_enable);
481 context->path = path;
482 context->co_context = co_context;
484 g_free(profile_name);
494 static gpointer __ps_context_create_context(GDBusConnection *conn, TcorePlugin *p,
495 gchar *mccmnc, GHashTable *property, gchar *cp_name)
497 PacketServiceContext *context;
498 GError *error = NULL;
499 ps_context_t *new_context;
504 /*Initializing the master list for internal referencing*/
505 new_context = g_try_malloc0(sizeof(ps_context_t));
506 if (NULL == new_context) {
507 err("Unable to allocate memory for context");
510 dbg("creating the skeleton object");
511 context = packet_service_context_skeleton_new();
512 if (NULL == context) {
517 dbg("Assigning the memory location for the internal data");
518 new_context->conn = conn;
519 new_context->plg = p;
520 new_context->if_obj = context;
521 new_context->mccmnc = g_strdup(mccmnc);
523 __ps_context_create_co_context(new_context, property , cp_name);
524 _ps_context_set_alwayson_enable(new_context, TRUE);
525 path = _ps_context_ref_path(new_context);
526 _ps_context_setup_interface(context, new_context);
528 dbg("registering the interface object");
530 dbg("exporting the interface object to the dbus connection");
531 /*exporting the interface object to the path mention for master*/
532 g_dbus_interface_skeleton_export((G_DBUS_INTERFACE_SKELETON(context)),
537 g_assert_no_error(error);
539 dbg("Successfully new object created for the interface for path [%s]", path);
543 /*To do : handle failure */
544 dbg("Unable to allocate memory for the new object");
548 static gboolean __ps_context_update_profile(ps_context_t *context, GHashTable *property)
550 CoreObject *co_context = NULL;
554 co_context = context->co_context;
558 g_hash_table_iter_init(&iter, property);
559 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
560 if (g_str_equal(key, "apn") == TRUE) {
561 tcore_context_set_apn(co_context, (const char *) value);
562 } else if (g_str_equal(key, "profile_name") == TRUE) {
563 tcore_context_set_profile_name(co_context, (const char *) value);
564 } else if (g_str_equal(key, "auth_type") == TRUE) {
567 i_tmp = atoi((const char *) value);
568 tcore_context_set_auth(co_context, i_tmp);
570 } else if (g_str_equal(key, "auth_id") == TRUE) {
571 tcore_context_set_username(co_context, (const char *) value);
572 } else if (g_str_equal(key, "auth_pwd") == TRUE) {
573 tcore_context_set_password(co_context, (const char *) value);
574 } else if (g_str_equal(key, "pdp_protocol") == TRUE) {
577 i_tmp = atoi((const char *) value);
578 tcore_context_set_type(co_context, i_tmp);
580 } else if (g_str_equal(key, "proxy_addr") == TRUE) {
581 tcore_context_set_proxy(co_context, (const char *) value);
582 } else if (g_str_equal(key, "home_url") == TRUE) {
583 tcore_context_set_mmsurl(co_context, (const char *) value);
584 } else if (g_str_equal(key, "profile_enable") == TRUE) {
587 if (g_str_equal(value, "FALSE") == TRUE)
589 _ps_context_set_profile_enable(context, tmp);
594 return __ps_context_update_database(context);
597 static gboolean __ps_context_update_default_internet_to_db(ps_context_t *context, gboolean enabled)
600 GHashTable *in_param;
603 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
604 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
606 g_return_val_if_fail(context != NULL, FALSE);
608 /* Initialize Storage */
609 if (g_str_has_suffix(cp_name, "1"))
610 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
612 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
613 if (handle == NULL) {
614 ps_err_ex_co(co_network, "Failed to get Storage handle");
618 /* Initialize parameters */
619 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
620 g_hash_table_insert(in_param, "1",
621 g_strdup_printf("%d", enabled)); /* Profile enabled/disabled */
622 g_hash_table_insert(in_param, "2",
623 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
626 memset(szQuery, 0x0, sizeof(szQuery));
627 snprintf(szQuery, sizeof(szQuery), "%s",
628 " update pdp_profile set \
629 default_internet_con = ? \
630 where profile_id = ?");
632 rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
633 ps_dbg_ex_co(co_network, "Update Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
636 g_hash_table_destroy(in_param);
638 /* De-initialize Storage */
639 tcore_storage_remove_handle(strg_db, handle);
644 static gboolean __ps_context_update_database(ps_context_t *context)
647 GHashTable *in_param;
650 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
651 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
653 g_return_val_if_fail(context != NULL, FALSE);
655 /* Initialize Storage */
656 if (g_str_has_suffix(cp_name, "1"))
657 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
659 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
660 if (handle == NULL) {
661 ps_err_ex_co(co_network, "Failed to get Storage handle");
665 /* Initialize parameters */
666 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
667 g_hash_table_insert(in_param, "1",
668 tcore_context_get_apn(context->co_context)); /* APN */
669 g_hash_table_insert(in_param, "2",
670 g_strdup_printf("%d", tcore_context_get_auth(context->co_context))); /* Auth Type */
671 g_hash_table_insert(in_param, "3",
672 tcore_context_get_username(context->co_context)); /* Username */
673 g_hash_table_insert(in_param, "4",
674 tcore_context_get_password(context->co_context)); /* Password */
675 g_hash_table_insert(in_param, "5",
676 tcore_context_get_proxy(context->co_context)); /* Proxy */
677 g_hash_table_insert(in_param, "6",
678 tcore_context_get_mmsurl(context->co_context)); /* MMS URL */
679 g_hash_table_insert(in_param, "7",
680 tcore_context_get_profile_name(context->co_context)); /* Profile Name */
681 g_hash_table_insert(in_param, "8",
682 g_strdup_printf("%d", tcore_context_get_type(context->co_context))); /* PDP protocol */
683 g_hash_table_insert(in_param, "9",
684 g_strdup_printf("%d", _ps_context_get_profile_enable(context))); /* Profile Enable */
685 g_hash_table_insert(in_param, "10",
686 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
689 memset(szQuery, 0x0, sizeof(szQuery));
690 snprintf(szQuery, sizeof(szQuery), "%s",
691 " update pdp_profile set \
692 apn = ?, auth_type = ?, auth_id = ?, auth_pwd = ?, \
693 proxy_ip_addr = ?, home_url = ?, profile_name = ?, \
694 pdp_protocol = ?, profile_enable = ? where profile_id = ?");
696 rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
697 ps_dbg_ex_co(co_network, "Update Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
700 g_hash_table_destroy(in_param);
702 /* De-initialize Storage */
703 tcore_storage_remove_handle(strg_db, handle);
708 static gboolean __ps_context_remove_database(ps_context_t *context)
711 GHashTable *in_param;
714 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
715 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
717 g_return_val_if_fail(context != NULL, FALSE);
719 /* Initialize Storage */
720 if (g_str_has_suffix(cp_name, "1"))
721 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
723 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
724 if (handle == NULL) {
725 ps_err_ex_co(co_network, "Failed to get Storage handle");
729 /* Initialize parameters */
730 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
731 g_hash_table_insert(in_param, "1",
732 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
735 memset(szQuery, 0x0, sizeof(szQuery));
736 snprintf(szQuery, sizeof(szQuery), "%s",
737 " delete from pdp_profile where profile_id = ? ");
739 rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, in_param);
740 ps_dbg_ex_co(co_network, "Remove from Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
743 g_hash_table_destroy(in_param);
745 /* De-initialize Storage */
746 tcore_storage_remove_handle(strg_db, handle);
751 static int __ps_context_insert_network_id_to_database(gchar *mccmnc, gchar *cp_name)
754 GHashTable *in_param, *out_param;
762 /* Initialize Storage */
763 if (g_str_has_suffix(cp_name, "1"))
764 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
766 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
767 if (handle == NULL) {
768 err("Failed to get Storage handle");
773 * Check the maximum Network ID that exists in database,
774 * if NONE exists, then 'Network ID' would be equal to 1
775 * else if there exists a valid maximum entry; 'Network ID' would be incremented value.
777 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
778 (GDestroyNotify) g_hash_table_destroy);
781 memset(szQuery, 0x0, sizeof(szQuery));
782 snprintf(szQuery, sizeof(szQuery), "%s",
783 "select max(network_info_id) as network_id from network_info");
785 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
786 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
788 g_hash_table_iter_init(&iter, out_param);
789 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
790 GHashTableIter iter2;
791 gpointer key2, value2;
794 g_hash_table_iter_init(&iter2, (GHashTable *)value);
795 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
796 dbg("key2(%s) value2(%s)", key2, value2);
797 if (g_str_equal(key2, "0") == TRUE) {
798 if (!value2 || g_strcmp0((const char *)value2, "") == 0)
801 network_id = atoi((const char *)value2);
803 /* TODO - Check this logic */
811 g_hash_table_destroy(out_param);
813 /* Increment Network ID */
817 memset(szQuery, 0x0, sizeof(szQuery));
818 snprintf(szQuery, sizeof(szQuery), "%s",
819 " insert into network_info(network_info_id, network_name, mccmnc) values(?, ?, ?) ");
821 /* Initialize parameters */
822 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
823 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_id)); /* Network ID */
824 g_hash_table_insert(in_param, "2", g_strdup_printf("PLMN_%s", mccmnc));
825 g_hash_table_insert(in_param, "3", g_strdup(mccmnc));
827 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
829 err("Failed to insert query to Storage");
834 g_hash_table_destroy(in_param);
836 /* De-initialize Storage */
837 tcore_storage_remove_handle(strg_db, handle);
842 static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id, gchar *cp_name)
845 GHashTable *in_param;
853 gchar *profile_name = NULL, *apn = NULL, *auth_type = NULL;
854 gchar *auth_id = NULL, *auth_pwd = NULL, *proxy_addr = NULL;
855 gchar *home_url = NULL, *svc_id = NULL, *pdp_protocol = NULL;
857 /* Initialize Storage */
858 if (g_str_has_suffix(cp_name, "1"))
859 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
861 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
862 if (handle == NULL) {
863 err("Failed to get Storage handle");
867 profile_id = __ps_context_load_profile_id_from_database(cp_name);
868 if (profile_id < 0) {
869 dbg("Failed to get last Profile ID");
875 /* Increment Profile ID */
878 g_hash_table_iter_init(&iter, property);
879 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
880 if (g_str_equal(key, "profile_name") == TRUE) { /* Profile Name */
882 FREE_AND_ASSIGN(profile_name, value);
885 g_free(profile_name);
887 profile_name = __ps_context_load_network_name_from_database(network_id, cp_name);
889 } else if (g_str_equal(key, "apn") == TRUE) { /* APN */
890 FREE_AND_ASSIGN(apn, value);
891 } else if (g_str_equal(key, "auth_type") == TRUE) { /* Auth Type */
892 FREE_AND_ASSIGN(auth_type, value);
893 } else if (g_str_equal(key, "auth_id") == TRUE) { /* Auth ID */
894 FREE_AND_ASSIGN(auth_id, value);
895 } else if (g_str_equal(key, "auth_pwd") == TRUE) { /* Auth Password */
896 FREE_AND_ASSIGN(auth_pwd, value);
897 } else if (g_str_equal(key, "proxy_addr") == TRUE) { /* Proxy Address */
898 FREE_AND_ASSIGN(proxy_addr, value);
899 } else if (g_str_equal(key, "home_url") == TRUE) { /* Home URL */
900 FREE_AND_ASSIGN(home_url, value);
901 } else if (g_str_equal(key, "svc_ctg_id") == TRUE) { /* Service ID */
902 FREE_AND_ASSIGN(svc_id, value);
903 } else if (g_str_equal(key, "pdp_protocol") == TRUE) { /* PDP protocol */
904 FREE_AND_ASSIGN(pdp_protocol, value);
908 /* Set default PDP protocol */
909 if (pdp_protocol == NULL) {
910 dbg("default pdp_protocol = IPv4");
911 pdp_protocol = g_strdup_printf("%d", CONTEXT_TYPE_IP);
914 /* Initialize parameters */
915 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
917 g_hash_table_insert(in_param, "1",
918 g_strdup_printf("%d", profile_id)); /* Profile ID */
919 g_hash_table_insert(in_param, "2", profile_name); /* Profile Name */
920 g_hash_table_insert(in_param, "3", apn); /* APN */
921 g_hash_table_insert(in_param, "4", auth_type); /* Auth Type */
922 g_hash_table_insert(in_param, "5", auth_id); /* Auth ID */
923 g_hash_table_insert(in_param, "6", auth_pwd); /* Auth Password */
924 g_hash_table_insert(in_param, "7", pdp_protocol); /* PDP Protocol */
925 g_hash_table_insert(in_param, "8", proxy_addr); /* Proxy Address */
926 g_hash_table_insert(in_param, "9", home_url); /* Home URL */
927 g_hash_table_insert(in_param, "10",
928 g_strdup_printf("%d", network_id)); /* Network ID */
929 g_hash_table_insert(in_param, "11", svc_id); /* Service ID */
931 dbg("Profile ID: [%d] Profile name: [%s] APN :[%s] Auth Type [%s] Auth ID: [%s] "
932 "Auth Password: [%s] PDP Protocol: [%s] Proxy Address: [%s] Home URL: [%s] Service ID: [%s]",
933 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, pdp_protocol, proxy_addr, home_url, svc_id);
936 memset(szQuery, 0x0, sizeof(szQuery));
937 snprintf(szQuery, sizeof(szQuery), "%s",
938 " insert into pdp_profile(\
939 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, \
940 pdp_protocol, proxy_ip_addr, home_url, linger_time, \
941 network_info_id, svc_category_id, hidden, editable, \
942 default_internet_con, user_defined, is_roaming_apn, profile_enable) values(\
945 ?, ?, 0, 1, 0, 1, 0, 1)");
947 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
949 err("Failed to insert to Storage");
954 g_hash_table_destroy(in_param);
957 /* De-initialize Storage */
958 tcore_storage_remove_handle(strg_db, handle);
963 static int __ps_context_load_network_id_from_database(gchar *mccmnc, gchar *cp_name)
966 GHashTable *in_param, *out_param;
975 /* Initialize Storage */
976 if (g_str_has_suffix(cp_name, "1"))
977 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
979 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
980 if (handle == NULL) {
981 err("Failed to get Storage handle");
985 /* Initialize parameters */
986 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
987 g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
989 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
990 (GDestroyNotify) g_hash_table_destroy);
993 memset(szQuery, 0x0, sizeof(szQuery));
994 snprintf(szQuery, sizeof(szQuery), "%s",
995 "select network_info_id from network_info where mccmnc = ? ");
997 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
998 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1000 g_hash_table_iter_init(&iter, out_param);
1001 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1002 GHashTableIter iter2;
1003 gpointer key2, value2;
1006 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1007 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1008 if (g_str_equal(key2, "0") == TRUE) {
1009 if (!value2 || (g_strcmp0((const char *)value2, "") == 0))
1012 network_id = atoi((const char *)value2);
1014 /* TODO - Check this out */
1021 /* Free resources */
1022 g_hash_table_destroy(in_param);
1023 g_hash_table_destroy(out_param);
1025 /* De-initialize Storage */
1026 tcore_storage_remove_handle(strg_db, handle);
1031 static gchar *__ps_context_load_network_name_from_database(int network_id, gchar *cp_name)
1034 GHashTable *in_param, *out_param;
1036 gboolean rv = FALSE;
1038 GHashTableIter iter;
1039 gpointer key, value;
1041 gchar *network_name = NULL;
1043 /* Initialize Storage */
1044 if (g_str_has_suffix(cp_name, "1"))
1045 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1047 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1048 if (handle == NULL) {
1049 err("Failed to get Storage handle");
1053 /* Initialize parameters */
1054 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1055 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_id));
1057 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1058 (GDestroyNotify)g_hash_table_destroy);
1061 memset(szQuery, 0x0, sizeof(szQuery));
1062 snprintf(szQuery, sizeof(szQuery), "%s",
1063 "select network_name from network_info where network_info_id = ? ");
1065 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1066 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1068 g_hash_table_iter_init(&iter, out_param);
1069 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1070 GHashTableIter iter2;
1071 gpointer key2, value2;
1074 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1075 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1076 if (g_str_equal(key2, "0") == TRUE) {
1077 g_free(network_name);
1078 network_name = g_strdup(value2);
1080 /* TODO - Check this logic */
1087 /* Free resources */
1088 g_hash_table_destroy(in_param);
1089 g_hash_table_destroy(out_param);
1091 /* De-initialize Storage */
1092 tcore_storage_remove_handle(strg_db, handle);
1094 return network_name;
1097 static int __ps_context_load_profile_id_from_database(gchar *cp_name)
1100 GHashTable *out_param;
1102 gboolean rv = FALSE;
1104 GHashTableIter iter;
1105 gpointer key, value;
1107 int profile_id = -1;
1109 /* Initialize Storage */
1110 if (g_str_has_suffix(cp_name, "1"))
1111 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1113 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1114 if (handle == NULL) {
1115 err("Failed to get Storage handle");
1119 /* Initialize parameters */
1120 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1121 (GDestroyNotify) g_hash_table_destroy);
1124 memset(szQuery, 0x0, sizeof(szQuery));
1125 snprintf(szQuery, sizeof(szQuery), "%s",
1126 "select max(profile_id) as last_profile from pdp_profile");
1128 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
1129 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1131 g_hash_table_iter_init(&iter, out_param);
1132 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1133 GHashTableIter iter2;
1134 gpointer key2, value2;
1137 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1138 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1139 if (g_str_equal(key2, "0") == TRUE) {
1140 if (!value2 || (g_strcmp0((const char *)value2, "") == 0))
1143 profile_id = atoi((const char *)value2);
1145 /* TODO - Check this logic */
1152 /* Free resources */
1153 g_hash_table_destroy(out_param);
1155 /* De-initialize Storage */
1156 tcore_storage_remove_handle(strg_db, handle);
1161 static int __ps_context_load_num_of_pdn_from_database(gchar *mccmnc, gchar *cp_name)
1164 GHashTable *in_param, *out_param;
1166 gboolean rv = FALSE;
1168 GHashTableIter iter;
1169 gpointer key, value;
1173 /* Initialize Storage */
1174 if (g_str_has_suffix(cp_name, "1"))
1175 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1177 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1178 if (handle == NULL) {
1179 err("Failed to get Storage handle");
1183 /* Initialize parameters */
1184 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1185 g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
1187 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1188 (GDestroyNotify) g_hash_table_destroy);
1191 memset(szQuery, 0x0, sizeof(szQuery));
1192 snprintf(szQuery, sizeof(szQuery), "%s",
1193 "select a.max_pdp_3g from max_pdp a, network_info b \
1194 where a.network_info_id = b.network_info_id and b.mccmnc = ? ");
1196 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1197 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1199 g_hash_table_iter_init(&iter, out_param);
1200 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1201 GHashTableIter iter2;
1202 gpointer key2, value2;
1205 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1206 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1207 if (g_str_equal(key2, "0") == TRUE) {
1208 if (!value2 || (g_strcmp0((const char *)value2, "") == 0)) {
1210 dbg("There is NO value... Using 'default'");
1212 num_of_pdn = atoi((const char *) value2);
1213 dbg("value (%d)", num_of_pdn);
1216 /* TODO - Check this logic */
1223 if (num_of_pdn <= 0) {
1224 dbg("Loaded value is wrong... restoring to 'default'");
1225 num_of_pdn = PS_MAX_CID;
1226 } else if (num_of_pdn > PS_MAX_CID) {
1227 dbg("Loaded value is gretaer than 3... restoring to 'default'");
1228 num_of_pdn = PS_MAX_CID;
1231 /* Free resources */
1232 g_hash_table_destroy(in_param);
1233 g_hash_table_destroy(out_param);
1235 /* De-initialize Storage */
1236 tcore_storage_remove_handle(strg_db, handle);
1241 static gboolean __ps_context_remove_profile_tuple(dictionary *dic, int profile_index, gchar *cp_name)
1244 gboolean rv = FALSE;
1245 GHashTable *in_param;
1246 gchar *network_info_id;
1247 gchar *section_key = NULL;
1250 /* Initialize Storage */
1251 if (g_str_has_suffix(cp_name, "1"))
1252 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1254 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1255 if (handle == NULL) {
1256 err("Failed to get Storage handle");
1260 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1262 /* network info id */
1263 section_key = g_strdup_printf("connection:network_info_id_%d", profile_index);
1264 network_info_id = iniparser_getstring(dic, section_key, NULL);
1265 g_hash_table_insert(in_param, "1", g_strdup(network_info_id));
1266 g_free(section_key);
1269 memset(szQuery, 0x0, sizeof(szQuery));
1270 snprintf(szQuery, sizeof(szQuery), "%s",
1271 " delete from pdp_profile where network_info_id = ?");
1273 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
1274 dbg("delete from pdp_profile where network_info_id = %s, result(%d)", network_info_id, rv);
1275 /* Free resources */
1276 g_hash_table_destroy(in_param);
1278 /* De-initialize Storage */
1279 tcore_storage_remove_handle(strg_db, handle);
1284 static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int profile_index, gchar *cp_name)
1287 GHashTable *in_param;
1288 gboolean rv = FALSE;
1290 /* Initialize Storage */
1291 if (g_str_has_suffix(cp_name, "1"))
1292 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1294 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1295 if (handle == NULL) {
1296 err("Failed to get Storage handle");
1300 /* Initialize parameters */
1301 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1305 gchar *item_key = NULL;
1306 item_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1307 profile_id = iniparser_getstring(dic, item_key, NULL);
1308 if (profile_id == NULL) {
1312 g_hash_table_insert(in_param, "1", g_strdup(profile_id));
1317 gchar *profile_name;
1318 gchar *item_key = NULL;
1319 item_key = g_strdup_printf("connection:profile_name_%d", profile_index);
1320 profile_name = iniparser_getstring(dic, item_key, NULL);
1321 if (profile_name == NULL) {
1325 g_hash_table_insert(in_param, "2", g_strdup(profile_name));
1331 gchar *item_key = NULL;
1332 item_key = g_strdup_printf("connection:apn_%d", profile_index);
1333 apn = iniparser_getstring(dic, item_key, NULL);
1338 g_hash_table_insert(in_param, "3", g_strdup(apn));
1344 gchar *item_key = NULL;
1345 item_key = g_strdup_printf("connection:auth_type_%d", profile_index);
1346 auth_type = iniparser_getstring(dic, item_key, NULL);
1347 if (auth_type == NULL)
1348 g_hash_table_insert(in_param, "4", g_strdup_printf("%d", CONTEXT_AUTH_NONE));
1350 g_hash_table_insert(in_param, "4", g_strdup(auth_type));
1356 gchar *item_key = NULL;
1357 item_key = g_strdup_printf("connection:auth_id_%d", profile_index);
1358 auth_id = iniparser_getstring(dic, item_key, NULL);
1359 g_hash_table_insert(in_param, "5", g_strdup(auth_id));
1365 gchar *item_key = NULL;
1366 item_key = g_strdup_printf("connection:auth_pwd_%d", profile_index);
1367 auth_pwd = iniparser_getstring(dic, item_key, NULL);
1368 g_hash_table_insert(in_param, "6", g_strdup(auth_pwd));
1373 gchar *pdp_protocol;
1374 gchar *item_key = NULL;
1375 item_key = g_strdup_printf("connection:pdp_protocol_%d", profile_index);
1376 pdp_protocol = iniparser_getstring(dic, item_key, NULL);
1377 if (pdp_protocol == NULL)
1378 g_hash_table_insert(in_param, "7", g_strdup_printf("%d", CONTEXT_TYPE_IP));
1380 g_hash_table_insert(in_param, "7", g_strdup(pdp_protocol));
1385 gchar *proxy_ip_addr;
1386 gchar *section_key = NULL;
1387 section_key = g_strdup_printf("connection:proxy_ip_addr_%d", profile_index);
1388 proxy_ip_addr = iniparser_getstring(dic, section_key, NULL);
1389 g_hash_table_insert(in_param, "8", g_strdup(proxy_ip_addr));
1390 g_free(section_key);
1395 gchar *section_key = NULL;
1396 section_key = g_strdup_printf("connection:home_url_%d", profile_index);
1397 home_url = iniparser_getstring(dic, section_key, NULL);
1398 g_hash_table_insert(in_param, "9", g_strdup(home_url));
1399 g_free(section_key);
1404 gchar *section_key = NULL;
1405 section_key = g_strdup_printf("connection:linger_time_%d", profile_index);
1406 linger_time = iniparser_getstring(dic, section_key, NULL);
1407 g_hash_table_insert(in_param, "10", g_strdup(linger_time));
1408 g_free(section_key);
1411 {/* traffic class */
1412 gchar *traffic_class;
1413 gchar *section_key = NULL;
1414 section_key = g_strdup_printf("connection:traffic_class_%d", profile_index);
1415 traffic_class = iniparser_getstring(dic, section_key, NULL);
1416 g_hash_table_insert(in_param, "11", g_strdup(traffic_class));
1417 g_free(section_key);
1420 {/* is static ip address */
1421 gchar *is_static_ip_addr;
1422 gchar *section_key = NULL;
1423 section_key = g_strdup_printf("connection:is_static_ip_addr_%d", profile_index);
1424 is_static_ip_addr = iniparser_getstring(dic, section_key, NULL);
1425 g_hash_table_insert(in_param, "12", g_strdup(is_static_ip_addr));
1426 g_free(section_key);
1429 {/* ip address if static ip is true */
1431 gchar *section_key = NULL;
1432 section_key = g_strdup_printf("connection:ip_addr_%d", profile_index);
1433 ip_addr = iniparser_getstring(dic, section_key, NULL);
1434 g_hash_table_insert(in_param, "13", g_strdup(ip_addr));
1435 g_free(section_key);
1438 {/* is static dns address */
1439 gchar *is_static_dns_addr;
1440 gchar *section_key = NULL;
1441 section_key = g_strdup_printf("connection:is_static_dns_addr_%d", profile_index);
1442 is_static_dns_addr = iniparser_getstring(dic, section_key, NULL);
1443 g_hash_table_insert(in_param, "14", g_strdup(is_static_dns_addr));
1444 g_free(section_key);
1447 {/* dns address 1 */
1449 gchar *section_key = NULL;
1450 section_key = g_strdup_printf("connection:dns_addr1_%d", profile_index);
1451 dns_addr1 = iniparser_getstring(dic, section_key, NULL);
1452 g_hash_table_insert(in_param, "15", g_strdup(dns_addr1));
1453 g_free(section_key);
1456 {/* dns address 2 */
1458 gchar *section_key = NULL;
1459 section_key = g_strdup_printf("connection:dns_addr2_%d", profile_index);
1460 dns_addr2 = iniparser_getstring(dic, section_key, NULL);
1461 g_hash_table_insert(in_param, "16", g_strdup(dns_addr2));
1462 g_free(section_key);
1465 {/* network info id */
1466 gchar *network_info_id;
1467 gchar *section_key = NULL;
1468 section_key = g_strdup_printf("connection:network_info_id_%d", profile_index);
1469 network_info_id = iniparser_getstring(dic, section_key, NULL);
1470 g_hash_table_insert(in_param, "17", g_strdup(network_info_id));
1471 g_free(section_key);
1474 {/* service category id */
1475 gchar *svc_category_id;
1476 gchar *section_key = NULL;
1477 section_key = g_strdup_printf("connection:svc_category_id_%d", profile_index);
1478 svc_category_id = iniparser_getstring(dic, section_key, NULL);
1479 if (svc_category_id == NULL)
1480 g_hash_table_insert(in_param, "18", g_strdup_printf("%d", CONTEXT_ROLE_UNKNOWN));
1482 g_hash_table_insert(in_param, "18", g_strdup(svc_category_id));
1483 g_free(section_key);
1488 gchar *section_key = NULL;
1489 section_key = g_strdup_printf("connection:hidden_%d", profile_index);
1490 hidden = iniparser_getstring(dic, section_key, NULL);
1492 g_hash_table_insert(in_param, "19", g_strdup_printf("%d", FALSE));
1494 g_hash_table_insert(in_param, "19", g_strdup(hidden));
1495 g_free(section_key);
1500 gchar *section_key = NULL;
1501 section_key = g_strdup_printf("connection:editable_%d", profile_index);
1502 editable = iniparser_getstring(dic, section_key, NULL);
1503 if (editable == NULL)
1504 g_hash_table_insert(in_param, "20", g_strdup_printf("%d", TRUE));
1506 g_hash_table_insert(in_param, "20", g_strdup(editable));
1507 g_free(section_key);
1510 {/* default internet connection */
1511 gchar *default_internet_con;
1512 gchar *section_key = NULL;
1513 section_key = g_strdup_printf("connection:default_internet_con_%d", profile_index);
1514 default_internet_con = iniparser_getstring(dic, section_key, NULL);
1515 if (default_internet_con == NULL)
1516 g_hash_table_insert(in_param, "21", g_strdup_printf("%d", FALSE));
1518 g_hash_table_insert(in_param, "21", g_strdup(default_internet_con));
1519 g_free(section_key);
1522 {/* insert data into table */
1523 gchar *is_roaming_apn;
1524 gchar *section_key = NULL;
1525 section_key = g_strdup_printf("connection:is_roaming_apn_%d", profile_index);
1526 is_roaming_apn = iniparser_getstring(dic, section_key, NULL);
1527 if (is_roaming_apn == NULL)
1528 g_hash_table_insert(in_param, "22", g_strdup_printf("%d", FALSE));
1530 g_hash_table_insert(in_param, "22", g_strdup(is_roaming_apn));
1531 g_free(section_key);
1534 {/* insert data into table */
1538 memset(szQuery, 0x0, sizeof(szQuery));
1539 snprintf(szQuery, sizeof(szQuery), "%s",
1540 " insert into pdp_profile(\
1541 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, \
1542 pdp_protocol, proxy_ip_addr, home_url, linger_time, \
1543 traffic_class, is_static_ip_addr, ip_addr, is_static_dns_addr, dns_addr1, dns_addr2, \
1544 network_info_id, svc_category_id, hidden, editable, default_internet_con, \
1545 user_defined, is_roaming_apn, profile_enable) values(\
1549 ?, ?, ?, ?, ?, 0, ?, 1)");
1551 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
1552 dbg("Insert to Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1556 /* Free resources */
1557 g_hash_table_destroy(in_param);
1559 /* De-initialize Storage */
1560 tcore_storage_remove_handle(strg_db, handle);
1565 static int __ps_context_get_network_id(gchar *mccmnc, gchar *cp_name)
1569 network_id = __ps_context_load_network_id_from_database(mccmnc, cp_name);
1570 dbg("network id(%d)", network_id);
1574 network_id = __ps_context_insert_network_id_to_database(mccmnc, cp_name);
1575 if (network_id <= 0)
1581 GVariant *__ps_context_get_profile_properties(gpointer object, GVariantBuilder *properties)
1583 gchar *s_authtype = NULL, *s_role = NULL, *s_type = NULL;
1584 ps_context_t *context = NULL;
1585 char *apn, *username, *password, *proxy_addr, *home_url, *profile_name;
1587 g_return_val_if_fail(object != NULL, NULL);
1588 g_return_val_if_fail(properties != NULL, NULL);
1590 context = (ps_context_t *) object;
1591 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)),
1592 "get profile properties, path(%s)", _ps_context_ref_path(context));
1594 s_authtype = g_strdup_printf("%d", tcore_context_get_auth(context->co_context));
1595 s_role = g_strdup_printf("%d", tcore_context_get_role(context->co_context));
1596 s_type = g_strdup_printf("%d", tcore_context_get_type(context->co_context));
1598 apn = tcore_context_get_apn(context->co_context);
1599 username = tcore_context_get_username(context->co_context);
1600 password = tcore_context_get_password(context->co_context);
1601 proxy_addr = tcore_context_get_proxy(context->co_context);
1602 home_url = tcore_context_get_mmsurl(context->co_context);
1603 profile_name = tcore_context_get_profile_name(context->co_context);
1604 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
1606 g_variant_builder_add(properties, "{ss}", "path", context->path);
1608 g_variant_builder_add(properties, "{ss}", "apn", apn);
1611 g_variant_builder_add(properties, "{ss}", "auth_type", s_authtype);
1614 g_variant_builder_add(properties, "{ss}", "auth_id", username);
1617 g_variant_builder_add(properties, "{ss}", "auth_pwd", password);
1620 g_variant_builder_add(properties, "{ss}", "pdp_protocol", s_type);
1623 g_variant_builder_add(properties, "{ss}", "proxy_addr", proxy_addr);
1626 g_variant_builder_add(properties, "{ss}", "home_url", home_url);
1629 g_variant_builder_add(properties, "{ss}", "svc_ctg_id", s_role);
1631 g_variant_builder_add(properties, "{ss}", "profile_name", profile_name);
1632 g_variant_builder_add(properties, "{ss}", "hidden", BOOL2STRING(context->hidden));
1633 g_variant_builder_add(properties, "{ss}", "editable", BOOL2STRING(context->editable));
1634 g_variant_builder_add(properties, "{ss}", "default_internet_conn", BOOL2STRING(context->is_default));
1635 g_variant_builder_add(properties, "{ss}", "profile_enable", BOOL2STRING(context->profile_enable));
1637 /* Freeing locally allocated memory */
1646 g_free(profile_name);
1650 return g_variant_builder_end(properties);
1653 static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled)
1655 ps_context_t *context = object;
1657 g_return_val_if_fail(context != NULL, FALSE);
1659 context->is_default = enabled;
1663 static gpointer __ps_context_add_context(gpointer modem, gchar *mccmnc, int profile_id)
1666 GHashTable *in_param, *out_param;
1668 gboolean rv = FALSE;
1670 ps_modem_t *mdm = modem;
1671 CoreObject *co_modem = _ps_modem_ref_co_modem(mdm);
1672 GDBusConnection *conn = NULL;
1673 TcorePlugin *p = NULL;
1676 GHashTableIter iter;
1677 gpointer object = NULL;
1678 gpointer key, value;
1680 /* Initialize Storage */
1681 if (g_str_has_suffix(mdm->cp_name, "1"))
1682 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1684 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1685 if (handle == NULL) {
1686 ps_err_ex_co(co_modem, "Failed to get Storage handle");
1690 /* Initialize parameters */
1691 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1692 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", profile_id));
1694 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1695 (GDestroyNotify) g_hash_table_destroy);
1698 memset(szQuery, 0x0, sizeof(szQuery));
1699 snprintf(szQuery, sizeof(szQuery), "%s",
1701 a.network_info_id, a.network_name, a.mccmnc, \
1702 b.profile_id, b.profile_name, b.apn, \
1703 b.auth_type, b.auth_id, b.auth_pwd, \
1704 b.proxy_ip_addr, b.home_url, b.pdp_protocol, \
1705 b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr, \
1706 b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, \
1707 b.default_internet_con, b.user_defined, b.is_roaming_apn, b.profile_enable \
1708 from network_info a, pdp_profile b \
1709 where b.profile_id = ? and a.network_info_id = b.network_info_id ");
1711 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 26);
1712 ps_dbg_ex_co(co_modem, "Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1714 ps_dbg_ex_co(co_modem, "Create profile by Profile ID: [%d]", profile_id);
1715 conn = _ps_modem_ref_dbusconn(modem);
1716 p = _ps_modem_ref_plugin(modem);
1718 g_hash_table_iter_init(&iter, out_param);
1719 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1720 /* Create context */
1721 object = __ps_context_create_context(conn, p, mccmnc, (GHashTable *)value, mdm->cp_name);
1722 path = _ps_context_ref_path(object);
1724 /* Insert to contexts */
1725 mdm->contexts = g_slist_append(mdm->contexts, object);
1726 ps_dbg_ex_co(co_modem, "context (%p, %s) insert to hash", object, path);
1729 /* Free resources */
1730 g_hash_table_destroy(in_param);
1731 g_hash_table_destroy(out_param);
1733 /* De-initialize Storage */
1734 tcore_storage_remove_handle(strg_db, handle);
1739 gboolean _ps_context_check_is_roaming_apn_support(gchar* mccmnc, gchar* cp_name)
1742 GHashTable *in_param, *out_param;
1744 gboolean rv = FALSE, ret = FALSE;
1746 int network_info_id = -1;
1748 /* Initialize Storage */
1749 if (g_str_has_suffix(cp_name, "1"))
1750 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1752 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1753 if (handle == NULL) {
1754 err("Failed to get Storage handle");
1758 network_info_id = __ps_context_load_network_id_from_database(mccmnc, cp_name);
1759 if (network_info_id == -1)
1760 err("Failed to load network_info_id from mccmnc (%s)", mccmnc);
1762 /* Initialize parameters */
1763 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1764 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_info_id));
1766 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1767 (GDestroyNotify) g_hash_table_destroy);
1770 memset(szQuery, 0x0, sizeof(szQuery));
1771 snprintf(szQuery, sizeof(szQuery), "%s", "select profile_id from pdp_profile \
1772 where network_info_id = ? and is_roaming_apn = 1 ");
1774 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1775 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1777 profile_cnt = g_hash_table_size(out_param);
1778 if (profile_cnt > 0) {
1779 dbg("roaming profiles for (mccmnc: %s [%d]) exists: count[%d]", mccmnc, network_info_id, profile_cnt);
1782 /* Free resources */
1783 g_hash_table_destroy(in_param);
1784 g_hash_table_destroy(out_param);
1786 /* De-initialize Storage */
1787 tcore_storage_remove_handle(strg_db, handle);
1791 gboolean _ps_context_initialize(gpointer plugin)
1795 rv &= __ps_context_create_storage_handle(plugin);
1796 dbg("Global variable initialized: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1801 gboolean _ps_context_reset_profile_table(gchar *cp_name)
1805 gboolean rv = FALSE;
1807 /* Initialize Storage */
1808 if (g_str_has_suffix(cp_name, "1"))
1809 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1811 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1812 if (handle == NULL) {
1813 err("Failed to get Storage handle");
1818 memset(szQuery, 0x0, sizeof(szQuery));
1819 snprintf(szQuery, sizeof(szQuery), "%s", " delete from pdp_profile");
1821 rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, NULL);
1822 dbg("Reset profile table: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1824 /* De-initialize Storage */
1825 tcore_storage_remove_handle(strg_db, handle);
1830 gboolean _ps_context_fill_profile_table_from_ini_file(gchar *cp_name)
1832 int profile_index = 1;
1834 gchar *section_key = NULL;
1835 dictionary *dic = NULL;
1837 if (g_str_has_suffix(cp_name, "1"))
1838 dic = iniparser_load("/opt/system/csc-default/data/csc-default-data-connection-2.ini");
1840 dic = iniparser_load("/opt/system/csc-default/data/csc-default-data-connection.ini");
1843 dbg("fail to load the csc default file");
1849 section_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1850 dbg("section key (%s)", section_key);
1851 data_exist = iniparser_find_entry(dic, section_key);
1853 g_free(section_key);
1854 dbg("no more data in ini");
1857 __ps_context_remove_profile_tuple(dic, profile_index, cp_name);
1858 g_free(section_key);
1865 section_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1866 dbg("section key (%s)", section_key);
1867 data_exist = iniparser_find_entry(dic, section_key);
1869 g_free(section_key);
1870 iniparser_freedict(dic);
1871 dbg("no more data in ini");
1874 __ps_context_insert_profile_tuple(dic, profile_index, cp_name);
1875 g_free(section_key);
1882 GSList* _ps_context_create_hashtable(gpointer modem, gboolean roaming)
1885 GHashTable *in_param;
1886 GSList *out_param = NULL;
1888 gboolean rv = FALSE, roaming_apn = FALSE;
1892 ps_modem_t *mdm = modem;
1893 CoreObject *co_modem = _ps_modem_ref_co_modem(mdm);
1895 /* Initialize Storage */
1896 if (g_str_has_suffix(mdm->cp_name, "1"))
1897 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1899 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1900 if (handle == NULL) {
1901 ps_err_ex_co(co_modem, "Failed to get Storage handle");
1905 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1907 /* Check/Store roaming APN support at every SIM init complete. */
1908 roaming_apn = _ps_context_check_is_roaming_apn_support(mdm->operator, mdm->cp_name);
1909 _ps_modem_set_roaming_apn_support(modem, roaming_apn);
1912 /* Check roaming APN support first in the Roaming network. */
1913 ps_warn_ex_co(co_modem, "Roaming Network[%s], Roaming APN Support[%s]",
1914 roaming ? "TRUE" : "FALSE", roaming_apn ? "TRUE" : "FALSE");
1915 roaming = roaming_apn;
1917 ps_dbg_ex_co(co_modem, "create profile by mccmnc (%s)", mdm->operator);
1919 memset(szQuery, 0x0, sizeof(szQuery));
1920 snprintf(szQuery, sizeof(szQuery), "%s",
1922 a.network_info_id, a.network_name, a.mccmnc, \
1923 b.profile_id, b.profile_name, b.apn, \
1924 b.auth_type, b.auth_id, b.auth_pwd, \
1925 b.proxy_ip_addr, b.home_url, b.pdp_protocol, \
1926 b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr, \
1927 b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, \
1928 b.default_internet_con, b.user_defined, b.is_roaming_apn, b.profile_enable \
1929 from network_info a, pdp_profile b \
1930 where a.mccmnc = ? and b.is_roaming_apn = ? and a.network_info_id = b.network_info_id ");
1932 g_hash_table_insert(in_param, "1", g_strdup(mdm->operator));
1933 g_hash_table_insert(in_param, "2", g_strdup_printf("%d", roaming));
1935 for (retry = 0; retry < 5; retry++) {
1936 ps_dbg_ex_co(co_modem, "Reading database", mdm->operator);
1937 rv = tcore_storage_read_query_database_in_order(strg_db, handle, szQuery, in_param, &out_param, 26);
1941 ps_dbg_ex_co(co_modem, "Read Database: [%s], Retry[%d]", (rv == TRUE ? "SUCCESS" : "FAIL"), retry);
1943 for (index = 0; index < g_slist_length(out_param); index++) {
1945 gpointer object = NULL;
1946 GHashTable *value = NULL;
1948 value = g_slist_nth_data(out_param, index);
1951 /* Create new 'context' */
1952 object = __ps_context_create_context(mdm->conn, mdm->plg, mdm->operator, value, mdm->cp_name);
1953 path = _ps_context_ref_path(object);
1955 mdm->contexts = g_slist_append(mdm->contexts, object);
1956 ps_dbg_ex_co(co_modem, "context (%p, %s) insert to linked-list", object, path);
1959 g_hash_table_destroy(in_param);
1960 g_slist_free_full(out_param, (GDestroyNotify)g_hash_table_destroy);
1962 /* De-initialize Storage */
1963 tcore_storage_remove_handle(strg_db, handle);
1966 return mdm->contexts;
1969 gboolean _ps_context_add_context(gpointer modem, gchar *operator, GHashTable *property)
1971 GHashTable *services = NULL;
1972 gpointer context = NULL;
1973 ps_modem_t *mdm = modem;
1975 GHashTableIter iter;
1976 gpointer key, value;
1980 network_id = __ps_context_get_network_id(operator, mdm->cp_name);
1981 if (network_id <= 0) {
1982 dbg("fail to add network info");
1986 profile_id = __ps_context_insert_profile_to_database(property, network_id, mdm->cp_name);
1987 if (profile_id <= 0) {
1988 dbg("fail to insert profile info to database");
1992 context = __ps_context_add_context(modem, operator, profile_id);
1996 services = _ps_modem_ref_services(modem);
2000 g_hash_table_iter_init(&iter, services);
2001 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE)
2002 _ps_service_ref_context(value, context);
2007 gboolean _ps_context_get_properties_handler(gpointer object, GVariantBuilder *properties)
2009 int context_state = 0;
2010 gboolean active = FALSE;
2011 ps_context_t *context = object;
2012 char *dev_name = NULL;
2014 char *ipv4_address, *ipv4_gateway, *ipv4_dns1, *ipv4_dns2;
2015 char *ipv6_address, *ipv6_gateway, *ipv6_dns1, *ipv6_dns2;
2018 dbg("get context properties");
2019 g_return_val_if_fail(context != NULL, FALSE);
2020 g_return_val_if_fail(properties != NULL, FALSE);
2022 context_state = tcore_context_get_state(context->co_context);
2023 if (context_state == CONTEXT_STATE_ACTIVATED)
2027 ipv4_address = tcore_context_get_ipv4_addr(context->co_context);
2028 ipv4_gateway = tcore_context_get_ipv4_gw(context->co_context);
2029 ipv4_dns1 = tcore_context_get_ipv4_dns1(context->co_context);
2030 ipv4_dns2 = tcore_context_get_ipv4_dns2(context->co_context);
2033 ipv6_address = tcore_context_get_ipv6_addr(context->co_context);
2034 ipv6_gateway = tcore_context_get_ipv6_gw(context->co_context);
2035 ipv6_dns1 = tcore_context_get_ipv6_dns1(context->co_context);
2036 ipv6_dns2 = tcore_context_get_ipv6_dns2(context->co_context);
2038 proxy = tcore_context_get_proxy(context->co_context);
2039 dev_name = tcore_context_get_ipv4_devname(context->co_context);
2041 g_variant_builder_open(properties, G_VARIANT_TYPE("a{ss}"));
2043 g_variant_builder_add(properties, "{ss}", "path", (context->path));
2044 g_variant_builder_add(properties, "{ss}", "active", (BOOL2STRING(active)));
2046 /* Adding IPV4 data to builder */
2048 g_variant_builder_add(properties, "{ss}", "ipv4_address", ipv4_address);
2051 g_variant_builder_add(properties, "{ss}", "ipv4_gateway", ipv4_gateway);
2054 g_variant_builder_add(properties, "{ss}", "ipv4_dns1", ipv4_dns1);
2057 g_variant_builder_add(properties, "{ss}", "ipv4_dns2", ipv4_dns2);
2059 /* Adding IPV6 data to builder */
2060 g_variant_builder_add(properties, "{ss}", "ipv6_address",
2061 (ipv6_address == NULL ? "::" : ipv6_address));
2062 g_variant_builder_add(properties, "{ss}", "ipv6_gateway",
2063 (ipv6_gateway == NULL ? "::" : ipv6_gateway));
2064 g_variant_builder_add(properties, "{ss}", "ipv6_dns1",
2065 (ipv6_dns1 == NULL ? "::" : ipv6_dns1));
2066 g_variant_builder_add(properties, "{ss}", "ipv6_dns2",
2067 (ipv6_dns2 == NULL ? "::" : ipv6_dns2));
2070 g_variant_builder_add(properties, "{ss}", "proxy", proxy);
2073 g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
2075 g_variant_builder_add(properties, "{ss}", "default_internet_conn", (BOOL2STRING(context->is_default)));
2076 g_variant_builder_close(properties);
2078 /* Freeing local memory */
2079 g_free(ipv4_address);
2080 g_free(ipv4_gateway);
2083 g_free(ipv6_address);
2084 g_free(ipv6_gateway);
2095 GVariant *_ps_context_get_properties(gpointer object, GVariantBuilder *properties)
2097 int context_state = 0;
2098 gboolean active = FALSE;
2099 ps_context_t *context = object;
2100 char *dev_name = NULL;
2102 char *ipv4_address, *ipv4_gateway, *ipv4_dns1, *ipv4_dns2;
2103 char *ipv6_address, *ipv6_gateway, *ipv6_dns1, *ipv6_dns2;
2104 pcscf_addr *pcscf_ipv4, *pcscf_ipv6;
2107 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "get context properties");
2108 g_return_val_if_fail(context != NULL, NULL);
2109 g_return_val_if_fail(properties != NULL, NULL);
2111 context_state = tcore_context_get_state(context->co_context);
2112 if (context_state == CONTEXT_STATE_ACTIVATED)
2115 active &= context->b_active;
2118 ipv4_address = tcore_context_get_ipv4_addr(context->co_context);
2119 ipv4_gateway = tcore_context_get_ipv4_gw(context->co_context);
2120 ipv4_dns1 = tcore_context_get_ipv4_dns1(context->co_context);
2121 ipv4_dns2 = tcore_context_get_ipv4_dns2(context->co_context);
2124 ipv6_address = tcore_context_get_ipv6_addr(context->co_context);
2125 ipv6_gateway = tcore_context_get_ipv6_gw(context->co_context);
2126 ipv6_dns1 = tcore_context_get_ipv6_dns1(context->co_context);
2127 ipv6_dns2 = tcore_context_get_ipv6_dns2(context->co_context);
2130 pcscf_ipv4 = tcore_context_get_pcscf_ipv4_addr(context->co_context);
2131 pcscf_ipv6 = tcore_context_get_pcscf_ipv6_addr(context->co_context);
2133 proxy = tcore_context_get_proxy(context->co_context);
2134 dev_name = tcore_context_get_ipv4_devname(context->co_context);
2136 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
2138 g_variant_builder_add(properties, "{ss}", "path", (context->path));
2139 g_variant_builder_add(properties, "{ss}", "active", (BOOL2STRING(active)));
2140 g_variant_builder_add(properties, "{ss}", "routing_only", (BOOL2STRING(context->b_routing_only)));
2142 /* Adding IPV4 data to builder */
2144 g_variant_builder_add(properties, "{ss}", "ipv4_address", ipv4_address);
2147 g_variant_builder_add(properties, "{ss}", "ipv4_gateway", ipv4_gateway);
2150 g_variant_builder_add(properties, "{ss}", "ipv4_dns1", ipv4_dns1);
2153 g_variant_builder_add(properties, "{ss}", "ipv4_dns2", ipv4_dns2);
2155 /* Adding IPV6 data to builder */
2156 g_variant_builder_add(properties, "{ss}", "ipv6_address",
2157 (ipv6_address == NULL ? "::" : ipv6_address));
2158 g_variant_builder_add(properties, "{ss}", "ipv6_gateway",
2159 (ipv6_gateway == NULL ? "::" : ipv6_gateway));
2160 g_variant_builder_add(properties, "{ss}", "ipv6_dns1",
2161 (ipv6_dns1 == NULL ? "::" : ipv6_dns1));
2162 g_variant_builder_add(properties, "{ss}", "ipv6_dns2",
2163 (ipv6_dns2 == NULL ? "::" : ipv6_dns2));
2166 gboolean ipv6_link_only = FALSE;
2167 if (g_ascii_strncasecmp(ipv6_address, "fe80::", (gsize)6) == 0)
2168 ipv6_link_only = TRUE;
2169 g_variant_builder_add(properties, "{ss}", "ipv6_link_only", BOOL2STRING(ipv6_link_only));
2173 g_variant_builder_add(properties, "{ss}", "proxy", proxy);
2176 g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
2181 buf = g_strdup_printf("%d", pcscf_ipv4->count);
2182 g_variant_builder_add(properties, "{ss}", "pcscf_ipv4_count", buf);
2185 for (i = 0; i < pcscf_ipv4->count; i++) {
2186 buf = g_strdup_printf("%s_%d", "pcscf_ipv4_addr", i);
2187 g_variant_builder_add(properties, "{ss}", buf, pcscf_ipv4->addr[i]);
2191 /* Update pCSCF address (IPv4) count as '0' */
2192 g_variant_builder_add(properties, "{ss}", "pcscf_ipv4_count", "0");
2198 buf = g_strdup_printf("%d", pcscf_ipv6->count);
2199 g_variant_builder_add(properties, "{ss}", "pcscf_ipv6_count", buf);
2202 for (i = 0; i < pcscf_ipv6->count; i++) {
2203 buf = g_strdup_printf("%s_%d", "pcscf_ipv6_addr", i);
2204 g_variant_builder_add(properties, "{ss}", buf, pcscf_ipv6->addr[i]);
2208 /* Update pCSCF address (IPv6) count as '0' */
2209 g_variant_builder_add(properties, "{ss}", "pcscf_ipv6_count", "0");
2212 g_variant_builder_add(properties, "{ss}", "default_internet_conn", BOOL2STRING(context->is_default));
2214 /* Freeing local memory */
2216 for (i = 0; i < pcscf_ipv4->count; i++)
2217 g_free(pcscf_ipv4->addr[i]);
2221 for (i = 0; i < pcscf_ipv6->count; i++)
2222 g_free(pcscf_ipv6->addr[i]);
2225 g_free(ipv4_address);
2226 g_free(ipv4_gateway);
2229 g_free(ipv6_address);
2230 g_free(ipv6_gateway);
2237 return g_variant_builder_end(properties);
2240 gboolean _ps_context_set_alwayson_enable(gpointer object, gboolean enabled)
2242 ps_context_t *context = object;
2243 int role = CONTEXT_ROLE_UNKNOWN;
2244 g_return_val_if_fail(context != NULL, FALSE);
2246 role = tcore_context_get_role(context->co_context);
2248 if ((role == CONTEXT_ROLE_INTERNET) && context->is_default)
2249 context->alwayson = enabled;
2251 #ifdef PREPAID_SIM_APN_SUPPORT
2252 if ((role == CONTEXT_ROLE_PREPAID_INTERNET) && context->is_default)
2253 context->prepaid_alwayson = enabled;
2255 dbg("context (%p) alwayson (%d)", context, context->alwayson);
2259 gboolean _ps_context_get_default_context(gpointer object, int svc_cat_id)
2261 ps_context_t *context = object;
2262 int role = CONTEXT_ROLE_UNKNOWN;
2263 g_return_val_if_fail(context != NULL, FALSE);
2265 role = tcore_context_get_role(context->co_context);
2266 if (role == svc_cat_id && context->is_default)
2272 gboolean _ps_context_set_service(gpointer object, gpointer service)
2274 ps_context_t *context = object;
2275 g_return_val_if_fail(context != NULL, FALSE);
2277 context->p_service = service;
2281 gpointer _ps_context_ref_service(gpointer object)
2283 ps_context_t *context = object;
2284 g_return_val_if_fail(context != NULL, NULL);
2286 return context->p_service;
2289 gchar *_ps_context_ref_path(gpointer object)
2291 ps_context_t *context = object;
2292 g_return_val_if_fail(context != NULL, NULL);
2294 return context->path;
2297 gboolean _ps_context_get_alwayson_enable(gpointer object)
2299 ps_context_t *context = object;
2300 g_return_val_if_fail(context != NULL, FALSE);
2301 dbg("context (%p) alwayson (%d)", context, context->alwayson);
2302 return context->alwayson;
2305 #ifdef PREPAID_SIM_APN_SUPPORT
2306 gboolean _ps_context_get_prepaid_alwayson_enable(gpointer object)
2308 ps_context_t *context = object;
2309 g_return_val_if_fail(context != NULL, FALSE);
2310 dbg("prepaid context (%p) alwayson (%d)",
2311 context, context->prepaid_alwayson);
2312 return context->prepaid_alwayson;
2315 int _ps_context_get_profile_id(gpointer object)
2317 ps_context_t *context = object;
2318 g_return_val_if_fail(context != NULL, -1);
2319 dbg("profile_id[%d]", context->profile_id);
2320 return context->profile_id;
2324 gpointer _ps_context_ref_co_context(gpointer object)
2326 ps_context_t *context = object;
2327 g_return_val_if_fail(context != NULL, NULL);
2329 return context->co_context;
2332 gboolean _ps_context_set_connected(gpointer object, gboolean enabled)
2336 ps_context_t *context = object;
2337 Storage *strg_vconf = NULL;
2338 gpointer p_modem = NULL;
2340 gboolean b_roaming_checker = TRUE;
2341 gboolean data_allowed = FALSE;
2342 gboolean b_mms_checker = FALSE;
2343 gboolean b_ims_checker = TRUE;
2345 enum co_context_role role = CONTEXT_ROLE_UNKNOWN;
2347 dbg("Entry [enabled :%d]", enabled);
2349 g_return_val_if_fail(context != NULL, FALSE);
2351 strg_vconf = tcore_server_find_storage(tcore_plugin_ref_server(context->plg), "vconf");
2352 data_allowed = tcore_storage_get_bool(strg_vconf, STORAGE_KEY_3G_ENABLE);
2353 ipv4 = tcore_context_get_ipv4_addr(context->co_context);
2354 ipv6 = tcore_context_get_ipv6_addr(context->co_context);
2355 role = tcore_context_get_role(context->co_context);
2356 p_modem = _ps_service_ref_modem(context->p_service);
2358 if (role == CONTEXT_ROLE_MMS || role == CONTEXT_ROLE_PREPAID_MMS)
2359 b_mms_checker = TRUE;
2361 if (role == CONTEXT_ROLE_IMS || role == CONTEXT_ROLE_IMS_EMERGENCY)
2362 b_ims_checker = TRUE;
2364 #if !defined(TIZEN_SUPPORT_MMS_CONNECT_FORCE)
2365 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "csc runtime feature disabled");
2366 b_mms_checker = FALSE;
2369 context->b_active = enabled;
2370 if ((_ps_modem_get_roaming(p_modem)) && !(_ps_modem_get_data_roaming_allowed(p_modem))) {
2371 dbg("roaming network is not allowed");
2372 b_roaming_checker = FALSE;
2378 tcore_context_set_state(context->co_context, CONTEXT_STATE_ACTIVATED);
2380 if (context->deact_required == TRUE) {
2381 warn("Deactivation is required for context(%p)", context);
2382 _ps_service_deactivate_context(context->p_service, context);
2383 context->deact_required = FALSE;
2388 if ((g_str_equal(ipv4, "0.0.0.0") == TRUE) && (ipv6 == NULL)) {
2389 dbg("ip address is NULL");
2390 _ps_service_deactivate_context(context->p_service, context);
2394 _ps_service_reset_connection_timer(context);
2396 /* In case of PDP is disconnected by network in UPS mode.
2397 * default internet PDP could be activated if LCD was on at trigger time.
2399 ps_mode = _ps_modem_get_psmode(p_modem);
2400 warn("ps_mode: %d", ps_mode);
2401 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2402 gint pm_state = tcore_storage_get_int(strg_vconf, STORAGE_KEY_PM_STATE);
2403 if (pm_state == 3 && _ps_context_get_default_context(context, CONTEXT_ROLE_INTERNET)) {
2404 char *devname = tcore_context_get_ipv4_devname(context->co_context);
2405 if (TCORE_RETURN_SUCCESS != tcore_util_netif_down(devname))
2406 err("Failed to bring up interface");
2408 warn("[EXCEPTION] do not emit signal for PDP activation.");
2409 context->b_notify = TRUE;
2414 if (b_roaming_checker && (data_allowed || b_mms_checker || b_ims_checker))
2415 __ps_context_emit_property_changed_signal(context);
2418 tcore_context_set_state(context->co_context, CONTEXT_STATE_DEACTIVATED);
2419 tcore_context_reset_devinfo(context->co_context);
2420 __ps_context_emit_property_changed_signal(context);
2431 gboolean _ps_context_set_profile_enable(gpointer object, gboolean value)
2433 ps_context_t *context = object;
2434 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
2436 dbg("Entry [value :%d]", value);
2438 g_return_val_if_fail(context != NULL, FALSE);
2440 context->profile_enable = value;
2441 ps_dbg_ex_co(co_network, "context(%p) profile_enable(%d)", context, context->profile_enable);
2445 gboolean _ps_context_get_profile_enable(gpointer object)
2447 ps_context_t *context = object;
2449 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context(%p), profile_enable(%d)", context, context->profile_enable);
2451 return context->profile_enable;
2454 gboolean _ps_context_set_ps_defined(gpointer object, gboolean value)
2456 ps_context_t *context = (ps_context_t *)object;
2457 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
2459 dbg("Entry [value :%d]", value);
2461 g_return_val_if_fail(context != NULL, FALSE);
2463 context->ps_defined = value;
2464 ps_dbg_ex_co(co_network, "context(%p) ps_defined(%d)", context, context->ps_defined);
2468 gboolean _ps_context_get_ps_defined(gpointer object)
2470 ps_context_t *context = (ps_context_t *)object;
2472 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context(%p), ps_defined(%d)", context, context->ps_defined);
2474 return context->ps_defined;
2477 gboolean _ps_context_reset_user_data(gpointer object)
2479 ps_context_t *context = (ps_context_t *)object;
2481 g_return_val_if_fail(context != NULL, FALSE);
2482 context->user_data = NULL;
2487 gboolean _ps_context_set_bearer_info(gpointer object, struct tnoti_ps_dedicated_bearer_info *bearer_info)
2489 ps_context_t *context = (ps_context_t *)object;
2490 CoreObject *co_context = NULL;
2492 g_return_val_if_fail(context != NULL, FALSE);
2493 g_return_val_if_fail(bearer_info != NULL, FALSE);
2495 co_context = _ps_context_ref_co_context(object);
2497 if (bearer_info->dedicated_bearer.num_dedicated_bearer > 0) {
2498 warn("num_dedicated_bearer: %d", bearer_info->dedicated_bearer.num_dedicated_bearer);
2499 /* reset previous bearer info. */
2500 tcore_context_reset_bearer_info(co_context);
2501 tcore_context_set_bearer_info(co_context, bearer_info);
2502 __ps_context_emit_dedicated_bearer_info_signal(context);
2508 gpointer _ps_context_get_user_data(gpointer object)
2510 ps_context_t *context = (ps_context_t *)object;
2511 return context->user_data;
2514 TReturn _ps_connection_hdlr(gpointer object)
2516 int rv = TCORE_RETURN_FAILURE;
2517 ps_context_t *pscontext = object;
2518 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2520 _ps_context_set_alwayson_enable(pscontext, TRUE);
2521 rv = _ps_service_activate_context(pscontext->p_service, pscontext);
2522 if (rv != TCORE_RETURN_SUCCESS) {
2523 ps_dbg_ex_co(co_network, "fail to activate context connection");
2527 ps_dbg_ex_co(co_network, "success to activate context");
2531 gboolean _ps_context_create_cdma_profile(gchar *mccmnc, gchar *cp_name)
2534 gboolean rv = FALSE;
2535 GHashTable *in_param;
2538 /* Initialize Storage */
2539 if (g_str_has_suffix(cp_name, "1"))
2540 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
2542 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
2543 if (handle == NULL) {
2544 err("Failed to get Storage handle");
2548 /* Make default MMS profile for CDMA */
2549 memset(szQuery, 0, 5000);
2550 snprintf(szQuery, sizeof(szQuery), "%s",
2551 " update pdp_profile set \
2553 where profile_id = 1 and svc_category_id = 2 ");
2555 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
2557 g_hash_table_insert(in_param, "1", g_strdup("http://mms.vtext.com/servlets/mms")); /* home_url */
2559 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
2560 dbg("insert into pdp_profile result(%d)", rv);
2561 g_hash_table_destroy(in_param);
2563 /* De-initialize Storage */
2564 tcore_storage_remove_handle(strg_db, handle);
2569 void _ps_default_connection_hdlr(gpointer object)
2571 ps_context_t *pscontext = (ps_context_t *)object;
2572 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2574 __ps_context_update_default_internet_to_db(pscontext, TRUE);
2576 /* set request profile */
2577 tcore_context_set_default_profile(pscontext->co_context, TRUE);
2578 __ps_context_set_default_connection_enable(pscontext, TRUE);
2579 _ps_context_set_alwayson_enable(pscontext, TRUE);
2580 __ps_context_emit_property_changed_signal(pscontext);
2582 if (CONTEXT_ROLE_INTERNET == tcore_context_get_role(_ps_context_ref_co_context(object))) {
2583 int rv = TCORE_RETURN_FAILURE;
2584 ps_dbg_ex_co(co_network, "activation requeset in new ps (%p)", pscontext);
2585 /* request to connect */
2586 _ps_service_reset_connection_timer(pscontext);
2587 rv = _ps_service_connect_default_context(pscontext->p_service);
2588 if (rv == TCORE_RETURN_PS_NETWORK_NOT_READY) {
2589 unsigned char cid = -1;
2590 ps_service_t * p_service = (ps_service_t *)pscontext->p_service;
2592 ps_dbg_ex_co(co_network, "PS is not attached yet, release resources.");
2594 cid = tcore_context_get_id(pscontext->co_context);
2595 _ps_context_set_ps_defined((gpointer)pscontext, FALSE);
2596 tcore_ps_set_cid_active(p_service->co_ps, cid, FALSE);
2597 tcore_ps_clear_context_id(p_service->co_ps, pscontext->co_context);
2600 ps_dbg_ex_co(co_network, "complete to change the default connection");
2604 gint _ps_context_get_number_of_pdn(gchar *operator, gchar *cp_name)
2606 gint num_of_pdn = 0;
2608 num_of_pdn = __ps_context_load_num_of_pdn_from_database(operator, cp_name);
2609 dbg("loaded num_of_pdn (%d)", num_of_pdn);
2614 gboolean _ps_context_handle_ifaceup(gpointer user_data)
2616 ps_context_t *pscontext = user_data;
2617 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2618 int context_state = 0;
2620 context_state = tcore_context_get_state(pscontext->co_context);
2621 ps_warn_ex_co(co_network, "context_state: %d", context_state);
2622 if (context_state == CONTEXT_STATE_ACTIVATED) {
2623 char *devname = tcore_context_get_ipv4_devname(pscontext->co_context);
2624 gint ps_mode = _ps_modem_get_psmode(_ps_service_ref_modem(pscontext->p_service));
2625 if (TCORE_RETURN_SUCCESS != tcore_util_netif_up(devname))
2626 ps_err_ex_co(co_network, "Failed to bring up interface");
2628 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2629 /* If this flag is true, Connman won't update cellular service state. */
2630 if (pscontext->b_notify) {
2631 ps_warn_ex_co(co_network, "[EXCEPTION] notify status change to upper layer.");
2632 pscontext->b_routing_only = FALSE;
2634 pscontext->b_routing_only = TRUE;
2638 * 20131212, Deprecated: Fixed by HTTP stack.
2639 * ===============================================================================
2640 * 20130801, JIRA DCM-2221: HTTP communication behavior while bearer switching
2641 * Observations: When contiguous HTTP requests while ME handovers from wi-fi to 3G,
2642 * libcurl does not make Aborted event to application
2643 * even if libcurl receives socket closed event by SIOCKILLADDR.
2644 * So, we add work-around patch set here.
2645 * ===============================================================================
2647 if (pscontext->b_active == FALSE) {
2648 pscontext->b_active = TRUE;
2649 ps_dbg_ex_co(co_network, "Celluar profile: Emit property signal to provide IP configuration, devname(%s)", devname);
2650 __ps_context_emit_property_changed_signal(pscontext);
2652 pscontext->b_routing_only = FALSE;
2653 pscontext->b_notify = FALSE;
2655 } else if (context_state == CONTEXT_STATE_DEACTIVATED) {
2656 /* trigger PDP activation. */
2657 _ps_service_activate_context(pscontext->p_service, pscontext);
2662 gboolean _ps_context_handle_ifacedown(gpointer user_data)
2664 ps_context_t *pscontext = user_data;
2665 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2666 int context_state = 0;
2668 context_state = tcore_context_get_state(pscontext->co_context);
2669 ps_warn_ex_co(co_network, "context_state: %d", context_state);
2670 if (context_state == CONTEXT_STATE_ACTIVATED) {
2671 char *devname = tcore_context_get_ipv4_devname(pscontext->co_context);
2672 gint ps_mode = _ps_modem_get_psmode(_ps_service_ref_modem(pscontext->p_service));
2673 ps_dbg_ex_co(co_network, "Cellular profile: Do not send PDP deactivation request message to Modem.");
2674 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2675 /* If this flag is true, Connman won't update cellular service state. */
2676 pscontext->b_routing_only = TRUE;
2678 ps_warn_ex_co(co_network, "reset socket connections, devname(%s)", devname);
2679 if (TCORE_RETURN_SUCCESS != tcore_util_reset_ipv4_socket(devname, tcore_context_get_ipv4_addr(pscontext->co_context)))
2680 ps_err_ex_co(co_network, "Failed to reset socket.");
2683 if (TCORE_RETURN_SUCCESS != tcore_util_netif_down(devname))
2684 ps_err_ex_co(co_network, "Failed to bring down interface");
2685 if (pscontext->b_active == TRUE) {
2686 pscontext->b_active = FALSE;
2687 __ps_context_emit_property_changed_signal(pscontext);
2689 pscontext->b_routing_only = FALSE;
2695 static gboolean on_context_get_properties(PacketServiceContext *obj_context,
2696 GDBusMethodInvocation *invocation,
2699 GVariant *gv = NULL;
2700 GVariantBuilder property;
2701 ps_context_t *pscontext = user_data;
2702 TcorePlugin *p = (pscontext) ? pscontext->plg : NULL;
2703 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
2704 cynara *p_cynara = (priv_info) ? priv_info->p_cynara : NULL;
2706 if (!ps_util_check_access_control(p_cynara, invocation, AC_PS_PUBLIC, "r"))
2710 gv = _ps_context_get_properties(user_data, &property);
2711 packet_service_context_complete_get_properties(obj_context, invocation, gv);
2715 static gboolean on_context_get_profile(PacketServiceContext *obj_context,
2716 GDBusMethodInvocation *invocation,
2719 GVariant *gv = NULL;
2720 GVariantBuilder profile;
2721 ps_context_t *pscontext = user_data;
2722 TcorePlugin *p = (pscontext) ? pscontext->plg : NULL;
2723 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
2724 cynara *p_cynara = (priv_info) ? priv_info->p_cynara : NULL;
2726 if (!ps_util_check_access_control(p_cynara, invocation, AC_PS_PUBLIC, "r"))
2730 gv = __ps_context_get_profile_properties(user_data, &profile);
2731 packet_service_context_complete_get_profile(obj_context, invocation, gv);
2736 static gboolean on_context_handle_activate(PacketServiceContext *obj_context,
2737 GDBusMethodInvocation *invocation,
2740 gboolean rv = FALSE;
2741 TReturn result = TCORE_RETURN_FAILURE;
2744 int context_state = 0;
2745 unsigned int max_pdn = 0, num_of_active_cids = 0;
2746 gpointer p_service = NULL; gpointer co_ps = NULL;
2747 gpointer c_def_context = NULL; unsigned char cid_def = 0;
2748 GSList *active_cids = NULL;
2749 CoreObject *co_network;
2751 ps_context_t *pscontext = user_data;
2752 TcorePlugin *p = (pscontext) ? pscontext->plg : NULL;
2753 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
2754 cynara *p_cynara = (priv_info) ? priv_info->p_cynara : NULL;
2756 if (!ps_util_check_access_control(p_cynara, invocation, AC_PS_PRIVATE, "w"))
2760 if (pscontext == NULL) {
2761 err("activation request object is NULL");
2762 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2766 p_service = pscontext->p_service;
2768 err("service object is null");
2769 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2773 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2774 co_ps = _ps_service_ref_co_ps(p_service);
2776 ps_err_ex_co(co_network, "core object is null");
2777 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2781 ps_dbg_ex_co(co_network, "activate context(%s)", _ps_context_ref_path(pscontext));
2783 apn = (gchar *)tcore_context_get_apn(pscontext->co_context);
2785 context_state = tcore_context_get_state(pscontext->co_context);
2786 if (context_state != CONTEXT_STATE_DEACTIVATED) {
2787 ps_warn_ex_co(co_network, "operation is in progress");
2788 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2792 ps_dbg_ex_co(co_network, "requested context(%p) co_context(%p) apn (%s)", pscontext, pscontext->co_context, apn);
2793 /* check apn is activated or not */
2794 rv = tcore_ps_is_active_apn(co_ps, (const char *)apn);
2796 ps_dbg_ex_co(co_network, "requested apn is already activated");
2798 result = _ps_connection_hdlr(pscontext);
2799 if (result != TCORE_RETURN_SUCCESS) {
2800 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2804 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2805 context_state = tcore_context_get_state(pscontext->co_context);
2806 if (context_state == CONTEXT_STATE_ACTIVATED) {
2807 ps_dbg_ex_co(co_network, "context is already connected");
2808 _ps_context_set_connected(pscontext, TRUE);
2811 ps_dbg_ex_co(co_network, "success to open connection request");
2815 active_cids = tcore_ps_get_active_cids(co_ps);
2816 num_of_active_cids = g_slist_length(active_cids);
2817 max_pdn = tcore_ps_get_num_of_pdn(co_ps);
2818 ps_dbg_ex_co(co_network, "activate cids(%d), max pdn(%d)", num_of_active_cids, max_pdn);
2819 if (num_of_active_cids < max_pdn) {
2820 ps_dbg_ex_co(co_network, "enough to active another pdn");
2821 result = _ps_connection_hdlr(pscontext);
2822 if (result != TCORE_RETURN_SUCCESS) {
2823 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2827 ps_dbg_ex_co(co_network, "success to open connection request");
2828 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2832 /* find the current default connection */
2833 c_def_context = _ps_service_return_default_context(p_service, CONTEXT_ROLE_INTERNET);
2834 if (c_def_context == NULL) {
2835 err("default context is NULL");
2836 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2839 cid_def = tcore_context_get_id(((ps_context_t *)c_def_context)->co_context);
2841 ps_err_ex_co(co_network, "it is not avaiable to open connection");
2842 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2846 /* check the status of def context */
2847 context_state = tcore_context_get_state(((ps_context_t *)c_def_context)->co_context);
2848 if (context_state != CONTEXT_STATE_ACTIVATED) {
2849 enum co_context_role context_role;
2850 context_role = tcore_context_get_role(pscontext->co_context);
2851 ps_err_ex_co(co_network, "default connection is in progress, new context_state[%d], role[%d]", context_state, context_role);
2852 if (context_state == CONTEXT_STATE_ACTIVATING &&
2853 (context_role == CONTEXT_ROLE_MMS ||context_role == CONTEXT_ROLE_PREPAID_MMS)) {
2854 ((ps_context_t *)c_def_context)->user_data = pscontext;
2855 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2858 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2862 _ps_service_reset_connection_timer(c_def_context);
2863 ((ps_context_t *)c_def_context)->user_data = pscontext;
2864 result = tcore_ps_deactivate_cid(co_ps, cid_def);
2865 if (result != TCORE_RETURN_SUCCESS) {
2866 ps_err_ex_co(co_network, "fail to deactivate exist network connection");
2867 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2871 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2876 static gboolean on_context_handle_deactiavte(PacketServiceContext *obj_context,
2877 GDBusMethodInvocation *invocation,
2880 gboolean rv = FALSE;
2881 CoreObject *co_network;
2882 int context_state = 0;
2883 ps_context_t *pscontext = user_data;
2884 TcorePlugin *p = (pscontext) ? pscontext->plg : NULL;
2885 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
2886 cynara *p_cynara = (priv_info) ? priv_info->p_cynara : NULL;
2888 if (!ps_util_check_access_control(p_cynara, invocation, AC_PS_PRIVATE, "w"))
2892 if (pscontext == NULL) {
2893 err("deactivation request object is NULL");
2894 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2898 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2899 context_state = tcore_context_get_state(pscontext->co_context);
2900 ps_dbg_ex_co(co_network, "requested context(%p) co_context(%p), context_state %d", pscontext, pscontext->co_context, context_state);
2901 if (context_state != CONTEXT_STATE_ACTIVATED) {
2902 ps_err_ex_co(co_network, "operation is in progress");
2903 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2907 ps_dbg_ex_co(co_network, "deactivate context(%s)", _ps_context_ref_path(pscontext));
2909 _ps_service_reset_connection_timer(pscontext);
2910 _ps_context_set_alwayson_enable(pscontext, FALSE);
2912 rv = _ps_service_deactivate_context(pscontext->p_service, pscontext);
2913 if (rv != TCORE_RETURN_SUCCESS) {
2914 ps_err_ex_co(co_network, "fail to deactivate context connection");
2915 FAIL_RESPONSE(invocation, PS_ERR_TRASPORT);
2919 ps_dbg_ex_co(co_network, "success to deactivate context");
2920 packet_service_context_complete_deactivate(obj_context, invocation, pscontext->path);
2922 context_state = tcore_context_get_state(pscontext->co_context);
2923 if (context_state == CONTEXT_STATE_DEACTIVATED) {
2924 ps_dbg_ex_co(co_network, "context is already disconnected");
2925 pscontext->ps_defined = FALSE;
2926 _ps_context_set_connected(pscontext, FALSE);
2932 static gboolean on_context_set_default_connection(PacketServiceContext *obj_context,
2933 GDBusMethodInvocation *invocation,
2937 int role = CONTEXT_ROLE_UNKNOWN;
2938 gboolean is_default = FALSE;
2940 gpointer co_ps = NULL;
2941 gpointer service = NULL;
2942 gpointer cur_default_ctx = NULL;
2943 ps_context_t *pscontext = user_data;
2944 TcorePlugin *p = (pscontext) ? pscontext->plg : NULL;
2945 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
2946 cynara *p_cynara = (priv_info) ? priv_info->p_cynara : NULL;
2947 CoreObject *co_network;
2949 if (!ps_util_check_access_control(p_cynara, invocation, AC_PS_PROFILE, "w"))
2952 dbg("enter set default connection ps_context_t(%p)", pscontext);
2953 if (pscontext == NULL) {
2954 err("activation request object is NULL");
2955 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2959 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2960 ps_dbg_ex_co(co_network, "start default connection");
2961 role = tcore_context_get_role(pscontext->co_context);
2962 is_default = tcore_context_get_default_profile(pscontext->co_context);
2965 ps_err_ex_co(co_network, "already default profile for role (%d).", role);
2969 service = pscontext->p_service;
2970 cur_default_ctx = _ps_service_return_default_context(service, role);
2971 ps_dbg_ex_co(co_network, "current default connection (%p)", cur_default_ctx);
2973 if (!cur_default_ctx) {
2974 ps_err_ex_co(co_network, "No current default connection.");
2978 /* First, send deactivation request first. */
2979 rv = _ps_service_deactivate_context(((ps_context_t *)cur_default_ctx)->p_service, cur_default_ctx);
2980 if (rv == TCORE_RETURN_PS_ACTIVATING) {
2981 ps_dbg_ex_co(co_network, "fail to deactivate default connection, rv(%d)", rv);
2982 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2986 /* Normal deactivation case. */
2987 if (tcore_context_get_state(((ps_context_t *)cur_default_ctx)->co_context) == CONTEXT_STATE_DEACTIVATING) {
2988 ps_dbg_ex_co(co_network, "deactivation request in current ps (%p)", cur_default_ctx);
2989 ((ps_context_t *)cur_default_ctx)->user_data = pscontext;
2993 ps_dbg_ex_co(co_network, "[Not normal] deactivation request in current ps (%p)", cur_default_ctx);
2995 cid = tcore_context_get_id(((ps_context_t *)cur_default_ctx)->co_context);
2996 _ps_context_set_ps_defined(cur_default_ctx, FALSE);
2997 co_ps = _ps_service_ref_co_ps(service);
2998 tcore_ps_set_cid_active((CoreObject *)co_ps, cid, FALSE);
2999 tcore_ps_clear_context_id((CoreObject *)co_ps, ((ps_context_t *)cur_default_ctx)->co_context);
3002 /* unset default info of previous connection */
3003 _ps_context_set_alwayson_enable(cur_default_ctx, FALSE);
3004 __ps_context_set_default_connection_enable(cur_default_ctx, FALSE);
3005 tcore_context_set_default_profile(((ps_context_t *)cur_default_ctx)->co_context, FALSE);
3007 /* db update - release default connection */
3008 ps_dbg_ex_co(co_network, "context(%p): release default connection property.", cur_default_ctx);
3009 __ps_context_update_default_internet_to_db((ps_context_t *)cur_default_ctx, FALSE);
3010 /* Allow Connman to update profile information. */
3011 __ps_context_emit_property_changed_signal(cur_default_ctx);
3013 ps_dbg_ex_co(co_network, "activation requeset in new ps (%p)", pscontext);
3015 _ps_default_connection_hdlr(pscontext);
3016 packet_service_context_complete_set_default_connection(obj_context, invocation, TRUE);
3021 static gboolean on_context_modify_profile(PacketServiceContext *obj_context,
3022 GDBusMethodInvocation *invocation,
3026 GVariantIter g_iter;
3030 gboolean rv = FALSE;
3031 int context_state = 0;
3032 ps_context_t *context = user_data;
3033 TcorePlugin *p = (context) ? context->plg : NULL;
3034 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
3035 cynara *p_cynara = (priv_info) ? priv_info->p_cynara : NULL;
3036 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
3037 GHashTable *profile_property = NULL;
3039 if (!ps_util_check_access_control(p_cynara, invocation, AC_PS_PROFILE, "w"))
3042 ps_dbg_ex_co(co_network, "modify context's profile properties");
3044 context_state = tcore_context_get_state(context->co_context);
3045 if (context_state == CONTEXT_STATE_ACTIVATING) {
3046 ps_dbg_ex_co(co_network, "Modify profile in activating state, set deactivate flag.");
3047 context->deact_required = TRUE;
3050 /*Creating the profile property hash for for internal handling*/
3051 /*Create a hash table for the profile property as all fucntion already use ghash table */
3052 profile_property = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
3053 g_variant_iter_init(&g_iter, property);
3054 while (g_variant_iter_next(&g_iter, "{ss}", &g_key, &g_value)) {
3056 g_hash_table_insert(profile_property, g_strdup(g_key), g_strdup(g_value));
3057 /* must free data for ourselves */
3062 rv = __ps_context_update_profile(context, profile_property);
3064 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
3065 g_hash_table_destroy(profile_property);
3069 _ps_service_deactivate_context(context->p_service, context);
3070 if (context_state == CONTEXT_STATE_DEACTIVATED) {
3071 ps_dbg_ex_co(co_network, "context is already disconnected");
3072 _ps_context_set_connected(context, FALSE);
3075 packet_service_context_complete_modify_profile(obj_context, invocation, TRUE);
3076 g_hash_table_destroy(profile_property);
3080 static gboolean on_context_remove_profile(PacketServiceContext *obj_context,
3081 GDBusMethodInvocation *invocation, gpointer user_data)
3083 ps_context_t *context = user_data;
3084 ps_service_t *service = _ps_context_ref_service(context);
3085 CoreObject *co_network = _ps_service_ref_co_network(service);
3086 TcorePlugin *p = (context) ? context->plg : NULL;
3087 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
3088 cynara *p_cynara = (priv_info) ? priv_info->p_cynara : NULL;
3090 if (!ps_util_check_access_control(p_cynara, invocation, AC_PS_PROFILE, "w"))
3092 g_return_val_if_fail(service != NULL, FALSE);
3094 ps_dbg_ex_co(co_network, "Remove context.");
3096 __ps_context_remove_database(context);
3097 _ps_service_unref_context(service, context);
3098 service->contexts = g_slist_remove(service->contexts, context);
3099 _ps_context_remove_context(context);
3101 packet_service_context_complete_remove_profile(obj_context, invocation, TRUE);
3103 ps_dbg_ex_co(co_network, "Exit");
3107 static void _ps_context_setup_interface(PacketServiceContext *context, ps_context_t *context_data)
3110 g_signal_connect(context,
3111 "handle-get-properties",
3112 G_CALLBACK(on_context_get_properties),
3115 g_signal_connect(context,
3116 "handle-get-profile",
3117 G_CALLBACK(on_context_get_profile),
3120 g_signal_connect(context,
3122 G_CALLBACK(on_context_handle_activate),
3125 g_signal_connect(context,
3126 "handle-deactivate",
3127 G_CALLBACK(on_context_handle_deactiavte),
3130 g_signal_connect(context,
3131 "handle-set-default-connection",
3132 G_CALLBACK(on_context_set_default_connection),
3135 g_signal_connect(context,
3136 "handle-modify-profile",
3137 G_CALLBACK(on_context_modify_profile),
3140 g_signal_connect(context,
3141 "handle-remove-profile",
3142 G_CALLBACK(on_context_remove_profile),