Skip to contentSkip to conversation

QMI LTE series

PATCH Applied Jonas Bonn 2 participants 22 messages Apr 11, 2017 – Apr 14, 2017 Kbuild

v1 of 5 Applied Latest is v5 →

lore
Share & tools
lore

Jonas Bonn

author
#0 lore raw

cover QMI LTE series

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.

This seems to work, but I think that this whole process needs to be re-thought a bit. It's far from obvious how this works. The GPRS atom is still responsible for maintaining some form of "online" status, but it does so in a round-about way where set_attached never gets called because LTE doesn't have an "attached" state like GPRS does.

Other open questions:

What happens when the modem moves from LTE to UMTS network, or from UMTS network to LTE when a context already has been set up? Should the default bearer still be set up on LTE? Or should the default bearer be taken down when moving away from LTE?

Jonas Bonn (8):
qmi: NAS definitions adjustment
qmi: add WDS parameter definition
qmi: retrieve GPRS context parameters
qmi: implement read_settings for automatic contexts
lte: activate default bearer on network registration
qmi: add LTE atom driver
qmi: watch for automatic context activation
gobi: add LTE atom

 Makefile.am                     |   1 +
 drivers/qmimodem/gprs-context.c |  78 ++++++++++++++
 drivers/qmimodem/gprs.c         |  90 ++++++++++++++++-
 drivers/qmimodem/lte.c          | 219 ++++++++++++++++++++++++++++++++++++++++
 drivers/qmimodem/nas.h          |  14 ++-
 drivers/qmimodem/qmimodem.c     |   2 +
 drivers/qmimodem/qmimodem.h     |   3 +
 drivers/qmimodem/wds.h          |   2 +
 include/lte.h                   |   2 +
 plugins/gobi.c                  |   3 +
 src/lte.c                       | 115 +++++++++++++++++++++
 11 files changed, 525 insertions(+), 4 deletions(-)
 create mode 100644 drivers/qmimodem/lte.c
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 1/8 qmi: NAS definitions adjustment

Calling the ps_state/cs_state alternatives *ATTACH_STATUS* was confusing because there is also a status field in the *serving_system structure. This patch does a minor rename and adds the appropriate definitions for the status field.

---
 drivers/qmimodem/gprs.c |  2 +-
 drivers/qmimodem/nas.h  | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/qmimodem/gprs.c +1 -1
index 983223e..05ad4bd 100644
@@ -47,7 +47,7 @@ static bool extract_ss_info(struct qmi_result *result, int *status)
 	if (!ss)
 		return false;
 
-	if (ss->ps_state == QMI_NAS_ATTACH_STATUS_ATTACHED)
+	if (ss->ps_state == QMI_NAS_ATTACH_STATE_ATTACHED)
 		*status = 0x01;
 	else
 		*status = 0x00;
