2 * tel-plugin-packetservice
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongHoo Park <donghoo.park@samsung.com>
7 * Arun Shukla <arun.shukla@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include "ps_common.h"
25 #include "generated-code.h"
27 #include <tzplatform_config.h>
32 #include <core_object.h>
34 #include <co_context.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
39 #include <iniparser.h>
41 #include <libxml/xmlmemory.h>
42 #include <libxml/parser.h>
43 #include <libxml/tree.h>
45 #define PROP_DEFAULT FALSE
46 #define PROP_DEFAULT_STR NULL
47 #define DATABASE_PATH_0 tzplatform_mkpath(TZ_SYS_DB, ".dnet.db")
48 #define DATABASE_PATH_1 tzplatform_mkpath(TZ_SYS_DB, ".dnet2.db")
49 #define DELAY_TO_SIGNAL_EMIT 1
54 enum co_context_type pdp_type;
55 enum co_context_role role;
56 const char *p_cscf_ipv4addr;
57 const char *p_cscf_ipv6addr;
60 #define FREE_AND_ASSIGN(ptr, value) do { \
63 ptr = g_strdup(value); \
66 static Storage *strg_db;
69 OperatorTable attach_apn_preference[] = {
70 {"45005", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "220.103.220.10", "2001:2d8:00e0:0220::10"},
71 {"45006", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "", ""},
72 {"45008", "", CONTEXT_TYPE_IPV4V6, CONTEXT_ROLE_IMS, "", ""},
75 static void __ps_context_emit_dedicated_bearer_info_signal(ps_context_t *context);
76 static void __ps_context_emit_property_changed_signal(ps_context_t *context);
77 static void _ps_context_setup_interface(PacketServiceContext *context, ps_context_t *context_data);
79 static gboolean __ps_context_create_storage_handle(gpointer plugin);
80 static gchar *__ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id, gchar *cp_name);
81 static gboolean __ps_context_profile_is_attach_apn(CoreObject *co_context, const gchar *mccmnc);
82 static gboolean __ps_context_create_co_context(gpointer context, GHashTable *property, gchar *cp_name);
83 static gboolean __ps_context_update_profile(ps_context_t *context, GHashTable *property);
84 static gboolean __ps_context_update_database(ps_context_t *context);
85 static gboolean __ps_context_update_default_internet_to_db(ps_context_t *context, gboolean enabled);
86 static gboolean __ps_context_remove_database(ps_context_t *context);
87 static int __ps_context_insert_network_id_to_database(gchar *mccmnc, gchar *cp_name);
88 static int __ps_context_load_network_id_from_database(gchar *mccmnc, gchar *cp_name);
89 static gchar *__ps_context_load_network_name_from_database(int network_id, gchar *cp_name);
90 static int __ps_context_load_profile_id_from_database(gchar *cp_name);
91 static int __ps_context_load_num_of_pdn_from_database(gchar *mccmnc, gchar *cp_name);
92 static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int index, gchar *cp_name);
93 static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id, gchar *cp_name);
94 static int __ps_context_get_network_id(gchar *mccmnc, gchar *cp_name);
95 GVariant *__ps_context_get_profile_properties(gpointer context, GVariantBuilder *properties);
96 static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled);
98 void __remove_context_handler(gpointer data)
100 ps_context_t *context = data;
105 dbg("Context is Null");
109 /*Need to UNexport and Unref the master Object */
110 g_object_unref(context->if_obj);
112 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context removed for the path [%s]", context->path);
114 g_free(context->path);
115 g_free(context->mccmnc);
122 static void __ps_context_emit_dedicated_bearer_info_signal(ps_context_t *context)
125 CoreObject *co_network = NULL, *co_context = NULL;
126 struct dedicated_bearer_info bearer_info;
127 GVariantBuilder properties;
129 char *num_dedicated_bearer, *primary_context_id;
130 char *secondary_context_id, *qci, *gbr_dl, *gbr_ul, *max_br_dl, *max_br_ul;
132 g_return_if_fail(context != NULL);
134 co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
135 co_context = _ps_context_ref_co_context(context);
136 tcore_context_get_bearer_info(co_context, &bearer_info);
138 if (bearer_info.num_dedicated_bearer == 0) {
139 ps_warn_ex_co(co_network, "No dedicated bearer information");
143 g_variant_builder_init(&properties, G_VARIANT_TYPE("a{ss}"));
145 primary_context_id = INT2STRING(tcore_context_get_id(co_context));
146 g_variant_builder_add(&properties, "{ss}", "primary_context_id", primary_context_id);
147 g_free(primary_context_id);
149 num_dedicated_bearer = CHAR2STRING(bearer_info.num_dedicated_bearer);
150 g_variant_builder_add(&properties, "{ss}", "num_dedicated_bearer", num_dedicated_bearer);
151 g_free(num_dedicated_bearer);
153 secondary_context_id = INT2STRING(bearer_info.secondary_context_id);
154 g_variant_builder_add(&properties, "{ss}", "secondary_context_id", secondary_context_id);
155 g_free(secondary_context_id);
157 for (i = 0; i < bearer_info.num_dedicated_bearer ; i++) {
159 buf = g_strdup_printf("%s_%d", "qci", i);
160 qci = CHAR2STRING(bearer_info.qos[i].qci);
161 g_variant_builder_add(&properties, "{ss}", buf, qci);
165 buf = g_strdup_printf("%s_%d", "gbr_dl", i);
166 gbr_dl = INT2STRING(bearer_info.qos[i].gbr_dl);
167 g_variant_builder_add(&properties, "{ss}", buf, gbr_dl);
171 buf = g_strdup_printf("%s_%d", "gbr_ul", i);
172 gbr_ul = INT2STRING(bearer_info.qos[i].gbr_ul);
173 g_variant_builder_add(&properties, "{ss}", buf, gbr_ul);
177 buf = g_strdup_printf("%s_%d", "max_br_dl", i);
178 max_br_dl = INT2STRING(bearer_info.qos[i].max_br_dl);
179 g_variant_builder_add(&properties, "{ss}", buf, max_br_dl);
183 buf = g_strdup_printf("%s_%d", "max_br_ul", i);
184 max_br_ul = INT2STRING(bearer_info.qos[i].max_br_ul);
185 g_variant_builder_add(&properties, "{ss}", buf, max_br_ul);
189 gv = g_variant_builder_end(&properties);
191 packet_service_context_emit_dedicated_bearer_info(context->if_obj, gv);
192 ps_warn_ex_co(co_network, "context (%p) emit the dedicated bearer infomation signal", context);
195 static void __ps_context_emit_property_changed_signal(ps_context_t *context)
198 GVariantBuilder property;
199 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
201 ps_dbg_ex_co(co_network, "get context Properties");
203 gv = _ps_context_get_properties(context, &property);
204 packet_service_context_emit_property_changed(context->if_obj, gv);
206 ps_dbg_ex_co(co_network, "context (%p) emit the context property changed signal", context);
210 /* Funtion : _ps_context_remove_context
211 * Description : removes and unregister the interface for the context
213 gboolean _ps_context_remove_context(gpointer context)
215 ps_context_t *pscontext = context;
216 ps_service_t *service = _ps_context_ref_service(pscontext);
218 g_return_val_if_fail(pscontext != NULL, FALSE);
219 g_return_val_if_fail(service != NULL, FALSE);
220 g_return_val_if_fail(pscontext->path != NULL, FALSE);
222 ps_dbg_ex_co(_ps_service_ref_co_network(service),
223 "remove context (%s)", pscontext->path);
225 /*Removing the context from the static list */
226 _ps_service_reset_connection_timer(context);
227 _ps_context_set_connected(context, FALSE);
229 /* Unexport object */
230 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(pscontext->if_obj));
232 /* remove context from the list (modem, service) */
233 tcore_ps_remove_context(service->co_ps,
234 (CoreObject *)_ps_context_ref_co_context(context));
235 tcore_context_free(pscontext->co_context);
237 /* free allocated resources for context. */
238 g_free(pscontext->mccmnc);
239 g_free(pscontext->path);
246 static gboolean __ps_context_create_storage_handle(gpointer plugin)
248 TcorePlugin *p = plugin;
250 strg_db = tcore_server_find_storage(tcore_plugin_ref_server(p), "database");
251 dbg("Storage: (%p)", strg_db);
256 static gchar *__ps_context_create_path(char *profile_name, int profile_id, int svc_ctg_id, gchar *cp_name)
258 gchar *path = NULL, *in_path = NULL;
259 int str_len = 0, context_index = 0;
262 dbg("profile_name is null");
266 str_len = strlen(profile_name);
267 in_path = g_strdup_printf("/%s%s", cp_name, "/context/");
269 for (context_index = 0; context_index < str_len; context_index++) {
270 gchar *buf = NULL, *tmp = NULL;
271 buf = g_strdup_printf("%02x", profile_name[context_index]);
272 tmp = g_strconcat(in_path, buf, NULL);
277 in_path = g_strdup(tmp);
281 dbg("converted name(%s) path(%s)", profile_name, in_path);
283 path = g_strdup_printf("%s_%d_%d", in_path, profile_id, svc_ctg_id);
284 dbg("path (%s)", path);
290 static gboolean __ps_context_profile_is_attach_apn(CoreObject *co_context, const gchar *mccmnc)
292 gboolean attach_apn = FALSE, default_conn = FALSE;
295 if (co_context == NULL)
298 default_conn = tcore_context_get_default_profile(co_context);
299 role = tcore_context_get_role(co_context);
302 * TODO: Read CSC Configuration routine.
303 * By default, default Ineternet profile will be used for PS attach.
304 * CSC will define APN for PS attach according to operator requirement.
308 gboolean matched = FALSE;
310 count = sizeof(attach_apn_preference) / sizeof(attach_apn_preference[0]);
311 for (i = 0; i < count ; i++) {
312 if (g_strcmp0(attach_apn_preference[i].mccmnc, mccmnc) == 0) {
313 if (attach_apn_preference[i].role == role) {
314 dbg("index[%d], attach_apn_preference[%d].role: %d, role: %d, apn: %s",
315 i, i, attach_apn_preference[i].role, role, attach_apn_preference[i].apn);
323 if (role == CONTEXT_ROLE_INTERNET)
328 dbg("role(%d), attach_apn (%d)", role, attach_apn);
332 static gboolean __ps_context_create_co_context(gpointer object, GHashTable *property, gchar *cp_name)
336 ps_context_t *context = NULL;
337 CoreObject *co_context = NULL;
341 gchar *profile_name = NULL;
343 gchar *auth_id = NULL, *auth_pwd = NULL, *home_url = NULL, *proxy_addr = NULL;
344 int auth_type = 0, svc_ctg_id = 0, pdp_type = 0, roam_pdp_type = 0;
345 gboolean hidden = FALSE, editable = FALSE, default_conn = FALSE, user_defined = FALSE, is_roaming_apn = FALSE, profile_enable = TRUE;
347 g_hash_table_iter_init(&iter, (GHashTable *) property);
348 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
349 if (g_str_equal(key, "3") == TRUE) { /*Profile ID*/
351 profile_id = atoi((const char *) value);
352 dbg("profile id (%d)", profile_id);
354 } else if (g_str_equal(key, "4") == TRUE) {
355 g_free(profile_name);
356 profile_name = g_strdup((const char *) value);
357 dbg("profile name (%s)", profile_name);
358 } else if (g_str_equal(key, "5") == TRUE) {
360 apn = g_strdup((const char *) value);
361 dbg("APN (%s)", apn);
362 } else if (g_str_equal(key, "6") == TRUE) {
364 auth_type = atoi((const char *) value);
365 dbg("auth type (%d)", auth_type);
367 } else if (g_str_equal(key, "7") == TRUE) {
369 auth_id = g_strdup((const char *) value);
370 dbg("auth id (%s)", auth_id);
371 } else if (g_str_equal(key, "8") == TRUE) {
373 auth_pwd = g_strdup((const char *) value);
374 dbg("auth pwd (%s)", auth_pwd);
375 } else if (g_str_equal(key, "9") == TRUE) {
376 if (!value || g_strcmp0((const gchar *) value, "") == 0) {
378 proxy_addr = g_strdup((const char *) value);
380 gboolean b_regex = FALSE;
381 b_regex = g_regex_match_simple("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+:[0-9]*", (const gchar *) value, 0, 0);
385 gchar **tmp_proxy = NULL;
387 tmp_proxy = g_strsplit_set((const gchar *) value, ".:", -1);
388 port_num = atoi(tmp_proxy[4]);
392 proxy_addr = g_strdup_printf("%d.%d.%d.%d",
393 atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]));
396 proxy_addr = g_strdup_printf("%d.%d.%d.%d:%d",
397 atoi(tmp_proxy[0]), atoi(tmp_proxy[1]), atoi(tmp_proxy[2]), atoi(tmp_proxy[3]), port_num);
399 g_strfreev(tmp_proxy);
402 proxy_addr = g_strdup((const char *) value);
403 } /* not in regular experssion */
406 dbg("proxy addr (%s)", proxy_addr);
407 } else if (g_str_equal(key, "10") == TRUE) {
409 home_url = g_strdup((const char *) value);
410 dbg("home url (%s)", home_url);
411 } else if (g_str_equal(key, "11") == TRUE) {
413 pdp_type = atoi((const char *) value);
414 dbg("pdp type (%d)", pdp_type);
416 } else if (g_str_equal(key, "19") == TRUE) {
418 svc_ctg_id = atoi((const char *) value);
419 dbg("context category type (%d)", svc_ctg_id);
421 } else if (g_str_equal(key, "20") == TRUE) {
423 hidden = atoi((const char *) value);
424 dbg("hidden profile (%d)", hidden);
426 } else if (g_str_equal(key, "21") == TRUE) {
428 editable = atoi((const char *) value);
429 dbg("editable profile (%d)", editable);
431 } else if (g_str_equal(key, "22") == TRUE) {
433 default_conn = atoi((const char*) value);
434 dbg("default connection profile (%d)", default_conn);
436 } else if (g_str_equal(key, "23") == TRUE) {
438 user_defined = atoi((const char*) value);
439 dbg("user defined profile (%d)", user_defined);
441 } else if (g_str_equal(key, "24") == TRUE) {
443 is_roaming_apn = atoi((const char*) value);
444 dbg("roaming APN profile (%d)", is_roaming_apn);
446 } else if (g_str_equal(key, "25") == TRUE) {
448 profile_enable = atoi((const char*) value);
449 dbg("profile enable (%d)", profile_enable);
451 } else if (g_str_equal(key, "26") == TRUE) {
453 roam_pdp_type = atoi((const char *) value);
454 info("Roam pdp type (%d)", roam_pdp_type);
459 path = __ps_context_create_path(profile_name, profile_id, svc_ctg_id, cp_name);
461 context = (ps_context_t *)object;
462 co_context = tcore_context_new(context->plg, path, NULL);
463 tcore_context_set_type(co_context, pdp_type);
464 tcore_context_set_roam_pdp_type(co_context, roam_pdp_type);
465 tcore_context_set_state(co_context, CONTEXT_STATE_DEACTIVATED);
466 tcore_context_set_role(co_context, svc_ctg_id);
467 tcore_context_set_apn(co_context, apn);
468 tcore_context_set_auth(co_context, auth_type);
469 tcore_context_set_username(co_context, auth_id);
470 tcore_context_set_password(co_context, auth_pwd);
471 tcore_context_set_proxy(co_context, proxy_addr);
472 tcore_context_set_mmsurl(co_context, home_url);
473 tcore_context_set_profile_name(co_context, profile_name);
474 tcore_context_set_default_profile(co_context, default_conn);
475 tcore_context_set_attach_apn(co_context, __ps_context_profile_is_attach_apn(co_context, context->mccmnc));
476 tcore_context_set_roaming_apn(co_context, is_roaming_apn);
478 context->profile_id = profile_id;
479 context->hidden = hidden;
480 context->editable = editable;
481 context->is_default = default_conn;
482 _ps_context_set_profile_enable(context, profile_enable);
483 context->path = path;
484 context->co_context = co_context;
486 g_free(profile_name);
496 static gpointer __ps_context_create_context(GDBusConnection *conn, TcorePlugin *p,
497 gchar *mccmnc, GHashTable *property, gchar *cp_name)
499 PacketServiceContext *context;
500 GError *error = NULL;
501 ps_context_t *new_context;
506 /*Initializing the master list for internal referencing*/
507 new_context = g_try_malloc0(sizeof(ps_context_t));
508 if (NULL == new_context) {
509 err("Unable to allocate memory for context");
512 dbg("creating the skeleton object");
513 context = packet_service_context_skeleton_new();
514 if (NULL == context) {
519 dbg("Assigning the memory location for the internal data");
520 new_context->conn = conn;
521 new_context->plg = p;
522 new_context->if_obj = context;
523 new_context->mccmnc = g_strdup(mccmnc);
525 __ps_context_create_co_context(new_context, property , cp_name);
526 _ps_context_set_alwayson_enable(new_context, TRUE);
527 path = _ps_context_ref_path(new_context);
528 _ps_context_setup_interface(context, new_context);
530 dbg("registering the interface object");
532 dbg("exporting the interface object to the dbus connection");
533 /*exporting the interface object to the path mention for master*/
534 g_dbus_interface_skeleton_export((G_DBUS_INTERFACE_SKELETON(context)),
539 g_assert_no_error(error);
541 dbg("Successfully new object created for the interface for path [%s]", path);
545 /*To do : handle failure */
546 dbg("Unable to allocate memory for the new object");
550 static gboolean __ps_context_update_profile(ps_context_t *context, GHashTable *property)
552 CoreObject *co_context = NULL;
556 co_context = context->co_context;
560 g_hash_table_iter_init(&iter, property);
561 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
562 if (g_str_equal(key, "apn") == TRUE) {
563 tcore_context_set_apn(co_context, (const char *) value);
564 } else if (g_str_equal(key, "profile_name") == TRUE) {
565 tcore_context_set_profile_name(co_context, (const char *) value);
566 } else if (g_str_equal(key, "auth_type") == TRUE) {
569 i_tmp = atoi((const char *) value);
570 tcore_context_set_auth(co_context, i_tmp);
572 } else if (g_str_equal(key, "auth_id") == TRUE) {
573 tcore_context_set_username(co_context, (const char *) value);
574 } else if (g_str_equal(key, "auth_pwd") == TRUE) {
575 tcore_context_set_password(co_context, (const char *) value);
576 } else if (g_str_equal(key, "pdp_protocol") == TRUE) {
579 i_tmp = atoi((const char *) value);
580 tcore_context_set_type(co_context, i_tmp);
582 } else if (g_str_equal(key, "roam_pdp_protocol") == TRUE) {
585 i_tmp = atoi((const char *) value);
586 tcore_context_set_roam_pdp_type(co_context, i_tmp);
588 } else if (g_str_equal(key, "proxy_addr") == TRUE) {
589 tcore_context_set_proxy(co_context, (const char *) value);
590 } else if (g_str_equal(key, "home_url") == TRUE) {
591 tcore_context_set_mmsurl(co_context, (const char *) value);
592 } else if (g_str_equal(key, "profile_enable") == TRUE) {
595 if (g_str_equal(value, "FALSE") == TRUE)
597 _ps_context_set_profile_enable(context, tmp);
602 return __ps_context_update_database(context);
605 static gboolean __ps_context_update_default_internet_to_db(ps_context_t *context, gboolean enabled)
608 GHashTable *in_param;
611 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
612 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
614 g_return_val_if_fail(context != NULL, FALSE);
616 /* Initialize Storage */
617 if (g_str_has_suffix(cp_name, "1"))
618 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
620 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
621 if (handle == NULL) {
622 ps_err_ex_co(co_network, "Failed to get Storage handle");
626 /* Initialize parameters */
627 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
628 g_hash_table_insert(in_param, "1",
629 g_strdup_printf("%d", enabled)); /* Profile enabled/disabled */
630 g_hash_table_insert(in_param, "2",
631 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
634 memset(szQuery, 0x0, sizeof(szQuery));
635 snprintf(szQuery, sizeof(szQuery), "%s",
636 " update pdp_profile set \
637 default_internet_con = ? \
638 where profile_id = ?");
640 rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
641 ps_dbg_ex_co(co_network, "Update Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
644 g_hash_table_destroy(in_param);
646 /* De-initialize Storage */
647 tcore_storage_remove_handle(strg_db, handle);
652 static gboolean __ps_context_update_database(ps_context_t *context)
655 GHashTable *in_param;
658 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
659 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
661 g_return_val_if_fail(context != NULL, FALSE);
663 /* Initialize Storage */
664 if (g_str_has_suffix(cp_name, "1"))
665 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
667 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
668 if (handle == NULL) {
669 ps_err_ex_co(co_network, "Failed to get Storage handle");
673 /* Initialize parameters */
674 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
675 g_hash_table_insert(in_param, "1",
676 tcore_context_get_apn(context->co_context)); /* APN */
677 g_hash_table_insert(in_param, "2",
678 g_strdup_printf("%d", tcore_context_get_auth(context->co_context))); /* Auth Type */
679 g_hash_table_insert(in_param, "3",
680 tcore_context_get_username(context->co_context)); /* Username */
681 g_hash_table_insert(in_param, "4",
682 tcore_context_get_password(context->co_context)); /* Password */
683 g_hash_table_insert(in_param, "5",
684 tcore_context_get_proxy(context->co_context)); /* Proxy */
685 g_hash_table_insert(in_param, "6",
686 tcore_context_get_mmsurl(context->co_context)); /* MMS URL */
687 g_hash_table_insert(in_param, "7",
688 tcore_context_get_profile_name(context->co_context)); /* Profile Name */
689 g_hash_table_insert(in_param, "8",
690 g_strdup_printf("%d", tcore_context_get_type(context->co_context))); /* PDP protocol */
691 g_hash_table_insert(in_param, "9",
692 g_strdup_printf("%d", tcore_context_get_roam_pdp_type(context->co_context))); /* Roam PDP protocol */
693 g_hash_table_insert(in_param, "10",
694 g_strdup_printf("%d", _ps_context_get_profile_enable(context))); /* Profile Enable */
695 g_hash_table_insert(in_param, "11",
696 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
699 memset(szQuery, 0x0, sizeof(szQuery));
700 snprintf(szQuery, sizeof(szQuery), "%s",
701 " update pdp_profile set \
702 apn = ?, auth_type = ?, auth_id = ?, auth_pwd = ?, \
703 proxy_ip_addr = ?, home_url = ?, profile_name = ?, \
704 pdp_protocol = ?, roam_pdp_protocol = ?, profile_enable = ? where profile_id = ?");
706 rv = tcore_storage_update_query_database(strg_db, handle, szQuery, in_param);
707 ps_dbg_ex_co(co_network, "Update Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
710 g_hash_table_destroy(in_param);
712 /* De-initialize Storage */
713 tcore_storage_remove_handle(strg_db, handle);
718 static gboolean __ps_context_remove_database(ps_context_t *context)
721 GHashTable *in_param;
724 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
725 char *cp_name = _ps_modem_ref_cp_name(_ps_service_ref_modem(_ps_context_ref_service(context)));
727 g_return_val_if_fail(context != NULL, FALSE);
729 /* Initialize Storage */
730 if (g_str_has_suffix(cp_name, "1"))
731 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
733 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
734 if (handle == NULL) {
735 ps_err_ex_co(co_network, "Failed to get Storage handle");
739 /* Initialize parameters */
740 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
741 g_hash_table_insert(in_param, "1",
742 g_strdup_printf("%d", context->profile_id)); /* Profile ID */
745 memset(szQuery, 0x0, sizeof(szQuery));
746 snprintf(szQuery, sizeof(szQuery), "%s",
747 " delete from pdp_profile where profile_id = ? ");
749 rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, in_param);
750 ps_dbg_ex_co(co_network, "Remove from Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
753 g_hash_table_destroy(in_param);
755 /* De-initialize Storage */
756 tcore_storage_remove_handle(strg_db, handle);
761 static int __ps_context_insert_network_id_to_database(gchar *mccmnc, gchar *cp_name)
764 GHashTable *in_param, *out_param;
772 /* Initialize Storage */
773 if (g_str_has_suffix(cp_name, "1"))
774 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
776 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
777 if (handle == NULL) {
778 err("Failed to get Storage handle");
783 * Check the maximum Network ID that exists in database,
784 * if NONE exists, then 'Network ID' would be equal to 1
785 * else if there exists a valid maximum entry; 'Network ID' would be incremented value.
787 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
788 (GDestroyNotify) g_hash_table_destroy);
791 memset(szQuery, 0x0, sizeof(szQuery));
792 snprintf(szQuery, sizeof(szQuery), "%s",
793 "select max(network_info_id) as network_id from network_info");
795 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
796 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
798 g_hash_table_iter_init(&iter, out_param);
799 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
800 GHashTableIter iter2;
801 gpointer key2, value2;
804 g_hash_table_iter_init(&iter2, (GHashTable *)value);
805 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
806 dbg("key2(%s) value2(%s)", key2, value2);
807 if (g_str_equal(key2, "0") == TRUE) {
808 if (!value2 || g_strcmp0((const char *)value2, "") == 0)
811 network_id = atoi((const char *)value2);
813 /* TODO - Check this logic */
821 g_hash_table_destroy(out_param);
823 /* Increment Network ID */
827 memset(szQuery, 0x0, sizeof(szQuery));
828 snprintf(szQuery, sizeof(szQuery), "%s",
829 " insert into network_info(network_info_id, network_name, mccmnc) values(?, ?, ?) ");
831 /* Initialize parameters */
832 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
833 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_id)); /* Network ID */
834 g_hash_table_insert(in_param, "2", g_strdup_printf("PLMN_%s", mccmnc));
835 g_hash_table_insert(in_param, "3", g_strdup(mccmnc));
837 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
839 err("Failed to insert query to Storage");
844 g_hash_table_destroy(in_param);
846 /* De-initialize Storage */
847 tcore_storage_remove_handle(strg_db, handle);
852 static int __ps_context_insert_profile_to_database(GHashTable *property, int network_id, gchar *cp_name)
855 GHashTable *in_param;
863 gchar *profile_name = NULL, *apn = NULL, *auth_type = NULL;
864 gchar *auth_id = NULL, *auth_pwd = NULL, *proxy_addr = NULL;
865 gchar *home_url = NULL, *svc_id = NULL, *pdp_protocol = NULL, *roam_pdp_protocol = NULL;
867 /* Initialize Storage */
868 if (g_str_has_suffix(cp_name, "1"))
869 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
871 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
872 if (handle == NULL) {
873 err("Failed to get Storage handle");
877 profile_id = __ps_context_load_profile_id_from_database(cp_name);
878 if (profile_id < 0) {
879 dbg("Failed to get last Profile ID");
885 /* Increment Profile ID */
888 g_hash_table_iter_init(&iter, property);
889 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
890 if (g_str_equal(key, "profile_name") == TRUE) { /* Profile Name */
892 FREE_AND_ASSIGN(profile_name, value);
895 g_free(profile_name);
897 profile_name = __ps_context_load_network_name_from_database(network_id, cp_name);
899 } else if (g_str_equal(key, "apn") == TRUE) { /* APN */
900 FREE_AND_ASSIGN(apn, value);
901 } else if (g_str_equal(key, "auth_type") == TRUE) { /* Auth Type */
902 FREE_AND_ASSIGN(auth_type, value);
903 } else if (g_str_equal(key, "auth_id") == TRUE) { /* Auth ID */
904 FREE_AND_ASSIGN(auth_id, value);
905 } else if (g_str_equal(key, "auth_pwd") == TRUE) { /* Auth Password */
906 FREE_AND_ASSIGN(auth_pwd, value);
907 } else if (g_str_equal(key, "proxy_addr") == TRUE) { /* Proxy Address */
908 FREE_AND_ASSIGN(proxy_addr, value);
909 } else if (g_str_equal(key, "home_url") == TRUE) { /* Home URL */
910 FREE_AND_ASSIGN(home_url, value);
911 } else if (g_str_equal(key, "svc_ctg_id") == TRUE) { /* Service ID */
912 FREE_AND_ASSIGN(svc_id, value);
913 } else if (g_str_equal(key, "pdp_protocol") == TRUE) { /* PDP protocol */
914 FREE_AND_ASSIGN(pdp_protocol, value);
915 } else if (g_str_equal(key, "roam_pdp_protocol") == TRUE) { /* Roam PDP protocol */
916 FREE_AND_ASSIGN(roam_pdp_protocol, value);
920 /* Set default PDP protocol */
921 if (pdp_protocol == NULL) {
922 dbg("[%s] default pdp_protocol = IPv4v6", cp_name);
923 pdp_protocol = g_strdup_printf("%d", CONTEXT_TYPE_IPV4V6);
926 /* Set default Roam PDP protocol */
927 if (roam_pdp_protocol == NULL) {
928 dbg("[%s] default roam_pdp_protocol = IPv4v6", cp_name);
929 roam_pdp_protocol = g_strdup_printf("%d", CONTEXT_TYPE_IPV4V6);
932 /* Initialize parameters */
933 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
935 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", profile_id)); /* Profile ID */
936 g_hash_table_insert(in_param, "2", g_strdup(profile_name)); /* Profile Name */
937 g_hash_table_insert(in_param, "3", g_strdup(apn)); /* APN */
938 g_hash_table_insert(in_param, "4", g_strdup(auth_type)); /* Auth Type */
939 g_hash_table_insert(in_param, "5", g_strdup(auth_id)); /* Auth ID */
940 g_hash_table_insert(in_param, "6", g_strdup(auth_pwd)); /* Auth Password */
941 g_hash_table_insert(in_param, "7", g_strdup(pdp_protocol)); /* PDP Protocol */
942 g_hash_table_insert(in_param, "8", g_strdup(roam_pdp_protocol)); /* Roam PDP Protocol */
943 g_hash_table_insert(in_param, "9", g_strdup(proxy_addr)); /* Proxy Address */
944 g_hash_table_insert(in_param, "10", g_strdup(home_url)); /* Home URL */
945 g_hash_table_insert(in_param, "11", g_strdup_printf("%d", network_id)); /* Network ID */
946 g_hash_table_insert(in_param, "12", g_strdup(svc_id)); /* Service ID */
948 info("[%s] Profile ID: [%d] Profile name: [%s] APN :[%s] Auth Type [%s] Auth ID: [%s] "
949 "Auth Password: [%s] PDP Protocol: [%s] Roam PDP Protocol: [%s] Proxy Address: [%s] Home URL: [%s] Service ID: [%s]",
950 cp_name, profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, pdp_protocol, roam_pdp_protocol, proxy_addr, home_url, svc_id);
953 memset(szQuery, 0x0, sizeof(szQuery));
954 snprintf(szQuery, sizeof(szQuery), "%s",
955 " insert into pdp_profile(\
956 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, \
957 pdp_protocol, roam_pdp_protocol, proxy_ip_addr, home_url, linger_time, \
958 network_info_id, svc_category_id, hidden, editable, \
959 default_internet_con, user_defined, is_roaming_apn, profile_enable) values(\
962 ?, ?, 0, 1, 0, 1, 0, 1)");
964 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
966 err("Failed to insert to Storage");
971 g_free(profile_name);
979 g_free(pdp_protocol);
980 g_free(roam_pdp_protocol);
981 g_hash_table_destroy(in_param);
983 /* De-initialize Storage */
984 tcore_storage_remove_handle(strg_db, handle);
989 static int __ps_context_load_network_id_from_database(gchar *mccmnc, gchar *cp_name)
992 GHashTable *in_param, *out_param;
1001 /* Initialize Storage */
1002 if (g_str_has_suffix(cp_name, "1"))
1003 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1005 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1006 if (handle == NULL) {
1007 err("Failed to get Storage handle");
1011 /* Initialize parameters */
1012 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1013 g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
1015 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1016 (GDestroyNotify) g_hash_table_destroy);
1019 memset(szQuery, 0x0, sizeof(szQuery));
1020 snprintf(szQuery, sizeof(szQuery), "%s",
1021 "select network_info_id from network_info where mccmnc = ? ");
1023 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1024 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1026 g_hash_table_iter_init(&iter, out_param);
1027 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1028 GHashTableIter iter2;
1029 gpointer key2, value2;
1032 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1033 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1034 if (g_str_equal(key2, "0") == TRUE) {
1035 if (!value2 || (g_strcmp0((const char *)value2, "") == 0))
1038 network_id = atoi((const char *)value2);
1040 /* TODO - Check this out */
1047 /* Free resources */
1048 g_hash_table_destroy(in_param);
1049 g_hash_table_destroy(out_param);
1051 /* De-initialize Storage */
1052 tcore_storage_remove_handle(strg_db, handle);
1057 static gchar *__ps_context_load_network_name_from_database(int network_id, gchar *cp_name)
1060 GHashTable *in_param, *out_param;
1062 gboolean rv = FALSE;
1064 GHashTableIter iter;
1065 gpointer key, value;
1067 gchar *network_name = NULL;
1069 /* Initialize Storage */
1070 if (g_str_has_suffix(cp_name, "1"))
1071 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1073 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1074 if (handle == NULL) {
1075 err("Failed to get Storage handle");
1079 /* Initialize parameters */
1080 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1081 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_id));
1083 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1084 (GDestroyNotify)g_hash_table_destroy);
1087 memset(szQuery, 0x0, sizeof(szQuery));
1088 snprintf(szQuery, sizeof(szQuery), "%s",
1089 "select network_name from network_info where network_info_id = ? ");
1091 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1092 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1094 g_hash_table_iter_init(&iter, out_param);
1095 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1096 GHashTableIter iter2;
1097 gpointer key2, value2;
1100 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1101 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1102 if (g_str_equal(key2, "0") == TRUE) {
1103 g_free(network_name);
1104 network_name = g_strdup(value2);
1106 /* TODO - Check this logic */
1113 /* Free resources */
1114 g_hash_table_destroy(in_param);
1115 g_hash_table_destroy(out_param);
1117 /* De-initialize Storage */
1118 tcore_storage_remove_handle(strg_db, handle);
1120 return network_name;
1123 static int __ps_context_load_profile_id_from_database(gchar *cp_name)
1126 GHashTable *out_param;
1128 gboolean rv = FALSE;
1130 GHashTableIter iter;
1131 gpointer key, value;
1133 int profile_id = -1;
1135 /* Initialize Storage */
1136 if (g_str_has_suffix(cp_name, "1"))
1137 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1139 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1140 if (handle == NULL) {
1141 err("Failed to get Storage handle");
1145 /* Initialize parameters */
1146 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1147 (GDestroyNotify) g_hash_table_destroy);
1150 memset(szQuery, 0x0, sizeof(szQuery));
1151 snprintf(szQuery, sizeof(szQuery), "%s",
1152 "select max(profile_id) as last_profile from pdp_profile");
1154 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, NULL, out_param, 1);
1155 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1157 g_hash_table_iter_init(&iter, out_param);
1158 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1159 GHashTableIter iter2;
1160 gpointer key2, value2;
1163 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1164 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1165 if (g_str_equal(key2, "0") == TRUE) {
1166 if (!value2 || (g_strcmp0((const char *)value2, "") == 0))
1169 profile_id = atoi((const char *)value2);
1171 /* TODO - Check this logic */
1178 /* Free resources */
1179 g_hash_table_destroy(out_param);
1181 /* De-initialize Storage */
1182 tcore_storage_remove_handle(strg_db, handle);
1187 static int __ps_context_load_num_of_pdn_from_database(gchar *mccmnc, gchar *cp_name)
1190 GHashTable *in_param, *out_param;
1192 gboolean rv = FALSE;
1194 GHashTableIter iter;
1195 gpointer key, value;
1199 /* Initialize Storage */
1200 if (g_str_has_suffix(cp_name, "1"))
1201 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1203 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1204 if (handle == NULL) {
1205 err("Failed to get Storage handle");
1209 /* Initialize parameters */
1210 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1211 g_hash_table_insert(in_param, "1", g_strdup(mccmnc));
1213 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1214 (GDestroyNotify) g_hash_table_destroy);
1217 memset(szQuery, 0x0, sizeof(szQuery));
1218 snprintf(szQuery, sizeof(szQuery), "%s",
1219 "select a.max_pdp_3g from max_pdp a, network_info b \
1220 where a.network_info_id = b.network_info_id and b.mccmnc = ? ");
1222 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1223 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1225 g_hash_table_iter_init(&iter, out_param);
1226 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1227 GHashTableIter iter2;
1228 gpointer key2, value2;
1231 g_hash_table_iter_init(&iter2, (GHashTable *)value);
1232 while (g_hash_table_iter_next(&iter2, &key2, &value2) == TRUE) {
1233 if (g_str_equal(key2, "0") == TRUE) {
1234 if (!value2 || (g_strcmp0((const char *)value2, "") == 0)) {
1236 dbg("There is NO value... Using 'default'");
1238 num_of_pdn = atoi((const char *) value2);
1239 dbg("value (%d)", num_of_pdn);
1242 /* TODO - Check this logic */
1249 if (num_of_pdn <= 0) {
1250 dbg("Loaded value is wrong... restoring to 'default'");
1251 num_of_pdn = PS_MAX_CID;
1252 } else if (num_of_pdn > PS_MAX_CID) {
1253 dbg("Loaded value is gretaer than 3... restoring to 'default'");
1254 num_of_pdn = PS_MAX_CID;
1257 /* Free resources */
1258 g_hash_table_destroy(in_param);
1259 g_hash_table_destroy(out_param);
1261 /* De-initialize Storage */
1262 tcore_storage_remove_handle(strg_db, handle);
1267 static gboolean __ps_context_remove_profile_tuple(dictionary *dic, int profile_index, gchar *cp_name)
1270 gboolean rv = FALSE;
1271 GHashTable *in_param;
1272 gchar *network_info_id;
1273 gchar *section_key = NULL;
1276 /* Initialize Storage */
1277 if (g_str_has_suffix(cp_name, "1"))
1278 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1280 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1281 if (handle == NULL) {
1282 err("Failed to get Storage handle");
1286 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1288 /* network info id */
1289 section_key = g_strdup_printf("connection:network_info_id_%d", profile_index);
1290 network_info_id = iniparser_getstring(dic, section_key, NULL);
1291 g_hash_table_insert(in_param, "1", g_strdup(network_info_id));
1292 g_free(section_key);
1295 memset(szQuery, 0x0, sizeof(szQuery));
1296 snprintf(szQuery, sizeof(szQuery), "%s",
1297 " delete from pdp_profile where network_info_id = ?");
1299 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
1300 dbg("delete from pdp_profile where network_info_id = %s, result(%d)", network_info_id, rv);
1301 /* Free resources */
1302 g_hash_table_destroy(in_param);
1304 /* De-initialize Storage */
1305 tcore_storage_remove_handle(strg_db, handle);
1310 static gboolean __ps_context_insert_profile_tuple(dictionary *dic, int profile_index, gchar *cp_name)
1313 GHashTable *in_param;
1314 gboolean rv = FALSE;
1316 /* Initialize Storage */
1317 if (g_str_has_suffix(cp_name, "1"))
1318 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1320 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1321 if (handle == NULL) {
1322 err("Failed to get Storage handle");
1326 /* Initialize parameters */
1327 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1331 gchar *item_key = NULL;
1332 item_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1333 profile_id = iniparser_getstring(dic, item_key, NULL);
1334 if (profile_id == NULL) {
1338 g_hash_table_insert(in_param, "1", g_strdup(profile_id));
1343 gchar *profile_name;
1344 gchar *item_key = NULL;
1345 item_key = g_strdup_printf("connection:profile_name_%d", profile_index);
1346 profile_name = iniparser_getstring(dic, item_key, NULL);
1347 if (profile_name == NULL) {
1351 g_hash_table_insert(in_param, "2", g_strdup(profile_name));
1357 gchar *item_key = NULL;
1358 item_key = g_strdup_printf("connection:apn_%d", profile_index);
1359 apn = iniparser_getstring(dic, item_key, NULL);
1364 g_hash_table_insert(in_param, "3", g_strdup(apn));
1370 gchar *item_key = NULL;
1371 item_key = g_strdup_printf("connection:auth_type_%d", profile_index);
1372 auth_type = iniparser_getstring(dic, item_key, NULL);
1373 if (auth_type == NULL)
1374 g_hash_table_insert(in_param, "4", g_strdup_printf("%d", CONTEXT_AUTH_NONE));
1376 g_hash_table_insert(in_param, "4", g_strdup(auth_type));
1382 gchar *item_key = NULL;
1383 item_key = g_strdup_printf("connection:auth_id_%d", profile_index);
1384 auth_id = iniparser_getstring(dic, item_key, NULL);
1385 g_hash_table_insert(in_param, "5", g_strdup(auth_id));
1391 gchar *item_key = NULL;
1392 item_key = g_strdup_printf("connection:auth_pwd_%d", profile_index);
1393 auth_pwd = iniparser_getstring(dic, item_key, NULL);
1394 g_hash_table_insert(in_param, "6", g_strdup(auth_pwd));
1399 gchar *pdp_protocol;
1400 gchar *item_key = NULL;
1401 item_key = g_strdup_printf("connection:pdp_protocol_%d", profile_index);
1402 pdp_protocol = iniparser_getstring(dic, item_key, NULL);
1403 if (pdp_protocol == NULL)
1404 g_hash_table_insert(in_param, "7", g_strdup_printf("%d", CONTEXT_TYPE_IP));
1406 g_hash_table_insert(in_param, "7", g_strdup(pdp_protocol));
1410 {/* roam pdp protocol */
1411 gchar *roam_pdp_protocol;
1412 gchar *item_key = NULL;
1413 item_key = g_strdup_printf("connection:roam_pdp_protocol_%d", profile_index);
1414 roam_pdp_protocol = iniparser_getstring(dic, item_key, NULL);
1415 if (roam_pdp_protocol == NULL)
1416 g_hash_table_insert(in_param, "8", g_strdup_printf("%d", CONTEXT_TYPE_IPV4V6));
1418 g_hash_table_insert(in_param, "8", g_strdup(roam_pdp_protocol));
1423 gchar *proxy_ip_addr;
1424 gchar *section_key = NULL;
1425 section_key = g_strdup_printf("connection:proxy_ip_addr_%d", profile_index);
1426 proxy_ip_addr = iniparser_getstring(dic, section_key, NULL);
1427 g_hash_table_insert(in_param, "9", g_strdup(proxy_ip_addr));
1428 g_free(section_key);
1433 gchar *section_key = NULL;
1434 section_key = g_strdup_printf("connection:home_url_%d", profile_index);
1435 home_url = iniparser_getstring(dic, section_key, NULL);
1436 g_hash_table_insert(in_param, "10", g_strdup(home_url));
1437 g_free(section_key);
1442 gchar *section_key = NULL;
1443 section_key = g_strdup_printf("connection:linger_time_%d", profile_index);
1444 linger_time = iniparser_getstring(dic, section_key, NULL);
1445 g_hash_table_insert(in_param, "11", g_strdup(linger_time));
1446 g_free(section_key);
1449 {/* traffic class */
1450 gchar *traffic_class;
1451 gchar *section_key = NULL;
1452 section_key = g_strdup_printf("connection:traffic_class_%d", profile_index);
1453 traffic_class = iniparser_getstring(dic, section_key, NULL);
1454 g_hash_table_insert(in_param, "12", g_strdup(traffic_class));
1455 g_free(section_key);
1458 {/* is static ip address */
1459 gchar *is_static_ip_addr;
1460 gchar *section_key = NULL;
1461 section_key = g_strdup_printf("connection:is_static_ip_addr_%d", profile_index);
1462 is_static_ip_addr = iniparser_getstring(dic, section_key, NULL);
1463 g_hash_table_insert(in_param, "13", g_strdup(is_static_ip_addr));
1464 g_free(section_key);
1467 {/* ip address if static ip is true */
1469 gchar *section_key = NULL;
1470 section_key = g_strdup_printf("connection:ip_addr_%d", profile_index);
1471 ip_addr = iniparser_getstring(dic, section_key, NULL);
1472 g_hash_table_insert(in_param, "14", g_strdup(ip_addr));
1473 g_free(section_key);
1476 {/* is static dns address */
1477 gchar *is_static_dns_addr;
1478 gchar *section_key = NULL;
1479 section_key = g_strdup_printf("connection:is_static_dns_addr_%d", profile_index);
1480 is_static_dns_addr = iniparser_getstring(dic, section_key, NULL);
1481 g_hash_table_insert(in_param, "15", g_strdup(is_static_dns_addr));
1482 g_free(section_key);
1485 {/* dns address 1 */
1487 gchar *section_key = NULL;
1488 section_key = g_strdup_printf("connection:dns_addr1_%d", profile_index);
1489 dns_addr1 = iniparser_getstring(dic, section_key, NULL);
1490 g_hash_table_insert(in_param, "16", g_strdup(dns_addr1));
1491 g_free(section_key);
1494 {/* dns address 2 */
1496 gchar *section_key = NULL;
1497 section_key = g_strdup_printf("connection:dns_addr2_%d", profile_index);
1498 dns_addr2 = iniparser_getstring(dic, section_key, NULL);
1499 g_hash_table_insert(in_param, "17", g_strdup(dns_addr2));
1500 g_free(section_key);
1503 {/* network info id */
1504 gchar *network_info_id;
1505 gchar *section_key = NULL;
1506 section_key = g_strdup_printf("connection:network_info_id_%d", profile_index);
1507 network_info_id = iniparser_getstring(dic, section_key, NULL);
1508 g_hash_table_insert(in_param, "18", g_strdup(network_info_id));
1509 g_free(section_key);
1512 {/* service category id */
1513 gchar *svc_category_id;
1514 gchar *section_key = NULL;
1515 section_key = g_strdup_printf("connection:svc_category_id_%d", profile_index);
1516 svc_category_id = iniparser_getstring(dic, section_key, NULL);
1517 if (svc_category_id == NULL)
1518 g_hash_table_insert(in_param, "19", g_strdup_printf("%d", CONTEXT_ROLE_UNKNOWN));
1520 g_hash_table_insert(in_param, "19", g_strdup(svc_category_id));
1521 g_free(section_key);
1526 gchar *section_key = NULL;
1527 section_key = g_strdup_printf("connection:hidden_%d", profile_index);
1528 hidden = iniparser_getstring(dic, section_key, NULL);
1530 g_hash_table_insert(in_param, "20", g_strdup_printf("%d", FALSE));
1532 g_hash_table_insert(in_param, "20", g_strdup(hidden));
1533 g_free(section_key);
1538 gchar *section_key = NULL;
1539 section_key = g_strdup_printf("connection:editable_%d", profile_index);
1540 editable = iniparser_getstring(dic, section_key, NULL);
1541 if (editable == NULL)
1542 g_hash_table_insert(in_param, "21", g_strdup_printf("%d", TRUE));
1544 g_hash_table_insert(in_param, "21", g_strdup(editable));
1545 g_free(section_key);
1548 {/* default internet connection */
1549 gchar *default_internet_con;
1550 gchar *section_key = NULL;
1551 section_key = g_strdup_printf("connection:default_internet_con_%d", profile_index);
1552 default_internet_con = iniparser_getstring(dic, section_key, NULL);
1553 if (default_internet_con == NULL)
1554 g_hash_table_insert(in_param, "22", g_strdup_printf("%d", FALSE));
1556 g_hash_table_insert(in_param, "22", g_strdup(default_internet_con));
1557 g_free(section_key);
1560 {/* insert data into table */
1561 gchar *is_roaming_apn;
1562 gchar *section_key = NULL;
1563 section_key = g_strdup_printf("connection:is_roaming_apn_%d", profile_index);
1564 is_roaming_apn = iniparser_getstring(dic, section_key, NULL);
1565 if (is_roaming_apn == NULL)
1566 g_hash_table_insert(in_param, "23", g_strdup_printf("%d", FALSE));
1568 g_hash_table_insert(in_param, "23", g_strdup(is_roaming_apn));
1569 g_free(section_key);
1572 {/* insert data into table */
1576 memset(szQuery, 0x0, sizeof(szQuery));
1577 snprintf(szQuery, sizeof(szQuery), "%s",
1578 " insert into pdp_profile(\
1579 profile_id, profile_name, apn, auth_type, auth_id, auth_pwd, \
1580 pdp_protocol, roam_pdp_protocol, proxy_ip_addr, home_url, linger_time, \
1581 traffic_class, is_static_ip_addr, ip_addr, is_static_dns_addr, dns_addr1, dns_addr2, \
1582 network_info_id, svc_category_id, hidden, editable, default_internet_con, \
1583 user_defined, is_roaming_apn, profile_enable) values(\
1587 ?, ?, ?, ?, ?, 0, ?, 1)");
1589 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
1590 dbg("Insert to Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1594 /* Free resources */
1595 g_hash_table_destroy(in_param);
1597 /* De-initialize Storage */
1598 tcore_storage_remove_handle(strg_db, handle);
1603 static int __ps_context_get_network_id(gchar *mccmnc, gchar *cp_name)
1607 network_id = __ps_context_load_network_id_from_database(mccmnc, cp_name);
1608 dbg("network id(%d)", network_id);
1612 network_id = __ps_context_insert_network_id_to_database(mccmnc, cp_name);
1613 if (network_id <= 0)
1619 GVariant *__ps_context_get_profile_properties(gpointer object, GVariantBuilder *properties)
1621 gchar *s_authtype = NULL, *s_role = NULL, *s_type = NULL, *s_roam_pdp_type = NULL;
1622 ps_context_t *context = NULL;
1623 char *apn, *username, *password, *proxy_addr, *home_url, *profile_name;
1625 g_return_val_if_fail(object != NULL, NULL);
1626 g_return_val_if_fail(properties != NULL, NULL);
1628 context = (ps_context_t *) object;
1629 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)),
1630 "get profile properties, path(%s)", _ps_context_ref_path(context));
1632 s_authtype = g_strdup_printf("%d", tcore_context_get_auth(context->co_context));
1633 s_role = g_strdup_printf("%d", tcore_context_get_role(context->co_context));
1634 s_type = g_strdup_printf("%d", tcore_context_get_type(context->co_context));
1635 s_roam_pdp_type = g_strdup_printf("%d", tcore_context_get_roam_pdp_type(context->co_context));
1637 apn = tcore_context_get_apn(context->co_context);
1638 username = tcore_context_get_username(context->co_context);
1639 password = tcore_context_get_password(context->co_context);
1640 proxy_addr = tcore_context_get_proxy(context->co_context);
1641 home_url = tcore_context_get_mmsurl(context->co_context);
1642 profile_name = tcore_context_get_profile_name(context->co_context);
1643 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
1645 g_variant_builder_add(properties, "{ss}", "path", context->path);
1647 g_variant_builder_add(properties, "{ss}", "apn", apn);
1650 g_variant_builder_add(properties, "{ss}", "auth_type", s_authtype);
1653 g_variant_builder_add(properties, "{ss}", "auth_id", username);
1656 g_variant_builder_add(properties, "{ss}", "auth_pwd", password);
1659 g_variant_builder_add(properties, "{ss}", "pdp_protocol", s_type);
1661 if (s_roam_pdp_type)
1662 g_variant_builder_add(properties, "{ss}", "roam_pdp_protocol", s_roam_pdp_type);
1665 g_variant_builder_add(properties, "{ss}", "proxy_addr", proxy_addr);
1668 g_variant_builder_add(properties, "{ss}", "home_url", home_url);
1671 g_variant_builder_add(properties, "{ss}", "svc_ctg_id", s_role);
1673 g_variant_builder_add(properties, "{ss}", "profile_name", profile_name);
1674 g_variant_builder_add(properties, "{ss}", "hidden", BOOL2STRING(context->hidden));
1675 g_variant_builder_add(properties, "{ss}", "editable", BOOL2STRING(context->editable));
1676 g_variant_builder_add(properties, "{ss}", "default_internet_conn", BOOL2STRING(context->is_default));
1677 g_variant_builder_add(properties, "{ss}", "profile_enable", BOOL2STRING(context->profile_enable));
1679 /* Freeing locally allocated memory */
1683 g_free(s_roam_pdp_type);
1689 g_free(profile_name);
1693 return g_variant_builder_end(properties);
1696 static gboolean __ps_context_set_default_connection_enable(gpointer object, gboolean enabled)
1698 ps_context_t *context = object;
1700 g_return_val_if_fail(context != NULL, FALSE);
1702 context->is_default = enabled;
1706 static gpointer __ps_context_add_context(gpointer modem, gchar *mccmnc, int profile_id)
1709 GHashTable *in_param, *out_param;
1711 gboolean rv = FALSE;
1713 ps_modem_t *mdm = modem;
1714 CoreObject *co_modem = _ps_modem_ref_co_modem(mdm);
1715 GDBusConnection *conn = NULL;
1716 TcorePlugin *p = NULL;
1719 GHashTableIter iter;
1720 gpointer object = NULL;
1721 gpointer key, value;
1723 /* Initialize Storage */
1724 if (g_str_has_suffix(mdm->cp_name, "1"))
1725 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1727 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1728 if (handle == NULL) {
1729 ps_err_ex_co(co_modem, "Failed to get Storage handle");
1733 /* Initialize parameters */
1734 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1735 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", profile_id));
1737 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1738 (GDestroyNotify) g_hash_table_destroy);
1741 memset(szQuery, 0x0, sizeof(szQuery));
1742 snprintf(szQuery, sizeof(szQuery), "%s",
1744 a.network_info_id, a.network_name, a.mccmnc, \
1745 b.profile_id, b.profile_name, b.apn, \
1746 b.auth_type, b.auth_id, b.auth_pwd, \
1747 b.proxy_ip_addr, b.home_url, b.pdp_protocol, \
1748 b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr, \
1749 b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, \
1750 b.default_internet_con, b.user_defined, b.is_roaming_apn, b.profile_enable, b.roam_pdp_protocol \
1751 from network_info a, pdp_profile b \
1752 where b.profile_id = ? and a.network_info_id = b.network_info_id ");
1754 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 27);
1755 ps_dbg_ex_co(co_modem, "Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1757 ps_dbg_ex_co(co_modem, "Create profile by Profile ID: [%d]", profile_id);
1758 conn = _ps_modem_ref_dbusconn(modem);
1759 p = _ps_modem_ref_plugin(modem);
1761 g_hash_table_iter_init(&iter, out_param);
1762 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1763 /* Create context */
1764 object = __ps_context_create_context(conn, p, mccmnc, (GHashTable *)value, mdm->cp_name);
1765 path = _ps_context_ref_path(object);
1767 /* Insert to contexts */
1768 mdm->contexts = g_slist_append(mdm->contexts, object);
1769 ps_dbg_ex_co(co_modem, "context (%p, %s) insert to hash", object, path);
1772 /* Free resources */
1773 g_hash_table_destroy(in_param);
1774 g_hash_table_destroy(out_param);
1776 /* De-initialize Storage */
1777 tcore_storage_remove_handle(strg_db, handle);
1782 gboolean _ps_context_check_is_roaming_apn_support(gchar* mccmnc, gchar* cp_name)
1785 GHashTable *in_param, *out_param;
1787 gboolean rv = FALSE, ret = FALSE;
1789 int network_info_id = -1;
1791 /* Initialize Storage */
1792 if (g_str_has_suffix(cp_name, "1"))
1793 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1795 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1796 if (handle == NULL) {
1797 err("Failed to get Storage handle");
1801 network_info_id = __ps_context_load_network_id_from_database(mccmnc, cp_name);
1802 if (network_info_id == -1)
1803 err("Failed to load network_info_id from mccmnc (%s)", mccmnc);
1805 /* Initialize parameters */
1806 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1807 g_hash_table_insert(in_param, "1", g_strdup_printf("%d", network_info_id));
1809 out_param = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1810 (GDestroyNotify) g_hash_table_destroy);
1813 memset(szQuery, 0x0, sizeof(szQuery));
1814 snprintf(szQuery, sizeof(szQuery), "%s", "select profile_id from pdp_profile \
1815 where network_info_id = ? and is_roaming_apn = 1 ");
1817 rv = tcore_storage_read_query_database(strg_db, handle, szQuery, in_param, out_param, 1);
1818 dbg("Read Database: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1820 profile_cnt = g_hash_table_size(out_param);
1821 if (profile_cnt > 0) {
1822 dbg("roaming profiles for (mccmnc: %s [%d]) exists: count[%d]", mccmnc, network_info_id, profile_cnt);
1825 /* Free resources */
1826 g_hash_table_destroy(in_param);
1827 g_hash_table_destroy(out_param);
1829 /* De-initialize Storage */
1830 tcore_storage_remove_handle(strg_db, handle);
1834 gboolean _ps_context_initialize(gpointer plugin)
1838 rv &= __ps_context_create_storage_handle(plugin);
1839 dbg("Global variable initialized: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1844 gboolean _ps_context_reset_profile_table(gchar *cp_name)
1848 gboolean rv = FALSE;
1850 /* Initialize Storage */
1851 if (g_str_has_suffix(cp_name, "1"))
1852 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1854 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1855 if (handle == NULL) {
1856 err("Failed to get Storage handle");
1861 memset(szQuery, 0x0, sizeof(szQuery));
1862 snprintf(szQuery, sizeof(szQuery), "%s", " delete from pdp_profile");
1864 rv = tcore_storage_remove_query_database(strg_db, handle, szQuery, NULL);
1865 dbg("Reset profile table: [%s]", (rv == TRUE ? "SUCCESS" : "FAIL"));
1867 /* De-initialize Storage */
1868 tcore_storage_remove_handle(strg_db, handle);
1873 gboolean _ps_context_fill_profile_table_from_ini_file(gchar *cp_name)
1875 int profile_index = 1;
1877 gchar *section_key = NULL;
1878 dictionary *dic = NULL;
1880 if (g_str_has_suffix(cp_name, "1"))
1881 dic = iniparser_load("/opt/system/csc-default/data/csc-default-data-connection-2.ini");
1883 dic = iniparser_load("/opt/system/csc-default/data/csc-default-data-connection.ini");
1886 dbg("fail to load the csc default file");
1892 section_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1893 dbg("section key (%s)", section_key);
1894 data_exist = iniparser_find_entry(dic, section_key);
1896 g_free(section_key);
1897 dbg("no more data in ini");
1900 __ps_context_remove_profile_tuple(dic, profile_index, cp_name);
1901 g_free(section_key);
1908 section_key = g_strdup_printf("connection:profile_id_%d", profile_index);
1909 dbg("section key (%s)", section_key);
1910 data_exist = iniparser_find_entry(dic, section_key);
1912 g_free(section_key);
1913 iniparser_freedict(dic);
1914 dbg("no more data in ini");
1917 __ps_context_insert_profile_tuple(dic, profile_index, cp_name);
1918 g_free(section_key);
1925 GSList* _ps_context_create_hashtable(gpointer modem, gboolean roaming)
1928 GHashTable *in_param;
1929 GSList *out_param = NULL;
1931 gboolean rv = FALSE, roaming_apn = FALSE;
1935 ps_modem_t *mdm = modem;
1936 CoreObject *co_modem = _ps_modem_ref_co_modem(mdm);
1938 /* Initialize Storage */
1939 if (g_str_has_suffix(mdm->cp_name, "1"))
1940 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
1942 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
1943 if (handle == NULL) {
1944 ps_err_ex_co(co_modem, "Failed to get Storage handle");
1948 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
1950 /* Check/Store roaming APN support at every SIM init complete. */
1951 roaming_apn = _ps_context_check_is_roaming_apn_support(mdm->operator, mdm->cp_name);
1952 _ps_modem_set_roaming_apn_support(modem, roaming_apn);
1955 /* Check roaming APN support first in the Roaming network. */
1956 ps_warn_ex_co(co_modem, "Roaming Network[%s], Roaming APN Support[%s]",
1957 roaming ? "TRUE" : "FALSE", roaming_apn ? "TRUE" : "FALSE");
1958 roaming = roaming_apn;
1960 ps_dbg_ex_co(co_modem, "create profile by mccmnc (%s)", mdm->operator);
1962 memset(szQuery, 0x0, sizeof(szQuery));
1963 snprintf(szQuery, sizeof(szQuery), "%s",
1965 a.network_info_id, a.network_name, a.mccmnc, \
1966 b.profile_id, b.profile_name, b.apn, \
1967 b.auth_type, b.auth_id, b.auth_pwd, \
1968 b.proxy_ip_addr, b.home_url, b.pdp_protocol, \
1969 b.linger_time, b.traffic_class, b.is_static_ip_addr, b.ip_addr, \
1970 b.is_static_dns_addr, b.dns_addr1, b.dns_addr2, b.svc_category_id, b.hidden, b.editable, \
1971 b.default_internet_con, b.user_defined, b.is_roaming_apn, b.profile_enable, b.roam_pdp_protocol \
1972 from network_info a, pdp_profile b \
1973 where a.mccmnc = ? and b.is_roaming_apn = ? and a.network_info_id = b.network_info_id ");
1975 g_hash_table_insert(in_param, "1", g_strdup(mdm->operator));
1976 g_hash_table_insert(in_param, "2", g_strdup_printf("%d", roaming));
1978 for (retry = 0; retry < 5; retry++) {
1979 ps_dbg_ex_co(co_modem, "Reading database", mdm->operator);
1980 rv = tcore_storage_read_query_database_in_order(strg_db, handle, szQuery, in_param, &out_param, 27);
1984 ps_dbg_ex_co(co_modem, "Read Database: [%s], Retry[%d]", (rv == TRUE ? "SUCCESS" : "FAIL"), retry);
1986 for (index = 0; index < g_slist_length(out_param); index++) {
1988 gpointer object = NULL;
1989 GHashTable *value = NULL;
1991 value = g_slist_nth_data(out_param, index);
1994 /* Create new 'context' */
1995 object = __ps_context_create_context(mdm->conn, mdm->plg, mdm->operator, value, mdm->cp_name);
1996 path = _ps_context_ref_path(object);
1998 mdm->contexts = g_slist_append(mdm->contexts, object);
1999 ps_dbg_ex_co(co_modem, "context (%p, %s) insert to linked-list", object, path);
2002 g_hash_table_destroy(in_param);
2003 g_slist_free_full(out_param, (GDestroyNotify)g_hash_table_destroy);
2005 /* De-initialize Storage */
2006 tcore_storage_remove_handle(strg_db, handle);
2009 return mdm->contexts;
2012 gboolean _ps_context_add_context(gpointer modem, gchar *operator, GHashTable *property)
2014 GHashTable *services = NULL;
2015 gpointer context = NULL;
2016 ps_modem_t *mdm = modem;
2018 GHashTableIter iter;
2019 gpointer key, value;
2023 network_id = __ps_context_get_network_id(operator, mdm->cp_name);
2024 if (network_id <= 0) {
2025 dbg("fail to add network info");
2029 profile_id = __ps_context_insert_profile_to_database(property, network_id, mdm->cp_name);
2030 if (profile_id <= 0) {
2031 dbg("fail to insert profile info to database");
2035 context = __ps_context_add_context(modem, operator, profile_id);
2039 services = _ps_modem_ref_services(modem);
2043 g_hash_table_iter_init(&iter, services);
2044 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE)
2045 _ps_service_ref_context(value, context);
2050 gboolean _ps_context_get_properties_handler(gpointer object, GVariantBuilder *properties)
2052 int context_state = 0;
2053 gboolean active = FALSE;
2054 ps_context_t *context = object;
2055 char *dev_name = NULL;
2057 char *ipv4_address, *ipv4_gateway, *ipv4_dns1, *ipv4_dns2;
2058 char *ipv6_address, *ipv6_gateway, *ipv6_dns1, *ipv6_dns2;
2061 dbg("get context properties");
2062 g_return_val_if_fail(context != NULL, FALSE);
2063 g_return_val_if_fail(properties != NULL, FALSE);
2065 context_state = tcore_context_get_state(context->co_context);
2066 if (context_state == CONTEXT_STATE_ACTIVATED)
2070 ipv4_address = tcore_context_get_ipv4_addr(context->co_context);
2071 ipv4_gateway = tcore_context_get_ipv4_gw(context->co_context);
2072 ipv4_dns1 = tcore_context_get_ipv4_dns1(context->co_context);
2073 ipv4_dns2 = tcore_context_get_ipv4_dns2(context->co_context);
2076 ipv6_address = tcore_context_get_ipv6_addr(context->co_context);
2077 ipv6_gateway = tcore_context_get_ipv6_gw(context->co_context);
2078 ipv6_dns1 = tcore_context_get_ipv6_dns1(context->co_context);
2079 ipv6_dns2 = tcore_context_get_ipv6_dns2(context->co_context);
2081 proxy = tcore_context_get_proxy(context->co_context);
2082 dev_name = tcore_context_get_ipv4_devname(context->co_context);
2084 g_variant_builder_open(properties, G_VARIANT_TYPE("a{ss}"));
2086 g_variant_builder_add(properties, "{ss}", "path", (context->path));
2087 g_variant_builder_add(properties, "{ss}", "active", (BOOL2STRING(active)));
2089 /* Adding IPV4 data to builder */
2091 g_variant_builder_add(properties, "{ss}", "ipv4_address", ipv4_address);
2094 g_variant_builder_add(properties, "{ss}", "ipv4_gateway", ipv4_gateway);
2097 g_variant_builder_add(properties, "{ss}", "ipv4_dns1", ipv4_dns1);
2100 g_variant_builder_add(properties, "{ss}", "ipv4_dns2", ipv4_dns2);
2102 /* Adding IPV6 data to builder */
2103 g_variant_builder_add(properties, "{ss}", "ipv6_address",
2104 (ipv6_address == NULL ? "::" : ipv6_address));
2105 g_variant_builder_add(properties, "{ss}", "ipv6_gateway",
2106 (ipv6_gateway == NULL ? "::" : ipv6_gateway));
2107 g_variant_builder_add(properties, "{ss}", "ipv6_dns1",
2108 (ipv6_dns1 == NULL ? "::" : ipv6_dns1));
2109 g_variant_builder_add(properties, "{ss}", "ipv6_dns2",
2110 (ipv6_dns2 == NULL ? "::" : ipv6_dns2));
2113 g_variant_builder_add(properties, "{ss}", "proxy", proxy);
2116 g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
2118 g_variant_builder_add(properties, "{ss}", "default_internet_conn", (BOOL2STRING(context->is_default)));
2119 g_variant_builder_close(properties);
2121 /* Freeing local memory */
2122 g_free(ipv4_address);
2123 g_free(ipv4_gateway);
2126 g_free(ipv6_address);
2127 g_free(ipv6_gateway);
2138 GVariant *_ps_context_get_properties(gpointer object, GVariantBuilder *properties)
2140 int context_state = 0;
2141 gboolean active = FALSE;
2142 ps_context_t *context = object;
2143 char *dev_name = NULL;
2145 char *ipv4_address, *ipv4_gateway, *ipv4_dns1, *ipv4_dns2;
2146 char *ipv6_address, *ipv6_gateway, *ipv6_dns1, *ipv6_dns2;
2147 pcscf_addr *pcscf_ipv4, *pcscf_ipv6;
2150 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "get context properties");
2151 g_return_val_if_fail(context != NULL, NULL);
2152 g_return_val_if_fail(properties != NULL, NULL);
2154 context_state = tcore_context_get_state(context->co_context);
2155 if (context_state == CONTEXT_STATE_ACTIVATED)
2158 active &= context->b_active;
2161 ipv4_address = tcore_context_get_ipv4_addr(context->co_context);
2162 ipv4_gateway = tcore_context_get_ipv4_gw(context->co_context);
2163 ipv4_dns1 = tcore_context_get_ipv4_dns1(context->co_context);
2164 ipv4_dns2 = tcore_context_get_ipv4_dns2(context->co_context);
2167 ipv6_address = tcore_context_get_ipv6_addr(context->co_context);
2168 ipv6_gateway = tcore_context_get_ipv6_gw(context->co_context);
2169 ipv6_dns1 = tcore_context_get_ipv6_dns1(context->co_context);
2170 ipv6_dns2 = tcore_context_get_ipv6_dns2(context->co_context);
2173 pcscf_ipv4 = tcore_context_get_pcscf_ipv4_addr(context->co_context);
2174 pcscf_ipv6 = tcore_context_get_pcscf_ipv6_addr(context->co_context);
2176 proxy = tcore_context_get_proxy(context->co_context);
2177 dev_name = tcore_context_get_ipv4_devname(context->co_context);
2179 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
2181 g_variant_builder_add(properties, "{ss}", "path", (context->path));
2182 g_variant_builder_add(properties, "{ss}", "active", (BOOL2STRING(active)));
2183 g_variant_builder_add(properties, "{ss}", "routing_only", (BOOL2STRING(context->b_routing_only)));
2185 /* Adding IPV4 data to builder */
2187 g_variant_builder_add(properties, "{ss}", "ipv4_address", ipv4_address);
2190 g_variant_builder_add(properties, "{ss}", "ipv4_gateway", ipv4_gateway);
2193 g_variant_builder_add(properties, "{ss}", "ipv4_dns1", ipv4_dns1);
2196 g_variant_builder_add(properties, "{ss}", "ipv4_dns2", ipv4_dns2);
2198 /* Adding IPV6 data to builder */
2199 g_variant_builder_add(properties, "{ss}", "ipv6_address",
2200 (ipv6_address == NULL ? "::" : ipv6_address));
2201 g_variant_builder_add(properties, "{ss}", "ipv6_gateway",
2202 (ipv6_gateway == NULL ? "::" : ipv6_gateway));
2203 g_variant_builder_add(properties, "{ss}", "ipv6_dns1",
2204 (ipv6_dns1 == NULL ? "::" : ipv6_dns1));
2205 g_variant_builder_add(properties, "{ss}", "ipv6_dns2",
2206 (ipv6_dns2 == NULL ? "::" : ipv6_dns2));
2209 gboolean ipv6_link_only = FALSE;
2210 if (g_ascii_strncasecmp(ipv6_address, "fe80::", (gsize)6) == 0)
2211 ipv6_link_only = TRUE;
2212 g_variant_builder_add(properties, "{ss}", "ipv6_link_only", BOOL2STRING(ipv6_link_only));
2216 g_variant_builder_add(properties, "{ss}", "proxy", proxy);
2219 g_variant_builder_add(properties, "{ss}", "dev_name", dev_name);
2224 buf = g_strdup_printf("%d", pcscf_ipv4->count);
2225 g_variant_builder_add(properties, "{ss}", "pcscf_ipv4_count", buf);
2228 for (i = 0; i < pcscf_ipv4->count; i++) {
2229 buf = g_strdup_printf("%s_%d", "pcscf_ipv4_addr", i);
2230 g_variant_builder_add(properties, "{ss}", buf, pcscf_ipv4->addr[i]);
2234 /* Update pCSCF address (IPv4) count as '0' */
2235 g_variant_builder_add(properties, "{ss}", "pcscf_ipv4_count", "0");
2241 buf = g_strdup_printf("%d", pcscf_ipv6->count);
2242 g_variant_builder_add(properties, "{ss}", "pcscf_ipv6_count", buf);
2245 for (i = 0; i < pcscf_ipv6->count; i++) {
2246 buf = g_strdup_printf("%s_%d", "pcscf_ipv6_addr", i);
2247 g_variant_builder_add(properties, "{ss}", buf, pcscf_ipv6->addr[i]);
2251 /* Update pCSCF address (IPv6) count as '0' */
2252 g_variant_builder_add(properties, "{ss}", "pcscf_ipv6_count", "0");
2255 g_variant_builder_add(properties, "{ss}", "default_internet_conn", BOOL2STRING(context->is_default));
2257 /* Freeing local memory */
2259 for (i = 0; i < pcscf_ipv4->count; i++)
2260 g_free(pcscf_ipv4->addr[i]);
2264 for (i = 0; i < pcscf_ipv6->count; i++)
2265 g_free(pcscf_ipv6->addr[i]);
2268 g_free(ipv4_address);
2269 g_free(ipv4_gateway);
2272 g_free(ipv6_address);
2273 g_free(ipv6_gateway);
2280 return g_variant_builder_end(properties);
2283 gboolean _ps_context_set_alwayson_enable(gpointer object, gboolean enabled)
2285 ps_context_t *context = object;
2286 int role = CONTEXT_ROLE_UNKNOWN;
2287 g_return_val_if_fail(context != NULL, FALSE);
2289 role = tcore_context_get_role(context->co_context);
2291 if ((role == CONTEXT_ROLE_INTERNET) && context->is_default)
2292 context->alwayson = enabled;
2294 #ifdef PREPAID_SIM_APN_SUPPORT
2295 if ((role == CONTEXT_ROLE_PREPAID_INTERNET) && context->is_default)
2296 context->prepaid_alwayson = enabled;
2298 dbg("context (%p) alwayson (%d)", context, context->alwayson);
2302 gboolean _ps_context_get_default_context(gpointer object, int svc_cat_id)
2304 ps_context_t *context = object;
2305 int role = CONTEXT_ROLE_UNKNOWN;
2306 g_return_val_if_fail(context != NULL, FALSE);
2308 role = tcore_context_get_role(context->co_context);
2309 if (role == svc_cat_id && context->is_default)
2315 gboolean _ps_context_set_service(gpointer object, gpointer service)
2317 ps_context_t *context = object;
2318 g_return_val_if_fail(context != NULL, FALSE);
2320 context->p_service = service;
2324 gpointer _ps_context_ref_service(gpointer object)
2326 ps_context_t *context = object;
2327 g_return_val_if_fail(context != NULL, NULL);
2329 return context->p_service;
2332 gchar *_ps_context_ref_path(gpointer object)
2334 ps_context_t *context = object;
2335 g_return_val_if_fail(context != NULL, NULL);
2337 return context->path;
2340 gboolean _ps_context_get_alwayson_enable(gpointer object)
2342 ps_context_t *context = object;
2343 g_return_val_if_fail(context != NULL, FALSE);
2344 dbg("context (%p) alwayson (%d)", context, context->alwayson);
2345 return context->alwayson;
2348 #ifdef PREPAID_SIM_APN_SUPPORT
2349 gboolean _ps_context_get_prepaid_alwayson_enable(gpointer object)
2351 ps_context_t *context = object;
2352 g_return_val_if_fail(context != NULL, FALSE);
2353 dbg("prepaid context (%p) alwayson (%d)",
2354 context, context->prepaid_alwayson);
2355 return context->prepaid_alwayson;
2358 int _ps_context_get_profile_id(gpointer object)
2360 ps_context_t *context = object;
2361 g_return_val_if_fail(context != NULL, -1);
2362 dbg("profile_id[%d]", context->profile_id);
2363 return context->profile_id;
2367 gpointer _ps_context_ref_co_context(gpointer object)
2369 ps_context_t *context = object;
2370 g_return_val_if_fail(context != NULL, NULL);
2372 return context->co_context;
2375 gboolean _ps_context_set_connected(gpointer object, gboolean enabled)
2379 ps_context_t *context = object;
2380 Storage *strg_vconf = NULL;
2381 gpointer p_modem = NULL;
2383 gboolean b_roaming_checker = TRUE;
2384 gboolean data_allowed = FALSE;
2385 gboolean b_mms_checker = FALSE;
2386 gboolean b_ims_checker = TRUE;
2388 enum co_context_role role = CONTEXT_ROLE_UNKNOWN;
2389 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
2391 dbg("Entry [enabled :%d]", enabled);
2393 g_return_val_if_fail(context != NULL, FALSE);
2395 strg_vconf = tcore_server_find_storage(tcore_plugin_ref_server(context->plg), "vconf");
2396 data_allowed = tcore_storage_get_bool(strg_vconf, STORAGE_KEY_3G_ENABLE);
2397 ipv4 = tcore_context_get_ipv4_addr(context->co_context);
2398 ipv6 = tcore_context_get_ipv6_addr(context->co_context);
2399 role = tcore_context_get_role(context->co_context);
2400 p_modem = _ps_service_ref_modem(context->p_service);
2402 if (role == CONTEXT_ROLE_MMS || role == CONTEXT_ROLE_PREPAID_MMS)
2403 b_mms_checker = TRUE;
2405 if (role == CONTEXT_ROLE_IMS || role == CONTEXT_ROLE_IMS_EMERGENCY)
2406 b_ims_checker = TRUE;
2408 #if !defined(TIZEN_SUPPORT_MMS_CONNECT_FORCE)
2409 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "csc runtime feature disabled");
2410 b_mms_checker = FALSE;
2413 context->b_active = enabled;
2414 if ((_ps_modem_get_roaming(p_modem)) && !(_ps_modem_get_data_roaming_allowed(p_modem))) {
2415 dbg("roaming network is not allowed");
2416 b_roaming_checker = FALSE;
2422 tcore_context_set_state(context->co_context, CONTEXT_STATE_ACTIVATED);
2424 if (context->deact_required == TRUE) {
2425 warn("Deactivation is required for context(%p)", context);
2426 _ps_service_deactivate_context(context->p_service, context);
2427 context->deact_required = FALSE;
2432 if ((g_str_equal(ipv4, "0.0.0.0") == TRUE) && (ipv6 == NULL)) {
2433 dbg("ip address is NULL");
2434 _ps_service_deactivate_context(context->p_service, context);
2438 _ps_service_reset_connection_timer(context);
2440 /* In case of PDP is disconnected by network in UPS mode.
2441 * default internet PDP could be activated if LCD was on at trigger time.
2443 ps_mode = _ps_modem_get_psmode(p_modem);
2444 warn("ps_mode: %d", ps_mode);
2445 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2446 gint pm_state = tcore_storage_get_int(strg_vconf, STORAGE_KEY_PM_STATE);
2447 if (pm_state == 3 && _ps_context_get_default_context(context, CONTEXT_ROLE_INTERNET)) {
2448 char *devname = tcore_context_get_ipv4_devname(context->co_context);
2449 if (TCORE_RETURN_SUCCESS != tcore_util_netif_down(devname))
2450 err("Failed to bring up interface");
2452 warn("[EXCEPTION] do not emit signal for PDP activation.");
2453 context->b_notify = TRUE;
2458 if (b_roaming_checker && (data_allowed || b_mms_checker || b_ims_checker))
2459 __ps_context_emit_property_changed_signal(context);
2462 if (context->deact_required == TRUE) {
2463 ps_dbg_ex_co(co_network, "set deact_required flag of context(%p) to FALSE", context);
2464 context->deact_required = FALSE;
2466 tcore_context_set_state(context->co_context, CONTEXT_STATE_DEACTIVATED);
2467 tcore_context_reset_devinfo(context->co_context);
2468 __ps_context_emit_property_changed_signal(context);
2479 gboolean _ps_context_set_profile_enable(gpointer object, gboolean value)
2481 ps_context_t *context = object;
2482 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
2484 dbg("Entry [value :%d]", value);
2486 g_return_val_if_fail(context != NULL, FALSE);
2488 context->profile_enable = value;
2489 ps_dbg_ex_co(co_network, "context(%p) profile_enable(%d)", context, context->profile_enable);
2493 gboolean _ps_context_get_profile_enable(gpointer object)
2495 ps_context_t *context = object;
2497 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context(%p), profile_enable(%d)", context, context->profile_enable);
2499 return context->profile_enable;
2502 gboolean _ps_context_set_ps_defined(gpointer object, gboolean value)
2504 ps_context_t *context = (ps_context_t *)object;
2505 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
2507 dbg("Entry [value :%d]", value);
2509 g_return_val_if_fail(context != NULL, FALSE);
2511 context->ps_defined = value;
2512 ps_dbg_ex_co(co_network, "context(%p) ps_defined(%d)", context, context->ps_defined);
2516 gboolean _ps_context_get_ps_defined(gpointer object)
2518 ps_context_t *context = (ps_context_t *)object;
2520 ps_dbg_ex_co(_ps_service_ref_co_network(_ps_context_ref_service(context)), "context(%p), ps_defined(%d)", context, context->ps_defined);
2522 return context->ps_defined;
2525 gboolean _ps_context_reset_user_data(gpointer object)
2527 ps_context_t *context = (ps_context_t *)object;
2529 g_return_val_if_fail(context != NULL, FALSE);
2530 context->user_data = NULL;
2535 gboolean _ps_context_set_bearer_info(gpointer object, struct tnoti_ps_dedicated_bearer_info *bearer_info)
2537 ps_context_t *context = (ps_context_t *)object;
2538 CoreObject *co_context = NULL;
2540 g_return_val_if_fail(context != NULL, FALSE);
2541 g_return_val_if_fail(bearer_info != NULL, FALSE);
2543 co_context = _ps_context_ref_co_context(object);
2545 if (bearer_info->dedicated_bearer.num_dedicated_bearer > 0) {
2546 warn("num_dedicated_bearer: %d", bearer_info->dedicated_bearer.num_dedicated_bearer);
2547 /* reset previous bearer info. */
2548 tcore_context_reset_bearer_info(co_context);
2549 tcore_context_set_bearer_info(co_context, bearer_info);
2550 __ps_context_emit_dedicated_bearer_info_signal(context);
2556 gpointer _ps_context_get_user_data(gpointer object)
2558 ps_context_t *context = (ps_context_t *)object;
2559 return context->user_data;
2562 TReturn _ps_connection_hdlr(gpointer object)
2564 int rv = TCORE_RETURN_FAILURE;
2565 ps_context_t *pscontext = object;
2566 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2568 _ps_context_set_alwayson_enable(pscontext, TRUE);
2569 rv = _ps_service_activate_context(pscontext->p_service, pscontext);
2570 if (rv != TCORE_RETURN_SUCCESS) {
2571 ps_dbg_ex_co(co_network, "fail to activate context connection");
2575 ps_dbg_ex_co(co_network, "success to activate context");
2579 gboolean _ps_context_create_cdma_profile(gchar *mccmnc, gchar *cp_name)
2582 gboolean rv = FALSE;
2583 GHashTable *in_param;
2586 /* Initialize Storage */
2587 if (g_str_has_suffix(cp_name, "1"))
2588 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_1);
2590 handle = tcore_storage_create_handle(strg_db, DATABASE_PATH_0);
2591 if (handle == NULL) {
2592 err("Failed to get Storage handle");
2596 /* Make default MMS profile for CDMA */
2597 memset(szQuery, 0, 5000);
2598 snprintf(szQuery, sizeof(szQuery), "%s",
2599 " update pdp_profile set \
2601 where profile_id = 1 and svc_category_id = 2 ");
2603 in_param = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
2605 g_hash_table_insert(in_param, "1", g_strdup("http://mms.vtext.com/servlets/mms")); /* home_url */
2607 rv = tcore_storage_insert_query_database(strg_db, handle, szQuery, in_param);
2608 dbg("insert into pdp_profile result(%d)", rv);
2609 g_hash_table_destroy(in_param);
2611 /* De-initialize Storage */
2612 tcore_storage_remove_handle(strg_db, handle);
2617 void _ps_default_connection_hdlr(gpointer object)
2619 ps_context_t *pscontext = (ps_context_t *)object;
2620 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2622 __ps_context_update_default_internet_to_db(pscontext, TRUE);
2624 /* set request profile */
2625 tcore_context_set_default_profile(pscontext->co_context, TRUE);
2626 __ps_context_set_default_connection_enable(pscontext, TRUE);
2627 _ps_context_set_alwayson_enable(pscontext, TRUE);
2628 __ps_context_emit_property_changed_signal(pscontext);
2630 if (CONTEXT_ROLE_INTERNET == tcore_context_get_role(_ps_context_ref_co_context(object))) {
2631 int rv = TCORE_RETURN_FAILURE;
2632 ps_dbg_ex_co(co_network, "activation requeset in new ps (%p)", pscontext);
2633 /* request to connect */
2634 _ps_service_reset_connection_timer(pscontext);
2635 rv = _ps_service_connect_default_context(pscontext->p_service);
2636 if (rv == TCORE_RETURN_PS_NETWORK_NOT_READY) {
2637 unsigned char cid = -1;
2638 ps_service_t * p_service = (ps_service_t *)pscontext->p_service;
2640 ps_dbg_ex_co(co_network, "PS is not attached yet, release resources.");
2642 cid = tcore_context_get_id(pscontext->co_context);
2643 _ps_context_set_ps_defined((gpointer)pscontext, FALSE);
2644 tcore_ps_set_cid_active(p_service->co_ps, cid, FALSE);
2645 tcore_ps_clear_context_id(p_service->co_ps, pscontext->co_context);
2648 ps_dbg_ex_co(co_network, "complete to change the default connection");
2652 gint _ps_context_get_number_of_pdn(gchar *operator, gchar *cp_name)
2654 gint num_of_pdn = 0;
2656 num_of_pdn = __ps_context_load_num_of_pdn_from_database(operator, cp_name);
2657 dbg("loaded num_of_pdn (%d)", num_of_pdn);
2662 gboolean _ps_context_handle_ifaceup(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 if (TCORE_RETURN_SUCCESS != tcore_util_netif_up(devname))
2674 ps_err_ex_co(co_network, "Failed to bring up interface");
2676 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2677 /* If this flag is true, Connman won't update cellular service state. */
2678 if (pscontext->b_notify) {
2679 ps_warn_ex_co(co_network, "[EXCEPTION] notify status change to upper layer.");
2680 pscontext->b_routing_only = FALSE;
2682 pscontext->b_routing_only = TRUE;
2686 * 20131212, Deprecated: Fixed by HTTP stack.
2687 * ===============================================================================
2688 * 20130801, JIRA DCM-2221: HTTP communication behavior while bearer switching
2689 * Observations: When contiguous HTTP requests while ME handovers from wi-fi to 3G,
2690 * libcurl does not make Aborted event to application
2691 * even if libcurl receives socket closed event by SIOCKILLADDR.
2692 * So, we add work-around patch set here.
2693 * ===============================================================================
2695 if (pscontext->b_active == FALSE) {
2696 pscontext->b_active = TRUE;
2697 ps_dbg_ex_co(co_network, "Celluar profile: Emit property signal to provide IP configuration, devname(%s)", devname);
2698 __ps_context_emit_property_changed_signal(pscontext);
2700 pscontext->b_routing_only = FALSE;
2701 pscontext->b_notify = FALSE;
2703 } else if (context_state == CONTEXT_STATE_DEACTIVATED) {
2704 /* trigger PDP activation. */
2705 _ps_service_activate_context(pscontext->p_service, pscontext);
2710 gboolean _ps_context_handle_ifacedown(gpointer user_data)
2712 ps_context_t *pscontext = user_data;
2713 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2714 int context_state = 0;
2716 context_state = tcore_context_get_state(pscontext->co_context);
2717 ps_warn_ex_co(co_network, "context_state: %d", context_state);
2718 if (context_state == CONTEXT_STATE_ACTIVATED) {
2719 char *devname = tcore_context_get_ipv4_devname(pscontext->co_context);
2720 gint ps_mode = _ps_modem_get_psmode(_ps_service_ref_modem(pscontext->p_service));
2721 ps_dbg_ex_co(co_network, "Cellular profile: Do not send PDP deactivation request message to Modem.");
2722 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
2723 /* If this flag is true, Connman won't update cellular service state. */
2724 pscontext->b_routing_only = TRUE;
2726 ps_warn_ex_co(co_network, "reset socket connections, devname(%s)", devname);
2727 if (TCORE_RETURN_SUCCESS != tcore_util_reset_ipv4_socket(devname, tcore_context_get_ipv4_addr(pscontext->co_context)))
2728 ps_err_ex_co(co_network, "Failed to reset socket.");
2731 if (TCORE_RETURN_SUCCESS != tcore_util_netif_down(devname))
2732 ps_err_ex_co(co_network, "Failed to bring down interface");
2733 if (pscontext->b_active == TRUE) {
2734 pscontext->b_active = FALSE;
2735 __ps_context_emit_property_changed_signal(pscontext);
2737 pscontext->b_routing_only = FALSE;
2743 static gboolean on_context_get_properties(PacketServiceContext *obj_context,
2744 GDBusMethodInvocation *invocation,
2747 GVariant *gv = NULL;
2748 GVariantBuilder property;
2751 gv = _ps_context_get_properties(user_data, &property);
2752 packet_service_context_complete_get_properties(obj_context, invocation, gv);
2756 static gboolean on_context_get_profile(PacketServiceContext *obj_context,
2757 GDBusMethodInvocation *invocation,
2760 GVariant *gv = NULL;
2761 GVariantBuilder profile;
2764 gv = __ps_context_get_profile_properties(user_data, &profile);
2765 packet_service_context_complete_get_profile(obj_context, invocation, gv);
2770 static gboolean on_context_handle_activate(PacketServiceContext *obj_context,
2771 GDBusMethodInvocation *invocation,
2774 gboolean rv = FALSE;
2775 TReturn result = TCORE_RETURN_FAILURE;
2778 int context_state = 0;
2779 unsigned int max_pdn = 0, num_of_active_cids = 0;
2780 gpointer p_service = NULL; gpointer co_ps = NULL;
2781 gpointer c_def_context = NULL; unsigned char cid_def = 0;
2782 GSList *active_cids = NULL;
2783 CoreObject *co_network;
2785 ps_context_t *pscontext = user_data;
2788 if (pscontext == NULL) {
2789 err("activation request object is NULL");
2790 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2794 p_service = pscontext->p_service;
2796 err("service object is null");
2797 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2801 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2802 co_ps = _ps_service_ref_co_ps(p_service);
2804 ps_err_ex_co(co_network, "core object is null");
2805 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2809 ps_dbg_ex_co(co_network, "activate context(%s)", _ps_context_ref_path(pscontext));
2811 apn = (gchar *)tcore_context_get_apn(pscontext->co_context);
2813 context_state = tcore_context_get_state(pscontext->co_context);
2814 if (context_state != CONTEXT_STATE_DEACTIVATED) {
2815 ps_warn_ex_co(co_network, "operation is in progress");
2816 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2820 ps_dbg_ex_co(co_network, "requested context(%p) co_context(%p) apn (%s)", pscontext, pscontext->co_context, apn);
2821 /* check apn is activated or not */
2822 rv = tcore_ps_is_active_apn(co_ps, (const char *)apn);
2824 ps_dbg_ex_co(co_network, "requested apn is already activated");
2826 result = _ps_connection_hdlr(pscontext);
2827 if (result != TCORE_RETURN_SUCCESS) {
2828 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2832 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2833 context_state = tcore_context_get_state(pscontext->co_context);
2834 if (context_state == CONTEXT_STATE_ACTIVATED) {
2835 ps_dbg_ex_co(co_network, "context is already connected");
2836 _ps_context_set_connected(pscontext, TRUE);
2839 ps_dbg_ex_co(co_network, "success to open connection request");
2843 active_cids = tcore_ps_get_active_cids(co_ps);
2844 num_of_active_cids = g_slist_length(active_cids);
2845 max_pdn = tcore_ps_get_num_of_pdn(co_ps);
2846 ps_dbg_ex_co(co_network, "activate cids(%d), max pdn(%d)", num_of_active_cids, max_pdn);
2847 if (num_of_active_cids < max_pdn) {
2848 ps_dbg_ex_co(co_network, "enough to active another pdn");
2849 result = _ps_connection_hdlr(pscontext);
2850 if (result != TCORE_RETURN_SUCCESS) {
2851 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2855 ps_dbg_ex_co(co_network, "success to open connection request");
2856 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2860 /* find the current default connection */
2861 c_def_context = _ps_service_return_default_context(p_service, CONTEXT_ROLE_INTERNET);
2862 if (c_def_context == NULL) {
2863 err("default context is NULL");
2864 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2867 cid_def = tcore_context_get_id(((ps_context_t *)c_def_context)->co_context);
2869 ps_err_ex_co(co_network, "it is not avaiable to open connection");
2870 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2874 /* check the status of def context */
2875 context_state = tcore_context_get_state(((ps_context_t *)c_def_context)->co_context);
2876 if (context_state != CONTEXT_STATE_ACTIVATED) {
2877 enum co_context_role context_role;
2878 context_role = tcore_context_get_role(pscontext->co_context);
2879 ps_err_ex_co(co_network, "default connection is in progress, new context_state[%d], role[%d]", context_state, context_role);
2880 if (context_state == CONTEXT_STATE_ACTIVATING &&
2881 (context_role == CONTEXT_ROLE_MMS ||context_role == CONTEXT_ROLE_PREPAID_MMS)) {
2882 ((ps_context_t *)c_def_context)->user_data = pscontext;
2883 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2886 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2890 _ps_service_reset_connection_timer(c_def_context);
2891 ((ps_context_t *)c_def_context)->user_data = pscontext;
2892 result = tcore_ps_deactivate_cid(co_ps, cid_def);
2893 if (result != TCORE_RETURN_SUCCESS) {
2894 ps_err_ex_co(co_network, "fail to deactivate exist network connection");
2895 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2899 packet_service_context_complete_activate(obj_context, invocation, pscontext->path);
2904 static gboolean on_context_handle_deactiavte(PacketServiceContext *obj_context,
2905 GDBusMethodInvocation *invocation,
2908 gboolean rv = FALSE;
2909 CoreObject *co_network;
2910 int context_state = 0;
2911 ps_context_t *pscontext = user_data;
2914 if (pscontext == NULL) {
2915 err("deactivation request object is NULL");
2916 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2920 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2921 context_state = tcore_context_get_state(pscontext->co_context);
2922 ps_dbg_ex_co(co_network, "requested context(%p) co_context(%p), context_state %d", pscontext, pscontext->co_context, context_state);
2923 if (context_state != CONTEXT_STATE_ACTIVATED) {
2924 ps_err_ex_co(co_network, "operation is in progress");
2925 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
2929 ps_dbg_ex_co(co_network, "deactivate context(%s)", _ps_context_ref_path(pscontext));
2931 _ps_service_reset_connection_timer(pscontext);
2932 _ps_context_set_alwayson_enable(pscontext, FALSE);
2934 rv = _ps_service_deactivate_context(pscontext->p_service, pscontext);
2935 if (rv != TCORE_RETURN_SUCCESS) {
2936 ps_err_ex_co(co_network, "fail to deactivate context connection");
2937 FAIL_RESPONSE(invocation, PS_ERR_TRASPORT);
2941 ps_dbg_ex_co(co_network, "success to deactivate context");
2942 packet_service_context_complete_deactivate(obj_context, invocation, pscontext->path);
2944 context_state = tcore_context_get_state(pscontext->co_context);
2945 if (context_state == CONTEXT_STATE_DEACTIVATED) {
2946 ps_dbg_ex_co(co_network, "context is already disconnected");
2947 pscontext->ps_defined = FALSE;
2948 _ps_context_set_connected(pscontext, FALSE);
2954 static gboolean on_context_set_default_connection(PacketServiceContext *obj_context,
2955 GDBusMethodInvocation *invocation,
2959 int role = CONTEXT_ROLE_UNKNOWN;
2960 gboolean is_default = FALSE;
2962 gpointer co_ps = NULL;
2963 gpointer service = NULL;
2964 gpointer cur_default_ctx = NULL;
2965 ps_context_t *pscontext = user_data;
2966 CoreObject *co_network;
2968 dbg("enter set default connection ps_context_t(%p)", pscontext);
2969 if (pscontext == NULL) {
2970 err("activation request object is NULL");
2971 FAIL_RESPONSE(invocation, PS_ERR_NO_PROFILE);
2975 co_network = _ps_service_ref_co_network(_ps_context_ref_service(pscontext));
2976 ps_dbg_ex_co(co_network, "start default connection");
2977 role = tcore_context_get_role(pscontext->co_context);
2978 is_default = tcore_context_get_default_profile(pscontext->co_context);
2981 ps_err_ex_co(co_network, "already default profile for role (%d).", role);
2985 service = pscontext->p_service;
2986 cur_default_ctx = _ps_service_return_default_context(service, role);
2987 ps_dbg_ex_co(co_network, "current default connection (%p)", cur_default_ctx);
2989 if (!cur_default_ctx) {
2990 ps_err_ex_co(co_network, "No current default connection.");
2994 /* First, send deactivation request first. */
2995 rv = _ps_service_deactivate_context(((ps_context_t *)cur_default_ctx)->p_service, cur_default_ctx);
2996 if (rv == TCORE_RETURN_PS_ACTIVATING) {
2997 ps_dbg_ex_co(co_network, "fail to deactivate default connection, rv(%d)", rv);
2998 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
3002 /* Normal deactivation case. */
3003 if (tcore_context_get_state(((ps_context_t *)cur_default_ctx)->co_context) == CONTEXT_STATE_DEACTIVATING) {
3004 ps_dbg_ex_co(co_network, "deactivation request in current ps (%p)", cur_default_ctx);
3005 ((ps_context_t *)cur_default_ctx)->user_data = pscontext;
3009 ps_dbg_ex_co(co_network, "[Not normal] deactivation request in current ps (%p)", cur_default_ctx);
3011 cid = tcore_context_get_id(((ps_context_t *)cur_default_ctx)->co_context);
3012 _ps_context_set_ps_defined(cur_default_ctx, FALSE);
3013 co_ps = _ps_service_ref_co_ps(service);
3014 tcore_ps_set_cid_active((CoreObject *)co_ps, cid, FALSE);
3015 tcore_ps_clear_context_id((CoreObject *)co_ps, ((ps_context_t *)cur_default_ctx)->co_context);
3018 /* unset default info of previous connection */
3019 _ps_context_set_alwayson_enable(cur_default_ctx, FALSE);
3020 __ps_context_set_default_connection_enable(cur_default_ctx, FALSE);
3021 tcore_context_set_default_profile(((ps_context_t *)cur_default_ctx)->co_context, FALSE);
3023 /* db update - release default connection */
3024 ps_dbg_ex_co(co_network, "context(%p): release default connection property.", cur_default_ctx);
3025 __ps_context_update_default_internet_to_db((ps_context_t *)cur_default_ctx, FALSE);
3026 /* Allow Connman to update profile information. */
3027 __ps_context_emit_property_changed_signal(cur_default_ctx);
3029 ps_dbg_ex_co(co_network, "activation requeset in new ps (%p)", pscontext);
3031 _ps_default_connection_hdlr(pscontext);
3032 packet_service_context_complete_set_default_connection(obj_context, invocation, TRUE);
3037 static gboolean on_context_modify_profile(PacketServiceContext *obj_context,
3038 GDBusMethodInvocation *invocation,
3042 GVariantIter g_iter;
3046 gboolean rv = FALSE;
3047 int context_state = 0;
3048 ps_context_t *context = user_data;
3049 CoreObject *co_network = _ps_service_ref_co_network(_ps_context_ref_service(context));
3050 GHashTable *profile_property = NULL;
3052 ps_dbg_ex_co(co_network, "modify context's profile properties");
3054 /*Creating the profile property hash for for internal handling*/
3055 /*Create a hash table for the profile property as all fucntion already use ghash table */
3056 profile_property = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
3057 g_variant_iter_init(&g_iter, property);
3058 while (g_variant_iter_next(&g_iter, "{ss}", &g_key, &g_value)) {
3060 g_hash_table_insert(profile_property, g_strdup(g_key), g_strdup(g_value));
3061 /* must free data for ourselves */
3066 rv = __ps_context_update_profile(context, profile_property);
3068 FAIL_RESPONSE(invocation, PS_ERR_INTERNAL);
3069 g_hash_table_destroy(profile_property);
3073 context_state = tcore_context_get_state(context->co_context);
3074 if (context_state == CONTEXT_STATE_ACTIVATING) {
3075 ps_dbg_ex_co(co_network, "Modify profile in activating state, set deactivate flag.");
3076 context->deact_required = TRUE;
3080 _ps_service_deactivate_context(context->p_service, context);
3081 if (context_state == CONTEXT_STATE_DEACTIVATED) {
3082 ps_dbg_ex_co(co_network, "context is already disconnected");
3083 _ps_context_set_connected(context, FALSE);
3086 packet_service_context_complete_modify_profile(obj_context, invocation, TRUE);
3087 g_hash_table_destroy(profile_property);
3091 static gboolean on_context_remove_profile(PacketServiceContext *obj_context,
3092 GDBusMethodInvocation *invocation, gpointer user_data)
3094 ps_context_t *context = user_data;
3095 ps_service_t *service = _ps_context_ref_service(context);
3096 CoreObject *co_network = _ps_service_ref_co_network(service);
3098 g_return_val_if_fail(service != NULL, FALSE);
3100 ps_dbg_ex_co(co_network, "Remove context.");
3102 __ps_context_remove_database(context);
3103 _ps_service_unref_context(service, context);
3104 service->contexts = g_slist_remove(service->contexts, context);
3105 _ps_context_remove_context(context);
3107 packet_service_context_complete_remove_profile(obj_context, invocation, TRUE);
3109 ps_dbg_ex_co(co_network, "Exit");
3113 static void _ps_context_setup_interface(PacketServiceContext *context, ps_context_t *context_data)
3116 g_signal_connect(context,
3117 "handle-get-properties",
3118 G_CALLBACK(on_context_get_properties),
3121 g_signal_connect(context,
3122 "handle-get-profile",
3123 G_CALLBACK(on_context_get_profile),
3126 g_signal_connect(context,
3128 G_CALLBACK(on_context_handle_activate),
3131 g_signal_connect(context,
3132 "handle-deactivate",
3133 G_CALLBACK(on_context_handle_deactiavte),
3136 g_signal_connect(context,
3137 "handle-set-default-connection",
3138 G_CALLBACK(on_context_set_default_connection),
3141 g_signal_connect(context,
3142 "handle-modify-profile",
3143 G_CALLBACK(on_context_modify_profile),
3146 g_signal_connect(context,
3147 "handle-remove-profile",
3148 G_CALLBACK(on_context_remove_profile),