From d4ced627e068e73a570da5d9e8ee451595c79c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20R=C3=B6jfors?= Date: Tue, 6 Aug 2019 08:33:56 +0000 Subject: [PATCH] gprs: Use -1 as netreg status during init. Previously the valid "unknown" netreg status was set during startup, but its a bit problematic for gprs. There might be cases where a LTE context is activated before netreg is finished updating its status. Resulting in gprs taking faulty actions. Instead we set the status to -1 until we are updated with a known value. During the time the status is -1, gprs postpones actions until the status is valid (>= 0). --- src/gprs.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/gprs.c b/src/gprs.c index bdb8c8a2..d554dab1 100644 --- a/src/gprs.c +++ b/src/gprs.c @@ -1661,6 +1661,15 @@ static void gprs_netreg_update(struct ofono_gprs *gprs) { ofono_bool_t attach; + /* + * This function can get called by other reasons than netreg + * updating its status. So check if we have a valid netreg status yet. + * The only reason for not having a valid status is basically during + * startup while the netreg atom is fetching the status. + */ + if (gprs->netreg_status < 0) + return; + attach = gprs->netreg_status == NETWORK_REGISTRATION_STATUS_REGISTERED; attach = attach || (gprs->roaming_allowed && @@ -3084,7 +3093,7 @@ struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem, } gprs->status = NETWORK_REGISTRATION_STATUS_UNKNOWN; - gprs->netreg_status = NETWORK_REGISTRATION_STATUS_UNKNOWN; + gprs->netreg_status = -1; gprs->used_pids = l_uintset_new(MAX_CONTEXTS); return gprs; @@ -3095,6 +3104,7 @@ static void netreg_watch(struct ofono_atom *atom, void *data) { struct ofono_gprs *gprs = data; + int status; if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) { gprs_netreg_removed(gprs); @@ -3102,7 +3112,16 @@ static void netreg_watch(struct ofono_atom *atom, } gprs->netreg = __ofono_atom_get_data(atom); - gprs->netreg_status = ofono_netreg_get_status(gprs->netreg); + status = ofono_netreg_get_status(gprs->netreg); + + /* + * If the status is known, assign it, otherwise keep the init value + * to indicate that the netreg atom is not initialised with a known + * value + */ + if (status != NETWORK_REGISTRATION_STATUS_UNKNOWN) + gprs->netreg_status = status; + gprs->status_watch = __ofono_netreg_add_status_watch(gprs->netreg, netreg_status_changed, gprs, NULL);