drivers/qmimodem/nas.h +11 -3
index dee9d70..9bb9a9a 100644
@@ -140,9 +140,17 @@ struct qmi_nas_current_plmn {
 #define QMI_NAS_RESULT_LOCATION_AREA_CODE	0x1d	/* uint16 */
 #define QMI_NAS_RESULT_CELL_ID			0x1e	/* uint32 */
 
-#define QMI_NAS_ATTACH_STATUS_INVALID		0x00
-#define QMI_NAS_ATTACH_STATUS_ATTACHED		0x01
-#define QMI_NAS_ATTACH_STATUS_DETACHED		0x02
+/* qmi_nas_serving_system.status */
+#define QMI_NAS_REGISTRATION_STATE_NOT_REGISTERED	0x00
+#define QMI_NAS_REGISTRATION_STATE_REGISTEREID		0x01
+#define QMI_NAS_REGISTRATION_STATE_SEARCHING		0x02
+#define QMI_NAS_REGISTRATION_STATE_DENIED		0x03
+#define QMI_NAS_REGISTRATION_STATE_UNKNOWN		0x04
+
+/* cs_state/ps_state */
+#define QMI_NAS_ATTACH_STATE_INVALID		0x00
+#define QMI_NAS_ATTACH_STATE_ATTACHED		0x01
+#define QMI_NAS_ATTACH_STATE_DETACHED		0x02
 
 /* Get info about home network */
 #define QMI_NAS_RESULT_HOME_NETWORK		0x01
Signature · 1 line
2.9.3
#2 lore raw

Re: [PATCH 1/8] qmi: NAS definitions adjustment

Hi Jonas,

Quoted 9 lines · Jonas Bonn

Calling the ps_state/cs_state alternatives *ATTACH_STATUS* was confusing because there is also a status field in the *serving_system structure. This patch does a minor rename and adds the appropriate definitions for the status field.

---
 drivers/qmimodem/gprs.c |  2 +-
 drivers/qmimodem/nas.h  | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

Applied, thanks.

Regards,
-Denis

author
#3 lore raw

PATCH 2/8 qmi: add WDS parameter definition

In reply to Jonas Bonn
---
 drivers/qmimodem/wds.h | 1 +
 1 file changed, 1 insertion(+)
drivers/qmimodem/wds.h +1 -0
index 4843f92..e03d177 100644
@@ -62,6 +62,7 @@ struct qmi_wds_notify_conn_status {
 #define QMI_WDS_RESULT_SECONDARY_DNS		0x16	/* uint32 IPv4 */
 #define QMI_WDS_RESULT_IP_ADDRESS		0x1e	/* uint32 IPv4 */
 #define QMI_WDS_RESULT_GATEWAY			0x20	/* uint32 IPv4 */
+#define QMI_WDS_RESULT_GATEWAY_NETMASK		0x21	/* uint32 IPv4 */
 #define QMI_WDS_RESULT_IP_FAMILY		0x2b	/* uint8 */
 
 #define QMI_WDS_PDP_TYPE_IPV4			0x00
Signature · 1 line
2.9.3
#4 lore raw

Re: [PATCH 2/8] qmi: add WDS parameter definition

Hi Jonas,

Quoted 4 lines · Jonas Bonn
---
 drivers/qmimodem/wds.h | 1 +
 1 file changed, 1 insertion(+)

Applied, thanks.

Regards,
-Denis

author
#5 lore raw

PATCH 3/8 qmi: retrieve GPRS context parameters

In reply to Jonas Bonn

The GPRS context needs to be configured with connection parameters when the bearer has been established. This was only partially implemented, so this patch adds additional parameters to those passed to the context.

---
 drivers/qmimodem/gprs-context.c | 52 +++++++++++++++++++++++++++++++++++++++++
 drivers/qmimodem/wds.h          |  1 +
 2 files changed, 53 insertions(+)
drivers/qmimodem/gprs-context.c +52 -0
index da2be24..1ae2a5a 100644
@@ -24,6 +24,7 @@
 #endif
 
 #include <string.h>
+#include <arpa/inet.h>
 
 #include <ofono/log.h>
 #include <ofono/modem.h>
@@ -78,18 +79,67 @@ static void get_settings_cb(struct qmi_result *result, void *user_data)
 	struct ofono_modem *modem;
 	const char *interface;
 	uint8_t pdp_type, ip_family;
+	uint32_t ip_addr;
+	struct in_addr addr;
+	char* straddr;
+	char* apn = NULL;
+	const char *dns[3] = { NULL, NULL, NULL };
 
 	DBG("");
 
 	if (qmi_result_set_error(result, NULL))
 		goto done;
 
+	apn = qmi_result_get_string(result, QMI_WDS_RESULT_APN);
+	if (apn) {
+		DBG("APN: %s", apn);
+	}
 	if (qmi_result_get_uint8(result, QMI_WDS_RESULT_PDP_TYPE, &pdp_type))
 		DBG("PDP type %d", pdp_type);
 
 	if (qmi_result_get_uint8(result, QMI_WDS_RESULT_IP_FAMILY, &ip_family))
 		DBG("IP family %d", ip_family);
 
+	if (qmi_result_get_uint32(result,QMI_WDS_RESULT_IP_ADDRESS, &ip_addr)) {
+
+		addr.s_addr = htonl(ip_addr);
+		straddr = inet_ntoa(addr);
+		DBG("IP addr: %s", straddr);
+		ofono_gprs_context_set_ipv4_address(gc, straddr, 1);
+	}
+	if (qmi_result_get_uint32(result,QMI_WDS_RESULT_GATEWAY, &ip_addr)) {
+
+		addr.s_addr = htonl(ip_addr);
+		straddr = inet_ntoa(addr);
+		DBG("Gateway: %s", straddr);
+		ofono_gprs_context_set_ipv4_gateway(gc, straddr);
+	}
+	if (qmi_result_get_uint32(result,
+				QMI_WDS_RESULT_GATEWAY_NETMASK, &ip_addr)) {
+
+		addr.s_addr = htonl(ip_addr);
+		straddr = inet_ntoa(addr);
+		DBG("Gateway netmask: %s", straddr);
+		ofono_gprs_context_set_ipv4_netmask(gc, straddr);
+	}
+	if (qmi_result_get_uint32(result,
+				QMI_WDS_RESULT_PRIMARY_DNS, &ip_addr)) {
+
+		addr.s_addr = htonl(ip_addr);
+		dns[0] = inet_ntoa(addr);
+		DBG("Primary DNS: %s", dns[0]);
+	}
+	if (qmi_result_get_uint32(result,
+				QMI_WDS_RESULT_SECONDARY_DNS, &ip_addr)) {
+
+		addr.s_addr = htonl(ip_addr);
+		dns[1] = inet_ntoa(addr);
+		DBG("Secondary DNS: %s", dns[1]);
+	}
+
+	if (dns[0])
+		ofono_gprs_context_set_ipv4_dns_servers(gc, dns);
+
 done:
 	modem = ofono_gprs_context_get_modem(gc);
 	interface = ofono_modem_get_string(modem, "NetworkInterface");
@@ -98,6 +148,8 @@ done:
 
 	CALLBACK_WITH_SUCCESS(cb, cbd->data);
 
+	g_free(apn);
+
 	g_free(cbd);
 }
 
drivers/qmimodem/wds.h +1 -0
index e03d177..8aae996 100644
@@ -58,6 +58,7 @@ struct qmi_wds_notify_conn_status {
 
 /* Get the runtime data session settings */
 #define QMI_WDS_RESULT_PDP_TYPE			0x11	/* uint8 */
+#define QMI_WDS_RESULT_APN			0x14	/* string */
 #define QMI_WDS_RESULT_PRIMARY_DNS		0x15	/* uint32 IPv4 */
 #define QMI_WDS_RESULT_SECONDARY_DNS		0x16	/* uint32 IPv4 */
 #define QMI_WDS_RESULT_IP_ADDRESS		0x1e	/* uint32 IPv4 */
Signature · 1 line
2.9.3
#6 lore raw

Re: [PATCH 3/8] qmi: retrieve GPRS context parameters

Hi Jonas,

Quoted 8 lines · Jonas Bonn

The GPRS context needs to be configured with connection parameters when the bearer has been established. This was only partially implemented, so this patch adds additional parameters to those passed to the context.

---
 drivers/qmimodem/gprs-context.c | 52 +++++++++++++++++++++++++++++++++++++++++
 drivers/qmimodem/wds.h          |  1 +
 2 files changed, 53 insertions(+)

I went ahead and applied a slightly modified version of this patch that fixed various style issues.

Regards,
-Denis

author
#7 lore raw

PATCH 4/8 qmi: implement read_settings for automatic contexts

In reply to Jonas Bonn

For LTE, a context is created automatically when the modem registers to the network. The read_settings function is called for these automatic contexts to get their configuration.

---
 drivers/qmimodem/gprs-context.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/qmimodem/gprs-context.c +26 -0
index 1ae2a5a..3841c7e 100644
@@ -153,6 +153,31 @@ done:
 	g_free(cbd);
 }
 
+static void qmi_gprs_read_settings(struct ofono_gprs_context* gc,
+					unsigned int cid,
+					ofono_gprs_context_cb_t cb,
+					void *user_data)
+{
+	struct cb_data *cbd = cb_data_new(cb, user_data);
+	struct gprs_context_data *data = ofono_gprs_context_get_data(gc);
+
+	DBG("cid %u", cid);
+
+	data->active_context = cid;
+
+	cbd->user = gc;
+
+	if (qmi_service_send(data->wds, QMI_WDS_GET_SETTINGS, NULL,
+					get_settings_cb, cbd, NULL) > 0)
+		return;
+
+	data->active_context = 0;
+
+	CALLBACK_WITH_FAILURE(cb, cbd->data);
+
+	g_free(cbd);
+}
+
 static void start_net_cb(struct qmi_result *result, void *user_data)
 {
 	struct cb_data *cbd = user_data;
@@ -450,6 +475,7 @@ static struct ofono_gprs_context_driver driver = {
 	.remove			= qmi_gprs_context_remove,
 	.activate_primary	= qmi_activate_primary,
 	.deactivate_primary	= qmi_deactivate_primary,
+	.read_settings		= qmi_gprs_read_settings,
 };
 
 void qmi_gprs_context_init(void)
Signature · 1 line
2.9.3
#8 lore raw

Re: [PATCH 4/8] qmi: implement read_settings for automatic contexts

Quoted 7 lines · Jonas Bonn

For LTE, a context is created automatically when the modem registers to the network. The read_settings function is called for these automatic contexts to get their configuration.

---
 drivers/qmimodem/gprs-context.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

I went ahead and applied this patch, but see below:

Quoted 14 lines
drivers/qmimodem/gprs-context.c +6 -0
index 1ae2a5a..3841c7e 100644
@@ -153,6 +153,31 @@ done:
 	g_free(cbd);
 }
 
+static void qmi_gprs_read_settings(struct ofono_gprs_context* gc,
+					unsigned int cid,
+					ofono_gprs_context_cb_t cb,
+					void *user_data)
+{
+	struct cb_data *cbd = cb_data_new(cb, user_data);

drivers/qmimodem/gprs-context.c done: · line 171

Quoted 10 lines
drivers/qmimodem/gprs-context.c +10 -0
+	struct gprs_context_data *data = ofono_gprs_context_get_data(gc);
+
+	DBG("cid %u", cid);
+
+	data->active_context = cid;
+
+	cbd->user = gc;
+
+	if (qmi_service_send(data->wds, QMI_WDS_GET_SETTINGS, NULL,
+					get_settings_cb, cbd, NULL) > 0)

You really should be setting the qmi_destroy_func_t for qmi_service_send. This saves you a g_free call inside get_settings_cb, but more importantly it avoids a memory leak in case the qmi_service/qmi_device is destroyed before the callback has been called.

I went ahead and fixed this in the upstream code in commits:
f29a316c918bfd67072bdb4f46ca90a3b8954108 7a2e198fd7430c468f2a15ff82467c18c649ddf3

But there may be other instances of this bug lurking around.

Quoted 14 lines
drivers/qmimodem/gprs-context.c +9 -0
+		return;
+
+	data->active_context = 0;
+
+	CALLBACK_WITH_FAILURE(cb, cbd->data);
+
+	g_free(cbd);
+}
+
 static void start_net_cb(struct qmi_result *result, void *user_data)
 {
 	struct cb_data *cbd = user_data;

drivers/qmimodem/gprs-context.c static struct ofono_gprs_context_driver driver = { · line 481

Quoted 7 lines
drivers/qmimodem/gprs-context.c +1 -0
@@ -450,6 +475,7 @@ static struct ofono_gprs_context_driver driver = {
 	.remove			= qmi_gprs_context_remove,
 	.activate_primary	= qmi_activate_primary,
 	.deactivate_primary	= qmi_deactivate_primary,
+	.read_settings		= qmi_gprs_read_settings,
 };
 
 void qmi_gprs_context_init(void)

Regards,
-Denis

author
#9 lore raw

PATCH 5/8 lte: activate default bearer on network registration

In reply to Jonas Bonn

The LTE atom should watch the network status and automatically activate the default bearer when the modem becomes registered to the LTE network.

This patch adds a device callback, activate_default_bearer(), to allow the device to start networking.

---
 include/lte.h |   2 +
 src/lte.c     | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
include/lte.h +2 -0
index f3ff405..9dc0109 100644
@@ -43,6 +43,8 @@ struct ofono_lte_driver {
 	void (*set_default_attach_info)(const struct ofono_lte *lte,
 			const struct ofono_lte_default_attach_info *info,
 			ofono_lte_cb_t cb, void *data);
+	void (*activate_default_bearer)(struct ofono_lte *lte,
+			ofono_lte_cb_t cb, void *data);
 };
 
 int ofono_lte_driver_register(const struct ofono_lte_driver *d);
src/lte.c +115 -0

142 lines not on this page · raw message

Signature · 1 line
2.9.3
#10 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Hi Jonas,

Quoted 5 lines · Jonas Bonn

The LTE atom should watch the network status and automatically activate the default bearer when the modem becomes registered to the LTE network.

This patch adds a device callback, activate_default_bearer(), to allow the device to start networking.

Nope, we're not doing it this way. Once we're attached to LTE there's no need to activate a default bearer. It is already active. The modem should tell us that this is the case.

Another issue is that the network is free to ignore our default bearer setting, so you might be activating (or trying to) yet another context.

Doesn't QMI provide an equivalent of +CGEV?

Regards,
-Denis

author
#11 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Hi Denis,

Quoted 7 lines · Denis Kenzior
Quoted 5 lines · Jonas Bonn

The LTE atom should watch the network status and automatically activate the default bearer when the modem becomes registered to the LTE network.

This patch adds a device callback, activate_default_bearer(), to allow the device to start networking.

Quoted 8 lines

Nope, we're not doing it this way. Once we're attached to LTE there's no need to activate a default bearer. It is already active. The modem should tell us that this is the case.

Another issue is that the network is free to ignore our default bearer setting, so you might be activating (or trying to) yet another context.

Doesn't QMI provide an equivalent of +CGEV?

I haven't found an equivalent. Right now it looks to me as though the only way to set up a PDP context is to call the "Start Networking" method. If I don't start networking, the packet status callback never gives me a "connected" status. It's not enough to just power on the modem... although that does get me registered to the network.

Furthermore, it doesn't matter what APN I use, I always get a usable data-connection. "Get Settings" never returns an APN string, either, which makes me that the network is ignoring my setting altogether and just giving me a default bearer...???

If anyone knows how this is supposed to work, I'd appreciate some guidance!

/Jonas

#12 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Hi Jonas,

Quoted 17 lines · Jonas Bonn

Hi Denis,

Quoted 14 lines · Denis Kenzior
Quoted 5 lines · Jonas Bonn

The LTE atom should watch the network status and automatically activate the default bearer when the modem becomes registered to the LTE network.

This patch adds a device callback, activate_default_bearer(), to allow the device to start networking.

Nope, we're not doing it this way. Once we're attached to LTE there's no need to activate a default bearer. It is already active. The modem should tell us that this is the case.

Another issue is that the network is free to ignore our default bearer setting, so you might be activating (or trying to) yet another context.

Quoted 7 lines
Quoted 1 line

Doesn't QMI provide an equivalent of +CGEV?

I haven't found an equivalent. Right now it looks to me as though the only way to set up a PDP context is to call the "Start Networking" method. If I don't start networking, the packet status callback never gives me a "connected" status. It's not enough to just power on the modem... although that does get me registered to the network.

QMI is an ancient protocol, so maybe it simply didn't get extended for LTE. Or we just don't know how to drive it properly. Is there an AT channel ? Does that one report anything related to CGEV?

Quoted 5 lines

Furthermore, it doesn't matter what APN I use, I always get a usable data-connection. "Get Settings" never returns an APN string, either, which makes me that the network is ignoring my setting altogether and just giving me a default bearer...???

The network is ultimately responsible for allocating an APN. It could be blank or null or whatever. Or maybe we don't know the right magic incantation.

Regards,
-Denis

author
#13 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Quoted 35 lines · Denis Kenzior

Hi Jonas,

Quoted 19 lines · Jonas Bonn

Hi Denis,

Quoted 16 lines · Denis Kenzior
Quoted 7 lines · Jonas Bonn

The LTE atom should watch the network status and automatically activate
the default bearer when the modem becomes registered to the LTE network.

This patch adds a device callback, activate_default_bearer(), to allow the device to start networking.

Nope, we're not doing it this way. Once we're attached to LTE there's no need to activate a default bearer. It is already active. The modem should tell us that this is the case.

Another issue is that the network is free to ignore our default bearer setting, so you might be activating (or trying to) yet another context.

Quoted 7 lines
Quoted 1 line

Doesn't QMI provide an equivalent of +CGEV?

I haven't found an equivalent. Right now it looks to me as though the only way to set up a PDP context is to call the "Start Networking" method. If I don't start networking, the packet status callback never gives me a "connected" status. It's not enough to just power on the modem... although that does get me registered to the network.

QMI is an ancient protocol, so maybe it simply didn't get extended for LTE. Or we just don't know how to drive it properly. Is there an AT channel ? Does that one report anything related to CGEV?

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Furthermore, it doesn't matter what APN I use, I always get a usable data-connection. "Get Settings" never returns an APN string, either, which makes me that the network is ignoring my setting altogether and just giving me a default bearer...???

The network is ultimately responsible for allocating an APN. It could be blank or null or whatever. Or maybe we don't know the right magic incantation.

Alright, I'm going to explain my understanding of how this works:

When the QMI modem registers to an LTE network, it negotiates a default bearer using the "default settings". The default settings are taken from the QMI WDS "default profile" which is presumably profile 1 by default.

Even though the network registration has taken place and the bearer is in place, the QMI modem doesn't bring up the network interface. Calling "get current settings" at this point gives you nothing.

At this point, you need to bring up the network interface by calling "Start network". Start network takes a bunch of parameters but these parameters are all ignored since the bearer is already set up.

I haven't tested this, but I suspect that calling "Start network" for the same profile again will fail...??? A profile number corresponds to a Context ID...??? Maybe...

If you need a specific setting for the default bearer (like APN), you need to set it in the default profile before registering to the network. This is what the LTE atom must take care of... and, hence, the atom must be created
before setting the modem online.

For non-LTE, the bearer isn't set up until "Start network" is called, so the usual context parameters can be passed to it at that time. Any parameters that are omitted are taken from the default profile.

Given all of the above, for QMI this means:

i) When the netreg atom detects registration to an LTE network then we can call "Start network" immediately.
ii) Start network will give us the packet-handle for the default bearer. This can be held by the netreg atom.
iii) The packet handle survives until the network becomes unregistered (even through a transition to UMTS,GPRS,etc networks).
iv) There is never any reason to call "Stop network" for the default bearer because a network unregistration will achieve the same thing. If the network becomes unregistered we can throw away the packet handle. The gprs-context associated with the default bearer won't know the packet-handle, so we need to make sure it doesn't try to call "Stop network" for it's instance... but that's a detail, I think.

