Re: [PATCH 4/4] qmimodem: get LTE default bearer APN from modem

2018-03-02 Thread Jonas Bonn

On 03/01/2018 11:30 PM, Reinhard Speyerer wrote:


Hi Jonas,

if you only need to know the APN and the IP version assigned by the network
for the default bearer you could try to use WDSGetLTEAttachParameters
(WDS msgid 0x0085) instead of using WDSStartNetworkInterface followed by
WDSGetCurrentSettings.


Thanks, Reinhard!

That information was invaluable.  I've been looking for that for ages!

I've reworked my patches using your suggestion and things work _much_ 
better.


/Jonas



Regards,
Reinhard
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono



___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 4/4] qmimodem: get LTE default bearer APN from modem

2018-03-01 Thread Reinhard Speyerer
On Thu, Mar 01, 2018 at 04:43:22PM +0100, Jonas Bonn wrote:
> On 03/01/2018 04:27 PM, Denis Kenzior wrote:
> > Hi Jonas,
> > 
> > On 03/01/2018 09:20 AM, Jonas Bonn wrote:
> > > On 03/01/2018 04:02 PM, Denis Kenzior wrote:
> > > > Hi Jonas,
> > > > 
> > > > On 03/01/2018 04:48 AM, Jonas Bonn wrote:
> > > > > When an LTE modem registers with the network, a default bearer is
> > > > > automatically established.  The APN used for this bearer is taken from
> > > > > whatever default settings the modem has.
> > > > > 
> > > > > In order to properly set up the ofono context, we need to find out 
> > > > > what
> > > > > APN the modem has used when negotiating this bearer.  Ideally, we 
> > > > > would
> > > > > want to query the 'current settings', but those aren't available until
> > > > > start_net has been called and that's done in the gprs-context atom.  
> > > > > As
> > > > > such, we query the 'default settings' here under the assumption that
> > > > > that's what the modem will have used.
> > > > 
> > > > I don't recall exactly, but from what I remember the default
> > > > attach APN is not guaranteed to be honored by the operator.  So
> > > > the default attach settings used for the actual active context
> > > > might be different.  It might be better to query those instead.
> > > 
> > > So, this becomes quite messy:
> > > 
> > > Getting "current settings" does not succeed until after we have
> > > called start_net.  This is done in the gprs-context atom as part of
> > > read_settings() for LTE and shares a bunch of code with
> > > activate_primary() that also calls start_net.
> > > 
> > > We can move the call of start_net to the gprs atom if we must, but
> > > we end up duplicating a whole bunch of code.  That's why I wanted to
> > > just grab the APN from the default settings in the GPRS atom, call
> > > cid_activated(), and then wait for read_settings() to be called
> > > before invoking start_net and then getting the rest of the settings.
> > > 
> > 
> > 3GPP extended +CGDCONT specifically for this case.  Does QMI have
> > anything similar?
> 
> Not that I am able to ascertain.  I'm hoping somebody here can tell me what
> that would be...
> 
> For +CGDCONT you effectively have an event saying that a 'transient' context
> has been activated.  There's nothing in the QMI protocol that resembles
> this.  We jsut get "network registered" and then we need to understand that
> there's an underlying bearer, call start_net (for whatever reason, despite
> the net effectively being started already), and then query the settings.
> The heuristic we have is (network_registered && tech==LTE)... if there
> something better, I'd love to know!

Hi Jonas,

if you only need to know the APN and the IP version assigned by the network
for the default bearer you could try to use WDSGetLTEAttachParameters
(WDS msgid 0x0085) instead of using WDSStartNetworkInterface followed by
WDSGetCurrentSettings.

Regards,
Reinhard
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 4/4] qmimodem: get LTE default bearer APN from modem

2018-03-01 Thread Jonas Bonn

On 03/01/2018 04:27 PM, Denis Kenzior wrote:

Hi Jonas,

On 03/01/2018 09:20 AM, Jonas Bonn wrote:

On 03/01/2018 04:02 PM, Denis Kenzior wrote:

Hi Jonas,

On 03/01/2018 04:48 AM, Jonas Bonn wrote:

When an LTE modem registers with the network, a default bearer is
automatically established.  The APN used for this bearer is taken from
whatever default settings the modem has.

In order to properly set up the ofono context, we need to find out what
APN the modem has used when negotiating this bearer.  Ideally, we would
want to query the 'current settings', but those aren't available until
start_net has been called and that's done in the gprs-context atom.  As
such, we query the 'default settings' here under the assumption that
that's what the modem will have used.


