Skip to contentSkip to conversation

QMI LTE series

PATCH In review Jonas Bonn 2 participants 6 messages Apr 29, 2017 – May 1, 2017

lore
Share & tools
lore

Jonas Bonn

author
#0 lore raw

v5 cover QMI LTE series

Changes since v4:

* Address feedback from Denis
* Lots of testing; this is robust against loss of network connectivity and transitions across technologies.
* Dropped LTE atom for now since it's not doing anything interesting currently... I'll resend it separately.

Original cover letter follows:

LTE is different from other 'GPRS' technologies in that a default bearer always gets set up when the modem registers to the network. Ofono has some support for this and this series tries to set this up for QMI modems.

The key to understanding this series is to understand that QMI modems do not automatically enable the network interface when connecting to an LTE network, even though the default bearer is already set up. A call to "start network" needs to be made in order to allow packets to flow. So the jist of this series is:

i) detect network registration to LTE network ii) call ofono_gprs_cid_activated
iii) in read_settings, start by calling "start network"

...and then there are some other adjustments in the series to make this all work.

I've tested this with my EC21, both on LTE and UMTS networks. It all seems to work, including moving out of network connectivity and bringing the modem repeatedly online/offline.

One open question at this point:

* What happens if the connection manager calls deactivate_context on the default bearer context? I don't see that any other drivers guard against this, and the QMI driver will happily stop the network interface even though the default bearer is still up in the background.

Jonas Bonn (4):
qmi: watch packet status for spontaneous disconnection only
qmi: use shared services
qmi: use named status values
qmi: activate default bearer context for LTE networks

 drivers/qmimodem/gprs-context.c         | 12 ++++--
 drivers/qmimodem/gprs.c                 | 72 +++++++++++++++++++++++++--------
 drivers/qmimodem/network-registration.c |  2 +-
 drivers/qmimodem/radio-settings.c       |  2 +-
 4 files changed, 66 insertions(+), 22 deletions(-)
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH v5 1/4 qmi: watch packet status for spontaneous disconnection only

There are three principal ways for a context to become disconnected:

i) deactivate_primary() is called
ii) the network registration is lost and the context is cleaned up via _detach_shutdown() (via release_all_contexts())
iii) the network decides to disconnect the context

We need to watch the packet status in order to detect case iii). For case i) and ii), stop_net will be called, the pkt_handle will be cleared, and subsequent packet status notifications be ignored.

This patch makes it so that the packet status "disconnected" event is only propagated when the pkt_handle has not been cleared, indicating an unrequested disconnection.

This should fix a race reported by Christophe Ronco whereby the packet status disconnect notification is called between activate_primary (start_net) and it's callback (start_net_cb).

---
 drivers/qmimodem/gprs-context.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/qmimodem/gprs-context.c +6 -2
index af1ce16..80cba76 100644
@@ -65,8 +65,12 @@ static void pkt_status_notify(struct qmi_result *result, void *user_data)
 
 	switch (status->status) {
 	case QMI_WDS_CONN_STATUS_DISCONNECTED:
-		ofono_gprs_context_deactivated(gc, data->active_context);
-		data->active_context = 0;
+		if (data->pkt_handle) {
+			/* The context has been disconnected by the network */ 
+			ofono_gprs_context_deactivated(gc, data->active_context);
+			data->pkt_handle = 0;
+			data->active_context = 0;
+		}
 		break;
 	}
 }
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH v5 2/4 qmi: use shared services

In reply to Jonas Bonn

Apparently it's not legal to create a QMI service multiple times for a device. I've been testing with a Quectel EC21 and here it works fine to do so, but the general case would require "shared" services across atoms.

This patch switches the users of the NAS and WDS services over to using a "shared" service instead of each instatiating their own instance.

---
 drivers/qmimodem/gprs-context.c         | 4 ++--
 drivers/qmimodem/gprs.c                 | 2 +-
 drivers/qmimodem/network-registration.c | 2 +-
 drivers/qmimodem/radio-settings.c       | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/qmimodem/gprs-context.c +2 -2
index 80cba76..0c34be6 100644
@@ -421,7 +421,7 @@ static void get_data_format_cb(struct qmi_result *result, void *user_data)
 	}
 
 done:
-	qmi_service_create(data->dev, QMI_SERVICE_WDS, create_wds_cb, gc,
+	qmi_service_create_shared(data->dev, QMI_SERVICE_WDS, create_wds_cb, gc,
 									NULL);
 }
 
@@ -444,7 +444,7 @@ static void create_wda_cb(struct qmi_service *service, void *user_data)
 		return;
 
 error:
-	qmi_service_create(data->dev, QMI_SERVICE_WDS, create_wds_cb, gc,
+	qmi_service_create_shared(data->dev, QMI_SERVICE_WDS, create_wds_cb, gc,
 									NULL);
 }
 
drivers/qmimodem/gprs.c +1 -1
index 05ad4bd..fb5e6ec 100644
@@ -201,7 +201,7 @@ static int qmi_gprs_probe(struct ofono_gprs *gprs,
 
 	ofono_gprs_set_data(gprs, data);
 
-	qmi_service_create(device, QMI_SERVICE_NAS, create_nas_cb, gprs, NULL);
+	qmi_service_create_shared(device, QMI_SERVICE_NAS, create_nas_cb, gprs, NULL);
 
 	return 0;
 }
drivers/qmimodem/network-registration.c +1 -1
index e2a5082..52ad69a 100644
@@ -542,7 +542,7 @@ static int qmi_netreg_probe(struct ofono_netreg *netreg,
 
 	ofono_netreg_set_data(netreg, data);
 
-	qmi_service_create(device, QMI_SERVICE_NAS,
+	qmi_service_create_shared(device, QMI_SERVICE_NAS,
 					create_nas_cb, netreg, NULL);
 
 	return 0;
drivers/qmimodem/radio-settings.c +1 -1
index d62a636..fb587b9 100644
@@ -74,7 +74,7 @@ static int qmi_radio_settings_probe(struct ofono_radio_settings *rs,
 
 	ofono_radio_settings_set_data(rs, data);
 
-	qmi_service_create(device, QMI_SERVICE_NAS, create_nas_cb, rs, NULL);
+	qmi_service_create_shared(device, QMI_SERVICE_NAS, create_nas_cb, rs, NULL);
 
 	return 0;
 
Signature · 1 line
2.9.3
author
#3 lore raw

PATCH v5 3/4 qmi: use named status values

In reply to Jonas Bonn
---
 drivers/qmimodem/gprs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/qmimodem/gprs.c +3 -2
index fb5e6ec..e3bfd1f 100644
@@ -30,6 +30,7 @@
 #include "qmi.h"
 #include "nas.h"
 
+#include "src/common.h"
 #include "qmimodem.h"
 
 struct gprs_data {
@@ -48,9 +49,9 @@ static bool extract_ss_info(struct qmi_result *result, int *status)
 		return false;
 
 	if (ss->ps_state == QMI_NAS_ATTACH_STATE_ATTACHED)
-		*status = 0x01;
+		*status = NETWORK_REGISTRATION_STATUS_REGISTERED;
 	else
-		*status = 0x00;
+		*status = NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
 
 	return true;
 }
Signature · 1 line
2.9.3
author
#4 lore raw

PATCH v5 4/4 qmi: activate default bearer context for LTE networks

In reply to Jonas Bonn

When the modem attaches to an LTE network, a default bearer is automatically negotiated using the "defalt profile" settings. The QMI modem, however, does not given any explicit indication that the bearer exists; instead, we must assume its existence based on the network registration state.

This patch extends the GPRS atom to signal the presence of a default bearer when it detects network connectivity on an LTE network.

---
 drivers/qmimodem/gprs.c | 65 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 52 insertions(+), 13 deletions(-)
drivers/qmimodem/gprs.c +52 -13
index e3bfd1f..a3461e4 100644
@@ -37,10 +37,11 @@ struct gprs_data {
 	struct qmi_service *nas;
 };
 
-static bool extract_ss_info(struct qmi_result *result, int *status)
+static bool extract_ss_info(struct qmi_result *result, int *status, int *tech)
 {
 	const struct qmi_nas_serving_system *ss;
 	uint16_t len;
+	int i;
 
 	DBG("");
 
@@ -53,20 +54,53 @@ static bool extract_ss_info(struct qmi_result *result, int *status)
 	else
 		*status = NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
 
+	*tech = -1;
+	for (i = 0; i < ss->radio_if_count; i++) {
+		DBG("radio in use %d", ss->radio_if[i]);
+
+		*tech = qmi_nas_rat_to_tech(ss->radio_if[i]);
+	}
+
 	return true;
 }
 
+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;
+
+	DBG("");
+
+	if (!extract_ss_info(result, &status, &tech))
+		return -1;
+
+	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 , "");
+		}
+
+	return status;
+}
+
 static void ss_info_notify(struct qmi_result *result, void *user_data)
 {
-	struct ofono_gprs *gprs = user_data;
+	struct ofono_gprs* gprs = user_data;
 	int status;
 
 	DBG("");
 
-	if (!extract_ss_info(result, &status))
-		return;
+	status = handle_ss_info(result, gprs);
 
-	ofono_gprs_status_notify(gprs, status);
+	if (status >= 0)
+		ofono_gprs_status_notify(gprs, status);
 }
 
 static void attach_detach_cb(struct qmi_result *result, void *user_data)