It seems that there exists a method to change the default profile number... it's undocumented, though, AFAICT.

What's a bit unclear to me, though, is how this interacts with network technology transitions... what happens when I move out of LTE coverage and into a UMTS/GPRS network?

Questions? Feedback appreciated...
/Jonas

author
#14 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Quoted 58 lines · Jonas Bonn
Quoted 37 lines · Denis Kenzior

Hi Jonas,

Quoted 21 lines · Jonas Bonn

Hi Denis,

Quoted 18 lines · Denis Kenzior
Quoted 8 lines · Jonas Bonn

The LTE atom should watch the network status and automatically activate
the default bearer when the modem becomes registered to the LTE network.

This patch adds a device callback, activate_default_bearer(), to allow
the device to start networking.

Nope, we're not doing it this way. Once we're attached to LTE there's no need to activate a default bearer. It is already active. The modem should tell us that this is the case.

Another issue is that the network is free to ignore our default bearer setting, so you might be activating (or trying to) yet another context.

Quoted 7 lines
Quoted 1 line

Doesn't QMI provide an equivalent of +CGEV?

I haven't found an equivalent. Right now it looks to me as though the only way to set up a PDP context is to call the "Start Networking" method. If I don't start networking, the packet status callback never gives me a "connected" status. It's not enough to just power on the modem... although that does get me registered to the network.