I don't recall exactly, but from what I remember the default attach 
APN is not guaranteed to be honored by the operator.  So the default 
attach settings used for the actual active context might be 
different.  It might be better to query those instead.


So, this becomes quite messy:

Getting "current settings" does not succeed until after we have called 
start_net.  This is done in the gprs-context atom as part of 
read_settings() for LTE and shares a bunch of code with 
activate_primary() that also calls start_net.


We can move the call of start_net to the gprs atom if we must, but we 
end up duplicating a whole bunch of code.  That's why I wanted to just 
grab the APN from the default settings in the GPRS atom, call 
cid_activated(), and then wait for read_settings() to be called before 
invoking start_net and then getting the rest of the settings.




3GPP extended +CGDCONT specifically for this case.  Does QMI have 
anything similar?


Not that I am able to ascertain.  I'm hoping somebody here can tell me 
what that would be...


For +CGDCONT you effectively have an event saying that a 'transient' 
context has been activated.  There's nothing in the QMI protocol that 
resembles this.  We jsut get "network registered" and then we need to 
understand that there's an underlying bearer, call start_net (for 
whatever reason, despite the net effectively being started already), and 
then query the settings.  The heuristic we have is (network_registered 
&& tech==LTE)... if there something better, I'd love to know!


/Jonas
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 4/4] qmimodem: get LTE default bearer APN from modem

2018-03-01 Thread Denis Kenzior

Hi Jonas,

On 03/01/2018 09:20 AM, Jonas Bonn wrote:

On 03/01/2018 04:02 PM, Denis Kenzior wrote:

Hi Jonas,

On 03/01/2018 04:48 AM, Jonas Bonn wrote:

When an LTE modem registers with the network, a default bearer is
automatically established.  The APN used for this bearer is taken from
whatever default settings the modem has.

In order to properly set up the ofono context, we need to find out what
APN the modem has used when negotiating this bearer.  Ideally, we would
want to query the 'current settings', but those aren't available until
start_net has been called and that's done in the gprs-context atom.  As
such, we query the 'default settings' here under the assumption that
that's what the modem will have used.


I don't recall exactly, but from what I remember the default attach 
APN is not guaranteed to be honored by the operator.  So the default 
attach settings used for the actual active context might be 
different.  It might be better to query those instead.


So, this becomes quite messy:

Getting "current settings" does not succeed until after we have called 
start_net.  This is done in the gprs-context atom as part of 
read_settings() for LTE and shares a bunch of code with 
activate_primary() that also calls start_net.


We can move the call of start_net to the gprs atom if we must, but we 
end up duplicating a whole bunch of code.  That's why I wanted to just 
grab the APN from the default settings in the GPRS atom, call 
cid_activated(), and then wait for read_settings() to be called before 
invoking start_net and then getting the rest of the settings.




3GPP extended +CGDCONT specifically for this case.  Does QMI have 
anything similar?





+    struct qmi_device* dev;
  struct qmi_service *nas;
+    struct qmi_service *wds;
+    unsigned int last_auto_context_id;


Just a nitpick, but why do you have the '*' in different places here?


Because I"m terribly inconsistent with my placement of the '*'...



:)

Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 4/4] qmimodem: get LTE default bearer APN from modem

2018-03-01 Thread Jonas Bonn

On 03/01/2018 04:02 PM, Denis Kenzior wrote:

Hi Jonas,

On 03/01/2018 04:48 AM, Jonas Bonn wrote:

When an LTE modem registers with the network, a default bearer is
automatically established.  The APN used for this bearer is taken from
whatever default settings the modem has.

In order to properly set up the ofono context, we need to find out what
APN the modem has used when negotiating this bearer.  Ideally, we would
want to query the 'current settings', but those aren't available until
start_net has been called and that's done in the gprs-context atom.  As
such, we query the 'default settings' here under the assumption that
that's what the modem will have used.


I don't recall exactly, but from what I remember the default attach APN 
is not guaranteed to be honored by the operator.  So the default attach 
settings used for the actual active context might be different.  It 
might be better to query those instead.


So, this becomes quite messy:

Getting "current settings" does not succeed until after we have called 
start_net.  This is done in the gprs-context atom as part of 
read_settings() for LTE and shares a bunch of code with 
activate_primary() that also calls start_net.


