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:
116 case NETWORK_ACT_UNKNOWN:
124 static gboolean __ps_service_check_connection_option(ps_service_t *service, ps_context_t *context)
126 gboolean b_connect = TRUE;
127 gboolean power = FALSE, sim = FALSE, data = FALSE, flight = FALSE;
128 gboolean profile_reset = FALSE;
130 enum co_context_role role = CONTEXT_ROLE_UNKNOWN;
132 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
134 gboolean nw_ops = FALSE;
137 ps_modem_t *modem = _ps_service_ref_modem(service);
138 ps_master_t *master = _ps_modem_ref_master(modem);
139 CoreObject *co_context = _ps_context_ref_co_context(context);
141 if (TRUE != _ps_context_get_profile_enable(context)) {
142 ps_warn_ex_svc(service, "Profile is disabled.");
146 sim = _ps_modem_get_sim_init(modem);
147 data = _ps_modem_get_data_allowed(modem);
148 flight = _ps_modem_get_flght_mode(modem);
149 profile_reset = _ps_modem_get_reset_profile(modem);
150 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
151 hook_flag = _ps_hook_get_hook_flag(modem);
152 if (hook_flag != PS_NO_PENDING_REQUEST)
155 if (PS_MODEM_STATE_ONLINE == _ps_modem_get_power(modem))
160 role = tcore_context_get_role(co_context);
161 if (role == CONTEXT_ROLE_IMS || role == CONTEXT_ROLE_IMS_EMERGENCY || role == CONTEXT_ROLE_IMS_UT
162 || role == CONTEXT_ROLE_FOTA || role == CONTEXT_ROLE_BIP) {
163 ps_info_ex_svc(service, "Do not check data and data roaming allowed value in case of IMS type");
165 if (service->roaming) {
166 gboolean roaming_allowed = FALSE;
167 roaming_allowed = _ps_modem_get_data_roaming_allowed(modem);
168 ps_warn_ex_svc(service, "roaming_allowed:[%d]", roaming_allowed);
169 b_connect &= roaming_allowed;
175 b_connect &= !flight;
176 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
177 b_connect &= !nw_ops;
179 b_connect &= !service->restricted;
180 b_connect &= !profile_reset;
181 if (role != CONTEXT_ROLE_IMS_EMERGENCY) {
182 b_connect &= service->ps_attached;
185 ps_mode = _ps_modem_get_psmode(modem);
188 * Kiran PLM P141017-05702
189 * Problem: PDP retry when Wifi connected.
190 * Reproducible cases:
191 * 1) Wifi auto connected but PDP has never been connected.
192 * 2) Quick switch Wifi On -> Off before PDP establishment is complete.
193 * 2nd exceptional case is handled by Connmand but 1st case should be
194 * taken care of by telephony.
195 * Solution: Do not PDP retry until initial PDP connection when Wifi connected.
197 if (master && master->initial_pdp_conn == FALSE) {
198 int wifi_state = PS_WIFI_STATE_OFF;
200 wifi_state = _ps_master_get_storage_value_int(master, KEY_WIFI_STATE);
201 if (wifi_state == PS_WIFI_STATE_CONNECTED) {
202 if (service->wifi_connected_checked == FALSE) {
203 ps_info_ex_svc(service, "DO NOT set PDP retry timer when WiFi connected but PDP never been connected yet.");
205 service->wifi_connected_checked = TRUE;
207 ps_info_ex_svc(service, "Wifi connected state was already checked.");
211 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
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), hook_flag(%d)",
213 b_connect, power, sim, data, flight, service->restricted, service->ps_attached, ps_mode, hook_flag);
215 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)",
216 b_connect, power, sim, data, flight, service->restricted, service->ps_attached, ps_mode);
218 /* In case of ME in LCD off & UPS mode.
219 * Do not allow PDP activation.
222 int ups_mode, emc_data_allowed;
223 ups_mode = ps_mode & ~POWER_SAVING_MODE_DATA_ALLOWED;
224 emc_data_allowed = ps_mode & POWER_SAVING_MODE_DATA_ALLOWED;
225 if (emc_data_allowed == FALSE &&
226 (ups_mode > POWER_SAVING_MODE_NORMAL && ups_mode < POWER_SAVING_MODE_WEARABLE)) {
227 gint pm_state = _ps_master_get_storage_value_int(master, STORAGE_KEY_PM_STATE);
229 (role != CONTEXT_ROLE_IMS && role != CONTEXT_ROLE_IMS_EMERGENCY && role != CONTEXT_ROLE_IMS_UT)) {
230 ps_warn_ex_svc(service, "PDP activation is not allowed in LCD off & UPS mode.");
238 static int __ps_service_connetion_timeout_handler(alarm_id_t alarm_id, void *context)
241 ps_context_t *ps_context = context;
242 ps_service_t *service = _ps_context_ref_service(ps_context);
243 enum co_context_role role;
244 if (service == NULL) {
245 err("service is NULL!!!");
249 if (ps_context->timer_src > 0) {
250 ps_info_ex_svc(service, "remove connection retry timer (%d)", ps_context->timer_src);
251 alarmmgr_remove_alarm(ps_context->timer_src);
252 ps_context->timer_src = 0;
255 role = tcore_context_get_role(_ps_context_ref_co_context(ps_context));
256 ps_info_ex_svc(service, "Re-try for %d type is_epdg_available: %d",
257 role, service->is_epdg_available);
258 if ((role == CONTEXT_ROLE_IMS) && (service->is_epdg_available == TRUE)) {
259 ps_info_ex_svc(service, "Do not re-try for IMS PDN as ePDG is available");
263 ps_info_ex_svc(service, "Re-try for context role [%d]", tcore_context_get_role(_ps_context_ref_co_context(ps_context)));
264 rv = _ps_service_activate_context(service, ps_context);
265 ps_info_ex_svc(service, "return rv(%d)", rv);
269 static gboolean __ps_service_check_is_network_in_serivce(ps_service_t *service)
271 CoreObject *co_network = _ps_service_ref_co_network(service);
272 enum telephony_network_service_type service_type = NETWORK_SERVICE_TYPE_UNKNOWN;
275 tcore_network_get_service_type(co_network, &service_type);
276 ps_warn_ex_svc(service, "service_type[%d]", service_type);
277 switch (service_type) {
278 case NETWORK_SERVICE_TYPE_UNKNOWN:
279 case NETWORK_SERVICE_TYPE_NO_SERVICE:
280 case NETWORK_SERVICE_TYPE_EMERGENCY:
281 case NETWORK_SERVICE_TYPE_SEARCH:
291 static TReturn __ps_service_set_attach_apn(ps_service_t *service, CoreObject *co_context, int set_cid)
294 char *apn = tcore_context_get_apn(co_context);
295 CoreObject *co_ps = _ps_service_ref_co_ps(service);
297 ps_dbg_ex_svc(service, "'Attach APN(%d)' [%s]", tcore_context_get_role(co_context), apn);
300 tcore_context_set_id(co_context, set_cid); // internet
302 if (tfeature_is_supported(TFEATURE_FUNCTION_SEND_APN_INFO)) {
303 gboolean is_refresh_apn_info = FALSE;
304 rv = tcore_ps_set_data_profile(co_ps, co_context, &is_refresh_apn_info);
305 if (rv != TCORE_RETURN_SUCCESS)
306 ps_err_ex_svc(service, "fail to set data profile");
308 rv = tcore_ps_define_context(co_ps, co_context, NULL);
309 if (rv != TCORE_RETURN_SUCCESS)
310 ps_err_ex_svc(service, "fail to define context");
317 void _ps_service_set_attach_apn(ps_service_t *service)
320 int default_data_subs;
321 ps_subs_type subs_type;
322 ps_modem_t *modem = NULL;
323 ps_master_t *master = NULL;
325 modem = _ps_service_ref_modem(service);
326 master = _ps_modem_ref_master(modem);
328 /* Check for default data subscription value if matchs for modem then only attach */
329 subs_type = _ps_modem_get_subs_type(modem);
330 default_data_subs = _ps_master_get_storage_value_int(master, STORAGE_KEY_TELEPHONY_DUALSIM_DEFAULT_DATA_SERVICE_INT);
331 if (default_data_subs != (int)subs_type) {
332 ps_warn_ex_svc(service, "Ignore Attach APN for non-dds sim [DDS - SIM%d]", default_data_subs + 1);
336 for (index = 0; index < g_slist_length(service->contexts); index++) {
337 ps_context_t *context = g_slist_nth_data(service->contexts, index);
338 CoreObject *co_context = _ps_context_ref_co_context(context);
339 gboolean attach_apn = tcore_context_get_attach_apn(co_context);
341 __ps_service_set_attach_apn(service, co_context, 0);
342 /* Attach APN is only one. */
348 ps_service_t *_ps_service_create_service(GDBusConnection *conn, TcorePlugin *p, ps_modem_t *modem,
349 CoreObject *co_network, CoreObject *co_ps, gchar *path)
351 ps_service_t *new_service;
353 g_return_val_if_fail(conn != NULL, NULL);
354 g_return_val_if_fail(modem != NULL, NULL);
356 ps_dbg_ex_modem(modem, "service object create");
358 /*Initializing the modem list for internal referencing*/
359 new_service = g_try_malloc0(sizeof(ps_service_t));
360 if (NULL == new_service) {
361 ps_err_ex_modem(modem, "Unable to allocate memory for master");
365 new_service->conn = conn;
366 new_service->plg = p;
367 new_service->p_modem = modem;
368 new_service->co_network = co_network;
369 new_service->co_ps = co_ps;
370 new_service->path = g_strdup(path);
371 new_service->subs_type = modem->subs_type;
373 _ps_add_co_network_event(new_service);
374 _ps_get_co_network_values(new_service);
375 _ps_add_co_ps_event(new_service);
377 /*Setting up the interface for the service */
378 if (!ps_service_setup_interface(new_service)) {
379 g_free(new_service->path);
383 // new_service->connection_timeout = PDP_RETRY_TIME_OUT_DEFAULT;
384 ps_info_ex_modem(modem, "Successfully Created the service");
388 /*To Do: Handle failure case*/
393 gboolean _ps_service_ref_context(ps_service_t *service, ps_context_t *context)
397 g_return_val_if_fail(service != NULL, FALSE);
399 ps_dbg_ex_svc(service, "service refer to context");
401 tmp = g_slist_find(service->contexts, context);
403 ps_dbg_ex_svc(service, "context(%p) already existed", tmp);
407 _ps_context_set_service(context, service);
408 tcore_ps_add_context(_ps_service_ref_co_ps(service), _ps_context_ref_co_context(context));
409 service->contexts = g_slist_append(service->contexts, context);
411 ps_info_ex_svc(service, "context(%p) insert to linked-list", context);
412 ps_service_emit_context_added_signal(service, context);
417 gboolean _ps_service_ref_contexts(ps_service_t *service, GSList *contexts, gchar *operator)
421 unsigned int index, count;
423 g_return_val_if_fail(service != NULL, FALSE);
425 count = g_slist_length(contexts);
426 ps_dbg_ex_svc(service, "service refer to contexts: count(%d)", count);
428 for (index = 0; index < count; index++) {
430 ps_context_t *context = g_slist_nth_data(contexts, index);
431 CoreObject *co_context = _ps_context_ref_co_context(context);
433 tmp = g_slist_find(service->contexts, context);
435 ps_dbg_ex_svc(service, "context(%p) already existed", tmp);
439 _ps_context_set_service(context, service);
440 tcore_ps_add_context(_ps_service_ref_co_ps(service), co_context);
441 service->contexts = g_slist_append(service->contexts, context);
443 ps_info_ex_svc(service, "context(%p) path(%s) insert to linked-list", context, _ps_context_ref_path(context));
444 ps_service_emit_context_added_signal(service, context);
446 #ifdef PREPAID_SIM_APN_SUPPORT
447 ret = _ps_service_connect_last_connected_context_ex(service, context, NULL, operator);
448 ps_info_ex_svc(service, "ret[%d]", ret);
450 /* process next available profile */
455 if (service->ps_attached) {
456 gboolean f_awo = _ps_context_get_alwayson_enable(context);
457 gboolean ims_activation_requested = FALSE;
460 rv = _ps_service_define_context(service, context);
461 ps_info_ex_svc(service, "Always-on started, return rv(%d)", rv);
464 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
465 if (ims_activation_requested && (CONTEXT_ROLE_IMS == tcore_context_get_role(co_context))) {
466 rv = _ps_service_define_context(service, context);
467 ps_info_ex_svc(service, "IMS PDN rv(%d)", rv);
468 ims_activation_requested = FALSE;
472 ps_dbg_ex_svc(service, "service->contexts: count(%d)", g_slist_length(service->contexts));
473 _ps_update_cellular_state_key(service);
477 gboolean _ps_service_get_properties_handler(ps_service_t *service, GVariantBuilder *properties)
479 g_return_val_if_fail(service != NULL, FALSE);
480 g_return_val_if_fail(properties != NULL, FALSE);
482 ps_info_ex_svc(service, "get service properties");
484 g_variant_builder_open(properties, G_VARIANT_TYPE("a{ss}"));
485 g_variant_builder_add(properties, "{ss}", "path", service->path);
486 g_variant_builder_add(properties, "{ss}", "ps_attached", BOOL2STRING(service->ps_attached));
487 g_variant_builder_add(properties, "{ss}", "roaming", BOOL2STRING(service->roaming));
488 g_variant_builder_add(properties, "{ss}", "act", __ps_service_act2string(service->act));
489 g_variant_builder_close(properties);
491 ps_dbg_ex_svc(service, "Exiting");
495 GVariant *_ps_service_get_properties(ps_service_t *service, GVariantBuilder *properties)
497 g_return_val_if_fail(service != NULL, FALSE);
498 g_return_val_if_fail(properties != NULL, FALSE);
500 ps_info_ex_svc(service, "get service properties");
502 g_variant_builder_init(properties, G_VARIANT_TYPE("a{ss}"));
504 g_variant_builder_add(properties, "{ss}", "path", service->path);
505 g_variant_builder_add(properties, "{ss}", "ps_attached", BOOL2STRING(service->ps_attached));
506 g_variant_builder_add(properties, "{ss}", "roaming", BOOL2STRING(service->roaming));
507 g_variant_builder_add(properties, "{ss}", "act", __ps_service_act2string(service->act));
509 ps_dbg_ex_svc(service, "Exiting");
510 return g_variant_builder_end(properties);
513 gchar *_ps_service_ref_path(ps_service_t *service)
515 g_return_val_if_fail(service != NULL, NULL);
516 return service->path;
519 TcorePlugin *_ps_service_ref_plugin(ps_service_t *service)
521 g_return_val_if_fail(service != NULL, NULL);
525 CoreObject *_ps_service_ref_co_network(ps_service_t *service)
527 g_return_val_if_fail(service != NULL, NULL);
528 return service->co_network;
531 CoreObject *_ps_service_ref_co_ps(ps_service_t *service)
533 g_return_val_if_fail(service != NULL, NULL);
534 return service->co_ps;
537 ps_modem_t *_ps_service_ref_modem(ps_service_t *service)
539 g_return_val_if_fail(service != NULL, NULL);
540 return service->p_modem;
543 gboolean _ps_service_set_context_devinfo(ps_service_t *service, struct tnoti_ps_pdp_ipconfiguration *devinfo)
545 GSList *co_contexts = NULL;
546 CoreObject *co_context = NULL;
548 g_return_val_if_fail(service != NULL, FALSE);
549 g_return_val_if_fail(devinfo != NULL, FALSE);
551 ps_info_ex_svc(service, "set context device info for cid %d", devinfo->context_id);
553 co_contexts = tcore_ps_ref_context_by_id(_ps_service_ref_co_ps(service), devinfo->context_id);
555 ps_err_ex_svc(service, "fail to ref context by cid.");
559 while (co_contexts) {
560 ps_modem_t *modem = NULL;
561 int role = CONTEXT_ROLE_UNKNOWN;
563 co_context = co_contexts->data;
565 co_contexts = co_contexts->next;
570 role = tcore_context_get_role(co_context);
571 modem = _ps_service_ref_modem(service);
572 if (g_strcmp0(modem->operator, "45005") == 0 && role == CONTEXT_ROLE_IMS) {
573 ps_dbg_ex_svc(service, "SKT IMS PDN");
575 if (devinfo->pcscf_ipv4_count == 0) {
577 snprintf(ipv4, 16, "%d.%d.%d.%d",
578 devinfo->ip_address[0], devinfo->ip_address[1],
579 devinfo->ip_address[2], devinfo->ip_address[3]);
580 if (!g_str_equal(ipv4, "0.0.0.0")) {
581 devinfo->pcscf_ipv4 = g_try_malloc0(sizeof(char *));
582 if (devinfo->pcscf_ipv4 == NULL)
584 devinfo->pcscf_ipv4[0] = g_strdup("220.103.220.10");
585 devinfo->pcscf_ipv4_count = 1;
589 if (devinfo->pcscf_ipv6_count == 0) {
590 if (devinfo->ipv6_address != NULL) {
591 devinfo->pcscf_ipv6 = g_try_malloc0(sizeof(char *));
592 if (devinfo->pcscf_ipv6 == NULL)
594 devinfo->pcscf_ipv6[0] = g_strdup("2001:2d8:00e0:0220::10");
595 devinfo->pcscf_ipv6_count = 1;
600 tcore_context_set_devinfo(co_context, devinfo);
602 co_contexts = co_contexts->next;
608 gboolean _ps_service_set_context_bearerinfo(ps_service_t *service, struct tnoti_ps_dedicated_bearer_info *bearer_info)
610 GSList *co_contexts = NULL;
611 CoreObject *co_context = NULL;
613 g_return_val_if_fail(service != NULL, FALSE);
614 g_return_val_if_fail(bearer_info != NULL, FALSE);
616 ps_info_ex_svc(service, "set context bearer info");
618 co_contexts = tcore_ps_ref_context_by_id(_ps_service_ref_co_ps(service), bearer_info->primary_context_id);
620 ps_err_ex_svc(service, "fail to ref context by cid.");
624 while (co_contexts) {
627 co_context = co_contexts->data;
629 co_contexts = co_contexts->next;
633 for (index = 0; index < g_slist_length(service->contexts); index++) {
634 ps_context_t *context = g_slist_nth_data(service->contexts, index);
635 if (co_context == _ps_context_ref_co_context(context)) {
636 _ps_context_set_bearer_info(context, bearer_info);
641 co_contexts = co_contexts->next;
647 int _ps_service_define_context(ps_service_t *service, ps_context_t *context)
649 CoreObject *co_context = NULL;
650 gboolean b_connect = TRUE;
652 g_return_val_if_fail(service != NULL, FALSE);
653 ps_dbg_ex_svc(service, "define context(%p)", context);
655 b_connect = __ps_service_check_connection_option(service, context);
657 return TCORE_RETURN_EPERM;
659 return tcore_ps_define_context(_ps_service_ref_co_ps(service), co_context, NULL);
662 int _ps_service_activate_context(ps_service_t *service, ps_context_t *context)
664 ps_modem_t *modem = NULL;
665 ps_master_t *master = NULL;
666 CoreObject *co_context = NULL;
667 gboolean b_connect = TRUE;
669 int ret = TCORE_RETURN_SUCCESS;
670 int default_data_subs = 1;
671 ps_subs_type subs_type = 1;
672 CoreObject *co_ps = _ps_service_ref_co_ps(service);
674 g_return_val_if_fail(service != NULL, FALSE);
676 ps_dbg_ex_svc(service, "activate context(%p)", context);
678 modem = _ps_service_ref_modem(service);
679 master = _ps_modem_ref_master(modem);
680 ps_defined = _ps_context_get_ps_defined(context);
681 co_context = _ps_context_ref_co_context(context);
682 #ifdef TIZEN_SUPPORT_REQUEST_HOOK_PDP_CONTROL
683 if (modem->hook_flag != PS_NO_PENDING_REQUEST) {
684 ps_info_ex_svc(service, "Pending request present in queue with flag %x", modem->hook_flag);
685 ret = TCORE_RETURN_FAILURE;
689 /* Check for default data subscription value if matchs for modem then only activate */
690 subs_type = _ps_modem_get_subs_type(modem);
691 default_data_subs = _ps_master_get_storage_value_int(master, STORAGE_KEY_TELEPHONY_DUALSIM_DEFAULT_DATA_SERVICE_INT);
692 if ((default_data_subs != -1) && (default_data_subs != (int)subs_type)) {
693 ps_warn_ex_svc(service, "activation for only [SIM%d] selected by Setting", default_data_subs + 1);
694 ret = TCORE_RETURN_FAILURE;
698 b_connect = __ps_service_check_connection_option(service, context);
700 ret = TCORE_RETURN_EPERM;
704 #ifdef TIZEN_SUPPORT_VOLTE
705 if (CONTEXT_ROLE_IMS == tcore_context_get_role(co_context)) {
706 enum telephony_network_service_type svc_type;
707 CoreObject *co_network = _ps_service_ref_co_network(service);
708 tcore_network_get_service_type(co_network, &svc_type);
710 if (svc_type != NETWORK_SERVICE_TYPE_LTE) {
711 ps_warn_ex_svc(service, "IMS PDN is not allowed in %d network", svc_type);
714 tcore_network_set_ims_on_deregistering(_ps_service_ref_co_network(service), FALSE);
719 ps_info_ex_svc(service, "pdp profile is not defined yet, define first. ");
720 ret = tcore_ps_define_context(co_ps, co_context, NULL);
722 ps_info_ex_svc(service, "pdp profile is defined, activate context. ");
723 ret = tcore_ps_activate_context(co_ps, co_context, NULL);
726 if (ret != TCORE_RETURN_SUCCESS) {
729 * CONTEXT_STATE_ACTIVATING : Never be happen.
730 * CONTEXT_STATE_ACTIVATED : Never be happen.
731 * CONTEXT_STATE_DEACTIVATING: Do not clear resources.
733 if (CONTEXT_STATE_DEACTIVATED == tcore_context_get_state(co_context)) {
734 ps_warn_ex_svc(service, "fail to activate context after PDP define complete, clear resources.");
735 _ps_context_set_ps_defined(context, FALSE);
736 tcore_ps_clear_context_id(co_ps, co_context);
738 ps_err_ex_svc(service, "invalid context state.");
745 int _ps_service_deactivate_context(ps_service_t *service, ps_context_t *context)
747 #ifdef TIZEN_SUPPORT_VOLTE
748 enum co_context_role role = CONTEXT_ROLE_UNKNOWN;
749 ps_modem_t *modem = NULL;
750 gboolean ims_registered = FALSE, ims_deregistering = FALSE;
751 struct tel_network_ims_registration_info ims_reg_info = { 0, };
753 CoreObject *co_context = _ps_context_ref_co_context(context);
754 CoreObject *co_ps = _ps_service_ref_co_ps(service);
755 TReturn ret = TCORE_RETURN_SUCCESS;
757 g_return_val_if_fail(service != NULL, FALSE);
758 ps_info_ex_svc(service, "deactivate context(%p)", context);
760 #ifdef TIZEN_SUPPORT_VOLTE
761 role = tcore_context_get_role(co_context);
762 modem = _ps_service_ref_modem(service);
764 tcore_network_get_ims_reg_info(_ps_service_ref_co_network(service), &ims_reg_info);
765 if (ims_reg_info.feature_mask & NET_IMS_MASK_REGI)
766 ims_registered = TRUE;
768 ims_deregistering = tcore_network_get_ims_on_deregistering(_ps_service_ref_co_network(service));
770 ps_dbg_ex_svc(service, "role(%d), ims_registered(%d), ims_deregistering(%d), context_state(%d), flight_mode(%d)",
771 role, ims_registered, ims_deregistering, tcore_context_get_state(co_context), modem->flight_mode);
773 if (!modem->flight_mode) {
774 if (role == CONTEXT_ROLE_IMS && (tcore_context_get_state(co_context) == CONTEXT_STATE_ACTIVATED) && ims_registered && !ims_deregistering)
775 if (_ps_context_deregister_ims(context) == TCORE_RETURN_SUCCESS)
776 return TCORE_RETURN_SUCCESS;
778 ret = tcore_ps_deactivate_context(co_ps, co_context, NULL);
781 ret = tcore_ps_deactivate_context(co_ps, co_context, NULL);
783 if (ret == TCORE_RETURN_PS_DEACTIVATED) {
784 ps_info_ex_svc(service, "context is deactivated");
785 return TCORE_RETURN_SUCCESS;
790 void _ps_service_set_retry_timeout_value(ps_context_t *context, guint value)
792 ps_service_t *service = _ps_context_ref_service(context);
793 g_return_if_fail(context != NULL);
795 if (context->connection_timeout != value) {
796 context->connection_timeout = value;
797 ps_dbg_ex_svc(service, "current timeout (%d)", context->connection_timeout);
801 void _ps_service_connection_timer(ps_service_t *service, ps_context_t *context)
804 gboolean f_awo = FALSE;
805 gboolean ims_activation_requested = FALSE;
807 CoreObject *co_context = _ps_context_ref_co_context(context);
809 g_return_if_fail(service != NULL);
811 f_awo = _ps_context_get_alwayson_enable(context);
812 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
813 if (!f_awo && (!ims_activation_requested && (CONTEXT_ROLE_IMS != tcore_context_get_role(co_context))))
816 if (context->timer_src > 0) {
817 ps_info_ex_svc(service, "remove connection retry timer (%d)", context->timer_src);
818 alarmmgr_remove_alarm(context->timer_src);
819 context->timer_src = 0;
823 ret = device_power_request_lock(POWER_LOCK_CPU, 0);
825 ps_err_ex_svc(service, "ret : (0x%x)", ret);
827 result = alarmmgr_add_alarm_withcb(ALARM_TYPE_VOLATILE, (time_t)(context->connection_timeout),
828 0, __ps_service_connetion_timeout_handler, context, &(context->timer_src));
831 ret = device_power_release_lock(POWER_LOCK_CPU);
833 ps_err_ex_svc(service, "ret : (0x%x)", ret);
835 if (result != ALARMMGR_RESULT_SUCCESS) {
836 ps_err_ex_svc(service, "Failed to add alarm(%d)", result);
840 ps_info_ex_svc(service, "cellular service timer started timer src(%d), timeout(%d)",
841 context->timer_src, context->connection_timeout);
842 context->connection_timeout = (context->connection_timeout) * 2;
843 if (context->connection_timeout >= PDP_RETRY_TIME_OUT_MAX)
844 context->connection_timeout = PDP_RETRY_TIME_OUT_MAX;
847 void _ps_service_reset_connection_timer(ps_context_t *context)
849 gboolean f_awo = FALSE;
850 #ifdef PREPAID_SIM_APN_SUPPORT
851 gboolean p_awo = FALSE;
853 gboolean ims_activation_requested = FALSE;
854 ps_service_t *service = NULL;
856 f_awo = _ps_context_get_alwayson_enable(context);
857 service = _ps_context_ref_service(context);
858 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
859 if (!f_awo && (!ims_activation_requested && (CONTEXT_ROLE_IMS != tcore_context_get_role(_ps_context_ref_co_context(context)))))
862 #ifdef PREPAID_SIM_APN_SUPPORT
863 p_awo = _ps_context_get_prepaid_alwayson_enable(context);
864 if (!f_awo && !p_awo)
868 service = _ps_context_ref_service(context);
869 if (service == NULL) {
870 err("service is NULL!!!");
873 context->connection_timeout = PDP_RETRY_TIME_OUT_DEFAULT;
875 if (context->timer_src > 0) {
876 ps_warn_ex_svc(service, "remove connection retry timer (%d)", context->timer_src);
877 alarmmgr_remove_alarm(context->timer_src);
878 context->timer_src = 0;
882 gboolean _ps_service_unref_context(ps_service_t *service, ps_context_t *context)
884 ps_modem_t *modem = _ps_service_ref_modem(service);
886 g_return_val_if_fail(service != NULL, FALSE);
887 g_return_val_if_fail(modem != NULL, FALSE);
888 g_return_val_if_fail(context != NULL, FALSE);
889 g_return_val_if_fail(context->path != NULL, FALSE);
891 ps_dbg_ex_modem(modem, "service unref context (%s)", context->path);
893 _ps_service_deactivate_context(service, context);
894 /* remove context from the list (modem, service) */
895 modem->contexts = g_slist_remove(modem->contexts, context);
896 ps_service_emit_context_removed_signal(service, context);
900 void _ps_service_remove_contexts(ps_service_t *service)
905 g_return_if_fail(service != NULL);
906 count = g_slist_length(service->contexts);
907 ps_info_ex_svc(service, "service remove all contexts: count(%d)", count);
909 for (index = 0; index < count; index++) {
910 ps_context_t *context = g_slist_nth_data(service->contexts, index);
911 ps_dbg_ex_svc(service, "path(%s), context(%p)", _ps_context_ref_path(context), context);
912 _ps_service_unref_context(service, context);
913 _ps_context_remove_context(context);
915 g_slist_free(service->contexts);
916 service->contexts = NULL;
919 void _ps_service_disconnect_contexts(ps_service_t *service)
923 g_return_if_fail(service != NULL);
924 ps_info_ex_svc(service, "service disconnect all contexts");
926 for (index = 0; index < g_slist_length(service->contexts); index++) {
927 ps_context_t *context = g_slist_nth_data(service->contexts, index);
928 _ps_service_reset_connection_timer(context);
929 _ps_service_deactivate_context(service, context);
933 void _ps_service_disconnect_internet_mms_tethering_contexts(ps_service_t *service)
937 g_return_if_fail(service != NULL);
938 ps_info_ex_svc(service, "Service disconnect Internet/MMS/Tethering contexts");
940 for (index = 0; index < g_slist_length(service->contexts); index++) {
941 ps_context_t *context = g_slist_nth_data(service->contexts, index);
942 CoreObject *co_context = _ps_context_ref_co_context(context);
943 enum co_context_role role = tcore_context_get_role(co_context);
946 * Deactivate following type of contexts -
954 case CONTEXT_ROLE_INTERNET:
955 case CONTEXT_ROLE_MMS:
956 case CONTEXT_ROLE_PREPAID_INTERNET:
957 case CONTEXT_ROLE_PREPAID_MMS:
958 case CONTEXT_ROLE_TETHERING:
959 _ps_service_reset_connection_timer(context);
960 _ps_service_deactivate_context(service, context);
964 ps_warn_ex_svc(service, "Need not deactivate for %d PDN type", role);
970 int _ps_service_connect_default_context(ps_service_t *service)
974 gboolean ims_activation_requested = FALSE;
975 gboolean reset_profile = FALSE;
976 ps_modem_t *modem = NULL;
978 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
980 ps_dbg_ex_svc(service, "service connect default context");
982 modem = _ps_service_ref_modem(service);
983 reset_profile = _ps_modem_get_reset_profile(modem);
985 ps_err_ex_svc(service, "reset_profile(%d) retun", reset_profile);
989 ims_activation_requested = _ps_service_get_ims_activation_requested(service);
991 for (index = 0; index < g_slist_length(service->contexts); index++) {
992 ps_context_t *context = g_slist_nth_data(service->contexts, index);
993 gboolean f_awo = FALSE;
995 f_awo = _ps_context_get_alwayson_enable(context);
997 enum co_context_state context_state;
999 /* FIX: Kiran PLM P141111-07502 */
1000 /* _ps_service_reset_connection_timer(value); */
1001 rv = _ps_service_activate_context(service, context);
1002 context_state = tcore_context_get_state(_ps_context_ref_co_context(context));
1003 if (context_state == CONTEXT_STATE_ACTIVATED) {
1004 ps_info_ex_svc(service, "context is already connected");
1005 _ps_context_set_connected(context, TRUE);
1007 ps_info_ex_svc(service, "return rv(%d)", rv);
1011 if (ims_activation_requested && (CONTEXT_ROLE_IMS == tcore_context_get_role(_ps_context_ref_co_context(context)))) {
1012 rv = _ps_service_activate_context(service, context);
1013 ps_info_ex_svc(service, "return rv(%d)", rv);
1014 ims_activation_requested = FALSE;
1021 #ifdef PREPAID_SIM_APN_SUPPORT
1022 gboolean _ps_service_connect_last_connected_context_ex(ps_service_t *service, ps_context_t *context,
1023 gboolean *defined, char *operator)
1025 ps_modem_t *modem = NULL;
1026 ps_master_t *master = NULL;
1027 int profile_id = -1;
1028 int current_profile_id = -1;
1029 gchar *last_connected_operator = NULL;
1030 gboolean last_connected_profile = FALSE;
1033 ps_info_ex_svc(service, "Entry");
1034 modem = _ps_service_ref_modem(service);
1035 master = _ps_modem_ref_master(modem);
1036 last_connected_profile = _ps_master_get_storage_value_bool(master, STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_BOOL);
1037 ps_info_ex_svc(service, "last_connected_profile [%s]", last_connected_profile ? "TRUE" : "FALSE");
1038 /* Last connected profile exist */
1039 if (last_connected_profile) {
1040 /* Fetch last connected profile's operator */
1041 last_connected_operator = _ps_master_get_storage_value_string(master, STORAGE_KEY_TELEPHONY_LAST_CONNECTED_CONTEXT_PLMN);
1042 ps_info_ex_svc(service, "last_connected_operator[%s] current operator[%s]", last_connected_operator, operator);
1044 if (g_strcmp0(last_connected_operator, operator) != 0) {
1045 /* different SIM, So reset STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_BOOL
1046 and continue to activate default profile */
1047 ps_info_ex_svc(service, "Different SIM, reset last connected context");
1048 _ps_master_set_storage_value_bool(master, STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_BOOL, FALSE);
1050 /* should be freed due to dynamic memory allocated by tcore_storage_get_string() */
1051 if (last_connected_operator) {
1052 free(last_connected_operator);
1053 last_connected_operator = NULL;
1057 /* Fetch last connected context profile id */
1058 ps_info_ex_svc(service, "Fetch last connected context profile id");
1059 profile_id = _ps_master_get_storage_value_int(master, STORAGE_KEY_PDP_LAST_CONNECTED_CONTEXT_PROFILE_ID);
1061 /* Fetch current context profile id */
1062 current_profile_id = _ps_context_get_profile_id(context);
1063 ps_info_ex_svc(service, "last connected context profile id[%d], current context profile id[%d]", profile_id, current_profile_id);
1065 /* should be freed due to dynamic memory allocated by tcore_storage_get_string() */
1066 if (last_connected_operator) {
1067 free(last_connected_operator);
1068 last_connected_operator = NULL;
1071 if (profile_id != current_profile_id) {
1072 ps_info_ex_svc(service, "Current context profile id and last connected profile does not match ..");
1073 /* Current context profile id and last connected profile does not match
1074 Check for next available profile */
1077 /* activate last connected context */
1078 ps_info_ex_svc(service, "activate last connected context");
1079 rv = _ps_service_define_context(service, context);
1080 ps_info_ex_svc(service, "return rv(%d)", rv);
1087 ps_info_ex_svc(service, "There is no last connected profile");
1093 gboolean _ps_service_connect_last_connected_context(ps_service_t *service)
1096 gboolean defined = FALSE;
1097 gchar *operator = NULL;
1100 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
1101 operator = _ps_modem_ref_operator(_ps_service_ref_modem(service));
1103 for (index = 0; index < g_slist_length(service->contexts); index++) {
1104 ps_context_t *ps_context = g_slist_nth_data(service->contexts, index);
1105 ret = _ps_service_connect_last_connected_context_ex(service, ps_context, &defined, operator);
1106 ps_info_ex_svc(service, "ret[%d]", ret);
1107 if (defined == TRUE) {
1108 ps_info_ex_svc(service, "context[%p]", ps_context);
1115 int _ps_service_connect_default_prepaid_context(ps_service_t *service)
1120 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
1122 for (index = 0; index < g_slist_length(service->contexts); index++) {
1123 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1124 gboolean f_awo = FALSE;
1125 f_awo = _ps_context_get_prepaid_alwayson_enable(context);
1127 _ps_service_reset_connection_timer(context);
1128 rv = _ps_service_activate_context(service, context);
1129 ps_info_ex_svc(service, "return rv(%d)", rv);
1133 ps_info_ex_svc(service, "Exit - rv[%d]", rv);
1137 ps_context_t *_ps_service_return_context_by_cid(ps_service_t *service, int context_id)
1141 g_return_val_if_fail(service != NULL, NULL);
1143 for (index = 0; index < g_slist_length(service->contexts); index++) {
1144 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1145 CoreObject *co_context = _ps_context_ref_co_context(context);
1146 int tmp_cid = tcore_context_get_id(co_context);
1148 if (tmp_cid != context_id)
1157 ps_context_t *_ps_service_return_default_context(ps_service_t *service, int svc_cat_id)
1161 g_return_val_if_fail(service != NULL, NULL);
1163 for (index = 0; index < g_slist_length(service->contexts); index++) {
1164 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1165 gboolean b_default = FALSE;
1166 b_default = _ps_context_get_default_context(context, svc_cat_id);
1175 int _ps_service_update_roaming_apn(ps_service_t *service)
1178 ps_modem_t *modem = _ps_service_ref_modem(service);
1179 gboolean p_from = FALSE; /* default <FLASE> : Home newtwork */
1180 GSList *contexts = NULL;
1182 g_return_val_if_fail(service != NULL, TCORE_RETURN_FAILURE);
1183 g_return_val_if_fail(modem != NULL, TCORE_RETURN_FAILURE);
1185 ps_dbg_ex_svc(service, "roaming status: %d", service->roaming);
1186 /* 1) Remove all contexts
1187 * 2) Load Home/Roaming profiles from database.
1189 * Home -> Roaming network:
1190 * 3-2) If Any roaming profile is not provided by service provider,
1191 * load Home profiles from database.
1194 p_from = _ps_modem_get_roaming_apn_support(modem);
1196 _ps_service_remove_contexts(service);
1197 contexts = _ps_context_create_hashtable((gpointer)modem, service->roaming);
1198 if (contexts != NULL) {
1199 rv = _ps_service_set_number_of_pdn_cnt(service, modem->operator);
1200 rv = _ps_service_ref_contexts(service, contexts, modem->operator);
1203 /* Iterate through each context and check home and roaming pdp protocol type.
1204 * If its same NO need to deactivate context.
1205 * Otherwise de-activate context as home and roam pdp protocol type mismatched
1207 enum co_context_type home_pdp_protocol, roam_pdp_protocol;
1210 for (index = 0; index < g_slist_length(service->contexts); index++) {
1211 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1212 home_pdp_protocol = tcore_context_get_type(_ps_context_ref_co_context(context));
1213 roam_pdp_protocol = tcore_context_get_roam_pdp_type(_ps_context_ref_co_context(context));
1214 if (home_pdp_protocol == roam_pdp_protocol) {
1215 ps_dbg_ex_svc(service, "home and roam pdp protocol type matched. No need to de-activate");
1219 /* De-activate context as home and roam pdp protocol type mismatched */
1220 ps_info_ex_modem(modem, "home[%d] and roam[%d] pdp protocol type mis-matched. De-activate if context is already activated",
1221 home_pdp_protocol, roam_pdp_protocol);
1222 _ps_service_reset_connection_timer(context);
1223 _ps_service_deactivate_context(service, context);
1230 gboolean _ps_service_processing_network_event(ps_service_t *service, gboolean ps_attached, gboolean roaming)
1232 #ifdef PREPAID_SIM_APN_SUPPORT
1233 gboolean ret = TRUE;
1235 gboolean prev_roaming_status;
1236 g_return_val_if_fail(service != NULL, FALSE);
1238 prev_roaming_status = _ps_service_get_roaming(service);
1239 if (__ps_service_check_is_network_in_serivce(service) != TRUE &&
1240 !_ps_modem_get_roaming_apn_support(_ps_service_ref_modem(service)))
1241 ps_warn_ex_svc(service, "Update roaming status only in IN SRV");
1243 _ps_service_set_roaming(service, roaming);
1245 _ps_service_set_ps_attached(service, ps_attached);
1246 _ps_update_cellular_state_key(service);
1248 if (prev_roaming_status != _ps_service_get_roaming(service)) {
1249 gboolean roaming_allowed = FALSE;
1250 roaming_allowed = _ps_modem_get_data_roaming_allowed(_ps_service_ref_modem(service));
1251 _ps_service_update_roaming_apn(service);
1253 if (!roaming_allowed && roaming) {
1254 ps_info_ex_svc(service, "Roaming allowed (%d), Roaming status (%d)", roaming_allowed, roaming);
1255 _ps_service_disconnect_contexts(service);
1260 if (service->ps_attached) {
1261 ps_context_t *def_context = NULL;
1262 #ifdef PREPAID_SIM_APN_SUPPORT
1263 ret = _ps_service_connect_last_connected_context(service);
1264 ps_dbg_ex_svc(service, "ret[%d]", ret);
1266 return TRUE; /* No need to activate default context */
1268 def_context = _ps_service_return_default_context(service, CONTEXT_ROLE_INTERNET);
1270 _ps_context_set_alwayson_enable(def_context, TRUE);
1271 _ps_service_connect_default_context(service);
1277 gboolean _ps_service_set_connected(ps_service_t *service, gpointer cstatus, gboolean enabled)
1280 gboolean def_awo = FALSE, b_def_conn = FALSE;
1281 gpointer def_conn = NULL;
1282 gpointer requested_conn = NULL;
1283 #ifdef TIZEN_SUPPORT_VOLTE
1284 gboolean def_ims_activation = FALSE;
1285 ps_modem_t *modem = _ps_service_ref_modem(service);
1287 ps_master_t *master = _ps_modem_ref_master(_ps_service_ref_modem(service));
1289 struct tnoti_ps_call_status *call_status = NULL;
1291 call_status = (struct tnoti_ps_call_status *)cstatus;
1293 if (enabled && master && master->initial_pdp_conn == FALSE) {
1294 ps_info_ex_svc(service, "Initial PDP connection.");
1295 master->initial_pdp_conn = TRUE;
1298 for (index = 0; index < g_slist_length(service->contexts); index++) {
1299 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1300 CoreObject *co_context = _ps_context_ref_co_context(context);
1302 gboolean b_tmp_def = FALSE;
1303 gpointer b_user_data = NULL;
1305 tmp_cid = tcore_context_get_id(co_context);
1306 if (tmp_cid != call_status->context_id)
1309 /* if there is default context in disconnected cid, it has to retry auto connection */
1310 b_tmp_def = _ps_context_get_default_context(context, CONTEXT_ROLE_INTERNET);
1312 b_def_conn = b_tmp_def;
1314 /* if disconnected connection has the user data, it is a priority connection. */
1315 b_user_data = _ps_context_get_user_data(context);
1318 requested_conn = b_user_data;
1323 gchar *devname = NULL;
1324 ps_info_ex_svc(service, "Reset socket connections.");
1325 tcore_ps_clear_context_id(_ps_service_ref_co_ps(service), co_context);
1326 ipv4 = tcore_context_get_ipv4_addr(co_context);
1327 devname = tcore_context_get_ipv4_devname(co_context);
1328 tcore_util_reset_ipv4_socket((const char *)devname, (const char *)ipv4);
1332 _ps_context_set_connected(context, enabled);
1335 /* connect to request profile */
1336 if (!enabled && requested_conn) {
1337 ps_info_ex_svc(service, "connect to request profile (%p)", requested_conn);
1338 _ps_connection_hdlr(requested_conn);
1339 _ps_service_reset_connection_timer(def_conn);
1340 _ps_context_reset_user_data(def_conn);
1344 /* default context and always on is true. - request to connect */
1347 def_conn = _ps_service_return_default_context(service, CONTEXT_ROLE_INTERNET);
1348 def_awo = _ps_context_get_alwayson_enable(def_conn);
1352 * In case of ME in LCD off & UPS mode.
1353 * Do not enable PDP retry timer for default internet context.
1355 ps_mode = _ps_modem_get_psmode(_ps_service_ref_modem(service));
1356 if (ps_mode > POWER_SAVING_MODE_NORMAL && ps_mode < POWER_SAVING_MODE_WEARABLE) {
1357 gint pm_state = _ps_master_get_storage_value_int(master, STORAGE_KEY_PM_STATE);
1358 if (pm_state == 3) {
1359 ps_warn_ex_svc(service, "PDP retry timer is not allowed in LCD off & UPS mode.");
1364 /* always on TRUE and default connection - NORMAL RETRY */
1365 /* always on TRUE and no default connection - WAIT 5 Secs for retry from application */
1367 /* retry connection */
1368 _ps_service_connection_timer(service, def_conn);
1371 /* with unexpected disconnection from network/me */
1372 _ps_service_set_retry_timeout_value(def_conn, PDP_RETRY_TIME_OUT_DEFAULT);
1373 _ps_service_connection_timer(service, def_conn);
1377 #ifdef TIZEN_SUPPORT_VOLTE
1378 if (tfeature_is_supported(TFEATURE_FUNCTION_IMS_PDN_AUTO_ACTIVATE))
1379 def_ims_activation = _ps_service_get_ims_activation_requested(service);
1381 if (def_ims_activation) {
1382 ps_context_t *def_ims = NULL;
1383 CoreObject *co_network = NULL;
1384 gboolean reset_profile = FALSE;
1385 enum telephony_network_service_type svc_type;
1387 co_network = _ps_service_ref_co_network(service);
1388 tcore_network_get_service_type(co_network, &svc_type);
1389 def_ims = _ps_service_return_default_context(service, CONTEXT_ROLE_IMS);
1390 reset_profile = _ps_modem_get_reset_profile(modem);
1392 ps_dbg_ex_svc(service, "svc_type[%d], reset_profile(%d)", svc_type, reset_profile);
1394 if (def_ims && svc_type == NETWORK_SERVICE_TYPE_LTE && !reset_profile) {
1395 ps_info_ex_svc(service, "Continue re-try for IMS PDN");
1396 _ps_service_connection_timer(service, def_ims);
1398 ps_warn_ex_svc(service, "IMS PDN retry timer is allowed in LTE mode.");
1404 /* To send deactivation request of default profile */
1405 if (enabled && requested_conn) {
1406 ps_info_ex_svc(service, "Send deactivation to default profile and connect to request profile (%p)", requested_conn);
1413 void _ps_service_set_ps_defined(ps_service_t *service, gboolean value, int cid)
1417 g_return_if_fail(service != NULL);
1419 for (index = 0; index < g_slist_length(service->contexts); index++) {
1420 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1421 CoreObject *co_context = _ps_context_ref_co_context(context);
1422 CoreObject *co_ps = _ps_service_ref_co_ps(service);
1423 unsigned char context_id = tcore_context_get_id(co_context);
1424 int role = tcore_context_get_role(co_context);
1425 if (context_id == cid) {
1426 gboolean proceed_activation = TRUE;
1428 /* Check attach apn complete */
1429 if (value && (!service->attach_apn_complete && role != CONTEXT_ROLE_IMS_EMERGENCY)) {
1430 ps_info_ex_svc(service, "Initial define of attach APN is complete for profile role(%d)", role);
1431 service->attach_apn_complete = TRUE;
1433 if (TRUE == _ps_context_get_default_context(context, CONTEXT_ROLE_INTERNET) && service->ps_attached)
1434 proceed_activation = TRUE;
1436 proceed_activation = FALSE;
1437 tcore_ps_clear_context_id(co_ps, co_context);
1440 proceed_activation &= value;
1442 /* Set 'ps_defined' */
1443 _ps_context_set_ps_defined(context, proceed_activation);
1445 if (proceed_activation) {
1446 /* Activate if define is completed */
1447 ps_dbg_ex_svc(service, "define is complete, activate context for cid(%d)", cid);
1448 if (_ps_service_activate_context(service, context) == TCORE_RETURN_SUCCESS) {
1449 ps_dbg_ex_svc(service, "Successful activate context");
1450 tcore_ps_set_cid_active(co_ps, cid, TRUE);
1459 gboolean _ps_service_set_ps_attached(ps_service_t *service, gboolean value)
1461 g_return_val_if_fail(service != NULL, FALSE);
1463 if (service->ps_attached != value) {
1464 service->ps_attached = value;
1465 ps_info_ex_svc(service, "service(%p) ps_attached(%d)", service, service->ps_attached);
1466 ps_service_emit_property_changed_signal(service);
1471 gboolean _ps_service_get_restricted(ps_service_t *service)
1473 g_return_val_if_fail(service != NULL, FALSE);
1474 return service->restricted;
1477 gboolean _ps_service_set_restricted(ps_service_t *service, gboolean value)
1479 g_return_val_if_fail(service != NULL, FALSE);
1481 if (service->restricted != value) {
1482 service->restricted = value;
1483 ps_info_ex_svc(service, "service(%p) restricted(%d)", service, service->restricted);
1484 _ps_update_cellular_state_key(service);
1489 gboolean _ps_service_set_ims_activation_requested(ps_service_t *service, gboolean enabled)
1491 g_return_val_if_fail(service != NULL, FALSE);
1492 service->ims_activation_requested = enabled;
1493 ps_info_ex_svc(service, "service (%p) ims_activation_requested (%d)", service, service->ims_activation_requested);
1497 gboolean _ps_service_get_ims_activation_requested(ps_service_t *service)
1499 g_return_val_if_fail(service != NULL, FALSE);
1500 ps_info_ex_svc(service, "service (%p) ims_activation_requested (%d)", service, service->ims_activation_requested);
1502 if (_ps_service_get_epdg_status(service) == TRUE)
1505 return service->ims_activation_requested;
1508 gboolean _ps_service_set_epdg_ip_configuration(ps_service_t *service, gint cid, char *ipv4_addr, char *ipv6_addr)
1510 GSList *contexts = NULL;
1511 CoreObject *co_context = NULL;
1513 unsigned char ip_address[IPV4_ADDR_LEN];
1515 g_return_val_if_fail(service != NULL, FALSE);
1517 ps_info_ex_svc(service, "service (%p) ipv4_addr (%s) ipv6_addr (%s)", service, ipv4_addr, ipv6_addr);
1519 contexts = tcore_ps_ref_context_by_id(service->co_ps, cid);
1521 co_context = contexts->data;
1523 contexts = contexts->next;
1526 if (tcore_context_get_role(co_context) == CONTEXT_ROLE_IMS) {
1529 pdp_address = __ps_service_convert_ipv4_address_int(ipv4_addr);
1530 pdp_address = htonl(pdp_address);
1531 memcpy(&ip_address, &pdp_address, IPV4_ADDR_LEN);
1532 tcore_context_set_ipv4_addr(co_context, ip_address);
1533 snprintf(addr_buf, 20, "%d.%d.%d.%d", ip_address[0], ip_address[1], ip_address[2], ip_address[3]);
1534 ps_info_ex_svc(service, "[IPv4] IP Address: [%s]", addr_buf);
1536 tcore_context_set_ipv6_addr(co_context, ipv6_addr);
1539 contexts = contexts->next;
1545 gboolean _ps_service_set_epdg_status(ps_service_t *service, gboolean available)
1547 g_return_val_if_fail(service != NULL, FALSE);
1548 service->is_epdg_available = available;
1549 ps_info_ex_svc(service, "service (%p) available (%d) ", service, service->is_epdg_available);
1554 gboolean _ps_service_get_epdg_status(ps_service_t *service)
1556 g_return_val_if_fail(service != NULL, FALSE);
1557 return service->is_epdg_available;
1560 gboolean _ps_service_set_number_of_pdn_cnt(ps_service_t *service, gchar *operator)
1564 g_return_val_if_fail(service != NULL, FALSE);
1566 ps_dbg_ex_svc(service, "Entered");
1567 num_of_pdn = _ps_context_get_number_of_pdn(operator, service);
1568 rv = tcore_ps_set_num_of_pdn(_ps_service_ref_co_ps(service), num_of_pdn);
1570 if (rv != TCORE_RETURN_SUCCESS)
1571 ps_err_ex_svc(service, "error to get maximum number of pdn");
1577 gboolean _ps_service_get_roaming(ps_service_t *service)
1579 g_return_val_if_fail(service != NULL, FALSE);
1580 return service->roaming;
1583 gboolean _ps_service_set_roaming(ps_service_t *service, gboolean value)
1585 g_return_val_if_fail(service != NULL, FALSE);
1587 if (service->roaming != value) {
1588 service->roaming = value;
1589 ps_info_ex_svc(service, "service(%p) roaming(%d)", service, service->roaming);
1590 ps_service_emit_property_changed_signal(service);
1596 static void _indicator_cb_dns_reply(GObject *src, GAsyncResult *res, gpointer user_data)
1601 GError *error = NULL;
1603 list = g_resolver_lookup_by_name_finish((GResolver *)src, res, &error);
1605 err("fail to get dns resolving");
1607 err("error:%d, %s", error->code, error->message);
1608 g_error_free(error);
1613 for (cur = list; cur; cur = cur->next) {
1615 str_addr = g_inet_address_to_string(addr);
1618 info("addr(%s)", str_addr);
1621 g_object_unref(cur->data);
1625 g_object_unref(src);
1630 gboolean _ps_service_set_access_technology(ps_service_t *service,
1631 enum telephony_network_access_technology value)
1633 #ifdef PREPAID_SIM_APN_SUPPORT
1634 gboolean ret = TRUE;
1636 enum telephony_network_access_technology p_act = 0;
1637 g_return_val_if_fail(service != NULL, FALSE);
1639 if (service->act != value) {
1640 p_act = service->act;
1641 service->act = value;
1642 ps_info_ex_svc(service, "service(%p) P ACT(%d) Access Technology(%d)", service, p_act, service->act);
1644 if ((p_act == NETWORK_ACT_LTE || p_act == NETWORK_ACT_NR) && (service->act >= NETWORK_ACT_GSM && service->act < NETWORK_ACT_LTE)) {
1645 GResolver *r = NULL;
1647 ps_dbg_ex_svc(service, "send the dns pkt for keeping connection");
1649 r = g_resolver_get_default();
1650 g_resolver_lookup_by_name_async(r, "www.tizen.org", NULL, _indicator_cb_dns_reply, NULL);
1653 if (service->act > NETWORK_ACT_UNKNOWN && service->act < NETWORK_ACT_NOT_SPECIFIED) {
1654 _ps_update_cellular_state_key(service);
1655 #ifdef PREPAID_SIM_APN_SUPPORT
1656 ret = _ps_service_connect_last_connected_context(service);
1657 ps_info_ex_svc(service, "ret[%d]", ret);
1659 return ret; /* No need to activate default context */
1661 _ps_service_connect_default_context(service);
1668 enum telephony_ps_state _ps_service_check_cellular_state(ps_service_t *service)
1670 gboolean state = FALSE;
1673 g_return_val_if_fail(service != NULL, TELEPHONY_PS_NO_SERVICE);
1675 modem = _ps_service_ref_modem(service);
1677 state = _ps_modem_get_flght_mode(modem);
1679 return TELEPHONY_PS_FLIGHT_MODE;
1681 state = _ps_modem_get_power(modem);
1683 return TELEPHONY_PS_NO_SERVICE;
1685 state = _ps_modem_get_sim_init(modem);
1687 return TELEPHONY_PS_NO_SERVICE;
1689 if (service->restricted)
1690 return TELEPHONY_PS_RESTRICTED_SERVICE;
1692 if (!service->ps_attached)
1693 return TELEPHONY_PS_NO_SERVICE;
1695 state = _ps_modem_get_data_allowed(modem);
1697 return TELEPHONY_PS_3G_OFF;
1699 state = _ps_modem_get_data_roaming_allowed(modem);
1700 if (service->roaming && !state)
1701 return TELEPHONY_PS_ROAMING_OFF;
1703 return TELEPHONY_PS_ON;
1706 void _ps_service_handling_nas_timer(ps_service_t *service, gboolean state)
1710 g_return_if_fail(service != NULL);
1711 ps_info_ex_svc(service, "Handleing nas timer, state(%d)", state);
1713 for (index = 0; index < g_slist_length(service->contexts); index++) {
1714 ps_context_t *context = g_slist_nth_data(service->contexts, index);
1715 CoreObject *co_context = _ps_context_ref_co_context(context);
1716 enum co_context_state co_state = tcore_context_get_state(co_context);
1718 if (co_state == CONTEXT_STATE_ACTIVATED) {
1719 enum co_context_role role = tcore_context_get_role(co_context);
1720 enum ims_data_pdn data_pdn = IMS_DATA_PDN_UNKNOWN;
1721 enum ims_data_state data_state = IMS_DATA_STATE_RESUME;
1722 gboolean drop_packet = FALSE;
1724 if (role == CONTEXT_ROLE_INTERNET)
1725 data_pdn = IMS_DATA_PDN_INTERNET;
1726 else if (role == CONTEXT_ROLE_IMS)
1727 data_pdn = IMS_DATA_PDN_IMS;
1728 else if (role == CONTEXT_ROLE_IMS_EMERGENCY)
1729 data_pdn = IMS_DATA_PDN_EMERGENCY;
1730 else if (role == CONTEXT_ROLE_MMS)
1731 data_pdn = IMS_DATA_PDN_CBS;
1733 if (state == PS_NAS_TIMER_STATE_START) {
1734 data_state = IMS_DATA_STATE_SUSPEND;
1737 data_state = IMS_DATA_STATE_RESUME;
1738 drop_packet = FALSE;
1741 ps_info_ex_svc(service, "co_context(%p) co_state(%d) role(%d) data_pdn(%d) data_state(%d) drop_packet(%d)",
1742 co_context, co_state, role, data_pdn, data_state, drop_packet);
1745 if (tcore_context_get_drop_packet(co_context) != drop_packet) {
1746 tcore_context_set_drop_packet(co_context, drop_packet);
1747 _ps_context_handling_nas_timer(context, drop_packet);
1749 if (role == CONTEXT_ROLE_IMS)
1750 tcore_ps_set_ims_data_state(_ps_service_ref_co_ps(service), data_pdn, data_state);