QMI is an ancient protocol, so maybe it simply didn't get extended for LTE. Or we just don't know how to drive it properly. Is there an AT channel ? Does that one report anything related to CGEV?

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Furthermore, it doesn't matter what APN I use, I always get a usable data-connection. "Get Settings" never returns an APN string, either, which makes me that the network is ignoring my setting altogether and just giving me a default bearer...???

The network is ultimately responsible for allocating an APN. It could be blank or null or whatever. Or maybe we don't know the right magic incantation.

Alright, I'm going to explain my understanding of how this works:

When the QMI modem registers to an LTE network, it negotiates a default bearer using the "default settings". The default settings are taken from the QMI WDS "default profile" which is presumably profile 1 by default.

Even though the network registration has taken place and the bearer is in place, the QMI modem doesn't bring up the network interface. Calling "get current settings" at this point gives you nothing.

Quoted 7 lines

At this point, you need to bring up the network interface by calling "Start network". Start network takes a bunch of parameters but these parameters are all ignored since the bearer is already set up.

I haven't tested this, but I suspect that calling "Start network" for the same profile again will fail...??? A profile number corresponds to a Context ID...??? Maybe...

I tested this and "start network" fails when attempting to connect a profile a second time.

Quoted 13 lines

If you need a specific setting for the default bearer (like APN), you need to set it in the default profile before registering to the network. This is what the LTE atom must take care of... and, hence, the atom must be created
before setting the modem online.

