Skip to contentSkip to conversation

gprs: Check for LTE in gprs_attached_update

PATCH Superseded [email protected] 2 participants 14 messages Aug 14, 2019 – Aug 20, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 gprs: Check for LTE in gprs_attached_update

From: Richard Röjfors <[email protected]>

Since we have a different condition for the attach state when running on LTE, we should consider it in gprs_attached_update. Previously it's done in some instances. But for instance if the driver got detached from GPRS but now running on LTE with a context up, we would be deattached.

---
 src/gprs.c | 52 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 23 deletions(-)
src/gprs.c +29 -23
index bba482cb..94d13f82 100644
@@ -1571,13 +1571,34 @@ static void release_active_contexts(struct ofono_gprs *gprs)
 	}
 }
 
+static gboolean on_lte(struct ofono_gprs *gprs)
+{
+	if (ofono_netreg_get_technology(gprs->netreg) ==
+			ACCESS_TECHNOLOGY_EUTRAN && have_read_settings(gprs))
+		return TRUE;
+
+	return FALSE;
+}
+
 static void gprs_attached_update(struct ofono_gprs *gprs)
 {
 	ofono_bool_t attached;
+	int status = gprs->status;
 
-	attached = gprs->driver_attached &&
-		(gprs->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
-			gprs->status == NETWORK_REGISTRATION_STATUS_ROAMING);
+	if (on_lte(gprs))
+		/*
+		 * For LTE we attached status reflects successful context
+		 * activation.
+		 * Since we in gprs_netreg_update not even try to attach
+		 * to GPRS if we are running on LTE, we can on some modems
+		 * expect the gprs status to be unknown. That must not
+		 * result in detaching...
+		 */
+		attached = have_active_contexts(gprs);
+	else
+		attached = gprs->driver_attached &&
+			(status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
+				status == NETWORK_REGISTRATION_STATUS_ROAMING);
 
 	if (attached == gprs->attached)
 		return;
@@ -1591,11 +1612,14 @@ static void gprs_attached_update(struct ofono_gprs *gprs)
 	if (attached == FALSE) {
 		release_active_contexts(gprs);
 		gprs->bearer = -1;
-	} else if (have_active_contexts(gprs) == TRUE) {
+	} else if (have_active_contexts(gprs) == TRUE &&
+		!on_lte(gprs)) {
 		/*
 		 * Some times the context activates after a detach event and
 		 * right before an attach. We close it to avoid unexpected open
 		 * contexts.
+		 * Skip that for LTE since the condition to be attached on LTE
+		 * is that a context gets activated
 		 */
 		release_active_contexts(gprs);
 		gprs->flags |= GPRS_FLAG_ATTACHED_UPDATE;
@@ -1660,15 +1684,6 @@ static void gprs_netreg_removed(struct ofono_gprs *gprs)
 	gprs_attached_update(gprs);
 }
 
-static gboolean on_lte(struct ofono_gprs *gprs)
-{
-	if (ofono_netreg_get_technology(gprs->netreg) ==
-			ACCESS_TECHNOLOGY_EUTRAN && have_read_settings(gprs))
-		return TRUE;
-
-	return FALSE;
-}
-
 static void gprs_netreg_update(struct ofono_gprs *gprs)
 {
 	ofono_bool_t attach;
@@ -2573,16 +2588,7 @@ void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)
 
 	if (status != NETWORK_REGISTRATION_STATUS_REGISTERED &&
 			status != NETWORK_REGISTRATION_STATUS_ROAMING) {
-		/*
-		 * For LTE we attached status reflects successful context
-		 * activation.
-		 * Since we in gprs_netreg_update not even try to attach
-		 * to GPRS if we are running on LTE, we can on some modems
-		 * expect the gprs status to be unknown. That must not
-		 * result in detaching...
-		 */
-		if (!on_lte(gprs))
-			gprs_attached_update(gprs);
+		gprs_attached_update(gprs);
 		return;
 	}
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/4 gprs: Always call gprs_attached_update on context deactivation.

From: Richard Röjfors <[email protected]>

Since its registered context is a condition for being attached when running LTE, we might need to update the attached state when a context is deactivated. Otherwise we might remain attached, and connection managers (at least connman) start to hammer us to connect a context, eventhough it happens automatically in LTE.

---
 src/gprs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
src/gprs.c +5 -4
index 94d13f82..cb31e2d2 100644
@@ -2738,11 +2738,12 @@ void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
 	 * If "Attached" property was about to be signalled as TRUE but there
 	 * were still active contexts, try again to signal "Attached" property
 	 * to registered applications after active contexts have been released.
+	 *
+	 * ... or in the case of LTE where the attached state were a registered
+	 * context is a condition for being attached
 	 */
-	if (gc->gprs->flags & GPRS_FLAG_ATTACHED_UPDATE) {
-		gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
-		gprs_attached_update(gc->gprs);
-	}
+	gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
+	gprs_attached_update(gc->gprs);
 }
 
 int ofono_gprs_context_driver_register(
Signature · 1 line
2.20.1
#6 lore raw

PATCH 3/4 Revert "gprs: set driver_attached when activating automatic contexts"

In reply to [email protected]

From: Richard Röjfors <[email protected]>

This reverts commit 0167c3339ca8f17a653592af995f439d24405de8.

Since gprs_attached_update now takes LTE in account this should be reverted. This was actually a bad solution since in case LTE was lost, and we should fall back on GPRS we have flagged the driver to already being attached, which is not...

---
 src/gprs.c | 1 -
 1 file changed, 1 deletion(-)
src/gprs.c +0 -1
index cb31e2d2..eb6cd30b 100644
@@ -940,7 +940,6 @@ static void pri_read_settings_callback(const struct ofono_error *error,
 
 	gprs->flags &= ~GPRS_FLAG_ATTACHING;
 
-	gprs->driver_attached = TRUE;
 	gprs_set_attached_property(gprs, TRUE);
 
 	ofono_dbus_signal_property_changed(conn, pri_ctx->path,
Signature · 1 line
2.20.1
#7 lore raw

PATCH 4/4 Revert "gprs: _cid_activated is an 'attaching' state"

In reply to [email protected]

From: Richard Röjfors <[email protected]>

This reverts commit 1fd419e5b4b3a87673f8e0219edb0f3ed9fca774.

Since gprs_attached_update now guarantees that we will not get attached without having a context activated in LTE, this is not needed anymore. It also potentially interferes in case the driver was actually attaching.

---
 src/gprs.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)
src/gprs.c +1 -17
index eb6cd30b..6bdc125d 100644
@@ -913,7 +913,6 @@ static void pri_read_settings_callback(const struct ofono_error *error,
 {
 	struct pri_context *pri_ctx = data;
 	struct ofono_gprs_context *gc = pri_ctx->context_driver;
-	struct ofono_gprs *gprs = pri_ctx->gprs;
 	DBusConnection *conn = ofono_dbus_get_connection();
 	dbus_bool_t value;
 
@@ -938,18 +937,11 @@ static void pri_read_settings_callback(const struct ofono_error *error,
 
 	value = pri_ctx->active;
 
-	gprs->flags &= ~GPRS_FLAG_ATTACHING;
-
-	gprs_set_attached_property(gprs, TRUE);
+	gprs_set_attached_property(pri_ctx->gprs, TRUE);
 
 	ofono_dbus_signal_property_changed(conn, pri_ctx->path,
 					OFONO_CONNECTION_CONTEXT_INTERFACE,
 					"Active", DBUS_TYPE_BOOLEAN, &value);
-
-	if (gprs->flags & GPRS_FLAG_RECHECK) {
-		gprs->flags &= ~GPRS_FLAG_RECHECK;
-		gprs_netreg_update(gprs);
-	}
 }
 
 static DBusMessage *pri_set_apn(struct pri_context *ctx, DBusConnection *conn,
@@ -2039,14 +2031,6 @@ void ofono_gprs_cid_activated(struct ofono_gprs  *gprs, unsigned int cid,
 					DBUS_TYPE_STRING, &apn);
 	}
 
-	/* Prevent ofono_gprs_status_notify from changing the 'attached'
-	 * state until after the context has been set to 'active' in
-	 * the pri_read_settings_callback; this prevents a race where
-	 * the connection manager sees the modem as attached before there
-	 * is an active context.
-	 */
-	gprs->flags |= GPRS_FLAG_ATTACHING;
-
 	gc->driver->read_settings(gc, cid, pri_read_settings_callback, pri_ctx);
 }
 
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 2/4] gprs: Always call gprs_attached_update on context deactivation.

In reply to [email protected]

Hi Richard,

Quoted 5 lines · richard.rojfors(a)gmail.com

From: Richard Röjfors <[email protected]>

Since its registered context is a condition for being attached when running LTE, we might need to update the attached state when a context is deactivated. Otherwise we might remain

Well, by definition if we're on LTE then we're attached. So I'm not quite sure what you mean here?

Quoted 3 lines

attached, and connection managers (at least connman) start to hammer us to connect a context, eventhough it happens automatically in LTE.

What happens automatically? Yes, it is true that you need a default context to attach to LTE. So activating a context is basically a part of the LTE attach procedure.

But that default context does not need to be an internet context (e.g. Verizon uses (or used to) use an ims context for this). So ConnMan still might need to activate an Internet context even if we're on LTE.

I'm also not sure that the heuristic of 0 active contexts means not attached is a good one. Shouldn't you be using +CREG or +CEREG status for this?

Quoted 16 lines
---
  src/gprs.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
src/gprs.c +3 -0
index 94d13f82..cb31e2d2 100644
@@ -2738,11 +2738,12 @@ void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
  	 * If "Attached" property was about to be signalled as TRUE but there
  	 * were still active contexts, try again to signal "Attached" property
  	 * to registered applications after active contexts have been released.
+	 *
+	 * ... or in the case of LTE where the attached state were a registered
+	 * context is a condition for being attached

src/gprs.c void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc, · line 2749

Quoted 10 lines
src/gprs.c +2 -4
  	 */
-	if (gc->gprs->flags & GPRS_FLAG_ATTACHED_UPDATE) {
-		gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
-		gprs_attached_update(gc->gprs);
-	}
+	gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
+	gprs_attached_update(gc->gprs);
  }
 
  int ofono_gprs_context_driver_register(

Regards,
-Denis

#8 lore raw
In reply to [email protected]

Hi Richard,

Quoted 7 lines · richard.rojfors(a)gmail.com

From: Richard Röjfors <[email protected]>

Since we have a different condition for the attach state when running on LTE, we should consider it in gprs_attached_update. Previously it's done in some instances. But for instance if the driver got detached from GPRS but now running on LTE with a context up, we would be deattached.

So are you talking about a hand-over? Do we have logs to help visualize this?

Quoted 29 lines
---
  src/gprs.c | 52 +++++++++++++++++++++++++++++-----------------------
  1 file changed, 29 insertions(+), 23 deletions(-)
src/gprs.c +10 -3
index bba482cb..94d13f82 100644
@@ -1571,13 +1571,34 @@ static void release_active_contexts(struct ofono_gprs *gprs)
  	}
  }
 
