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.
23 #include "ps_common.h"
24 #include "ps_context.h"
25 #include "ps_master.h"
27 #include "ps_service.h"
29 #include "ps_tcore_interface.h"
30 #include "ps_service_interface.h"
32 #include <core_object.h>
34 #include <co_context.h>
35 #include <co_network.h>
38 #include <arpa/inet.h>
41 #include <user_request.h>
45 static guint __ps_service_convert_ipv4_address_int(char *ip_address)
47 #define HEX_ENCODING_VALUE 16
48 gchar **temp_str = NULL;
55 temp_str = g_strsplit(ip_address, ".", 5);
56 temp_address = g_strdup_printf("%02x%02x%02x%02x", atoi(temp_str[0]), atoi(temp_str[1]), atoi(temp_str[2]), atoi(temp_str[3]));
60 address = strtoul(temp_address, (char **)NULL, HEX_ENCODING_VALUE);
65 void __remove_service_handler(gpointer data)
67 ps_service_t *service = data;
70 err("Service is Null");
74 ps_info_ex_svc(service, "Entered");
75 /*Need to remove the compelete hash table*/
76 g_slist_free(service->contexts);
78 /*Need to UNexport and Unref the master Object */
79 if (service->if_obj) {
80 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(service->if_obj));
81 g_object_unref(service->if_obj);
82 service->if_obj = NULL;
85 /*Need to free the memory of the internal structure*/
86 g_free(service->path);
90 static char *__ps_service_act2string(enum telephony_network_access_technology act)
94 case NETWORK_ACT_GPRS:
95 case NETWORK_ACT_EGPRS:
96 case NETWORK_ACT_UMTS:
97 case NETWORK_ACT_GSM_UTRAN:
100 case NETWORK_ACT_IS95A:
101 case NETWORK_ACT_IS95B:
102 case NETWORK_ACT_CDMA_1X:
103 case NETWORK_ACT_EVDO_REV0:
104 case NETWORK_ACT_CDMA_1X_EVDO_REV0:
105 case NETWORK_ACT_EVDO_REVA:
106 case NETWORK_ACT_CDMA_1X_EVDO_REVA:
107 case NETWORK_ACT_EVDV:
110 case NETWORK_ACT_LTE:
113 case NETWORK_ACT_UNKNOWN:
121 static gboolean __ps_service_check_connection_option(ps_service_t *service, ps_context_t *context)
123 gboolean b_connect = TRUE;
124 gboolean power = FALSE, sim = FALSE, data = FALSE, flight = FALSE;
125 gboolean profile_reset = FALSE;
127 enum co_context_role role = CONTEXT_ROLE_UNKNOWN;
129 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
131 gboolean nw_ops = FALSE;
134 ps_modem_t *modem = _ps_service_ref_modem(service);
135 ps_master_t *master = _ps_modem_ref_master(modem);
136 CoreObject *co_context = _ps_context_ref_co_context(context);
138 if (TRUE != _ps_context_get_profile_enable(context)) {
139 ps_warn_ex_svc(service, "Profile is disabled.");
143 sim = _ps_modem_get_sim_init(modem);
144 data = _ps_modem_get_data_allowed(modem);
145 flight = _ps_modem_get_flght_mode(modem);
146 profile_reset = _ps_modem_get_reset_profile(modem);
147 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
148 hook_flag = _ps_hook_get_hook_flag(modem);
149 if (hook_flag != PS_NO_PENDING_REQUEST)
152 if (PS_MODEM_STATE_ONLINE == _ps_modem_get_power(modem))
157 role = tcore_context_get_role(co_context);
158 if (role == CONTEXT_ROLE_IMS || role == CONTEXT_ROLE_IMS_EMERGENCY || role == CONTEXT_ROLE_IMS_UT
159 || role == CONTEXT_ROLE_FOTA || role == CONTEXT_ROLE_BIP) {
160 ps_info_ex_svc(service, "Do not check data and data roaming allowed value in case of IMS type");
162 if (service->roaming) {
163 gboolean roaming_allowed = FALSE;
164 roaming_allowed = _ps_modem_get_data_roaming_allowed(modem);
165 ps_warn_ex_svc(service, "roaming_allowed:[%d]", roaming_allowed);
166 b_connect &= roaming_allowed;
172 b_connect &= !flight;
173 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
174 b_connect &= !nw_ops;
176 b_connect &= !service->restricted;
177 b_connect &= !profile_reset;
178 if (role != CONTEXT_ROLE_IMS_EMERGENCY) {
179 b_connect &= service->ps_attached;
182 ps_mode = _ps_modem_get_psmode(modem);
185 * Kiran PLM P141017-05702
186 * Problem: PDP retry when Wifi connected.
187 * Reproducible cases:
188 * 1) Wifi auto connected but PDP has never been connected.
189 * 2) Quick switch Wifi On -> Off before PDP establishment is complete.
190 * 2nd exceptional case is handled by Connmand but 1st case should be
191 * taken care of by telephony.
192 * Solution: Do not PDP retry until initial PDP connection when Wifi connected.
194 if (master && master->initial_pdp_conn == FALSE) {
195 int wifi_state = PS_WIFI_STATE_OFF;
197 wifi_state = _ps_master_get_storage_value_int(master, KEY_WIFI_STATE);
198 if (wifi_state == PS_WIFI_STATE_CONNECTED) {
199 if (service->wifi_connected_checked == FALSE) {
200 ps_info_ex_svc(service, "DO NOT set PDP retry timer when WiFi connected but PDP never been connected yet.");
202 service->wifi_connected_checked = TRUE;
204 ps_info_ex_svc(service, "Wifi connected state was already checked.");
208 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
209 ps_info_ex_svc(service, "b_connect(%d), power(%d), sim init(%d), data allowed(%d), flight mode(%d) restricted(%d) ps_attached(%d), ps_mode(%d), hook_flag(%d)",
210 b_connect, power, sim, data, flight, service->restricted, service->ps_attached, ps_mode, hook_flag);
212 ps_info_ex_svc(service, "b_connect(%d), power(%d), sim init(%d), data allowed(%d), flight mode(%d) restricted(%d) ps_attached(%d), ps_mode(%d)",
213 b_connect, power, sim, data, flight, service->restricted, service->ps_attached, ps_mode);
215 /* In case of ME in LCD off & UPS mode.
216 * Do not allow PDP activation.
219 int ups_mode, emc_data_allowed;
220 ups_mode = ps_mode & ~POWER_SAVING_MODE_DATA_ALLOWED;
221 emc_data_allowed = ps_mode & POWER_SAVING_MODE_DATA_ALLOWED;
222 if (emc_data_allowed == FALSE &&
223 (ups_mode > POWER_SAVING_MODE_NORMAL && ups_mode < POWER_SAVING_MODE_WEARABLE)) {
224 gint pm_state = _ps_master_get_storage_value_int(master, STORAGE_KEY_PM_STATE);
226 (role != CONTEXT_ROLE_IMS && role != CONTEXT_ROLE_IMS_EMERGENCY && role != CONTEXT_ROLE_IMS_UT)) {
227 ps_warn_ex_svc(service, "PDP activation is not allowed in LCD off & UPS mode.");
235 static int __ps_service_connetion_timeout_handler(alarm_id_t alarm_id, void *context)
238 ps_context_t *ps_context = context;
239 ps_service_t *service = _ps_context_ref_service(ps_context);
240 enum co_context_role role;
241 if (service == NULL) {
242 err("service is NULL!!!");
246 if (ps_context->timer_src > 0) {
247 ps_info_ex_svc(service, "remove connection retry timer (%d)", ps_context->timer_src);
248 alarmmgr_remove_alarm(ps_context->timer_src);
249 ps_context->timer_src = 0;
252 role = tcore_context_get_role(_ps_context_ref_co_context(ps_context));
253 ps_info_ex_svc(service, "Re-try for %d type is_epdg_available: %d",
254 role, service->is_epdg_available);
255 if ((role == CONTEXT_ROLE_IMS) && (service->is_epdg_available == TRUE)) {
256 ps_info_ex_svc(service, "Do not re-try for IMS PDN as ePDG is available");
260 ps_info_ex_svc(service, "Re-try for context role [%d]", tcore_context_get_role(_ps_context_ref_co_context(ps_context)));
261 rv = _ps_service_activate_context(service, ps_context);
262 ps_info_ex_svc(service, "return rv(%d)", rv);
266 static gboolean __ps_service_check_is_network_in_serivce(ps_service_t *service)
268 CoreObject *co_network = _ps_service_ref_co_network(service);
269 enum telephony_network_service_type service_type = NETWORK_SERVICE_TYPE_UNKNOWN;
272 tcore_network_get_service_type(co_network, &service_type);
273 ps_warn_ex_svc(service, "service_type[%d]", service_type);
274 switch (service_type) {
275 case NETWORK_SERVICE_TYPE_UNKNOWN:
276 case NETWORK_SERVICE_TYPE_NO_SERVICE:
277 case NETWORK_SERVICE_TYPE_EMERGENCY:
278 case NETWORK_SERVICE_TYPE_SEARCH:
288 static TReturn __ps_service_set_attach_apn(ps_service_t *service, CoreObject *co_context, int set_cid)
291 char *apn = tcore_context_get_apn(co_context);
292 CoreObject *co_ps = _ps_service_ref_co_ps(service);
294 ps_dbg_ex_svc(service, "'Attach APN(%d)' [%s]", tcore_context_get_role(co_context), apn);
297 tcore_context_set_id(co_context, set_cid); // internet
299 if (tfeature_is_supported(TFEATURE_FUNCTION_SEND_APN_INFO)) {
300 gboolean is_refresh_apn_info = FALSE;
301 rv = tcore_ps_set_data_profile(co_ps, co_context, &is_refresh_apn_info);
302 if (rv != TCORE_RETURN_SUCCESS)
303 ps_err_ex_svc(service, "fail to set data profile");
305 rv = tcore_ps_define_context(co_ps, co_context, NULL);
306 if (rv != TCORE_RETURN_SUCCESS)
307 ps_err_ex_svc(service, "fail to define context");
314 void _ps_service_set_attach_apn(ps_service_t *service)
317 int default_data_subs;
318 ps_subs_type subs_type;
319 ps_modem_t *modem = NULL;
320 ps_master_t *master = NULL;
322 modem = _ps_service_ref_modem(service);
323 master = _ps_modem_ref_master(modem);
325 /* Check for default data subscription value if matchs for modem then only attach */
326 subs_type = _ps_modem_get_subs_type(modem);
327 default_data_subs = _ps_master_get_storage_value_int(master, STORAGE_KEY_TELEPHONY_DUALSIM_DEFAULT_DATA_SERVICE_INT);
328 if (default_data_subs != (int)subs_type) {
329 ps_warn_ex_svc(service, "Ignore Attach APN for non-dds sim [DDS - SIM%d]", default_data_subs + 1);
333 for (index = 0; index < g_slist_length(service->contexts); index++) {
334 ps_context_t *context = g_slist_nth_data(service->contexts, index);
335 CoreObject *co_context = _ps_context_ref_co_context(context);
336 gboolean attach_apn = tcore_context_get_attach_apn(co_context);
338 __ps_service_set_attach_apn(service, co_context, 0);
339 /* Attach APN is only one. */
345 ps_service_t *_ps_service_create_service(GDBusConnection *conn, TcorePlugin *p, ps_modem_t *modem,
346 CoreObject *co_network, CoreObject *co_ps, gchar *path)
348 ps_service_t *new_service;
350 g_return_val_if_fail(conn != NULL, NULL);
351 g_return_val_if_fail(modem != NULL, NULL);
353 ps_dbg_ex_modem(modem, "service object create");
355 /*Initializing the modem list for internal referencing*/
356 new_service = g_try_malloc0(sizeof(ps_service_t));
357 if (NULL == new_service) {
358 ps_err_ex_modem(modem, "Unable to allocate memory for master");
362 new_service->conn = conn;
363 new_service->plg = p;
364 new_service->p_modem = modem;
365 new_service->co_network = co_network;
366 new_service->co_ps = co_ps;
367 new_service->path = g_strdup(path);
368 new_service->subs_type = modem->subs_type;
370 _ps_add_co_network_event(new_service);
371 _ps_get_co_network_values(new_service);
372 _ps_add_co_ps_event(new_service);
374 /*Setting up the interface for the service */
375 if (!ps_service_setup_interface(new_service)) {
376 g_free(new_service->path);
380 // new_service->connection_timeout = PDP_RETRY_TIME_OUT_DEFAULT;
381 ps_info_ex_modem(modem, "Successfully Created the service");
385 /*To Do: Handle failure case*/
390 gboolean _ps_service_ref_context(ps_service_t *service, ps_context_t *context)
394 g_return_val_if_fail(service != NULL, FALSE);
396 ps_dbg_ex_svc(service, "service refer to context");
398 tmp = g_slist_find(service->contexts, context);
400 ps_dbg_ex_svc(service, "context(%p) already existed", tmp);
404 _ps_context_set_service(context, service);
405 tcore_ps_add_context(_ps_service_ref_co_ps(service), _ps_context_ref_co_context(context));
406 service->contexts = g_slist_append(service->contexts, context);
408 ps_info_ex_svc(service, "context(%p) insert to linked-list", context);
409 ps_service_emit_context_added_signal(service, context);
414 gboolean _ps_service_ref_contexts(ps_service_t *service, GSList *contexts, gchar *operator)
418 unsigned int index, count;
420 g_return_val_if_fail(service != NULL, FALSE);
422 count = g_slist_length(contexts);
423 ps_dbg_ex_svc(service, "service refer to contexts: count(%d)", count);
425 for (index = 0; index < count; index++) {
427 ps_context_t *context = g_slist_nth_data(contexts, index);
428 CoreObject *co_context = _ps_context_ref_co_context(context);
430 tmp = g_slist_find(service->contexts, context);
432 ps_dbg_ex_svc(service, "context(%p) already existed", tmp);
436 _ps_context_set_service(context, service);
437 tcore_ps_add_context(_ps_service_ref_co_ps(service), co_context);
438 service->contexts = g_slist_append(service->contexts, context);
440 ps_info_ex_svc(service, "context(%p) path(%s) insert to linked-list", context, _ps_context_ref_path(context));
441 ps_service_emit_context_added_signal(service, context);
443 #ifdef PREPAID_SIM_APN_SUPPORT
444 ret = _ps_service_connect_last_connected_context_ex(service, context, NULL, operator);
445 ps_info_ex_svc(service, "ret[%d]", ret);
447 /* process next available profile */
452 if (service->ps_attached) {
453 gboolean f_awo = _ps_context_get_alwayson_enable(context);
454 gboolean ims_activation_requested = FALSE;
457 rv = _ps_service_define_context(service, context);
458 ps_info_ex_svc(service, "Always-on started, return rv(%d)", rv);
461 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
462 if (ims_activation_requested && (CONTEXT_ROLE_IMS == tcore_context_get_role(co_context))) {
463 rv = _ps_service_define_context(service, context);
464 ps_info_ex_svc(service, "IMS PDN rv(%d)", rv);
465 ims_activation_requested = FALSE;
469 ps_dbg_ex_svc(service, "service->contexts: count(%d)", g_slist_length(service->contexts));
470 _ps_update_cellular_state_key(service);
474 gboolean _ps_service_get_properties_handler(ps_service_t *service, GVariantBuilder *properties)
476 g_return_val_if_fail(service != NULL, FALSE);
477 g_return_val_if_fail(properties != NULL, FALSE);
479 ps_info_ex_svc(service, "get service properties");
481 g_variant_builder_open(properties, G_VARIANT_TYPE("a{ss}"));
482 g_variant_builder_add(properties, "{ss}", "path", service->path);
483 g_variant_builder_add(properties, "{ss}", "ps_attached", BOOL2STRING(service->ps_attached));
484 g_variant_builder_add(properties, "{ss}", "roaming", BOOL2STRING(service->roaming));
485 g_variant_builder_add(properties, "{ss}", "act", __ps_service_act2string(service->act));
486 g_variant_builder_close(properties);
488 ps_dbg_ex_svc(service, "Exiting");
492 GVariant *_ps_service_get_properties(ps_service_t *service, GVariantBuilder *properties)
494 g_return_val_if_fail(service != NULL, FALSE);
495 g_return_val_if_fail(properties != NULL, FALSE);
497 ps_info_ex_svc(service, "get service properties");
499 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
501 g_variant_builder_add(properties, "{ss}", "path", service->path);
502 g_variant_builder_add(properties, "{ss}", "ps_attached", BOOL2STRING(service->ps_attached));
503 g_variant_builder_add(properties, "{ss}", "roaming", BOOL2STRING(service->roaming));
504 g_variant_builder_add(properties, "{ss}", "act", __ps_service_act2string(service->act));
506 ps_dbg_ex_svc(service, "Exiting");
507 return g_variant_builder_end(properties);
510 gchar *_ps_service_ref_path(ps_service_t *service)
512 g_return_val_if_fail(service != NULL, NULL);
513 return service->path;
516 TcorePlugin *_ps_service_ref_plugin(ps_service_t *service)
518 g_return_val_if_fail(service != NULL, NULL);
522 CoreObject *_ps_service_ref_co_network(ps_service_t *service)
524 g_return_val_if_fail(service != NULL, NULL);
525 return service->co_network;
528 CoreObject *_ps_service_ref_co_ps(ps_service_t *service)
530 g_return_val_if_fail(service != NULL, NULL);
531 return service->co_ps;
534 ps_modem_t *_ps_service_ref_modem(ps_service_t *service)
536 g_return_val_if_fail(service != NULL, NULL);
537 return service->p_modem;
540 gboolean _ps_service_set_context_devinfo(ps_service_t *service, struct tnoti_ps_pdp_ipconfiguration *devinfo)
542 GSList *co_contexts = NULL;
543 CoreObject *co_context = NULL;
545 g_return_val_if_fail(service != NULL, FALSE);
546 g_return_val_if_fail(devinfo != NULL, FALSE);
548 ps_info_ex_svc(service, "set context device info for cid %d", devinfo->context_id);
550 co_contexts = tcore_ps_ref_context_by_id(_ps_service_ref_co_ps(service), devinfo->context_id);
552 ps_err_ex_svc(service, "fail to ref context by cid.");
556 while (co_contexts) {
557 ps_modem_t *modem = NULL;
558 int role = CONTEXT_ROLE_UNKNOWN;
560 co_context = co_contexts->data;
562 co_contexts = co_contexts->next;
567 role = tcore_context_get_role(co_context);
568 modem = _ps_service_ref_modem(service);
569 if (g_strcmp0(modem->operator, "45005") == 0 && role == CONTEXT_ROLE_IMS) {
570 ps_dbg_ex_svc(service, "SKT IMS PDN");
572 if (devinfo->pcscf_ipv4_count == 0) {
574 snprintf(ipv4, 16, "%d.%d.%d.%d",
575 devinfo->ip_address[0], devinfo->ip_address[1],
576 devinfo->ip_address[2], devinfo->ip_address[3]);
577 if (!g_str_equal(ipv4, "0.0.0.0")) {
578 devinfo->pcscf_ipv4 = g_try_malloc0(sizeof(char *));
579 if (devinfo->pcscf_ipv4 == NULL)
581 devinfo->pcscf_ipv4[0] = g_strdup("220.103.220.10");
582 devinfo->pcscf_ipv4_count = 1;
586 if (devinfo->pcscf_ipv6_count == 0) {
587 if (devinfo->ipv6_address != NULL) {
588 devinfo->pcscf_ipv6 = g_try_malloc0(sizeof(char *));
589 if (devinfo->pcscf_ipv6 == NULL)
591 devinfo->pcscf_ipv6[0] = g_strdup("2001:2d8:00e0:0220::10");
592 devinfo->pcscf_ipv6_count = 1;
597 tcore_context_set_devinfo(co_context, devinfo);
599 co_contexts = co_contexts->next;
605 gboolean _ps_service_set_context_bearerinfo(ps_service_t *service, struct tnoti_ps_dedicated_bearer_info *bearer_info)
607 GSList *co_contexts = NULL;
608 CoreObject *co_context = NULL;
610 g_return_val_if_fail(service != NULL, FALSE);
611 g_return_val_if_fail(bearer_info != NULL, FALSE);
613 ps_info_ex_svc(service, "set context bearer info");
615 co_contexts = tcore_ps_ref_context_by_id(_ps_service_ref_co_ps(service), bearer_info->primary_context_id);
617 ps_err_ex_svc(service, "fail to ref context by cid.");
621 while (co_contexts) {
624 co_context = co_contexts->data;
626 co_contexts = co_contexts->next;
630 for (index = 0; index < g_slist_length(service->contexts); index++) {
631 ps_context_t *context = g_slist_nth_data(service->contexts, index);
632 if (co_context == _ps_context_ref_co_context(context)) {
633 _ps_context_set_bearer_info(context, bearer_info);
638 co_contexts = co_contexts->next;
644 int _ps_service_define_context(ps_service_t *service, ps_context_t *context)
646 CoreObject *co_context = NULL;
647 gboolean b_connect = TRUE;
649 g_return_val_if_fail(service != NULL, FALSE);
650 ps_dbg_ex_svc(service, "define context(%p)", context);
652 b_connect = __ps_service_check_connection_option(service, context);
654 return TCORE_RETURN_EPERM;
656 return tcore_ps_define_context(_ps_service_ref_co_ps(service), co_context, NULL);
659 int _ps_service_activate_context(ps_service_t *service, ps_context_t *context)
661 ps_modem_t *modem = NULL;
662 ps_master_t *master = NULL;
663 CoreObject *co_context = NULL;
664 gboolean b_connect = TRUE;
666 int ret = TCORE_RETURN_SUCCESS;
667 int default_data_subs = 1;
668 ps_subs_type subs_type = 1;
669 CoreObject *co_ps = _ps_service_ref_co_ps(service);
671 g_return_val_if_fail(service != NULL, FALSE);
673 ps_dbg_ex_svc(service, "activate context(%p)", context);
675 modem = _ps_service_ref_modem(service);
676 master = _ps_modem_ref_master(modem);
677 ps_defined = _ps_context_get_ps_defined(context);
678 co_context = _ps_context_ref_co_context(context);
679 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
680 if (modem->hook_flag != PS_NO_PENDING_REQUEST) {
681 ps_info_ex_svc(service, "Pending request present in queue with flag %x", modem->hook_flag);
682 ret = TCORE_RETURN_FAILURE;
686 /* Check for default data subscription value if matchs for modem then only activate */
687 subs_type = _ps_modem_get_subs_type(modem);
688 default_data_subs = _ps_master_get_storage_value_int(master, STORAGE_KEY_TELEPHONY_DUALSIM_DEFAULT_DATA_SERVICE_INT);
689 if ((default_data_subs != -1) && (default_data_subs != (int)subs_type)) {
690 ps_warn_ex_svc(service, "activation for only [SIM%d] selected by Setting", default_data_subs + 1);
691 ret = TCORE_RETURN_FAILURE;
695 b_connect = __ps_service_check_connection_option(service, context);
697 ret = TCORE_RETURN_EPERM;
701 #ifdef TIZEN_SUPPORT_VOLTE
702 if (CONTEXT_ROLE_IMS == tcore_context_get_role(co_context)) {
703 enum telephony_network_service_type svc_type;
704 CoreObject *co_network = _ps_service_ref_co_network(service);
705 tcore_network_get_service_type(co_network, &svc_type);
707 if (svc_type != NETWORK_SERVICE_TYPE_LTE) {
708 ps_warn_ex_svc(service, "IMS PDN is not allowed in %d network", svc_type);
711 tcore_network_set_ims_on_deregistering(_ps_service_ref_co_network(service), FALSE);
716 ps_info_ex_svc(service, "pdp profile is not defined yet, define first. ");
717 ret = tcore_ps_define_context(co_ps, co_context, NULL);
719 ps_info_ex_svc(service, "pdp profile is defined, activate context. ");
720 ret = tcore_ps_activate_context(co_ps, co_context, NULL);
723 if (ret != TCORE_RETURN_SUCCESS) {
726 * CONTEXT_STATE_ACTIVATING : Never be happen.
727 * CONTEXT_STATE_ACTIVATED : Never be happen.
728 * CONTEXT_STATE_DEACTIVATING: Do not clear resources.
730 if (CONTEXT_STATE_DEACTIVATED == tcore_context_get_state(co_context)) {
731 ps_warn_ex_svc(service, "fail to activate context after PDP define complete, clear resources.");
732 _ps_context_set_ps_defined(context, FALSE);
733 tcore_ps_clear_context_id(co_ps, co_context);
735 ps_err_ex_svc(service, "invalid context state.");
742 int _ps_service_deactivate_context(ps_service_t *service, ps_context_t *context)
744 #ifdef TIZEN_SUPPORT_VOLTE
745 enum co_context_role role = CONTEXT_ROLE_UNKNOWN;
746 ps_modem_t *modem = NULL;
747 gboolean ims_registered = FALSE, ims_deregistering = FALSE;
748 struct tel_network_ims_registration_info ims_reg_info = { 0, };
750 CoreObject *co_context = _ps_context_ref_co_context(context);
751 CoreObject *co_ps = _ps_service_ref_co_ps(service);
752 TReturn ret = TCORE_RETURN_SUCCESS;
754 g_return_val_if_fail(service != NULL, FALSE);
755 ps_info_ex_svc(service, "deactivate context(%p)", context);
757 #ifdef TIZEN_SUPPORT_VOLTE
758 role = tcore_context_get_role(co_context);
759 modem = _ps_service_ref_modem(service);
761 tcore_network_get_ims_reg_info(_ps_service_ref_co_network(service), &ims_reg_info);
762 if (ims_reg_info.feature_mask & NET_IMS_MASK_REGI)
763 ims_registered = TRUE;
765 ims_deregistering = tcore_network_get_ims_on_deregistering(_ps_service_ref_co_network(service));
767 ps_dbg_ex_svc(service, "role(%d), ims_registered(%d), ims_deregistering(%d), context_state(%d), flight_mode(%d)",
768 role, ims_registered, ims_deregistering, tcore_context_get_state(co_context), modem->flight_mode);
770 if (!modem->flight_mode) {
771 if (role == CONTEXT_ROLE_IMS && (tcore_context_get_state(co_context) == CONTEXT_STATE_ACTIVATED) && ims_registered && !ims_deregistering)
772 if (_ps_context_deregister_ims(context) == TCORE_RETURN_SUCCESS)
773 return TCORE_RETURN_SUCCESS;
775 ret = tcore_ps_deactivate_context(co_ps, co_context, NULL);
778 ret = tcore_ps_deactivate_context(co_ps, co_context, NULL);
780 if (ret == TCORE_RETURN_PS_DEACTIVATED) {
781 ps_info_ex_svc(service, "context is deactivated");
782 return TCORE_RETURN_SUCCESS;
787 void _ps_service_set_retry_timeout_value(ps_context_t *context, guint value)
789 ps_service_t *service = _ps_context_ref_service(context);
790 g_return_if_fail(context != NULL);
792 if (context->connection_timeout != value) {
793 context->connection_timeout = value;
794 ps_dbg_ex_svc(service, "current timeout (%d)", context->connection_timeout);
798 void _ps_service_connection_timer(ps_service_t *service, ps_context_t *context)
801 gboolean f_awo = FALSE;
802 gboolean ims_activation_requested = FALSE;
804 CoreObject *co_context = _ps_context_ref_co_context(context);
806 g_return_if_fail(service != NULL);
808 f_awo = _ps_context_get_alwayson_enable(context);
809 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
810 if (!f_awo && (!ims_activation_requested && (CONTEXT_ROLE_IMS != tcore_context_get_role(co_context))))
813 if (context->timer_src > 0) {
814 ps_info_ex_svc(service, "remove connection retry timer (%d)", context->timer_src);
815 alarmmgr_remove_alarm(context->timer_src);
816 context->timer_src = 0;
820 ret = device_power_request_lock(POWER_LOCK_CPU, 0);
822 ps_err_ex_svc(service, "ret : (0x%x)", ret);
824 result = alarmmgr_add_alarm_withcb(ALARM_TYPE_VOLATILE, (time_t)(context->connection_timeout),
825 0, __ps_service_connetion_timeout_handler, context, &(context->timer_src));
828 ret = device_power_release_lock(POWER_LOCK_CPU);
830 ps_err_ex_svc(service, "ret : (0x%x)", ret);
832 if (result != ALARMMGR_RESULT_SUCCESS) {
833 ps_err_ex_svc(service, "Failed to add alarm(%d)", result);
837 ps_info_ex_svc(service, "cellular service timer started timer src(%d), timeout(%d)",
838 context->timer_src, context->connection_timeout);
839 context->connection_timeout = (context->connection_timeout) * 2;
840 if (context->connection_timeout >= PDP_RETRY_TIME_OUT_MAX)
841 context->connection_timeout = PDP_RETRY_TIME_OUT_MAX;
844 void _ps_service_reset_connection_timer(ps_context_t *context)
846 gboolean f_awo = FALSE;
847 #ifdef PREPAID_SIM_APN_SUPPORT
848 gboolean p_awo = FALSE;
850 gboolean ims_activation_requested = FALSE;
851 ps_service_t *service = NULL;
853 f_awo = _ps_context_get_alwayson_enable(context);
854 service = _ps_context_ref_service(context);
855 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
856 if (!f_awo && (!ims_activation_requested && (CONTEXT_ROLE_IMS != tcore_context_get_role(_ps_context_ref_co_context(context)))))
859 #ifdef PREPAID_SIM_APN_SUPPORT
860 p_awo = _ps_context_get_prepaid_alwayson_enable(context);
861 if (!f_awo && !p_awo)
865 service = _ps_context_ref_service(context);
866 if (service == NULL) {
867 err("service is NULL!!!");
870 context->connection_timeout = PDP_RETRY_TIME_OUT_DEFAULT;
872 if (context->timer_src > 0) {
873 ps_warn_ex_svc(service, "remove connection retry timer (%d)", context->timer_src);
874 alarmmgr_remove_alarm(context->timer_src);
875 context->timer_src = 0;
879 gboolean _ps_service_unref_context(ps_service_t *service, ps_context_t *context)
881 ps_modem_t *modem = _ps_service_ref_modem(service);
883 g_return_val_if_fail(service != NULL, FALSE);
884 g_return_val_if_fail(modem != NULL, FALSE);
885 g_return_val_if_fail(context != NULL, FALSE);
886 g_return_val_if_fail(context->path != NULL, FALSE);
888 ps_dbg_ex_modem(modem, "service unref context (%s)", context->path);
890 _ps_service_deactivate_context(service, context);
891 /* remove context from the list (modem, service) */
892 modem->contexts = g_slist_remove(modem->contexts, context);
893 ps_service_emit_context_removed_signal(service, context);
897 void _ps_service_remove_contexts(ps_service_t *service)
902 g_return_if_fail(service != NULL);
903 count = g_slist_length(service->contexts);
904 ps_info_ex_svc(service, "service remove all contexts: count(%d)", count);
906 for (index = 0; index < count; index++) {
907 ps_context_t *context = g_slist_nth_data(service->contexts, index);
908 ps_dbg_ex_svc(service, "path(%s), context(%p)", _ps_context_ref_path(context), context);
909 _ps_service_unref_context(service, context);
910 _ps_context_remove_context(context);
912 g_slist_free(service->contexts);
913 service->contexts = NULL;
916 void _ps_service_disconnect_contexts(ps_service_t *service)
920 g_return_if_fail(service != NULL);
921 ps_info_ex_svc(service, "service disconnect all contexts");
923 for (index = 0; index < g_slist_length(service->contexts); index++) {
924 ps_context_t *context = g_slist_nth_data(service->contexts, index);
925 _ps_service_reset_connection_timer(context);
926 _ps_service_deactivate_context(service, context);
930 void _ps_service_disconnect_internet_mms_tethering_contexts(ps_service_t *service)
934 g_return_if_fail(service != NULL);
935 ps_info_ex_svc(service, "Service disconnect Internet/MMS/Tethering contexts");
937 for (index = 0; index < g_slist_length(service->contexts); index++) {
938 ps_context_t *context = g_slist_nth_data(service->contexts, index);
939 CoreObject *co_context = _ps_context_ref_co_context(context);
940 enum co_context_role role = tcore_context_get_role(co_context);
943 * Deactivate following type of contexts -
951 case CONTEXT_ROLE_INTERNET:
952 case CONTEXT_ROLE_MMS:
953 case CONTEXT_ROLE_PREPAID_INTERNET:
954 case CONTEXT_ROLE_PREPAID_MMS:
955 case CONTEXT_ROLE_TETHERING:
956 _ps_service_reset_connection_timer(context);
957 _ps_service_deactivate_context(service, context);
961 ps_warn_ex_svc(service, "Need not deactivate for %d PDN type", role);
967 int _ps_service_connect_default_context(ps_service_t *service)
971 gboolean ims_activation_requested = FALSE;
972 gboolean reset_profile = FALSE;
973 ps_modem_t *modem = NULL;
975 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
977 ps_dbg_ex_svc(service, "service connect default context");
979 modem = _ps_service_ref_modem(service);
980 reset_profile = _ps_modem_get_reset_profile(modem);
982 ps_err_ex_svc(service, "reset_profile(%d) retun", reset_profile);
986 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
988 for (index = 0; index < g_slist_length(service->contexts); index++) {
989 ps_context_t *context = g_slist_nth_data(service->contexts, index);
990 gboolean f_awo = FALSE;
992 f_awo = _ps_context_get_alwayson_enable(context);
994 enum co_context_state context_state;
996 /* FIX: Kiran PLM P141111-07502 */
997 /* _ps_service_reset_connection_timer(value); */
998 rv = _ps_service_activate_context(service, context);
999 context_state = tcore_context_get_state(_ps_context_ref_co_context(context));
1000 if (context_state == CONTEXT_STATE_ACTIVATED) {
1001 ps_info_ex_svc(service, "context is already connected");
1002 _ps_context_set_connected(context, TRUE);
1004 ps_info_ex_svc(service, "return rv(%d)", rv);
1008 if (ims_activation_requested && (CONTEXT_ROLE_IMS == tcore_context_get_role(_ps_context_ref_co_context(context)))) {
1009 rv = _ps_service_activate_context(service, context);
1010 ps_info_ex_svc(service, "return rv(%d)", rv);
1011 ims_activation_requested = FALSE;
1018 #ifdef PREPAID_SIM_APN_SUPPORT
1019 gboolean _ps_service_connect_last_connected_context_ex(ps_service_t *service, ps_context_t *context,
1020 gboolean *defined, char *operator)
1022 ps_modem_t *modem = NULL;
1023 ps_master_t *master = NULL;
1024 int profile_id = -1;
1025 int current_profile_id = -1;
1026 gchar *last_connected_operator = NULL;
1027 gboolean last_connected_profile = FALSE;
1030 ps_info_ex_svc(service, "Entry");
1031 modem = _ps_service_ref_modem(service);
1032 master = _ps_modem_ref_master(modem);
1033 last_connected_profile = _ps_master_get_storage_value_bool(master, STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_BOOL);
1034 ps_info_ex_svc(service, "last_connected_profile [%s]", last_connected_profile ? "TRUE" : "FALSE");
1035 /* Last connected profile exist */
1036 if (last_connected_profile) {
1037 /* Fetch last connected profile's operator */
1038 last_connected_operator = _ps_master_get_storage_value_string(master, STORAGE_KEY_TELEPHONY_LAST_CONNECTED_CONTEXT_PLMN);
1039 ps_info_ex_svc(service, "last_connected_operator[%s] current operator[%s]", last_connected_operator, operator);
1041 if (g_strcmp0(last_connected_operator, operator) != 0) {
1042 /* different SIM, So reset STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_BOOL
1043 and continue to activate default profile */
1044 ps_info_ex_svc(service, "Different SIM, reset last connected context");
1045 _ps_master_set_storage_value_bool(master, STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_BOOL, FALSE);
1047 /* should be freed due to dynamic memory allocated by tcore_storage_get_string() */
1048 if (last_connected_operator) {
1049 free(last_connected_operator);
1050 last_connected_operator = NULL;
1054 /* Fetch last connected context profile id */
1055 ps_info_ex_svc(service, "Fetch last connected context profile id");
1056 profile_id = _ps_master_get_storage_value_int(master, STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_PROFILE_ID);
1058 /* Fetch current context profile id */
1059 current_profile_id = _ps_context_get_profile_id(context);
1060 ps_info_ex_svc(service, "last connected context profile id[%d], current context profile id[%d]", profile_id, current_profile_id);
1062 /* should be freed due to dynamic memory allocated by tcore_storage_get_string() */
1063 if (last_connected_operator) {
1064 free(last_connected_operator);
1065 last_connected_operator = NULL;
1068 if (profile_id != current_profile_id) {
1069 ps_info_ex_svc(service, "Current context profile id and last connected profile does not match ..");
1070 /* Current context profile id and last connected profile does not match
1071 Check for next available profile */
1074 /* activate last connected context */
1075 ps_info_ex_svc(service, "activate last connected context");
1076 rv = _ps_service_define_context(service, context);
1077 ps_info_ex_svc(service, "return rv(%d)", rv);
1084 ps_info_ex_svc(service, "There is no last connected profile");
1090 gboolean _ps_service_connect_last_connected_context(ps_service_t *service)
1093 gboolean defined = FALSE;
1094 gchar *operator = NULL;
1097 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
1098 operator = _ps_modem_ref_operator(_ps_service_ref_modem(service));
1100 for (index = 0; index < g_slist_length(service->contexts); index++) {
1101 ps_context_t *ps_context = g_slist_nth_data(service->contexts, index);
1102 ret = _ps_service_connect_last_connected_context_ex(service, ps_context, &defined, operator);
1103 ps_info_ex_svc(service, "ret[%d]", ret);
1104 if (defined == TRUE) {
1105 ps_info_ex_svc(service, "context[%p]", ps_context);
1112 int _ps_service_connect_default_prepaid_context(ps_service_t *service)
1117 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
1119 for (index = 0; index < g_slist_length(service->contexts); index++) {
1120 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1121 gboolean f_awo = FALSE;
1122 f_awo = _ps_context_get_prepaid_alwayson_enable(context);
1124 _ps_service_reset_connection_timer(context);
1125 rv = _ps_service_activate_context(service, context);
1126 ps_info_ex_svc(service, "return rv(%d)", rv);
1130 ps_info_ex_svc(service, "Exit - rv[%d]", rv);
1134 ps_context_t *_ps_service_return_context_by_cid(ps_service_t *service, int context_id)
1138 g_return_val_if_fail(service != NULL, NULL);
1140 for (index = 0; index < g_slist_length(service->contexts); index++) {
1141 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1142 CoreObject *co_context = _ps_context_ref_co_context(context);
1143 int tmp_cid = tcore_context_get_id(co_context);
1145 if (tmp_cid != context_id)
1154 ps_context_t *_ps_service_return_default_context(ps_service_t *service, int svc_cat_id)
1158 g_return_val_if_fail(service != NULL, NULL);
1160 for (index = 0; index < g_slist_length(service->contexts); index++) {
1161 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1162 gboolean b_default = FALSE;
1163 b_default = _ps_context_get_default_context(context, svc_cat_id);
1172 int _ps_service_update_roaming_apn(ps_service_t *service)
1175 ps_modem_t *modem = _ps_service_ref_modem(service);
1176 gboolean p_from = FALSE; /* default <FLASE> : Home newtwork */
1177 GSList *contexts = NULL;
1179 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
1180 g_return_val_if_fail(modem != NULL, TCORE_RETURN_FAILURE);
1182 ps_dbg_ex_svc(service, "roaming status: %d", service->roaming);
1183 /* 1) Remove all contexts
1184 * 2) Load Home/Roaming profiles from database.
1186 * Home -> Roaming network:
1187 * 3-2) If Any roaming profile is not provided by service provider,
1188 * load Home profiles from database.
1191 p_from = _ps_modem_get_roaming_apn_support(modem);
1193 _ps_service_remove_contexts(service);
1194 contexts = _ps_context_create_hashtable((gpointer)modem, service->roaming);
1195 if (contexts != NULL) {
1196 rv = _ps_service_set_number_of_pdn_cnt(service, modem->operator);
1197 rv = _ps_service_ref_contexts(service, contexts, modem->operator);
1200 /* Iterate through each context and check home and roaming pdp protocol type.
1201 * If its same NO need to deactivate context.
1202 * Otherwise de-activate context as home and roam pdp protocol type mismatched
1204 enum co_context_type home_pdp_protocol, roam_pdp_protocol;
1207 for (index = 0; index < g_slist_length(service->contexts); index++) {
1208 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1209 home_pdp_protocol = tcore_context_get_type(_ps_context_ref_co_context(context));
1210 roam_pdp_protocol = tcore_context_get_roam_pdp_type(_ps_context_ref_co_context(context));
1211 if (home_pdp_protocol == roam_pdp_protocol) {
1212 ps_dbg_ex_svc(service, "home and roam pdp protocol type matched. No need to de-activate");
1216 /* De-activate context as home and roam pdp protocol type mismatched */
1217 ps_info_ex_modem(modem, "home[%d] and roam[%d] pdp protocol type mis-matched. De-activate if context is already activated",
1218 home_pdp_protocol, roam_pdp_protocol);
1219 _ps_service_reset_connection_timer(context);
1220 _ps_service_deactivate_context(service, context);
1227 gboolean _ps_service_processing_network_event(ps_service_t *service, gboolean ps_attached, gboolean roaming)
1229 #ifdef PREPAID_SIM_APN_SUPPORT
1230 gboolean ret = TRUE;
1232 gboolean prev_roaming_status;
1233 g_return_val_if_fail(service != NULL, FALSE);
1235 prev_roaming_status = _ps_service_get_roaming(service);
1236 if (__ps_service_check_is_network_in_serivce(service) != TRUE &&
1237 !_ps_modem_get_roaming_apn_support(_ps_service_ref_modem(service)))
1238 ps_warn_ex_svc(service, "Update roaming status only in IN SRV");
1240 _ps_service_set_roaming(service, roaming);
1242 _ps_service_set_ps_attached(service, ps_attached);
1243 _ps_update_cellular_state_key(service);
1245 if (prev_roaming_status != _ps_service_get_roaming(service)) {
1246 gboolean roaming_allowed = FALSE;
1247 roaming_allowed = _ps_modem_get_data_roaming_allowed(_ps_service_ref_modem(service));
1248 _ps_service_update_roaming_apn(service);
1250 if (!roaming_allowed && roaming) {
1251 ps_info_ex_svc(service, "Roaming allowed (%d), Roaming status (%d)", roaming_allowed, roaming);
1252 _ps_service_disconnect_contexts(service);
1257 if (service->ps_attached) {
1258 ps_context_t *def_context = NULL;
1259 #ifdef PREPAID_SIM_APN_SUPPORT
1260 ret = _ps_service_connect_last_connected_context(service);
1261 ps_dbg_ex_svc(service, "ret[%d]", ret);
1263 return TRUE; /* No need to activate default context */
1265 def_context = _ps_service_return_default_context(service, CONTEXT_ROLE_INTERNET);
1267 _ps_context_set_alwayson_enable(def_context, TRUE);
1268 _ps_service_connect_default_context(service);
1274 gboolean _ps_service_set_connected(ps_service_t *service, gpointer cstatus, gboolean enabled)
1277 gboolean def_awo = FALSE, b_def_conn = FALSE;
1278 gpointer def_conn = NULL;
1279 gpointer requested_conn = NULL;
1280 #ifdef TIZEN_SUPPORT_VOLTE
1281 gboolean def_ims_activation = FALSE;
1282 ps_modem_t *modem = _ps_service_ref_modem(service);
1284 ps_master_t *master = _ps_modem_ref_master(_ps_service_ref_modem(service));
1286 struct tnoti_ps_call_status *call_status = NULL;
1288 call_status = (struct tnoti_ps_call_status *)cstatus;
1290 if (enabled && master && master->initial_pdp_conn == FALSE) {
1291 ps_info_ex_svc(service, "Initial PDP connection.");
1292 master->initial_pdp_conn = TRUE;
1295 for (index = 0; index < g_slist_length(service->contexts); index++) {
1296 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1297 CoreObject *co_context = _ps_context_ref_co_context(context);
1299 gboolean b_tmp_def = FALSE;
1300 gpointer b_user_data = NULL;
1302 tmp_cid = tcore_context_get_id(co_context);
1303 if (tmp_cid != call_status->context_id)
1306 /* if there is default context in disconnected cid, it has to retry auto connection */
1307 b_tmp_def = _ps_context_get_default_context(context, CONTEXT_ROLE_INTERNET);
1309 b_def_conn = b_tmp_def;
1311 /* if disconnected connection has the user data, it is a priority connection. */
1312 b_user_data = _ps_context_get_user_data(context);
1315 requested_conn = b_user_data;
1320 gchar *devname = NULL;
1321 ps_info_ex_svc(service, "Reset socket connections.");
1322 tcore_ps_clear_context_id(_ps_service_ref_co_ps(service), co_context);
1323 ipv4 = tcore_context_get_ipv4_addr(co_context);
1324 devname = tcore_context_get_ipv4_devname(co_context);
1325 tcore_util_reset_ipv4_socket((const char *)devname, (const char *)ipv4);
1329 _ps_context_set_connected(context, enabled);
1332 /* connect to request profile */
1333 if (!enabled && requested_conn) {
1334 ps_info_ex_svc(service, "connect to request profile (%p)", requested_conn);
1335 _ps_connection_hdlr(requested_conn);
1336 _ps_service_reset_connection_timer(def_conn);
1337 _ps_context_reset_user_data(def_conn);
1341 /* default context and always on is true. - request to connect */
1344 def_conn = _ps_service_return_default_context(service, CONTEXT_ROLE_INTERNET);
1345 def_awo = _ps_context_get_alwayson_enable(def_conn);
1349 * In case of ME in LCD off & UPS mode.
1350 * Do not enable PDP retry timer for default internet context.
1352 ps_mode = _ps_modem_get_psmode(_ps_service_ref_modem(service));
1353 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
1354 gint pm_state = _ps_master_get_storage_value_int(master, STORAGE_KEY_PM_STATE);
1355 if (pm_state == 3) {
1356 ps_warn_ex_svc(service, "PDP retry timer is not allowed in LCD off & UPS mode.");
1361 /* always on TRUE and default connection - NORMAL RETRY */
1362 /* always on TRUE and no default connection - WAIT 5 Secs for retry from application */
1364 /* retry connection */
1365 _ps_service_connection_timer(service, def_conn);
1368 /* with unexpected disconnection from network/me */
1369 _ps_service_set_retry_timeout_value(def_conn, PDP_RETRY_TIME_OUT_DEFAULT);
1370 _ps_service_connection_timer(service, def_conn);
1374 #ifdef TIZEN_SUPPORT_VOLTE
1375 if (tfeature_is_supported(TFEATURE_FUNCTION_IMS_PDN_AUTO_ACTIVATE))
1376 def_ims_activation = _ps_service_get_ims_activation_requested(service);
1378 if (def_ims_activation) {
1379 ps_context_t *def_ims = NULL;
1380 CoreObject *co_network = NULL;
1381 gboolean reset_profile = FALSE;
1382 enum telephony_network_service_type svc_type;
1384 co_network = _ps_service_ref_co_network(service);
1385 tcore_network_get_service_type(co_network, &svc_type);
1386 def_ims = _ps_service_return_default_context(service, CONTEXT_ROLE_IMS);
1387 reset_profile = _ps_modem_get_reset_profile(modem);
1389 ps_dbg_ex_svc(service, "svc_type[%d], reset_profile(%d)", svc_type, reset_profile);
1391 if (def_ims && svc_type == NETWORK_SERVICE_TYPE_LTE && !reset_profile) {
1392 ps_info_ex_svc(service, "Continue re-try for IMS PDN");
1393 _ps_service_connection_timer(service, def_ims);
1395 ps_warn_ex_svc(service, "IMS PDN retry timer is allowed in LTE mode.");
1401 /* To send deactivation request of default profile */
1402 if (enabled && requested_conn) {
1403 ps_info_ex_svc(service, "Send deactivation to default profile and connect to request profile (%p)", requested_conn);
1410 void _ps_service_set_ps_defined(ps_service_t *service, gboolean value, int cid)
1414 g_return_if_fail(service != NULL);
1416 for (index = 0; index < g_slist_length(service->contexts); index++) {
1417 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1418 CoreObject *co_context = _ps_context_ref_co_context(context);
1419 CoreObject *co_ps = _ps_service_ref_co_ps(service);
1420 unsigned char context_id = tcore_context_get_id(co_context);
1421 int role = tcore_context_get_role(co_context);
1422 if (context_id == cid) {
1423 gboolean proceed_activation = TRUE;
1425 /* Check attach apn complete */
1426 if (value && (!service->attach_apn_complete && role != CONTEXT_ROLE_IMS_EMERGENCY)) {
1427 ps_info_ex_svc(service, "Initial define of attach APN is complete for profile role(%d)", role);
1428 service->attach_apn_complete = TRUE;
1430 if (TRUE == _ps_context_get_default_context(context, CONTEXT_ROLE_INTERNET) && service->ps_attached)
1431 proceed_activation = TRUE;
1433 proceed_activation = FALSE;
1434 tcore_ps_clear_context_id(co_ps, co_context);
1437 proceed_activation &= value;
1439 /* Set 'ps_defined' */
1440 _ps_context_set_ps_defined(context, proceed_activation);
1442 if (proceed_activation) {
1443 /* Activate if define is completed */
1444 ps_dbg_ex_svc(service, "define is complete, activate context for cid(%d)", cid);
1445 if (_ps_service_activate_context(service, context) == TCORE_RETURN_SUCCESS) {
1446 ps_dbg_ex_svc(service, "Successful activate context");
1447 tcore_ps_set_cid_active(co_ps, cid, TRUE);
1456 gboolean _ps_service_set_ps_attached(ps_service_t *service, gboolean value)
1458 g_return_val_if_fail(service != NULL, FALSE);
1460 if (service->ps_attached != value) {
1461 service->ps_attached = value;
1462 ps_info_ex_svc(service, "service(%p) ps_attached(%d)", service, service->ps_attached);
1463 ps_service_emit_property_changed_signal(service);
1468 gboolean _ps_service_get_restricted(ps_service_t *service)
1470 g_return_val_if_fail(service != NULL, FALSE);
1471 return service->restricted;
1474 gboolean _ps_service_set_restricted(ps_service_t *service, gboolean value)
1476 g_return_val_if_fail(service != NULL, FALSE);
1478 if (service->restricted != value) {
1479 service->restricted = value;
1480 ps_info_ex_svc(service, "service(%p) restricted(%d)", service, service->restricted);
1481 _ps_update_cellular_state_key(service);
1486 gboolean _ps_service_set_ims_activation_requested(ps_service_t *service, gboolean enabled)
1488 g_return_val_if_fail(service != NULL, FALSE);
1489 service->ims_activation_requested = enabled;
1490 ps_info_ex_svc(service, "service (%p) ims_activation_requested (%d)", service, service->ims_activation_requested);
1494 gboolean _ps_service_get_ims_activation_requested(ps_service_t *service)
1496 g_return_val_if_fail(service != NULL, FALSE);
1497 ps_info_ex_svc(service, "service (%p) ims_activation_requested (%d)", service, service->ims_activation_requested);
1499 if (_ps_service_get_epdg_status(service) == TRUE)
1502 return service->ims_activation_requested;
1505 gboolean _ps_service_set_epdg_ip_configuration(ps_service_t *service, gint cid, char *ipv4_addr, char *ipv6_addr)
1507 GSList *contexts = NULL;
1508 CoreObject *co_context = NULL;
1510 unsigned char ip_address[IPV4_ADDR_LEN];
1512 g_return_val_if_fail(service != NULL, FALSE);
1514 ps_info_ex_svc(service, "service (%p) ipv4_addr (%s) ipv6_addr (%s)", service, ipv4_addr, ipv6_addr);
1516 contexts = tcore_ps_ref_context_by_id(service->co_ps, cid);
1518 co_context = contexts->data;
1520 contexts = contexts->next;
1523 if (tcore_context_get_role(co_context) == CONTEXT_ROLE_IMS) {
1526 pdp_address = __ps_service_convert_ipv4_address_int(ipv4_addr);
1527 pdp_address = htonl(pdp_address);
1528 memcpy(&ip_address, &pdp_address, IPV4_ADDR_LEN);
1529 tcore_context_set_ipv4_addr(co_context, ip_address);
1530 snprintf(addr_buf, 20, "%d.%d.%d.%d", ip_address[0], ip_address[1], ip_address[2], ip_address[3]);
1531 ps_info_ex_svc(service, "[IPv4] IP Address: [%s]", addr_buf);
1533 tcore_context_set_ipv6_addr(co_context, ipv6_addr);
1536 contexts = contexts->next;
1542 gboolean _ps_service_set_epdg_status(ps_service_t *service, gboolean available)
1544 g_return_val_if_fail(service != NULL, FALSE);
1545 service->is_epdg_available = available;
1546 ps_info_ex_svc(service, "service (%p) available (%d) ", service, service->is_epdg_available);
1551 gboolean _ps_service_get_epdg_status(ps_service_t *service)
1553 g_return_val_if_fail(service != NULL, FALSE);
1554 return service->is_epdg_available;
1557 gboolean _ps_service_set_number_of_pdn_cnt(ps_service_t *service, gchar *operator)
1561 g_return_val_if_fail(service != NULL, FALSE);
1563 ps_dbg_ex_svc(service, "Entered");
1564 num_of_pdn = _ps_context_get_number_of_pdn(operator, service);
1565 rv = tcore_ps_set_num_of_pdn(_ps_service_ref_co_ps(service), num_of_pdn);
1567 if (rv != TCORE_RETURN_SUCCESS)
1568 ps_err_ex_svc(service, "error to get maximum number of pdn");
1574 gboolean _ps_service_get_roaming(ps_service_t *service)
1576 g_return_val_if_fail(service != NULL, FALSE);
1577 return service->roaming;
1580 gboolean _ps_service_set_roaming(ps_service_t *service, gboolean value)
1582 g_return_val_if_fail(service != NULL, FALSE);
1584 if (service->roaming != value) {
1585 service->roaming = value;
1586 ps_info_ex_svc(service, "service(%p) roaming(%d)", service, service->roaming);
1587 ps_service_emit_property_changed_signal(service);
1593 static void _indicator_cb_dns_reply(GObject *src, GAsyncResult *res, gpointer user_data)
1598 GError *error = NULL;
1600 list = g_resolver_lookup_by_name_finish((GResolver *)src, res, &error);
1602 err("fail to get dns resolving");
1604 err("error:%d, %s", error->code, error->message);
1605 g_error_free(error);
1610 for (cur = list; cur; cur = cur->next) {
1612 str_addr = g_inet_address_to_string(addr);
1615 info("addr(%s)", str_addr);
1618 g_object_unref(cur->data);
1622 g_object_unref(src);
1627 gboolean _ps_service_set_access_technology(ps_service_t *service,
1628 enum telephony_network_access_technology value)
1630 #ifdef PREPAID_SIM_APN_SUPPORT
1631 gboolean ret = TRUE;
1633 enum telephony_network_access_technology p_act = 0;
1634 g_return_val_if_fail(service != NULL, FALSE);
1636 if (service->act != value) {
1637 p_act = service->act;
1638 service->act = value;
1639 ps_info_ex_svc(service, "service(%p) P ACT(%d) Access Technology(%d)", service, p_act, service->act);
1641 if (p_act == NETWORK_ACT_LTE && (service->act >= NETWORK_ACT_GSM && service->act < NETWORK_ACT_LTE)) {
1642 GResolver *r = NULL;
1644 ps_dbg_ex_svc(service, "send the dns pkt for keeping connection");
1646 r = g_resolver_get_default();
1647 g_resolver_lookup_by_name_async(r, "www.tizen.org", NULL, _indicator_cb_dns_reply, NULL);
1650 if (service->act > NETWORK_ACT_UNKNOWN && service->act < NETWORK_ACT_NOT_SPECIFIED) {
1651 _ps_update_cellular_state_key(service);
1652 #ifdef PREPAID_SIM_APN_SUPPORT
1653 ret = _ps_service_connect_last_connected_context(service);
1654 ps_info_ex_svc(service, "ret[%d]", ret);
1656 return ret; /* No need to activate default context */
1658 _ps_service_connect_default_context(service);
1665 enum telephony_ps_state _ps_service_check_cellular_state(ps_service_t *service)
1667 gboolean state = FALSE;
1670 g_return_val_if_fail(service != NULL, TELEPHONY_PS_NO_SERVICE);
1672 modem = _ps_service_ref_modem(service);
1674 state = _ps_modem_get_flght_mode(modem);
1676 return TELEPHONY_PS_FLIGHT_MODE;
1678 state = _ps_modem_get_power(modem);
1680 return TELEPHONY_PS_NO_SERVICE;
1682 state = _ps_modem_get_sim_init(modem);
1684 return TELEPHONY_PS_NO_SERVICE;
1686 if (service->restricted)
1687 return TELEPHONY_PS_RESTRICTED_SERVICE;
1689 if (!service->ps_attached)
1690 return TELEPHONY_PS_NO_SERVICE;
1692 state = _ps_modem_get_data_allowed(modem);
1694 return TELEPHONY_PS_3G_OFF;
1696 state = _ps_modem_get_data_roaming_allowed(modem);
1697 if (service->roaming && !state)
1698 return TELEPHONY_PS_ROAMING_OFF;
1700 return TELEPHONY_PS_ON;
1703 void _ps_service_handling_nas_timer(ps_service_t *service, gboolean state)
1707 g_return_if_fail(service != NULL);
1708 ps_info_ex_svc(service, "Handleing nas timer, state(%d)", state);
1710 for (index = 0; index < g_slist_length(service->contexts); index++) {
1711 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1712 CoreObject *co_context = _ps_context_ref_co_context(context);
1713 enum co_context_state co_state = tcore_context_get_state(co_context);
1715 if (co_state == CONTEXT_STATE_ACTIVATED) {
1716 enum co_context_role role = tcore_context_get_role(co_context);
1717 enum ims_data_pdn data_pdn = IMS_DATA_PDN_UNKNOWN;
1718 enum ims_data_state data_state = IMS_DATA_STATE_RESUME;
1719 gboolean drop_packet = FALSE;
1721 if (role == CONTEXT_ROLE_INTERNET)
1722 data_pdn = IMS_DATA_PDN_INTERNET;
1723 else if (role == CONTEXT_ROLE_IMS)
1724 data_pdn = IMS_DATA_PDN_IMS;
1725 else if (role == CONTEXT_ROLE_IMS_EMERGENCY)
1726 data_pdn = IMS_DATA_PDN_EMERGENCY;
1727 else if (role == CONTEXT_ROLE_MMS)
1728 data_pdn = IMS_DATA_PDN_CBS;
1730 if (state == PS_NAS_TIMER_STATE_START) {
1731 data_state = IMS_DATA_STATE_SUSPEND;
1734 data_state = IMS_DATA_STATE_RESUME;
1735 drop_packet = FALSE;
1738 ps_info_ex_svc(service, "co_context(%p) co_state(%d) role(%d) data_pdn(%d) data_state(%d) drop_packet(%d)",
1739 co_context, co_state, role, data_pdn, data_state, drop_packet);
1742 if (tcore_context_get_drop_packet(co_context) != drop_packet) {
1743 tcore_context_set_drop_packet(co_context, drop_packet);
1744 _ps_context_handling_nas_timer(context, drop_packet);
1746 if (role == CONTEXT_ROLE_IMS)
1747 tcore_ps_set_ims_data_state(_ps_service_ref_co_ps(service), data_pdn, data_state);