For non-LTE, the bearer isn't set up until "Start network" is called, so the usual context parameters can be passed to it at that time. Any parameters that are omitted are taken from the default profile.

Given all of the above, for QMI this means:

Quoted 12 lines

i) When the netreg atom detects registration to an LTE network then we can call "Start network" immediately.
ii) Start network will give us the packet-handle for the default bearer. This can be held by the netreg atom.
iii) The packet handle survives until the network becomes unregistered (even through a transition to UMTS,GPRS,etc networks). iv) There is never any reason to call "Stop network" for the default bearer because a network unregistration will achieve the same thing. If the network becomes unregistered we can throw away the packet handle. The gprs-context associated with the default bearer won't know the packet-handle, so we need to make sure it doesn't try to call "Stop network" for it's instance... but that's a detail, I think.

Point iv) is wrong... we need to release the packet handle using "stop network" when the bearer goes away.

/Jonas

Quoted 10 lines

It seems that there exists a method to change the default profile number... it's undocumented, though, AFAICT.

What's a bit unclear to me, though, is how this interacts with network technology transitions... what happens when I move out of LTE coverage and into a UMTS/GPRS network?

Questions? Feedback appreciated...
/Jonas

#15 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Hi Jonas,

Quoted 7 lines
Quoted 7 lines