+static gboolean on_lte(struct ofono_gprs *gprs)
+{
+	if (ofono_netreg_get_technology(gprs->netreg) ==
+			ACCESS_TECHNOLOGY_EUTRAN && have_read_settings(gprs))
+		return TRUE;
+
+	return FALSE;
+}
+
  static void gprs_attached_update(struct ofono_gprs *gprs)
  {
  	ofono_bool_t attached;
+	int status = gprs->status;
 
-	attached = gprs->driver_attached &&
-		(gprs->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
-			gprs->status == NETWORK_REGISTRATION_STATUS_ROAMING);

src/gprs.c static void release_active_contexts(struct ofono_gprs *gprs) · line 1597

Quoted 10 lines
src/gprs.c +10 -0
+	if (on_lte(gprs))
+		/*
+		 * For LTE we attached status reflects successful context
+		 * activation.
+		 * Since we in gprs_netreg_update not even try to attach
+		 * to GPRS if we are running on LTE, we can on some modems
+		 * expect the gprs status to be unknown. That must not
+		 * result in detaching...
+		 */
+		attached = have_active_contexts(gprs);

On LTE Attached should just be always True. Someone can correct me if I'm wrong, but a default context is a pre-requisite for E-UTRAN attachment.

Quoted 8 lines
src/gprs.c +4 -0
+	else
+		attached = gprs->driver_attached &&
+			(status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
+				status == NETWORK_REGISTRATION_STATUS_ROAMING);
 
  	if (attached == gprs->attached)
  		return;

src/gprs.c static void gprs_attached_update(struct ofono_gprs *gprs) · line 1616

Quoted 6 lines
src/gprs.c +2 -1
@@ -1591,11 +1612,14 @@ static void gprs_attached_update(struct ofono_gprs *gprs)
  	if (attached == FALSE) {
  		release_active_contexts(gprs);
  		gprs->bearer = -1;
-	} else if (have_active_contexts(gprs) == TRUE) {
+	} else if (have_active_contexts(gprs) == TRUE &&
+		!on_lte(gprs)) {

Not our style. See item M4. Might want to see if it fits on the previous line.

Quoted 34 lines
src/gprs.c +2 -13
  		/*
  		 * Some times the context activates after a detach event and
  		 * right before an attach. We close it to avoid unexpected open
  		 * contexts.
+		 * Skip that for LTE since the condition to be attached on LTE
+		 * is that a context gets activated
  		 */
  		release_active_contexts(gprs);
  		gprs->flags |= GPRS_FLAG_ATTACHED_UPDATE;
@@ -1660,15 +1684,6 @@ static void gprs_netreg_removed(struct ofono_gprs *gprs)
  	gprs_attached_update(gprs);
  }
 
-static gboolean on_lte(struct ofono_gprs *gprs)
-{
-	if (ofono_netreg_get_technology(gprs->netreg) ==
-			ACCESS_TECHNOLOGY_EUTRAN && have_read_settings(gprs))
-		return TRUE;
-
-	return FALSE;
-}
-
  static void gprs_netreg_update(struct ofono_gprs *gprs)
  {
  	ofono_bool_t attach;
@@ -2573,16 +2588,7 @@ void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)
 
  	if (status != NETWORK_REGISTRATION_STATUS_REGISTERED &&
  			status != NETWORK_REGISTRATION_STATUS_ROAMING) {
-		/*
-		 * For LTE we attached status reflects successful context
-		 * activation.
-		 * Since we in gprs_netreg_update not even try to attach

src/gprs.c void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status) · line 2594

Quoted 10 lines
src/gprs.c +1 -6
-		 * to GPRS if we are running on LTE, we can on some modems
-		 * expect the gprs status to be unknown. That must not
-		 * result in detaching...
-		 */
-		if (!on_lte(gprs))
-			gprs_attached_update(gprs);
+		gprs_attached_update(gprs);
  		return;
  	}
 

Otherwise I'm fine moving the on_lte logic into gprs_attached_update itself...

Regards,
-Denis

#9 lore raw

Hi Denis,

Den tors 15 aug. 2019 kl 22:47 skrev Denis Kenzior <[email protected]>:

Quoted 5 lines

Hi Richard,

Quoted 2 lines · richard.rojfors(a)gmail.com

From: Richard Röjfors <[email protected]>

Quoted 9 lines
Quoted 5 lines

Since we have a different condition for the attach state when running on LTE, we should consider it in gprs_attached_update. Previously it's done in some instances. But for instance if the driver got detached from GPRS but now running on LTE with a context up, we would be deattached.

So are you talking about a hand-over? Do we have logs to help visualize this?

Sorry I have no logs.
I think an example would be;
Let say we are registered on non-LTE, and GPRS do attach.
Then we flip to LTE and if GPRS gets de-attached. We would brutally exit the attached state, since LTE is currently not considered in that code path.

Quoted 44 lines

src/gprs.c static void release_active_contexts(struct

Quoted 10 lines
---
  src/gprs.c | 52 +++++++++++++++++++++++++++++-----------------------
  1 file changed, 29 insertions(+), 23 deletions(-)
src/gprs.c +0 -0
index bba482cb..94d13f82 100644
@@ -1571,13 +1571,34 @@ static void release_active_contexts(struct

ofono_gprs *gprs)

src/gprs.c static void release_active_contexts(struct ofono_gprs *gprs)

Quoted 7 lines
src/gprs.c +4 -0
      }
  }
 