@@ -125,22 +159,26 @@ error:
 static void get_ss_info_cb(struct qmi_result *result, void *user_data)
 {
 	struct cb_data *cbd = user_data;
+	struct ofono_gprs* gprs = cbd->user;
 	ofono_gprs_status_cb_t cb = cbd->cb;
 	int status;
 
 	DBG("");
 
-	if (qmi_result_set_error(result, NULL)) {
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		return;
-	}
+	if (qmi_result_set_error(result, NULL))
+		goto error;
 
-	if (!extract_ss_info(result, &status)) {
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		return;
-	}
+	status = handle_ss_info(result, gprs);
+
+	if (status < 0)
+		goto error;
 
 	CALLBACK_WITH_SUCCESS(cb, status, cbd->data);
+
+	return;
+
+error:
+	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
 }
 
 static void qmi_attached_status(struct ofono_gprs *gprs,
@@ -151,6 +189,7 @@ static void qmi_attached_status(struct ofono_gprs *gprs,
 
 	DBG("");
 
+	cbd->user = gprs;
 	if (qmi_service_send(data->nas, QMI_NAS_GET_SS_INFO, NULL,
 					get_ss_info_cb, cbd, g_free) > 0)
 		return;
Signature · 1 line
2.9.3
#5 lore raw
In reply to Jonas Bonn

Hi Jonas,

Quoted 32 lines · Jonas Bonn

Changes since v4:

* Address feedback from Denis
* Lots of testing; this is robust against loss of network connectivity and transitions across technologies.
* Dropped LTE atom for now since it's not doing anything interesting currently... I'll resend it separately.

Original cover letter follows:

LTE is different from other 'GPRS' technologies in that a default bearer always gets set up when the modem registers to the network. Ofono has some support for this and this series tries to set this up for QMI modems.

The key to understanding this series is to understand that QMI modems do not automatically enable the network interface when connecting to an LTE network, even though the default bearer is already set up. A call to "start network" needs to be made in order to allow packets to flow. So the jist of this series is:

i) detect network registration to LTE network ii) call ofono_gprs_cid_activated
iii) in read_settings, start by calling "start network"

...and then there are some other adjustments in the series to make this all work.

I've tested this with my EC21, both on LTE and UMTS networks. It all seems to work, including moving out of network connectivity and bringing the modem repeatedly online/offline.

Quoted 7 lines

One open question at this point:

* What happens if the connection manager calls deactivate_context on the default bearer context? I don't see that any other drivers guard against this, and the QMI driver will happily stop the network interface even though the default bearer is still up in the background.

Good question. I think the core might need to prevent such a situation.
However, it is a bit tricky since we don't know about the default
bearer with 100% certainty. We can only make assumptions.

Quoted 6 lines

Jonas Bonn (4):
qmi: watch packet status for spontaneous disconnection only
qmi: use shared services
qmi: use named status values
qmi: activate default bearer context for LTE networks

Quoted 6 lines
 drivers/qmimodem/gprs-context.c         | 12 ++++--
 drivers/qmimodem/gprs.c                 | 72 +++++++++++++++++++++++++--------
 drivers/qmimodem/network-registration.c |  2 +-
 drivers/qmimodem/radio-settings.c       |  2 +-
 4 files changed, 66 insertions(+), 22 deletions(-)

All 4 applied, thanks.

Regards,
-Denis