Alright, I'm going to explain my understanding of how this works:

When the QMI modem registers to an LTE network, it negotiates a default bearer using the "default settings". The default settings are taken from the QMI WDS "default profile" which is presumably profile 1 by default.

Quoted 8 lines
Quoted 8 lines

Even though the network registration has taken place and the bearer is in place, the QMI modem doesn't bring up the network interface. Calling "get current settings" at this point gives you nothing.

At this point, you need to bring up the network interface by calling "Start network". Start network takes a bunch of parameters but these parameters are all ignored since the bearer is already set up.

Sounds like some 'creative thinking' from Qualcomm guys ;) But so far this makes sense. The parameters are already set in stone. For QMI, the .read_settings method should be also bringing up the network interface, e.g. 'Start network' in your case. For ublox devices the network device flows packets as soon as the context is active...

Quoted 4 lines
Quoted 3 lines

I haven't tested this, but I suspect that calling "Start network" for the same profile again will fail...??? A profile number corresponds to a Context ID...??? Maybe...

I would imagine that a profile has the same meaning as the 27.007 equivalent of +CGDCONT <cid>

Quoted 3 lines

I tested this and "start network" fails when attempting to connect a profile a second time.

Makes sense. Do note that the same APN can be (in theory) double, triple, etc activated. But this requires a separate cid for each instance.

Quoted 6 lines
Quoted 6 lines

If you need a specific setting for the default bearer (like APN), you need to set it in the default profile before registering to the network. This is what the LTE atom must take care of... and, hence, the atom must be created
before setting the modem online.

Correct. This is what .set_default_attach_info does. lte atom should be created in post_sim.

Quoted 5 lines
Quoted 5 lines

For non-LTE, the bearer isn't set up until "Start network" is called, so the usual context parameters can be passed to it at that time. Any parameters that are omitted are taken from the default profile.

Again, sounds right.

Quoted 4 lines
Quoted 4 lines

Given all of the above, for QMI this means:

i) When the netreg atom detects registration to an LTE network then we can call "Start network" immediately.

gprs atom driver needs to tell ofono core that a context is active. This means gprs driver should call ofono_gprs_cid_activated

Quoted 2 lines
Quoted 2 lines

ii) Start network will give us the packet-handle for the default bearer. This can be held by the netreg atom.

why netreg atom? This should be managed by gprs-context.

Quoted 10 lines
Quoted 8 lines

iii) The packet handle survives until the network becomes unregistered (even through a transition to UMTS,GPRS,etc networks). iv) There is never any reason to call "Stop network" for the default bearer because a network unregistration will achieve the same thing. If the network becomes unregistered we can throw away the packet handle. The gprs-context associated with the default bearer won't know the packet-handle, so we need to make sure it doesn't try to call "Stop network" for it's instance... but that's a detail, I think.

Point iv) is wrong... we need to release the packet handle using "stop network" when the bearer goes away.

Much of this has to be handled by the driver. E.g. the driver has to detect that a default bearer has been activated. Then:
1. call ofono_gprs_cid_activated
2. Step 1 in turn assigns a context and calls .read_settings
3. .read_settings should setup the active context and call 'start network'
4. When a context is de-activated for whatever reason, gprs-context driver needs to clean up, e.g. call 'stop network'.

Quoted 9 lines

/Jonas

Quoted 6 lines

It seems that there exists a method to change the default profile number... it's undocumented, though, AFAICT.

What's a bit unclear to me, though, is how this interacts with network technology transitions... what happens when I move out of LTE coverage and into a UMTS/GPRS network?

The context should survive and keep going. If it doesn't, then the network / model should tell us that a context is no longer active. There must be some notification to that effect.

Regards,
-Denis

author
#16 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Hi Denis,

Quoted 7 lines · Denis Kenzior

I haven't tested this, but I suspect that calling "Start network" for

Quoted 3 lines
Quoted 2 lines

the same profile again will fail...??? A profile number corresponds to a Context ID...??? Maybe...

I would imagine that a profile has the same meaning as the 27.007 equivalent of +CGDCONT <cid>

Yes, it does. Others have tested modifying context parameters with AT commands and the changes are visible in the corresponding QMI profile. However, this could theoretically be firmware dependent as it's not actually specified anywhere that it must be so.