+static gboolean on_lte(struct ofono_gprs *gprs)
+{
+     if (ofono_netreg_get_technology(gprs->netreg) ==
+                     ACCESS_TECHNOLOGY_EUTRAN &&

have_read_settings(gprs))

src/gprs.c static void release_active_contexts(struct ofono_gprs *gprs)

Quoted 13 lines
src/gprs.c +6 -3
+             return TRUE;
+
+     return FALSE;
+}
+
  static void gprs_attached_update(struct ofono_gprs *gprs)
  {
      ofono_bool_t attached;
+     int status = gprs->status;
 
-     attached = gprs->driver_attached &&
-             (gprs->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
-                     gprs->status ==

NETWORK_REGISTRATION_STATUS_ROAMING);

src/gprs.c static void release_active_contexts(struct ofono_gprs *gprs) · line 1597

Quoted 10 lines
src/gprs.c +10 -0
+     if (on_lte(gprs))
+             /*
+              * For LTE we attached status reflects successful context
+              * activation.
+              * Since we in gprs_netreg_update not even try to attach
+              * to GPRS if we are running on LTE, we can on some modems
+              * expect the gprs status to be unknown. That must not
+              * result in detaching...
+              */
+             attached = have_active_contexts(gprs);
Quoted 3 lines

On LTE Attached should just be always True. Someone can correct me if I'm wrong, but a default context is a pre-requisite for E-UTRAN attachment.

I guess this is about race conditions, since we read back settings of the context,
so in theory I think we might not consider the context available yet. Should be
a very short period of time.
In netreg status we do not immediately change to attached in case of LTE, we require the context settings to have been read first.

Quoted 19 lines

src/gprs.c static void release_active_contexts(struct ofono_gprs *gprs)

Quoted 4 lines
src/gprs.c +3 -0
+     else
+             attached = gprs->driver_attached &&
+                     (status == NETWORK_REGISTRATION_STATUS_REGISTERED
||
> +                             status ==

NETWORK_REGISTRATION_STATUS_ROAMING);

src/gprs.c static void gprs_attached_update(struct

Quoted 4 lines
src/gprs.c +0 -0
      if (attached == gprs->attached)
              return;
@@ -1591,11 +1612,14 @@ static void gprs_attached_update(struct

ofono_gprs *gprs)

src/gprs.c static void gprs_attached_update(struct ofono_gprs *gprs) · line 1616

Quoted 6 lines
src/gprs.c +2 -1
      if (attached == FALSE) {
              release_active_contexts(gprs);
              gprs->bearer = -1;
-     } else if (have_active_contexts(gprs) == TRUE) {
+     } else if (have_active_contexts(gprs) == TRUE &&
+             !on_lte(gprs)) {
Quoted 3 lines

Not our style. See item M4. Might want to see if it fits on the previous line.

Will updat!

Quoted 58 lines

src/gprs.c static void gprs_attached_update(struct · line 1618

Quoted 3 lines
src/gprs.c +0 -0
              /*
               * Some times the context activates after a detach event

and

src/gprs.c static void gprs_attached_update(struct · line 1619

Quoted 1 line
src/gprs.c +0 -0
               * right before an attach. We close it to avoid unexpected

open

src/gprs.c static void gprs_attached_update(struct · line 1621

Quoted 2 lines
src/gprs.c +1 -0
               * contexts.
+              * Skip that for LTE since the condition to be attached on

LTE

src/gprs.c static void gprs_netreg_removed(struct ofono_gprs

Quoted 5 lines
src/gprs.c +1 -0
+              * is that a context gets activated
               */
              release_active_contexts(gprs);
              gprs->flags |= GPRS_FLAG_ATTACHED_UPDATE;
@@ -1660,15 +1684,6 @@ static void gprs_netreg_removed(struct ofono_gprs

*gprs)

src/gprs.c static void gprs_netreg_removed(struct ofono_gprs *gprs)

Quoted 7 lines
src/gprs.c +0 -4
      gprs_attached_update(gprs);
  }
 
-static gboolean on_lte(struct ofono_gprs *gprs)
-{
-     if (ofono_netreg_get_technology(gprs->netreg) ==
-                     ACCESS_TECHNOLOGY_EUTRAN &&

have_read_settings(gprs))

src/gprs.c void ofono_gprs_status_notify(struct ofono_gprs

Quoted 9 lines
src/gprs.c +0 -5
-             return TRUE;
-
-     return FALSE;
-}
-
  static void gprs_netreg_update(struct ofono_gprs *gprs)
  {
      ofono_bool_t attach;
@@ -2573,16 +2588,7 @@ void ofono_gprs_status_notify(struct ofono_gprs

*gprs, int status)

Quoted 8 lines
src/gprs.c +0 -5
      if (status != NETWORK_REGISTRATION_STATUS_REGISTERED &&
                      status != NETWORK_REGISTRATION_STATUS_ROAMING) {
-             /*
-              * For LTE we attached status reflects successful context
-              * activation.
-              * Since we in gprs_netreg_update not even try to attach
-              * to GPRS if we are running on LTE, we can on some modems

src/gprs.c void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)

Quoted 10 lines
src/gprs.c +1 -5
-              * expect the gprs status to be unknown. That must not
-              * result in detaching...
-              */
-             if (!on_lte(gprs))
-                     gprs_attached_update(gprs);
+             gprs_attached_update(gprs);
              return;
      }
 
 

Otherwise I'm fine moving the on_lte logic into gprs_attached_update itself...

Regards,
-Denis

#3 lore raw

Re: [PATCH 2/4] gprs: Always call gprs_attached_update on context deactivation.

In reply to Denis Kenzior

Hi Denis,

Den tors 15 aug. 2019 kl 22:41 skrev Denis Kenzior <[email protected]>:

Quoted 12 lines

Hi Richard,

Quoted 5 lines · richard.rojfors(a)gmail.com

From: Richard Röjfors <[email protected]>

Since its registered context is a condition for being attached when running LTE, we might need to update the attached state when a context is deactivated. Otherwise we might remain

Well, by definition if we're on LTE then we're attached. So I'm not quite sure what you mean here?

OK, maybe this is overkill. And about the order things are happening in reporting from the modem.

Quoted 5 lines
Quoted 4 lines

attached, and connection managers (at least connman) start to hammer us to connect a context, eventhough it happens automatically in LTE.

Quoted 8 lines

What happens automatically? Yes, it is true that you need a default context to attach to LTE. So activating a context is basically a part of the LTE attach procedure.

But that default context does not need to be an internet context (e.g. Verizon uses (or used to) use an ims context for this). So ConnMan still might need to activate an Internet context even if we're on LTE.

To do that wouldn't we need to be able to flag attached even without registered context for LTE?
Or will the modem not attach to 4G until the context is configured? I can not test that case with my modems.

Quoted 4 lines

I'm also not sure that the heuristic of 0 active contexts means not attached is a good one. Shouldn't you be using +CREG or +CEREG status for this?

As you say that is probably more correct :)
First I wanted to get things running with the current solution which uses an active
context as condition.

Quoted 36 lines

src/gprs.c void ofono_gprs_context_deactivated(struct

Quoted 10 lines
---
  src/gprs.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
src/gprs.c +0 -0
index 94d13f82..cb31e2d2 100644
@@ -2738,11 +2738,12 @@ void ofono_gprs_context_deactivated(struct

ofono_gprs_context *gc,

src/gprs.c void ofono_gprs_context_deactivated(struct · line 2738

Quoted 1 line
src/gprs.c +0 -0
       * If "Attached" property was about to be signalled as TRUE but

there

src/gprs.c void ofono_gprs_context_deactivated(struct · line 2739

Quoted 1 line
src/gprs.c +0 -0
       * were still active contexts, try again to signal "Attached"

property

src/gprs.c void ofono_gprs_context_deactivated(struct · line 2740

Quoted 1 line
src/gprs.c +0 -0
       * to registered applications after active contexts have been

released.

src/gprs.c void ofono_gprs_context_deactivated(struct · line 2742

Quoted 2 lines
src/gprs.c +2 -0
+      *
+      * ... or in the case of LTE where the attached state were a

registered

src/gprs.c void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc, · line 2749

Quoted 12 lines
src/gprs.c +3 -4
+      * context is a condition for being attached
       */
-     if (gc->gprs->flags & GPRS_FLAG_ATTACHED_UPDATE) {
-             gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
-             gprs_attached_update(gc->gprs);
-     }
+     gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
+     gprs_attached_update(gc->gprs);
  }
 
  int ofono_gprs_context_driver_register(

Regards,
-Denis

#4 lore raw

Re: [PATCH 2/4] gprs: Always call gprs_attached_update on context deactivation.

Hi Richard,

Quoted 14 lines

> attached, and connection managers (at least connman) start > to hammer us to connect a context, eventhough it happens > automatically in LTE.

What happens automatically?  Yes, it is true that you need a default context to attach to LTE.  So activating a context is basically a part of the LTE attach procedure.

But that default context does not need to be an internet context (e.g. Verizon uses (or used to) use an ims context for this). So ConnMan still
might need to activate an Internet context even if we're on LTE.

Quoted 4 lines

To do that wouldn't we need to be able to flag attached even without registered context for LTE?
Or will the modem not attach to 4G until the context is configured? I can not test that case with my modems.

It sort of depends on the configuration. But basically we will not get on LTE without a default bearer. The default bearer configuration can come from the modem itself, or actually from the network. That default bearer is essentially an active context. This is why gprs.c goes to the trouble of matching it against existing contexts, but if it isn't found, then adds a new one (which is supposed to be transient/temporary).

Typically, on a well-configured system, you'll have the default bearer setup via LongTermEvolution.DefaultAccessPointName and also provisioned in the provisioning database. But as I mentioned earlier, the default context doesn't have to be an internet one.

Regards,
-Denis

Quoted 48 lines

I'm also not sure that the heuristic of 0 active contexts means not attached is a good one.  Shouldn't you be using +CREG or +CEREG status for this?

As you say that is probably more correct :)
First I wanted to get things running with the current solution which uses an active
context as condition.

     > ---
     >   src/gprs.c | 9 +++++----
     >   1 file changed, 5 insertions(+), 4 deletions(-)
     >
     > diff --git a/src/gprs.c b/src/gprs.c
     > index 94d13f82..cb31e2d2 100644
     > --- a/src/gprs.c
     > +++ b/src/gprs.c
     > @@ -2738,11 +2738,12 @@ void
    ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
     >        * If "Attached" property was about to be signalled as TRUE
    but there
     >        * were still active contexts, try again to signal
    "Attached" property
     >        * to registered applications after active contexts have
    been released.
     > +      *
     > +      * ... or in the case of LTE where the attached state were
    a registered
     > +      * context is a condition for being attached
     >        */
     > -     if (gc->gprs->flags & GPRS_FLAG_ATTACHED_UPDATE) {
     > -             gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
     > -             gprs_attached_update(gc->gprs);
     > -     }
     > +     gc->gprs->flags &= ~GPRS_FLAG_ATTACHED_UPDATE;
     > +     gprs_attached_update(gc->gprs);
     >   }
     >
     >   int ofono_gprs_context_driver_register(
     >

    Regards,
    -Denis
#10 lore raw
In reply to Richard Röjfors

Hi Richard,

Quoted 22 lines · Richard Röjfors

Hi Denis,

Den tors 15 aug. 2019 kl 22:47 skrev Denis Kenzior <[email protected] <mailto:[email protected]>>:

Hi Richard,

On 8/14/19 1:24 PM, richard.rojfors(a)gmail.com <mailto:[email protected]> wrote:
> From: Richard Röjfors <[email protected]
<mailto:[email protected]>>
>
> Since we have a different condition for the attach state > when running on LTE, we should consider it in gprs_attached_update. > Previously it's done in some instances. But for instance if > the driver got detached from GPRS but now running on LTE with a > context up, we would be deattached.

So are you talking about a hand-over? Do we have logs to help visualize this?

Quoted 6 lines

Sorry I have no logs.
I think an example would be;
Let say we are registered on non-LTE, and GPRS do attach. Then we flip to LTE and if GPRS gets de-attached. We would brutally exit the attached state, since LTE is currently not considered in that code path.

Okay, so handover. It would be helpful to have logs to help visualize what is happening.

Quoted 55 lines

     > ---
     >   src/gprs.c | 52
    +++++++++++++++++++++++++++++-----------------------
     >   1 file changed, 29 insertions(+), 23 deletions(-)
     >
     > diff --git a/src/gprs.c b/src/gprs.c
     > index bba482cb..94d13f82 100644
     > --- a/src/gprs.c
     > +++ b/src/gprs.c
     > @@ -1571,13 +1571,34 @@ static void
    release_active_contexts(struct ofono_gprs *gprs)
     >       }
     >   }
     >
     > +static gboolean on_lte(struct ofono_gprs *gprs)
     > +{
     > +     if (ofono_netreg_get_technology(gprs->netreg) ==
     > +                     ACCESS_TECHNOLOGY_EUTRAN &&
    have_read_settings(gprs))
     > +             return TRUE;
     > +
     > +     return FALSE;
     > +}
     > +
     >   static void gprs_attached_update(struct ofono_gprs *gprs)
     >   {
     >       ofono_bool_t attached;
     > +     int status = gprs->status;
     >
     > -     attached = gprs->driver_attached &&
     > -             (gprs->status ==
    NETWORK_REGISTRATION_STATUS_REGISTERED ||
     > -                     gprs->status ==
    NETWORK_REGISTRATION_STATUS_ROAMING);
     > +     if (on_lte(gprs))
     > +             /*
     > +              * For LTE we attached status reflects successful
    context
     > +              * activation.
     > +              * Since we in gprs_netreg_update not even try to
    attach
     > +              * to GPRS if we are running on LTE, we can on some
    modems
     > +              * expect the gprs status to be unknown. That must not
     > +              * result in detaching...
     > +              */
     > +             attached = have_active_contexts(gprs);

    On LTE Attached should just be always True.  Someone can correct me if
    I'm wrong, but a default context is a pre-requisite for E-UTRAN
    attachment.
Quoted 7 lines

I guess this is about race conditions, since we read back settings of the context,
so in theory I think we might not consider the context available yet. Should be
a very short period of time.
In netreg status we do not immediately change to attached in case of LTE, we require the context settings to have been read first.

I think it makes sense to signal Attached right away in the case that we know we are on LTE. But I can accept your argument of not signaling Attached until the first context is active. That is likely more driven by ConMan not being updated for LTE, which likely won't work in the end.

Regards,
-Denis

#11 lore raw

Hi Denis,

Den fre 16 aug. 2019 kl 17:55 skrev Denis Kenzior <[email protected]>:

Quoted 34 lines

Hi Richard,

Quoted 7 lines · Richard Röjfors

Hi Denis,

Den tors 15 aug. 2019 kl 22:47 skrev Denis Kenzior <[email protected] <mailto:[email protected]>>:

Hi Richard,

Quoted 7 lines

On 8/14/19 1:24 PM, richard.rojfors(a)gmail.com <mailto:[email protected]> wrote:
> From: Richard Röjfors <[email protected]
<mailto:[email protected]>>
>
> Since we have a different condition for the attach state > when running on LTE, we should consider it in

gprs_attached_update.

Quoted 5 lines

> Previously it's done in some instances. But for instance if > the driver got detached from GPRS but now running on LTE with a > context up, we would be deattached.

So are you talking about a hand-over? Do we have logs to help

visualize

Quoted 9 lines

this?

Sorry I have no logs.
I think an example would be;
Let say we are registered on non-LTE, and GPRS do attach. Then we flip to LTE and if GPRS gets de-attached. We would brutally exit the attached state, since LTE is currently not considered in that code path.

Quoted 3 lines

Okay, so handover. It would be helpful to have logs to help visualize what is happening.

As I said, I'm afraid I have no logs for this. I tried to visualize how it could happen.

But anyway I think it makes more sense to "calculate" the attached state in one place,
(gprs_attached_update) and one of the places this gets called from is when GPRS detaches.

Quoted 66 lines
Quoted 39 lines


     > ---
     >   src/gprs.c | 52
    +++++++++++++++++++++++++++++-----------------------
     >   1 file changed, 29 insertions(+), 23 deletions(-)
     >
     > diff --git a/src/gprs.c b/src/gprs.c
     > index bba482cb..94d13f82 100644
     > --- a/src/gprs.c
     > +++ b/src/gprs.c
     > @@ -1571,13 +1571,34 @@ static void
    release_active_contexts(struct ofono_gprs *gprs)
     >       }
     >   }
     >
     > +static gboolean on_lte(struct ofono_gprs *gprs)
     > +{
     > +     if (ofono_netreg_get_technology(gprs->netreg) ==
     > +                     ACCESS_TECHNOLOGY_EUTRAN &&
    have_read_settings(gprs))
     > +             return TRUE;
     > +
     > +     return FALSE;
     > +}
     > +
     >   static void gprs_attached_update(struct ofono_gprs *gprs)
     >   {
     >       ofono_bool_t attached;
     > +     int status = gprs->status;
     >
     > -     attached = gprs->driver_attached &&
     > -             (gprs->status ==
    NETWORK_REGISTRATION_STATUS_REGISTERED ||
     > -                     gprs->status ==
    NETWORK_REGISTRATION_STATUS_ROAMING);
     > +     if (on_lte(gprs))
     > +             /*
Quoted 8 lines
     > +              * For LTE we attached status reflects successful
    context
     > +              * activation.
     > +              * Since we in gprs_netreg_update not even try to
    attach
     > +              * to GPRS if we are running on LTE, we can on some
    modems
     > +              * expect the gprs status to be unknown. That must

not

Quoted 5 lines

> + * result in detaching...
> + */
> + attached = have_active_contexts(gprs);

On LTE Attached should just be always True. Someone can correct me

if

Quoted 11 lines

I'm wrong, but a default context is a pre-requisite for E-UTRAN attachment.

I guess this is about race conditions, since we read back settings of the context,
so in theory I think we might not consider the context available yet. Should be
a very short period of time.
In netreg status we do not immediately change to attached in case of LTE, we require the context settings to have been read first.

Quoted 5 lines

I think it makes sense to signal Attached right away in the case that we know we are on LTE. But I can accept your argument of not signaling Attached until the first context is active. That is likely more driven by ConMan not being updated for LTE, which likely won't work in the end.

And I would like to add, that this how things are today, its nothing I have or
inteded to change.
I just want to make sure we don't get deattached
because we miss to check for LTE in some places in the code.

#5 lore raw

Re: [PATCH 2/4] gprs: Always call gprs_attached_update on context deactivation.

In reply to Denis Kenzior

Hi Denis,

Den fre 16 aug. 2019 kl 17:42 skrev Denis Kenzior <[email protected]>:

Quoted 30 lines

Hi Richard,

Quoted 6 lines

> attached, and connection managers (at least connman) start > to hammer us to connect a context, eventhough it happens > automatically in LTE.

What happens automatically? Yes, it is true that you need a default context to attach to LTE. So activating a context is basically a

part

Quoted 3 lines

of the LTE attach procedure.

But that default context does not need to be an internet context

(e.g.

Quoted 9 lines

Verizon uses (or used to) use an ims context for this). So ConnMan still
might need to activate an Internet context even if we're on LTE.

To do that wouldn't we need to be able to flag attached even without registered context for LTE?
Or will the modem not attach to 4G until the context is configured? I can not test that case with my modems.

It sort of depends on the configuration. But basically we will not get on LTE without a default bearer. The default bearer configuration can come from the modem itself, or actually from the network. That default bearer is essentially an active context. This is why gprs.c goes to the trouble of matching it against existing contexts, but if it isn't found, then adds a new one (which is supposed to be transient/temporary).

Quoted 5 lines

Typically, on a well-configured system, you'll have the default bearer setup via LongTermEvolution.DefaultAccessPointName and also provisioned in the provisioning database. But as I mentioned earlier, the default context doesn't have to be an internet one.

For the modem I use, it would be a bit messy to update the default APN on the fly,
because it requires to turn off the radio to change that. We have written it into
non volatile memory beforehand.

But anyway, you have convinced me so I think we can skip this patch, I guess its just the matter of the order things happen and the time span will be very short.

--Richard

#12 lore raw
In reply to Richard Röjfors

Hi Richard,

Quoted 2 lines

As I said, I'm afraid I have no logs for this. I tried to visualize how it could happen.

Sorry for the repeat. Just take it as a strong hint for the "next time" :)

Quoted 5 lines

But anyway I think it makes more sense to "calculate" the attached state in one place,
(gprs_attached_update) and one of the places this gets called from is when GPRS detaches.

Care to resend a cleaned up patch? I'm fine taking at least 1/4.

Regards,
-Denis

#13 lore raw

Hi Denis,

Den mån 19 aug. 2019 kl 21:48 skrev Denis Kenzior <[email protected]>:

Quoted 7 lines

Hi Richard,

Quoted 2 lines

As I said, I'm afraid I have no logs for this. I tried to visualize how it could happen.

Sorry for the repeat. Just take it as a strong hint for the "next time" :)

I got the hint ;-)

Quoted 10 lines
Quoted 6 lines

But anyway I think it makes more sense to "calculate" the attached state in one place,
(gprs_attached_update) and one of the places this gets called from is when GPRS detaches.

Care to resend a cleaned up patch? I'm fine taking at least 1/4.

Will do. I think we can skip 2/4. But I think 3 and 4/4 should be applied

too. But we can start with the first.

--Richard