Skip to contentSkip to conversation

netreg, gprs: Use -1 as netreg status during init.

PATCH In review [email protected] 2 participants 5 messages Aug 1, 2019 – Aug 2, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netreg, gprs: Use -1 as netreg status during init.

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

Previously the valid "unknown" registration 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.
And then gprs could make faulty actions.
Instead we set the status to -1 when the drivers supports fetching the status manually, which is done during startup. During the time the status is -1, gprs postpones actions until the status is valid (>= 0).

---
 src/gprs.c    | 12 ++++++++++--
 src/network.c |  5 ++++-
 2 files changed, 14 insertions(+), 3 deletions(-)
src/gprs.c +10 -2
index bdb8c8a2..07802c36 100644
@@ -1661,6 +1661,14 @@ 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 &&
@@ -3083,8 +3091,8 @@ struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem,
 		break;
 	}
 
-	gprs->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
-	gprs->netreg_status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
+	gprs->status = -1;
+	gprs->netreg_status = -1;
 	gprs->used_pids = l_uintset_new(MAX_CONTEXTS);
 
 	return gprs;
src/network.c +4 -1
index 2824eae6..1db01bcf 100644
@@ -1874,7 +1874,7 @@ struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem,
 	if (netreg == NULL)
 		return NULL;
 
-	netreg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
+	netreg->status = -1;
 	netreg->location = -1;
 	netreg->cellid = -1;
 	netreg->technology = -1;
@@ -1893,6 +1893,9 @@ struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem,
 			continue;
 
 		netreg->driver = drv;
+		/* Check if we can init the status properly using the driver */
+		if (netreg->driver->registration_status == NULL)
+			netreg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
 		break;
 	}
 
Signature · 1 line
2.20.1
#1 lore raw

Hi Richard,

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

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

Previously the valid "unknown" registration 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.
And then gprs could make faulty actions.
Instead we set the status to -1 when the drivers supports fetching the status manually, which is done during startup. During the time the status is -1, gprs postpones actions until the status is valid (>= 0).

---
  src/gprs.c    | 12 ++++++++++--
  src/network.c |  5 ++++-
  2 files changed, 14 insertions(+), 3 deletions(-)
src/gprs.c +0 -0
index bdb8c8a2..07802c36 100644

src/gprs.c static void gprs_netreg_update(struct ofono_gprs *gprs) · line 1668

Quoted 8 lines
src/gprs.c +5 -0
@@ -1661,6 +1661,14 @@ 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.
+	 */

Note doc/coding-style.txt item M2 for our commenting style...

src/gprs.c struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem, · line 3094

Quoted 13 lines
src/gprs.c +4 -2
+	if (gprs->netreg_status < 0)
+		return;
+
  	attach = gprs->netreg_status == NETWORK_REGISTRATION_STATUS_REGISTERED;
 
  	attach = attach || (gprs->roaming_allowed &&
@@ -3083,8 +3091,8 @@ struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem,
  		break;
  	}
 
-	gprs->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
-	gprs->netreg_status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
+	gprs->status = -1;

Why do you need to mess with this? It seems to be not used

src/gprs.c struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem, · line 3097

Quoted 3 lines
src/gprs.c +1 -0
+	gprs->netreg_status = -1;
  	gprs->used_pids = l_uintset_new(MAX_CONTEXTS);
 

Wouldn't changes to gprs.c be sufficient, without touching netreg.c?

src/network.c struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem, · line 1877

Quoted 11 lines
src/gprs.c +0 -0
  	return gprs;
src/network.c +1 -1
index 2824eae6..1db01bcf 100644
@@ -1874,7 +1874,7 @@ struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem,
  	if (netreg == NULL)
  		return NULL;
 
-	netreg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
+	netreg->status = -1;

Okay, but a minor problem with this is that there now exists a brief moment in type where the Status property has a weird value...

Quoted 5 lines
src/network.c +0 -0
  	netreg->location = -1;
  	netreg->cellid = -1;
  	netreg->technology = -1;

src/network.c struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem, · line 1901

Quoted 9 lines
src/network.c +3 -0
@@ -1893,6 +1893,9 @@ struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem,
  			continue;
 
  		netreg->driver = drv;