Quoted 8 lines
Quoted 4 lines

I tested this and "start network" fails when attempting to connect a profile a second time.

Makes sense. Do note that the same APN can be (in theory) double, triple, etc activated. But this requires a separate cid for each instance.

Yes, exactly. Multiple profiles with identical parameters can be activated, as far as I can tell.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

Given all of the above, for QMI this means:

i) When the netreg atom detects registration to an LTE network then we can call "Start network" immediately.

Quoted 7 lines

gprs atom driver needs to tell ofono core that a context is active. This means gprs driver should call ofono_gprs_cid_activated

Quoted 2 lines
Quoted 2 lines

ii) Start network will give us the packet-handle for the default bearer. This can be held by the netreg atom.

why netreg atom? This should be managed by gprs-context.

Yes, you're right. I also came to this insight after writing this email! :)

I originally implemented this as described above but have now posted a new series that works as you described. It really hasn't been easy to understand how this all was supposed to work but what I've got now seems reasonable and functions well.

One question: ofono_gprs_notify_bearer()... why do we need this when netreg already provides the technology to the GPRS atom?

Thanks for taking the time to help me work through all of this! Much appreciated.

/Jonas

#17 lore raw

Re: [PATCH 5/8] lte: activate default bearer on network registration

Hi Jonas,

Quoted 5 lines

I originally implemented this as described above but have now posted a new series that works as you described. It really hasn't been easy to understand how this all was supposed to work but what I've got now seems reasonable and functions well.

This is one of the most complex pieces of the stack. It makes my brain hurt every time I look at it as well.

Quoted 3 lines

One question: ofono_gprs_notify_bearer()... why do we need this when netreg already provides the technology to the GPRS atom?

Many devices send out +CREG/CGREG which only reports status as 'umts'. It never elaborates whether the connection is utilizing plain UMTS, HSUPA, HSDPA or combined HSUPA/HSDPA. Since many carriers made a big deal (and special icons) for notifying the user that they're on a 'fast' network, we needed a convenient way of grabbing that info.

Manufacturers came up with a bunch of proprietary indications for this and eventually 3GPP standardized this inside 27.007 with +CPSB command. If you look at drivers/atmodem/gprs.c you can see some of the variants.

Quoted 4 lines

Thanks for taking the time to help me work through all of this! Much appreciated.

Sure, thanks for doing all the work :)

Regards,
-Denis

author
#18 lore raw

PATCH 6/8 qmi: add LTE atom driver

In reply to Jonas Bonn

When the LTE atom detects that the modem is registered to an LTE network, the driver will be asked to activate the default bearer. For QMI modems, this means that the "Start Network" method needs to be called with the default APN.

---
 Makefile.am                 |   1 +
 drivers/qmimodem/lte.c      | 219 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/qmimodem/qmimodem.c |   2 +
 drivers/qmimodem/qmimodem.h |   3 +
 4 files changed, 225 insertions(+)
 create mode 100644 drivers/qmimodem/lte.c
Makefile.am +1 -0
index b232f97..a7767f9 100644
@@ -231,6 +231,7 @@ builtin_sources += $(qmi_sources) \
 			drivers/qmimodem/ussd.c \
 			drivers/qmimodem/gprs.c \
 			drivers/qmimodem/gprs-context.c \
+			drivers/qmimodem/lte.c \
 			drivers/qmimodem/radio-settings.c \
 			drivers/qmimodem/location-reporting.c
 
drivers/qmimodem/lte.c new file +219 -0

219 lines not on this page · raw message

drivers/qmimodem/qmimodem.c +2 -0
index 959a901..2ce5c02 100644
@@ -39,6 +39,7 @@ static int qmimodem_init(void)
 	qmi_ussd_init();
 	qmi_gprs_init();
 	qmi_gprs_context_init();
+	qmi_lte_init();
 	qmi_radio_settings_init();
 	qmi_location_reporting_init();
 