We can move the call of start_net to the gprs atom if we must, but we 
end up duplicating a whole bunch of code.  That's why I wanted to just 
grab the APN from the default settings in the GPRS atom, call 
cid_activated(), and then wait for read_settings() to be called before 
invoking start_net and then getting the rest of the settings.




+    struct qmi_device* dev;
  struct qmi_service *nas;
+    struct qmi_service *wds;
+    unsigned int last_auto_context_id;


Just a nitpick, but why do you have the '*' in different places here?


Because I"m terribly inconsistent with my placement of the '*'...


+error:
+    if (apn) {
+    if (!data->last_auto_context_id) {
+    data->last_auto_context_id = 1;
+    ofono_gprs_cid_activated(gprs, 1, apn);
+    }


Why is a success path under an error: label?  This really should be 
reworked to be more readable.


Yeah, I can see how that looks odd...

/Jonas
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 4/4] qmimodem: get LTE default bearer APN from modem

2018-03-01 Thread Denis Kenzior

Hi Jonas,

On 03/01/2018 04:48 AM, Jonas Bonn wrote:

When an LTE modem registers with the network, a default bearer is
automatically established.  The APN used for this bearer is taken from
whatever default settings the modem has.

In order to properly set up the ofono context, we need to find out what
APN the modem has used when negotiating this bearer.  Ideally, we would
want to query the 'current settings', but those aren't available until
start_net has been called and that's done in the gprs-context atom.  As
such, we query the 'default settings' here under the assumption that
that's what the modem will have used.


I don't recall exactly, but from what I remember the default attach APN 
is not guaranteed to be honored by the operator.  So the default attach 
settings used for the actual active context might be different.  It 
might be better to query those instead.




If we can't get the APN, we do what the AT driver does:  pretend the
bearer wasn't established.  This is a reasonable fallback, currently,
because connman can't handle zero-length APN's anyway; the previous
approach of setting the APN to 'automatic' breaks connman badly when it
needs to switch between LTE and non-LTE networks.
---
  drivers/qmimodem/gprs.c | 90 -
  1 file changed, 82 insertions(+), 8 deletions(-)

diff --git a/drivers/qmimodem/gprs.c b/drivers/qmimodem/gprs.c
index a80d55fe..567e8925 100644
--- a/drivers/qmimodem/gprs.c
+++ b/drivers/qmimodem/gprs.c
@@ -29,12 +29,16 @@
  
  #include "qmi.h"

  #include "nas.h"
+#include "wds.h"
  
  #include "src/common.h"

  #include "qmimodem.h"
  
  struct gprs_data {

+   struct qmi_device* dev;
struct qmi_service *nas;
+   struct qmi_service *wds;
+   unsigned int last_auto_context_id;


Just a nitpick, but why do you have the '*' in different places here?


  };
  
  static bool extract_ss_info(struct qmi_result *result, int *status, int *tech)

@@ -64,8 +68,57 @@ static bool extract_ss_info(struct qmi_result *result, int 
*status, int *tech)
return true;
  }
  
+static void get_default_settings_cb(struct qmi_result *result, void *user_data)

+{
+   struct ofono_gprs* gprs = user_data;
+   struct gprs_data *data = ofono_gprs_get_data(gprs);
+   char* apn = NULL;
+   uint16_t error;
+
+   DBG("");
+
+   if (qmi_result_set_error(result, )) {
+   ofono_error("Failed to query default settings: %hd", error);
+   goto error;
+   }
+
+   apn = qmi_result_get_string(result, QMI_WDS_RESULT_APN);
+   if (!apn) {
+   DBG("Default profile has no APN setting");
+   }
+
+error:
+   if (apn) {
+   if (!data->last_auto_context_id) {
+   data->last_auto_context_id = 1;
+   ofono_gprs_cid_activated(gprs, 1, apn);
+   }


Why is a success path under an error: label?  This really should be 
reworked to be more readable.



+   } else {
+   ofono_warn("LTE context activated but APN missing");
+   }
+}
+


Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 4/4] qmimodem: get LTE default bearer APN from modem

2018-03-01 Thread Jonas Bonn
When an LTE modem registers with the network, a default bearer is
automatically established.  The APN used for this bearer is taken from
whatever default settings the modem has.

In order to properly set up the ofono context, we need to find out what
APN the modem has used when negotiating this bearer.  Ideally, we would
want to query the 'current settings', but those aren't available until
start_net has been called and that's done in the gprs-context atom.  As
such, we query the 'default settings' here under the assumption that
that's what the modem will have used.