+		/* Check if we can init the status properly using the driver */
+		if (netreg->driver->registration_status == NULL)
+			netreg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
  		break;
  	}
 

Regards,
-Denis

#2 lore raw

Hi Denis,

Den fre 2 aug. 2019 kl 13:04 skrev Denis Kenzior <[email protected]>:

Quoted 30 lines

Hi Richard,

src/gprs.c static void gprs_netreg_update(struct ofono_gprs

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

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

Previously the valid "unknown" registration 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.
And then gprs could make faulty actions.
Instead we set the status to -1 when the drivers supports fetching the status manually, which is done during startup. During the time the status is -1, gprs postpones actions until the status is valid (>= 0).

---
  src/gprs.c    | 12 ++++++++++--
  src/network.c |  5 ++++-
  2 files changed, 14 insertions(+), 3 deletions(-)
src/gprs.c +0 -0
index bdb8c8a2..07802c36 100644
@@ -1661,6 +1661,14 @@ static void gprs_netreg_update(struct ofono_gprs

*gprs)

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

Quoted 5 lines
src/gprs.c +2 -0
  {
      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
Quoted 8 lines

yet.

src/gprs.c static void gprs_netreg_update(struct ofono_gprs · line 1666

Quoted 1 line
src/gprs.c +1 -0
+      * The only reason for not having a valid status is basically

during

src/gprs.c static void gprs_netreg_update(struct ofono_gprs *gprs) · line 1668

Quoted 2 lines
src/gprs.c +2 -0
+      * startup while the netreg atom is fetching the status.
+      */

Note doc/coding-style.txt item M2 for our commenting style...

Will fix the comment!

Quoted 10 lines

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

Quoted 5 lines
src/gprs.c +3 -0
+     if (gprs->netreg_status < 0)
+             return;
+
      attach = gprs->netreg_status ==

NETWORK_REGISTRATION_STATUS_REGISTERED;

src/gprs.c struct ofono_gprs *ofono_gprs_create(struct

Quoted 3 lines
src/gprs.c +0 -0
      attach = attach || (gprs->roaming_allowed &&
@@ -3083,8 +3091,8 @@ struct ofono_gprs *ofono_gprs_create(struct

ofono_modem *modem,

Quoted 9 lines

src/gprs.c struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem, · line 3094

Quoted 6 lines
src/gprs.c +1 -2
              break;
      }
 
-     gprs->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
-     gprs->netreg_status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
+     gprs->status = -1;

Why do you need to mess with this? It seems to be not used

This was just of convenience reasons so it would look the same for gprs and netreg status.

Quoted 7 lines

src/gprs.c struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem, · line 3097

Quoted 4 lines
src/gprs.c +1 -0
+     gprs->netreg_status = -1;
      gprs->used_pids = l_uintset_new(MAX_CONTEXTS);
 

Wouldn't changes to gprs.c be sufficient, without touching netreg.c?

No unfortunately not. gprs reads the netreg status when it attaches to the atom. Which would be unknown if we do not touch netreg.c.
.. and unknown is a valid status which can not be distinguished from "not yet updated".

Quoted 8 lines

src/network.c struct ofono_netreg *ofono_netreg_create(struct

Quoted 7 lines
src/gprs.c +0 -0
      return gprs;
src/network.c +0 -0
index 2824eae6..1db01bcf 100644
@@ -1874,7 +1874,7 @@ struct ofono_netreg *ofono_netreg_create(struct

ofono_modem *modem,

Quoted 9 lines

src/network.c struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem, · line 1877

Quoted 5 lines
src/network.c +1 -1
      if (netreg == NULL)
              return NULL;
 
-     netreg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
+     netreg->status = -1;

Okay, but a minor problem with this is that there now exists a brief moment in type where the Status property has a weird value...

I looked at this, and most statuses, even some defined results as unknown. Any unhandled values as negative would do that too.
If you are refering to the D-Bus property?

Quoted 6 lines

src/network.c struct ofono_netreg *ofono_netreg_create(struct

Quoted 5 lines
src/network.c +0 -0
      netreg->location = -1;
      netreg->cellid = -1;
      netreg->technology = -1;
@@ -1893,6 +1893,9 @@ struct ofono_netreg *ofono_netreg_create(struct

ofono_modem *modem,

Quoted 13 lines

src/network.c struct ofono_netreg *ofono_netreg_create(struct ofono_modem *modem,

Quoted 4 lines
src/network.c +1 -0
                      continue;
 
              netreg->driver = drv;
+             /* Check if we can init the status properly using the

driver */

src/network.c struct ofono_netreg *ofono_netreg_create(struct · line 1898

Quoted 2 lines
src/network.c +2 -0
+             if (netreg->driver->registration_status == NULL)
+                     netreg->status =

NETWORK_REGISTRATION_STATUS_UNKNOWN;

Quoted 4 lines
src/network.c +0 -0
              break;
      }
 

--Richard

#3 lore raw

Hi Richard,

Quoted 11 lines
     > +     gprs->netreg_status = -1;
     >       gprs->used_pids = l_uintset_new(MAX_CONTEXTS);
     >

    Wouldn't changes to gprs.c be sufficient, without touching netreg.c?

No unfortunately not. gprs reads the netreg status when it attaches to the atom. Which would be unknown if we do not touch netreg.c. .. and unknown is a valid status which can not be distinguished from "not yet updated".

Hmm, okay. But then, can't you set gprs->netreg_status to -1 inside netreg_watch and just wait until netreg_status_changed to get it set properly?

That seems to be your real culprit, the gprs->netreg_status assignment from ofono_netreg_get_status()

Quoted 19 lines

     >       return gprs;
     > diff --git a/src/network.c b/src/network.c
     > index 2824eae6..1db01bcf 100644
     > --- a/src/network.c
     > +++ b/src/network.c
     > @@ -1874,7 +1874,7 @@ struct ofono_netreg
    *ofono_netreg_create(struct ofono_modem *modem,
     >       if (netreg == NULL)
     >               return NULL;
     >
     > -     netreg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
     > +     netreg->status = -1;

    Okay, but a minor problem with this is that there now exists a brief
    moment in type where the Status property has a weird value...
Quoted 3 lines

I looked at this, and most statuses, even some defined results as unknown. Any unhandled values as negative would do that too. If you are refering to the D-Bus property?

Yes. Most of the time -1 simply means the property is omitted. In this case that is not actually what happens. Refer to src/common.c registration_status_to_string()

Regards,
-Denis

#4 lore raw

Hi Denis,

Den fre 2 aug. 2019 kl 13:39 skrev Denis Kenzior <[email protected]>:

Quoted 9 lines

Hi Richard,

Quoted 7 lines
     > +     gprs->netreg_status = -1;
     >       gprs->used_pids = l_uintset_new(MAX_CONTEXTS);
     >

    Wouldn't changes to gprs.c be sufficient, without touching netreg.c?
Quoted 9 lines
Quoted 4 lines

No unfortunately not. gprs reads the netreg status when it attaches to the atom. Which would be unknown if we do not touch netreg.c. .. and unknown is a valid status which can not be distinguished from "not yet updated".

Hmm, okay. But then, can't you set gprs->netreg_status to -1 inside netreg_watch and just wait until netreg_status_changed to get it set properly?

That would work in my case.

I was just worried in case any driver would have
updated netreg with status before calling ofono_netreg_register, then we would not get the status since there wont be any initial callback. But if that is not allowed/happens anywhere I agree that its better.

Quoted 23 lines

That seems to be your real culprit, the gprs->netreg_status assignment from ofono_netreg_get_status()

Quoted 19 lines

     >       return gprs;
     > diff --git a/src/network.c b/src/network.c
     > index 2824eae6..1db01bcf 100644
     > --- a/src/network.c
     > +++ b/src/network.c
     > @@ -1874,7 +1874,7 @@ struct ofono_netreg
    *ofono_netreg_create(struct ofono_modem *modem,
     >       if (netreg == NULL)
     >               return NULL;
     >
     > -     netreg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
     > +     netreg->status = -1;

    Okay, but a minor problem with this is that there now exists a brief
    moment in type where the Status property has a weird value...
Quoted 9 lines
Quoted 3 lines

I looked at this, and most statuses, even some defined results as unknown. Any unhandled values as negative would do that too. If you are refering to the D-Bus property?

Yes. Most of the time -1 simply means the property is omitted. In this case that is not actually what happens. Refer to src/common.c registration_status_to_string()

--Richard