@@ -49,6 +50,7 @@ static void qmimodem_exit(void)
 {
 	qmi_location_reporting_exit();
 	qmi_radio_settings_exit();
+	qmi_lte_exit();
 	qmi_gprs_context_exit();
 	qmi_gprs_exit();
 	qmi_ussd_exit();
drivers/qmimodem/qmimodem.h +3 -0
index 1fc8682..4667334 100644
@@ -48,6 +48,9 @@ extern void qmi_gprs_exit(void);
 extern void qmi_gprs_context_init(void);
 extern void qmi_gprs_context_exit(void);
 
+extern void qmi_lte_init(void);
+extern void qmi_lte_exit(void);
+
 extern void qmi_radio_settings_init(void);
 extern void qmi_radio_settings_exit(void);
 
Signature · 1 line
2.9.3
#19 lore raw

Re: [PATCH 6/8] qmi: add LTE atom driver

Hi Jonas,

drivers/qmimodem/lte.c line 6

Quoted 8 lines

+++ b/drivers/qmimodem/lte.c

drivers/qmimodem/lte.c new file +6 -0
@@ -0,0 +1,219 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2016  Endocode AG. All rights reserved.
+ *

You might want to update the Copyright when copy-pasting stuff.

Regards,
-Denis

author
#20 lore raw

PATCH 7/8 qmi: watch for automatic context activation

In reply to Jonas Bonn

For LTE, a default bearer gets set up as soon as the modem registers to the network. The GPRS atom needs to detect the presence of this bearer in order to set up the appropriate context atom.

This is all a bit confusing but it's a result of the way ofono is currently architected. The GPRS atom serves two purposes: to "attach" to the network, and to hold "online" (attached) state for the purpose of communication with the connection manager (via DBus). For LTE, there is no concept of being "attached"; when the modem is online, a default bearer is automatically set so "attached" becomes synonymous with attached-and-context-activated. Context activation thus becomes "attached" in LTE, but this information still needs to be held in the GPRS atom which otherwise has no purpose.

---
 drivers/qmimodem/gprs.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
drivers/qmimodem/gprs.c +88 -0
index 05ad4bd..d4ced1c 100644
@@ -29,13 +29,76 @@
 
 #include "qmi.h"
 #include "nas.h"
+#include "wds.h"
 
 #include "qmimodem.h"
 
 struct gprs_data {
 	struct qmi_service *nas;
+	struct qmi_service *wds;
+	int default_bearer_cid;
 };
 
+static void get_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;
+
+	DBG("");
+
+	if (qmi_result_set_error(result, NULL))
+		goto done;
+
+	apn = qmi_result_get_string(result, QMI_WDS_RESULT_APN);
+	if (apn) {
+		DBG("APN: %s", apn);
+	}
+
+done:
+	if (!apn)
+		apn = g_strdup("");
+
+	ofono_gprs_cid_activated(gprs, data->default_bearer_cid, apn);
+
+	g_free(apn);
+}
+
+static void pkt_status_notify(struct qmi_result *result, void *user_data)
+{
+	struct ofono_gprs *gprs = user_data;
+	struct gprs_data *data = ofono_gprs_get_data(gprs);
+	const struct qmi_wds_notify_conn_status *status;
+	uint16_t len;
+
+	DBG("");
+
+	status = qmi_result_get(result, QMI_WDS_NOTIFY_CONN_STATUS, &len);
+	if (!status)
+		return;
+
+	DBG("conn status %d", status->status);
+
+	switch (status->status) {
+	case QMI_WDS_CONN_STATUS_CONNECTED:
+		DBG("connection status connected");
+		if (!data->default_bearer_cid)
+			data->default_bearer_cid = 1;
+
+		if (qmi_service_send(data->wds, QMI_WDS_GET_SETTINGS, NULL,
+					get_settings_cb, gprs, NULL) > 0)
+			return;
+
+		ofono_gprs_cid_activated(gprs, data->default_bearer_cid, "");
+		break;
+	case QMI_WDS_CONN_STATUS_DISCONNECTED:
+		data->default_bearer_cid = 0;
+		DBG("connection status disconnected");
+		break;
+	}
+}
+
+
 static bool extract_ss_info(struct qmi_result *result, int *status)
 {
 	const struct qmi_nas_serving_system *ss;
@@ -159,6 +222,28 @@ static void qmi_attached_status(struct ofono_gprs *gprs,
 	g_free(cbd);
 }
 
+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);
+
+	DBG("");
+
+	if (!service) {
+		ofono_error("Failed to request WDS service");
+		ofono_gprs_remove(gprs);
+		return;
+	}
+
+	data->wds = qmi_service_ref(service);
+
+	qmi_service_send(data->wds, QMI_WDS_GET_PKT_STATUS, NULL,
+					pkt_status_notify, gprs, NULL);
+
+	qmi_service_register(data->wds, QMI_WDS_PKT_STATUS_IND,
+					pkt_status_notify, gprs, NULL);
+}
+
 static void create_nas_cb(struct qmi_service *service, void *user_data)
 {
 	struct ofono_gprs *gprs = user_data;
@@ -202,6 +287,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(device, QMI_SERVICE_WDS, create_wds_cb, gprs, NULL);
 
 	return 0;
 }
@@ -215,8 +301,10 @@ static void qmi_gprs_remove(struct ofono_gprs *gprs)
 	ofono_gprs_set_data(gprs, NULL);
 
 	qmi_service_unregister_all(data->nas);
+	qmi_service_unregister_all(data->wds);
 
 	qmi_service_unref(data->nas);
+	qmi_service_unref(data->wds);
 
 	g_free(data);
 }
Signature · 1 line
2.9.3
author
#21 lore raw

PATCH 8/8 gobi: add LTE atom

In reply to Jonas Bonn
---
 plugins/gobi.c | 3 +++
 1 file changed, 3 insertions(+)
plugins/gobi.c +3 -0
index df35f94..58df2ce 100644
@@ -42,6 +42,7 @@
 #include <ofono/ussd.h>
 #include <ofono/gprs.h>
 #include <ofono/gprs-context.h>
+#include <ofono/lte.h>
 #include <ofono/radio-settings.h>
 #include <ofono/location-reporting.h>
 #include <ofono/log.h>
@@ -506,6 +507,8 @@ static void gobi_post_online(struct ofono_modem *modem)
 		if (gprs && gc)
 			ofono_gprs_add_context(gprs, gc);
 	}
+
+	ofono_lte_create(modem, "qmimodem", data->device);
 }
 
 static struct ofono_modem_driver gobi_driver = {
Signature · 1 line
2.9.3