If we can't get the APN, we do what the AT driver does:  pretend the
bearer wasn't established.  This is a reasonable fallback, currently,
because connman can't handle zero-length APN's anyway; the previous
approach of setting the APN to 'automatic' breaks connman badly when it
needs to switch between LTE and non-LTE networks.
---
 drivers/qmimodem/gprs.c | 90 -
 1 file changed, 82 insertions(+), 8 deletions(-)

diff --git a/drivers/qmimodem/gprs.c b/drivers/qmimodem/gprs.c
index a80d55fe..567e8925 100644
--- a/drivers/qmimodem/gprs.c
+++ b/drivers/qmimodem/gprs.c
@@ -29,12 +29,16 @@
 
 #include "qmi.h"
 #include "nas.h"
+#include "wds.h"
 
 #include "src/common.h"
 #include "qmimodem.h"
 
 struct gprs_data {
+   struct qmi_device* dev;
struct qmi_service *nas;
+   struct qmi_service *wds;
+   unsigned int last_auto_context_id;
 };
 
 static bool extract_ss_info(struct qmi_result *result, int *status, int *tech)
@@ -64,8 +68,57 @@ static bool extract_ss_info(struct qmi_result *result, int 
*status, int *tech)
return true;
 }
 
+static void get_default_settings_cb(struct qmi_result *result, void *user_data)
+{
+   struct ofono_gprs* gprs = user_data;
+   struct gprs_data *data = ofono_gprs_get_data(gprs);
+   char* apn = NULL;
+   uint16_t error;
+
+   DBG("");
+
+   if (qmi_result_set_error(result, )) {
+   ofono_error("Failed to query default settings: %hd", error);
+   goto error;
+   }
+
+   apn = qmi_result_get_string(result, QMI_WDS_RESULT_APN);
+   if (!apn) {
+   DBG("Default profile has no APN setting");
+   }
+
+error:
+   if (apn) {
+   if (!data->last_auto_context_id) {
+   data->last_auto_context_id = 1;
+   ofono_gprs_cid_activated(gprs, 1, apn);
+   }
+   } else {
+   ofono_warn("LTE context activated but APN missing");
+   }
+}
+
+/*
+ * When an LTE default bearer is established, we need to callback into the
+ * ofono core to let it know; at this point, we are interested in the
+ * finding out what APN is in use so we try to query that first
+ */
+static void get_cid_and_apn(struct ofono_gprs* gprs)
+{
+   struct gprs_data *data = ofono_gprs_get_data(gprs);
+
+   DBG("");
+
+   if (qmi_service_send(data->wds, 0x2c, NULL,
+   get_default_settings_cb, gprs, NULL) > 0)
+   return;
+
+   ofono_warn("Unable to query LTE APN... will not activate context");
+}
+
 static int handle_ss_info(struct qmi_result *result, struct ofono_gprs *gprs)
 {
+   struct gprs_data *data = ofono_gprs_get_data(gprs);
int status;
int tech;
 
@@ -74,17 +127,17 @@ static int handle_ss_info(struct qmi_result *result, 
struct ofono_gprs *gprs)
if (!extract_ss_info(result, , ))
return -1;
 
-   if (status == NETWORK_REGISTRATION_STATUS_REGISTERED)
+   if (status == NETWORK_REGISTRATION_STATUS_REGISTERED) {
if (tech == ACCESS_TECHNOLOGY_EUTRAN) {
/* On LTE we are effectively always attached; and
 * the default bearer is established as soon as the
 * network is joined.
 */
-   /* FIXME: query default profile number and APN
-* instead of assuming profile 1 and ""
-*/
-   ofono_gprs_cid_activated(gprs, 1 , "automatic");
+   get_cid_and_apn(gprs);
}
+   } else {
+   data->last_auto_context_id = 0;
+   }
 
return status;
 }
@@ -198,7 +251,7 @@ static void qmi_attached_status(struct ofono_gprs *gprs,
g_free(cbd);
 }
 
-static void create_nas_cb(struct qmi_service *service, void *user_data)
+static void create_wds_cb(struct qmi_service *service, void *user_data)
 {
struct ofono_gprs *gprs = user_data;
struct gprs_data *data = ofono_gprs_get_data(gprs);
@@ -206,12 +259,12 @@ static void create_nas_cb(struct qmi_service *service, 
void *user_data)
DBG("");
 
if (!service) {
-   ofono_error("Failed to request NAS service");
+   ofono_error("Failed to request WDS service");