All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/19] Support for U-Blox Toby L2 modems
@ 2016-03-09 15:44 Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 01/19] plugins/udevng: support the U-Blox TOBY-L2 series Dragos Tatulea
                   ` (18 more replies)
  0 siblings, 19 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2132 bytes --]

This patchset adds support for Toby L2 modems in high throughput
mode.

Besides basic support, the following things are supported:
* bridged AND routed modes.
* LTE default bearers.
* Multiple primary PDP contexts.


Dongsu Park (4):
  plugins/udevng: support the U-Blox TOBY-L2 series
  plugins/udevng: support different interface strings to detect TOBY
    series
  plugins/ublox: read network mode
  ubloxmodem: add routed mode support

Dragos Tatulea (15):
  plugins/udevng: ublox: set model string
  include: vendor.h: add vendor for ublox toby
  plugins/ublox: allow enabling of TOBY L2 modems
  plugins/ublox: use vendor from structure instead of fixed
  atmodem: ublox: EPS now supported by newer ublox
  atmodem: add support for U-Blox TOBY L2 modems
  atmodem: work around CGREG issues in UBlox Toby L2
  ubloxmodem: add Toby L2 gprs context driver
  gprs-context.h: add function for setting APN
  gprs: allow APN updates from gprs-context driver
  ubloxmodem: push back APN into gprs context
  plugins/ublox: give names to model ids
  plugins/ublox: enable ubloxmodem driver when possible
  plugins/ublox: support more internet contexts
  ubloxmodem: support authentication

 Makefile.am                            |   7 +
 drivers/atmodem/gprs-context.c         |   2 +
 drivers/atmodem/gprs.c                 |  27 +-
 drivers/atmodem/network-registration.c |  12 +-
 drivers/atmodem/sim.c                  |   1 +
 drivers/atmodem/vendor.h               |   1 +
 drivers/ubloxmodem/gprs-context.c      | 714 +++++++++++++++++++++++++++++++++
 drivers/ubloxmodem/ubloxmodem.c        |  49 +++
 drivers/ubloxmodem/ubloxmodem.h        |  25 ++
 include/gprs-context.h                 |   3 +
 plugins/ublox.c                        | 129 +++++-
 plugins/udevng.c                       |  25 +-
 src/gprs.c                             |  25 +-
 13 files changed, 987 insertions(+), 33 deletions(-)
 create mode 100644 drivers/ubloxmodem/gprs-context.c
 create mode 100644 drivers/ubloxmodem/ubloxmodem.c
 create mode 100644 drivers/ubloxmodem/ubloxmodem.h

-- 
2.5.0


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 01/19] plugins/udevng: support the U-Blox TOBY-L2 series
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:00   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 02/19] plugins/udevng: support different interface strings to detect TOBY series Dragos Tatulea
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

From: Dongsu Park <dongsu@endocode.com>

The newest generation of U-Blox TOBY-L2 series can be detected with
VID 0x1546 (the same as before), and one of the following PIDs:

* "0x1146" : high throughput profile
* "0x1141" : fairly back-compatible profile
* "0x1143" : low/medium throughput profile

This patch adds detection for high throughput mode.
---
 plugins/udevng.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index e43d045..52b667e 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -1120,6 +1120,8 @@ static struct {
 	{ "samsung",	"kalmia"			},
 	{ "quectel",	"option",	"05c6", "9090"	},
 	{ "ublox",	"cdc_acm",	"1546", "1102"	},
+	{ "ublox",	"rndis_host",	"1546", "1146"	},
+	{ "ublox",	"cdc_acm",	"1546", "1146"	},
 	{ }
 };
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 02/19] plugins/udevng: support different interface strings to detect TOBY series
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 01/19] plugins/udevng: support the U-Blox TOBY-L2 series Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:01   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 03/19] plugins/udevng: ublox: set model string Dragos Tatulea
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2554 bytes --]

From: Dongsu Park <dongsu@endocode.com>

Each modem expresses their interfaces with its own interface string,
which is composed of 3 different USB attributes:
"bInterfaceClass/bInterfaceSubClass/bInterfaceProtocol".
While the old models like LISA support only "2/2/1" for modem
interfaces, TOBY-L2 also supports an unique string for NetworkInterface
for each profile.

* low-medium throughput profile : 2/6/0
* fairly backward-compatible profile : 10/0/0
* high throughput profile : 224/1/3

Besides the condition for checking NULL for mdm/aux/net should be relaxed
a little bit.
---
 plugins/udevng.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 52b667e..2170c90 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -838,7 +838,7 @@ static gboolean setup_quectel(struct modem_info *modem)
 
 static gboolean setup_ublox(struct modem_info *modem)
 {
-	const char *aux = NULL, *mdm = NULL;
+	const char *aux = NULL, *mdm = NULL, *net = NULL;
 	GSList *list;
 
 	DBG("%s", modem->syspath);
@@ -857,21 +857,37 @@ static gboolean setup_ublox(struct modem_info *modem)
 			mdm = info->devnode;
 			if (aux != NULL)
 				break;
+		/*
+		 * "2/2/1"
+		 *  - a common modem interface both for older models like LISA,
+		 *    and for newer models like TOBY.
+		 * For TOBY-L2, NetworkInterface can be detected for each profile:
+		 *  - low-medium throughput profile : 2/6/0
+		 *  - fairly backward-compatible profile : 10/0/0
+		 *  - high throughput profile : 224/1/3
+		 * */
 		} else if (g_strcmp0(info->interface, "2/2/1") == 0) {
 			if (g_strcmp0(info->number, "02") == 0)
 				aux = info->devnode;
 			else if (g_strcmp0(info->number, "00") == 0)
 				mdm = info->devnode;
+		} else if (g_strcmp0(info->interface, "2/6/0") == 0 ||
+			   g_strcmp0(info->interface, "10/0/0") == 0 ||
+			   g_strcmp0(info->interface, "224/1/3") == 0) {
+			net = info->devnode;
 		}
 	}
 
-	if (aux == NULL || mdm == NULL)
+	/* Abort only if both interfaces are NULL, as it's highly possible that
+	 * only one of 2 interfaces is available for U-blox modem. */
+	if (aux == NULL && mdm == NULL)
 		return FALSE;
 
-	DBG("aux=%s modem=%s", aux, mdm);
+	DBG("aux=%s modem=%s net=%s", aux, mdm, net);
 
 	ofono_modem_set_string(modem->modem, "Aux", aux);
 	ofono_modem_set_string(modem->modem, "Modem", mdm);
+	ofono_modem_set_string(modem->modem, "NetworkInterface", net);
 
 	return TRUE;
 }
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 03/19] plugins/udevng: ublox: set model string
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 01/19] plugins/udevng: support the U-Blox TOBY-L2 series Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 02/19] plugins/udevng: support different interface strings to detect TOBY series Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:04   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 04/19] include: vendor.h: add vendor for ublox toby Dragos Tatulea
                   ` (15 subsequent siblings)
  18 siblings, 1 reply; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

Necessary for supporting the ublox TOBY L2 modem.
---
 plugins/udevng.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 2170c90..4b84323 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -888,6 +888,7 @@ static gboolean setup_ublox(struct modem_info *modem)
 	ofono_modem_set_string(modem->modem, "Aux", aux);
 	ofono_modem_set_string(modem->modem, "Modem", mdm);
 	ofono_modem_set_string(modem->modem, "NetworkInterface", net);
+	ofono_modem_set_string(modem->modem, "Model", modem->model);
 
 	return TRUE;
 }
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 04/19] include: vendor.h: add vendor for ublox toby
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (2 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 03/19] plugins/udevng: ublox: set model string Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:05   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 05/19] plugins/ublox: allow enabling of TOBY L2 modems Dragos Tatulea
                   ` (14 subsequent siblings)
  18 siblings, 1 reply; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]

Required to differentiate between the old LISA family
of supported devices and future TOBY L2 devices.
---
 drivers/atmodem/vendor.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/atmodem/vendor.h b/drivers/atmodem/vendor.h
index 52071c8..71a9af7 100644
--- a/drivers/atmodem/vendor.h
+++ b/drivers/atmodem/vendor.h
@@ -45,5 +45,6 @@ enum ofono_vendor {
 	OFONO_VENDOR_ALCATEL,
 	OFONO_VENDOR_QUECTEL,
 	OFONO_VENDOR_UBLOX,
+	OFONO_VENDOR_UBLOX_TOBY_L2,
 	OFONO_VENDOR_CINTERION,
 };
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 05/19] plugins/ublox: allow enabling of TOBY L2 modems
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (3 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 04/19] include: vendor.h: add vendor for ublox toby Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:11   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 06/19] plugins/ublox: use vendor from structure instead of fixed Dragos Tatulea
                   ` (13 subsequent siblings)
  18 siblings, 1 reply; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2569 bytes --]

For this we need to:
* Set the vendor family based on model id.
* Not use modem interface for the TOBY L2 family.
---
 plugins/ublox.c | 53 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index 89ca709..171d59d 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -47,6 +47,7 @@ static const char *none_prefix[] = { NULL };
 struct ublox_data {
 	GAtChat *modem;
 	GAtChat *aux;
+	enum ofono_vendor vendor_family;
 };
 
 static void ublox_debug(const char *str, void *user_data)
@@ -138,24 +139,58 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 static int ublox_enable(struct ofono_modem *modem)
 {
 	struct ublox_data *data = ofono_modem_get_data(modem);
+	const char *model_str = NULL;
+	int model_id;
 
 	DBG("%p", modem);
 
-	data->modem = open_device(modem, "Modem", "Modem: ");
-	if (data->modem == NULL)
+	model_str = ofono_modem_get_string(modem, "Model");
+	if (model_str == NULL)
 		return -EINVAL;
 
+	/*
+	 * Toby L2 devices are more complex and special than previously
+	 * supported U-Blox devices. So they need a vendor of their own.
+	 */
+	model_id = atoi(model_str);
+	switch (model_id) {
+		case 1102:
+			data->vendor_family = OFONO_VENDOR_UBLOX;
+			break;
+		case 1141:
+		case 1146:
+			data->vendor_family = OFONO_VENDOR_UBLOX_TOBY_L2;
+			break;
+		case 1143:
+			DBG("low/medium throughtput profile unsupported");
+		default:
+			DBG("unknown ublox model id %d", model_id);
+			return -EINVAL;
+	}
+
 	data->aux = open_device(modem, "Aux", "Aux: ");
-	if (data->aux == NULL) {
-		g_at_chat_unref(data->modem);
-		data->modem = NULL;
-		return -EIO;
+	if (data->aux == NULL)
+		return -EINVAL;
+
+	if (data->vendor_family == OFONO_VENDOR_UBLOX) {
+
+		data->modem = open_device(modem, "Modem", "Modem: ");
+		if (data->modem == NULL) {
+			g_at_chat_unref(data->aux);
+			data->aux = NULL;
+			return -EIO;
+		}
+
+		g_at_chat_set_slave(data->modem, data->aux);
+
+		g_at_chat_send(data->modem, "ATE0 +CMEE=1", none_prefix,
+						NULL, NULL, NULL);
+
 	}
 
-	g_at_chat_set_slave(data->modem, data->aux);
+	/* The modem can take a while to wake up if just powered on. */
+	g_at_chat_set_wakeup_command(data->aux, "AT\r", 1000, 11000);
 
-	g_at_chat_send(data->modem, "ATE0 +CMEE=1", none_prefix,
-					NULL, NULL, NULL);
 	g_at_chat_send(data->aux, "ATE0 +CMEE=1", none_prefix,
 					NULL, NULL, NULL);
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 06/19] plugins/ublox: use vendor from structure instead of fixed
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (4 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 05/19] plugins/ublox: allow enabling of TOBY L2 modems Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox Dragos Tatulea
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]

That's because we need to differentiate between multiple ublox
devices.
---
 plugins/ublox.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index 171d59d..0965ad1 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -269,8 +269,8 @@ static void ublox_pre_sim(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	ofono_devinfo_create(modem, 0, "atmodem", data->aux);
-	sim = ofono_sim_create(modem, OFONO_VENDOR_UBLOX, "atmodem",
+	ofono_devinfo_create(modem, data->vendor_family, "atmodem", data->aux);
+	sim = ofono_sim_create(modem, data->vendor_family, "atmodem",
 					data->aux);
 
 	if (sim)
@@ -285,10 +285,10 @@ static void ublox_post_sim(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	gprs = ofono_gprs_create(modem, OFONO_VENDOR_UBLOX, "atmodem",
+	gprs = ofono_gprs_create(modem, data->vendor_family, "atmodem",
 					data->aux);
-	gc = ofono_gprs_context_create(modem, OFONO_VENDOR_UBLOX, "atmodem",
-					data->modem);
+	gc = ofono_gprs_context_create(modem, data->vendor_family, "atmodem",
+					data->modem ? data->modem : data->aux);
 
 	if (gprs && gc)
 		ofono_gprs_add_context(gprs, gc);
@@ -298,7 +298,7 @@ static void ublox_post_online(struct ofono_modem *modem)
 {
 	struct ublox_data *data = ofono_modem_get_data(modem);
 
-	ofono_netreg_create(modem, 0, "atmodem", data->aux);
+	ofono_netreg_create(modem, data->vendor_family, "atmodem", data->aux);
 }
 
 static struct ofono_modem_driver ublox_driver = {
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (5 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 06/19] plugins/ublox: use vendor from structure instead of fixed Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:29   ` Denis Kenzior
  2016-03-10 14:43   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 08/19] atmodem: add support for U-Blox TOBY L2 modems Dragos Tatulea
                   ` (11 subsequent siblings)
  18 siblings, 2 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 512 bytes --]

Based on UBX-13002752 R33
---
 drivers/atmodem/gprs.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
index 5551316..0165253 100644
--- a/drivers/atmodem/gprs.c
+++ b/drivers/atmodem/gprs.c
@@ -303,10 +303,6 @@ static void ublox_ureg_notify(GAtResult *result, gpointer user_data)
 	case 5:
 		bearer = 4;
 		break;
-	case 7:
-		/* XXX: reserved - assume none. */
-		bearer = 0;
-		break;
 	case 8:
 		bearer = 1;
 		break;
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 08/19] atmodem: add support for U-Blox TOBY L2 modems
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (6 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:34   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 09/19] atmodem: work around CGREG issues in UBlox Toby L2 Dragos Tatulea
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3900 bytes --]

Besides exceptions below, act like normal U-Blox devices.

gprs-context: don't set auth for TOBY L2. U-Blox Toby L2
doesn't support PAP/CHAP APN auth method.

atmodem: TOBY L2 supports only CMER mode 1. Also chaged original
mode variable to ind, which is a more appropriate name.
mode is what is being set first.
---
 drivers/atmodem/gprs-context.c         |  2 ++
 drivers/atmodem/gprs.c                 |  1 +
 drivers/atmodem/network-registration.c | 12 +++++++-----
 drivers/atmodem/sim.c                  |  1 +
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/atmodem/gprs-context.c b/drivers/atmodem/gprs-context.c
index f6e6c2e..ab47b25 100644
--- a/drivers/atmodem/gprs-context.c
+++ b/drivers/atmodem/gprs-context.c
@@ -304,6 +304,8 @@ static void at_gprs_activate_primary(struct ofono_gprs_context *gc,
 				break;
 			}
 			break;
+		case OFONO_VENDOR_UBLOX_TOBY_L2:
+			/* Above not true for Toby L2 family, default is ok. */
 		default:
 			snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
 					ctx->apn);
diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
index 0165253..4505477 100644
--- a/drivers/atmodem/gprs.c
+++ b/drivers/atmodem/gprs.c
@@ -351,6 +351,7 @@ static void gprs_initialized(gboolean ok, GAtResult *result, gpointer user_data)
 						FALSE, gprs, NULL);
 		break;
 	case OFONO_VENDOR_UBLOX:
+	case OFONO_VENDOR_UBLOX_TOBY_L2:
 		g_at_chat_register(gd->chat, "+UREG:", ublox_ureg_notify,
 						FALSE, gprs, NULL);
 		g_at_chat_send(gd->chat, "AT+UREG=1", none_prefix,
diff --git a/drivers/atmodem/network-registration.c b/drivers/atmodem/network-registration.c
index 7cfd6b2..81e8b8d 100644
--- a/drivers/atmodem/network-registration.c
+++ b/drivers/atmodem/network-registration.c
@@ -1580,8 +1580,10 @@ static inline ofono_bool_t append_cmer_element(char *buf, int *len, int cap,
 static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
 					struct netreg_data *nd)
 {
-	const char *mode;
+	const char *ind;
 	int len = sprintf(buf, "AT+CMER=");
+	/* UBX-13002752 R33: TOBY L2 doesn't support mode 2 and 3 */
+	const char *mode = nd->vendor == OFONO_VENDOR_UBLOX_TOBY_L2 ? "1":"3";
 
 	DBG("");
 
@@ -1590,7 +1592,7 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
 	 * TA‑TE link specific inband technique used to embed result codes and
 	 * data when TA is in on‑line data mode
 	 */
-	if (!append_cmer_element(buf, &len, cmer_opts[0], "3", FALSE))
+	if (!append_cmer_element(buf, &len, cmer_opts[0], mode, FALSE))
 		return FALSE;
 
 	/* No keypad event reporting */
@@ -1607,14 +1609,14 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
 		 * Telit does not support mode 1.
 		 * All indicator events shall be directed from TA to TE.
 		 */
-		mode = "2";
+		ind = "2";
 		break;
 	default:
 		/*
 		 * Only those indicator events, which are not caused by +CIND
 		 * shall be indicated by the TA to the TE.
 		 */
-		mode = "1";
+		ind = "1";
 		break;
 	}
 
@@ -1623,7 +1625,7 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
 	 * <ind> indicates the indicator order number (as specified for +CIND)
 	 * and <value> is the new value of indicator.
 	 */
-	if (!append_cmer_element(buf, &len, cmer_opts[3], mode, TRUE))
+	if (!append_cmer_element(buf, &len, cmer_opts[3], ind, TRUE))
 		return FALSE;
 
 	return TRUE;
diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index d6a0dcf..081d342 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -1120,6 +1120,7 @@ static void at_pin_retries_query(struct ofono_sim *sim,
 			return;
 		break;
 	case OFONO_VENDOR_UBLOX:
+	case OFONO_VENDOR_UBLOX_TOBY_L2:
 		if (g_at_chat_send(sd->chat, "AT+UPINCNT", upincnt_prefix,
 					upincnt_cb, cbd, g_free) > 0)
 			return;
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 09/19] atmodem: work around CGREG issues in UBlox Toby L2
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (7 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 08/19] atmodem: add support for U-Blox TOBY L2 modems Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-10 14:40   ` Denis Kenzior
  2016-03-09 15:44 ` [PATCH 10/19] ubloxmodem: add Toby L2 gprs context driver Dragos Tatulea
                   ` (9 subsequent siblings)
  18 siblings, 1 reply; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2016 bytes --]

Don't use CGREG for network notifications. It will return
4 both when registered in LTE and in unknown state.

For the CGREG? query, interpret 4 as registered.
---
 drivers/atmodem/gprs.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
index 4505477..0b4bce8 100644
--- a/drivers/atmodem/gprs.c
+++ b/drivers/atmodem/gprs.c
@@ -101,6 +101,17 @@ static void at_cgreg_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		return;
 	}
 
+	if (gd->vendor == OFONO_VENDOR_UBLOX_TOBY_L2 && status == 4) {
+		/*
+		 * UBX-13002752-R33 says:
+		 * If the module is registered to E-UTRAN the <stat> parameter is 4.
+		 * So this means we are actually registered.
+		 * It could also mean that state is unknown, but if we are
+		 * here we know we already registered.
+		 */
+		 status = 1;
+	}
+
 	cb(&error, status, cbd->data);
 }
 
@@ -342,16 +353,23 @@ static void gprs_initialized(gboolean ok, GAtResult *result, gpointer user_data)
 	struct gprs_data *gd = ofono_gprs_get_data(gprs);
 
 	g_at_chat_register(gd->chat, "+CGEV:", cgev_notify, FALSE, gprs, NULL);
-	g_at_chat_register(gd->chat, "+CGREG:", cgreg_notify,
-						FALSE, gprs, NULL);
+
+	/*
+	 * You really don't want to get CGREG notifications on Toby l2.
+	 * It sends 4 when BOTH for unknown state and for registered in LTE.
+	 * +UREG usage is recommended by them.
+	 */
+	if (gd->vendor != OFONO_VENDOR_UBLOX_TOBY_L2)
+		g_at_chat_register(gd->chat, "+CGREG:", cgreg_notify,
+							FALSE, gprs, NULL);
 
 	switch (gd->vendor) {
 	case OFONO_VENDOR_HUAWEI:
 		g_at_chat_register(gd->chat, "^MODE:", huawei_mode_notify,
 						FALSE, gprs, NULL);
 		break;
-	case OFONO_VENDOR_UBLOX:
 	case OFONO_VENDOR_UBLOX_TOBY_L2:
+	case OFONO_VENDOR_UBLOX:
 		g_at_chat_register(gd->chat, "+UREG:", ublox_ureg_notify,
 						FALSE, gprs, NULL);
 		g_at_chat_send(gd->chat, "AT+UREG=1", none_prefix,
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 10/19] ubloxmodem: add Toby L2 gprs context driver
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (8 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 09/19] atmodem: work around CGREG issues in UBlox Toby L2 Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 11/19] gprs-context.h: add function for setting APN Dragos Tatulea
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 16912 bytes --]

For now the driver works only with bridged mode.

Once it activates the context it reads the ip, netmask,
gw, dns and sets them in the context settings.

4G default bearer is supported as well by reading the
automatic activation cid and using it in the first context
activation.
---
 Makefile.am                       |   7 +
 drivers/ubloxmodem/gprs-context.c | 498 ++++++++++++++++++++++++++++++++++++++
 drivers/ubloxmodem/ubloxmodem.c   |  49 ++++
 drivers/ubloxmodem/ubloxmodem.h   |  25 ++
 4 files changed, 579 insertions(+)
 create mode 100644 drivers/ubloxmodem/gprs-context.c
 create mode 100644 drivers/ubloxmodem/ubloxmodem.c
 create mode 100644 drivers/ubloxmodem/ubloxmodem.h

diff --git a/Makefile.am b/Makefile.am
index cde998d..7652cfe 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -374,6 +374,13 @@ builtin_sources += drivers/atmodem/atutil.h \
 			drivers/speedupmodem/speedupmodem.c \
 			drivers/speedupmodem/ussd.c
 
+builtin_modules += ubloxmodem
+builtin_sources += drivers/atmodem/atutil.h \
+			drivers/ubloxmodem/ubloxmodem.h \
+			drivers/ubloxmodem/ubloxmodem.c \
+			drivers/ubloxmodem/gprs-context.c
+
+
 if PHONESIM
 builtin_modules += phonesim
 builtin_sources += plugins/phonesim.c
diff --git a/drivers/ubloxmodem/gprs-context.c b/drivers/ubloxmodem/gprs-context.c
new file mode 100644
index 0000000..f80e1d8
--- /dev/null
+++ b/drivers/ubloxmodem/gprs-context.c
@@ -0,0 +1,498 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2016  EndoCode AG. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/gprs-context.h>
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "ubloxmodem.h"
+
+static const char *none_prefix[] = { NULL };
+static const char *cgcontrdp_prefix[] = { "+CGCONTRDP:", NULL };
+
+struct gprs_context_data {
+	GAtChat *chat;
+	unsigned int active_context;
+	unsigned int gprs_cid;
+	char apn[OFONO_GPRS_MAX_APN_LENGTH + 1];
+	ofono_gprs_context_cb_t cb;
+	void *cb_data;
+};
+
+#define UBLOX_MAX_DEF_CONTEXT 8
+
+struct ublox_data {
+	/* Stores default PDP context/default EPS bearer. */
+	unsigned int default_context_id;
+	struct gprs_context_data contexts[UBLOX_MAX_DEF_CONTEXT];
+	unsigned int ncontexts;
+
+	/* Save used cids on the modem. */
+	bool active[UBLOX_MAX_DEF_CONTEXT];
+	unsigned int nactive;
+};
+
+static struct ublox_data ublox_data;
+
+static int get_context_id()
+{
+	int i = 0;
+
+	if (!ublox_data.nactive && ublox_data.default_context_id) {
+		/* Try to assign default context first. */
+		i = ublox_data.default_context_id - 1;
+		goto found;
+	}
+
+	for (i = 0; i < UBLOX_MAX_DEF_CONTEXT; i++) {
+		if (!ublox_data.active[i])
+			goto found;
+	}
+
+	return 0;
+found:
+	ublox_data.active[i] = true;
+	ublox_data.nactive++;
+
+	return i+1;
+}
+
+static void release_context_id(unsigned cid)
+{
+	int i;
+
+	if (!cid || cid > UBLOX_MAX_DEF_CONTEXT)
+		return;
+
+	for (i = 0; i < UBLOX_MAX_DEF_CONTEXT; i++) {
+		if (ublox_data.contexts[i].active_context == cid) {
+
+			ublox_data.active[i] = false;
+			ublox_data.nactive--;
+
+			ublox_data.contexts[i].active_context = 0;
+			ublox_data.contexts[i].gprs_cid = 0;
+
+			return;
+		}
+	}
+}
+
+/*
+ * CGCONTRDP returns addr + netmask in the same string in the form
+ * of "a.b.c.d.m.m.m.m" for IPv4. IPv6 is not supported so we ignore it.
+ */
+static int read_addrnetmask(struct ofono_gprs_context *gc,
+				const char *addrnetmask)
+{
+	char *dup = strdup(addrnetmask);
+	char *s = dup;
+
+	const char *addr = s;
+	const char *netmask = NULL;
+
+	int ret = -EINVAL;
+	int i;
+
+	/* Count 7 dots for ipv4, less or more means error. */
+	for (i = 0; i < 8; i++, s++) {
+		s = strchr(s, '.');
+		if (!s)
+			break;
+
+		if (i == 3) {
+			/* set netmask ptr and break the string */
+			netmask = s+1;
+			s[0] = 0;
+		}
+	}
+
+	if (i == 7) {
+		ofono_gprs_context_set_ipv4_address(gc, addr, 1);
+		ofono_gprs_context_set_ipv4_netmask(gc, netmask);
+
+		ret = 0;
+	}
+
+	free(dup);
+
+	return ret;
+}
+
+static void callback_with_error(struct gprs_context_data *gcd, GAtResult *res)
+{
+	struct ofono_error error;
+
+	decode_at_error(&error, g_at_result_final_response(res));
+	gcd->cb(&error, gcd->cb_data);
+}
+
+
+static void set_gprs_context_interface(struct ofono_gprs_context *gc)
+{
+	struct ofono_modem *modem;
+	const char *interface;
+
+	/* read interface name read at detection time */
+	modem = ofono_gprs_context_get_modem(gc);
+	interface = ofono_modem_get_string(modem, "NetworkInterface");
+	ofono_gprs_context_set_interface(gc, interface);
+}
+
+static void cgcontrdp_bridge_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	GAtResultIter iter;
+	int cid = -1;
+
+	const char *laddrnetmask = NULL;
+	const char *gw = NULL;
+	const char *dns[2+1] = { NULL, NULL, NULL };
+
+	DBG("ok %d", ok);
+
+	if (!ok) {
+		callback_with_error(gcd, result);
+
+		return;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+	while (g_at_result_iter_next(&iter, "+CGCONTRDP:")) {
+		/* tmp vals for ignored fields */
+		int bearer_id;
+		char *apn;
+
+		if (!g_at_result_iter_next_number(&iter, &cid))
+			break;
+
+		if (!g_at_result_iter_next_number(&iter, &bearer_id))
+			break;
+
+		if (!g_at_result_iter_next_string(&iter, &apn))
+			break;
+
+		if (!g_at_result_iter_next_string(&iter, &laddrnetmask))
+			break;
+
+		if (!g_at_result_iter_next_string(&iter, &gw))
+			break;
+
+		if (!g_at_result_iter_next_string(&iter, &dns[0]))
+			break;
+
+		if (!g_at_result_iter_next_string(&iter, &dns[1]))
+			break;
+	}
+
+	set_gprs_context_interface(gc);
+
+	if (!laddrnetmask || read_addrnetmask(gc, laddrnetmask) < 0) {
+		CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+		return;
+	}
+
+	if (gw)
+		ofono_gprs_context_set_ipv4_gateway(gc, gw);
+
+	if (dns[0])
+		ofono_gprs_context_set_ipv4_dns_servers(gc, dns);
+
+	CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
+}
+
+static int ublox_read_ip_config_bridge(struct ofono_gprs_context *gc)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	char buf[64];
+
+	/* read ip configuration info */
+	snprintf(buf, sizeof(buf), "AT+CGCONTRDP=%u", gcd->active_context);
+	return g_at_chat_send(gcd->chat, buf, cgcontrdp_prefix,
+				cgcontrdp_bridge_cb, gc, NULL);
+
+}
+
+static void ublox_post_activation(struct ofono_gprs_context *gc)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+
+	if (ublox_read_ip_config_bridge(gc) < 0)
+		CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
+static void cgact_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+
+	DBG("ok %d", ok);
+	if (!ok) {
+		release_context_id(gcd->active_context);
+		callback_with_error(gcd, result);
+
+		return;
+	}
+
+	ublox_post_activation(gc);
+}
+
+static void cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	char buf[64];
+
+	DBG("ok %d", ok);
+
+	if (!ok) {
+		release_context_id(gcd->active_context);
+		callback_with_error(gcd, result);
+
+		return;
+	}
+
+	snprintf(buf, sizeof(buf), "AT+CGACT=1,%u", gcd->active_context);
+	if (g_at_chat_send(gcd->chat, buf, none_prefix,
+				cgact_enable_cb, gc, NULL))
+		return;
+
+	CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
+static void ublox_activate_ctx(struct ofono_gprs_context *gc)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	char buf[OFONO_GPRS_MAX_APN_LENGTH + 128];
+	int len;
+
+	len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IP\"",
+				gcd->active_context);
+
+	if (gcd->apn)
+		snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
+					gcd->apn);
+
+	if (g_at_chat_send(gcd->chat, buf, none_prefix,
+				cgdcont_cb, gc, NULL) > 0)
+		return;
+
+	CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
+#define UBLOX_MAX_USER_LEN 50
+#define UBLOX_MAX_PASS_LEN 50
+
+static void ublox_gprs_activate_primary(struct ofono_gprs_context *gc,
+				const struct ofono_gprs_primary_context *ctx,
+				ofono_gprs_context_cb_t cb, void *data)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+
+	/* IPv6 support not implemented */
+	if (ctx->proto != OFONO_GPRS_PROTO_IP) {
+		CALLBACK_WITH_FAILURE(cb, data);
+		return;
+	}
+
+	DBG("cid %u", ctx->cid);
+
+	gcd->active_context = get_context_id();
+	if (!gcd->active_context) {
+		ofono_error("can't activate more contexts");
+		CALLBACK_WITH_FAILURE(cb, data);
+		return;
+	}
+
+	gcd->cb = cb;
+	gcd->cb_data = data;
+	gcd->gprs_cid = ctx->cid;
+	memcpy(gcd->apn, ctx->apn, sizeof(ctx->apn));
+
+	if (gcd->active_context == ublox_data.default_context_id)
+		/* Default context already active, only read details. */
+		ublox_post_activation(gc);
+	else
+		ublox_activate_ctx(gc);
+}
+
+static void cgact_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+
+	DBG("ok %d", ok);
+	if (!ok) {
+		if (gcd->active_context && ublox_data.default_context_id)
+			ofono_warn("Disabling the default context is not "
+					"allowed on LTE.");
+		CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+		return;
+	}
+
+	release_context_id(gcd->active_context);
+
+	CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
+}
+
+static void ublox_gprs_deactivate_primary(struct ofono_gprs_context *gc,
+					unsigned int cid,
+					ofono_gprs_context_cb_t cb, void *data)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	char buf[64];
+
+	DBG("cid %u", cid);
+
+	gcd->cb = cb;
+	gcd->cb_data = data;
+
+	snprintf(buf, sizeof(buf), "AT+CGACT=0,%u", gcd->active_context);
+	g_at_chat_send(gcd->chat, buf, none_prefix,
+			cgact_disable_cb, gc, NULL);
+}
+
+static void cgev_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	GAtResultIter iter;
+	const char *event;
+	unsigned int cid;
+	char tmp[5] = {0};
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+CGEV:"))
+		return;
+
+	if (!g_at_result_iter_next_unquoted_string(&iter, &event))
+		return;
+
+	if (g_str_has_prefix(event, "ME PDN ACT") == TRUE) {
+		/*
+		 * We only care about the first even coming in before any user
+		 * activations happen. This is for detecting the default
+		 * context in LTE networks which doesn't require user
+		 * activation.
+		 */
+		sscanf(event, "%s %s %s %u", tmp, tmp, tmp, &cid);
+		if (!ublox_data.default_context_id && !ublox_data.nactive)
+			ublox_data.default_context_id = cid;
+		DBG("cid=%d activated", cid);
+
+		return;
+	} else if (g_str_has_prefix(event, "NW PDN DEACT") == TRUE) {
+		sscanf(event, "%s %s %s %u", tmp, tmp, tmp, &cid);
+		DBG("cid=%d deactivated", cid);
+	} else
+		return;
+
+	/* Can happen if non-default context is deactivated. Ignore. */
+	if (gcd->active_context != cid)
+		return;
+
+	if (ublox_data.default_context_id == cid)
+		ublox_data.default_context_id = 0;
+
+	ofono_gprs_context_deactivated(gc, gcd->gprs_cid);
+
+	release_context_id(gcd->active_context);
+}
+
+
+static int ublox_gprs_context_probe(struct ofono_gprs_context *gc,
+					unsigned int vendor, void *data)
+{
+	GAtChat *chat = data;
+	struct gprs_context_data *gcd;
+
+	DBG("");
+
+	if (ublox_data.ncontexts >= UBLOX_MAX_DEF_CONTEXT) {
+		ofono_error("modem supports defining max 8 contexts");
+		return -E2BIG;
+	}
+
+	gcd = &ublox_data.contexts[ublox_data.ncontexts];
+	memset(gcd, 0, sizeof(*gcd));
+	ublox_data.ncontexts++;
+
+	gcd->chat = g_at_chat_clone(chat);
+
+	ofono_gprs_context_set_data(gc, gcd);
+
+	/* Not sure if ok to register all contexts with the callback. */
+	g_at_chat_register(chat, "+CGEV:", cgev_notify, FALSE, gc, NULL);
+
+	return 0;
+}
+
+static void ublox_gprs_context_remove(struct ofono_gprs_context *gc)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+
+	DBG("");
+
+	ofono_gprs_context_set_data(gc, NULL);
+
+	g_at_chat_unref(gcd->chat);
+
+	memset(gcd, 0, sizeof(*gcd));
+	ublox_data.ncontexts--;
+}
+
+static struct ofono_gprs_context_driver driver = {
+	.name			= "ubloxmodem",
+	.probe			= ublox_gprs_context_probe,
+	.remove			= ublox_gprs_context_remove,
+	.activate_primary	= ublox_gprs_activate_primary,
+	.deactivate_primary	= ublox_gprs_deactivate_primary,
+};
+
+
+void ublox_gprs_context_init(void)
+{
+	ofono_gprs_context_driver_register(&driver);
+}
+
+void ublox_gprs_context_exit(void)
+{
+	ofono_gprs_context_driver_unregister(&driver);
+}
diff --git a/drivers/ubloxmodem/ubloxmodem.c b/drivers/ubloxmodem/ubloxmodem.c
new file mode 100644
index 0000000..7fc671e
--- /dev/null
+++ b/drivers/ubloxmodem/ubloxmodem.c
@@ -0,0 +1,49 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2016  Endocode AG. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <gatchat.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/types.h>
+
+#include "ubloxmodem.h"
+
+static int ubloxmodem_init(void)
+{
+	ublox_gprs_context_init();
+
+	return 0;
+}
+
+static void ubloxmodem_exit(void)
+{
+	ublox_gprs_context_exit();
+}
+
+OFONO_PLUGIN_DEFINE(ubloxmodem, "U-Blox Toby L2 high speed modem driver",
+			VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+			ubloxmodem_init, ubloxmodem_exit)
diff --git a/drivers/ubloxmodem/ubloxmodem.h b/drivers/ubloxmodem/ubloxmodem.h
new file mode 100644
index 0000000..0c8a621
--- /dev/null
+++ b/drivers/ubloxmodem/ubloxmodem.h
@@ -0,0 +1,25 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2016  Endocode AG. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <drivers/atmodem/atutil.h>
+
+extern void ublox_gprs_context_init(void);
+extern void ublox_gprs_context_exit(void);
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 11/19] gprs-context.h: add function for setting APN
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (9 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 10/19] ubloxmodem: add Toby L2 gprs context driver Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 12/19] gprs: allow APN updates from gprs-context driver Dragos Tatulea
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 660 bytes --]

---
 include/gprs-context.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/gprs-context.h b/include/gprs-context.h
index 0090cc4..11d2132 100644
--- a/include/gprs-context.h
+++ b/include/gprs-context.h
@@ -107,6 +107,9 @@ enum ofono_gprs_context_type ofono_gprs_context_get_type(
 void ofono_gprs_context_set_interface(struct ofono_gprs_context *gc,
 					const char *interface);
 
+void ofono_gprs_context_set_apn(struct ofono_gprs_context *gc,
+					const char *interface);
+
 void ofono_gprs_context_set_ipv4_address(struct ofono_gprs_context *gc,
 						const char *address,
 						ofono_bool_t static_ip);
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 12/19] gprs: allow APN updates from gprs-context driver
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (10 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 11/19] gprs-context.h: add function for setting APN Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 13/19] ubloxmodem: push back APN into gprs context Dragos Tatulea
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2625 bytes --]

In the context activation callback, check for a changed APN. The default
PDP in a 4G network is usually automatically activated. We might not know
the APN. So allow the driver to read the APN and push it back into the
core context.
---
 src/gprs.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 9192e68..d31e91b 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -103,6 +103,7 @@ struct ipv6_settings {
 };
 
 struct context_settings {
+	char *apn;
 	char *interface;
 	struct ipv4_settings *ipv4;
 	struct ipv6_settings *ipv6;
@@ -383,6 +384,9 @@ static void context_settings_free(struct context_settings *settings)
 		settings->ipv6 = NULL;
 	}
 
+	g_free(settings->apn);
+	settings->apn = NULL;
+
 	g_free(settings->interface);
 	settings->interface = NULL;
 }
@@ -867,6 +871,9 @@ static DBusMessage *pri_get_properties(DBusConnection *conn,
 	return reply;
 }
 
+static DBusMessage *pri_set_apn(struct pri_context *ctx, DBusConnection *conn,
+				DBusMessage *msg, const char *apn);
+
 static void pri_activate_callback(const struct ofono_error *error, void *data)
 {
 	struct pri_context *ctx = data;
@@ -886,6 +893,11 @@ static void pri_activate_callback(const struct ofono_error *error, void *data)
 		return;
 	}
 
+
+	if (gc->settings->apn && strcmp(gc->settings->apn, ctx->context.apn))
+		/* APN changed  during context activation. */
+		pri_set_apn(ctx, conn, NULL, gc->settings->apn);
+
 	ctx->active = TRUE;
 	__ofono_dbus_pending_reply(&ctx->pending,
 				dbus_message_new_method_return(ctx->pending));
@@ -955,13 +967,13 @@ static DBusMessage *pri_set_apn(struct pri_context *ctx, DBusConnection *conn,
 		storage_sync(ctx->gprs->imsi, SETTINGS_STORE, settings);
 	}
 
-	g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);
+	if (msg)
+		g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);
 
 	ofono_dbus_signal_property_changed(conn, ctx->path,
 					OFONO_CONNECTION_CONTEXT_INTERFACE,
 					"AccessPointName",
 					DBUS_TYPE_STRING, &apn);
-
 	return NULL;
 }
 
@@ -2688,6 +2700,15 @@ void ofono_gprs_context_set_interface(struct ofono_gprs_context *gc,
 	settings->interface = g_strdup(interface);
 }
 
+void ofono_gprs_context_set_apn(struct ofono_gprs_context *gc,
+					const char *apn)
+{
+	struct context_settings *settings = gc->settings;
+
+	g_free(settings->apn);
+	settings->apn = g_strdup(apn);
+}
+
 void ofono_gprs_context_set_ipv4_address(struct ofono_gprs_context *gc,
 						const char *address,
 						ofono_bool_t static_ip)
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 13/19] ubloxmodem: push back APN into gprs context
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (11 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 12/19] gprs: allow APN updates from gprs-context driver Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 14/19] plugins/ublox: give names to model ids Dragos Tatulea
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1637 bytes --]

It can be that the APN is different than what a user provided. So let
the core know. This happens for example when using the default bearer:
the user doesn't provide any APN, so read the one from CGCONTRDP.
---
 drivers/ubloxmodem/gprs-context.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/ubloxmodem/gprs-context.c b/drivers/ubloxmodem/gprs-context.c
index f80e1d8..b6eaa5e 100644
--- a/drivers/ubloxmodem/gprs-context.c
+++ b/drivers/ubloxmodem/gprs-context.c
@@ -183,6 +183,7 @@ static void cgcontrdp_bridge_cb(gboolean ok, GAtResult *result, gpointer user_da
 	const char *laddrnetmask = NULL;
 	const char *gw = NULL;
 	const char *dns[2+1] = { NULL, NULL, NULL };
+	const char *apn = NULL;
 
 	DBG("ok %d", ok);
 
@@ -197,7 +198,6 @@ static void cgcontrdp_bridge_cb(gboolean ok, GAtResult *result, gpointer user_da
 	while (g_at_result_iter_next(&iter, "+CGCONTRDP:")) {
 		/* tmp vals for ignored fields */
 		int bearer_id;
-		char *apn;
 
 		if (!g_at_result_iter_next_number(&iter, &cid))
 			break;
@@ -234,6 +234,16 @@ static void cgcontrdp_bridge_cb(gboolean ok, GAtResult *result, gpointer user_da
 	if (dns[0])
 		ofono_gprs_context_set_ipv4_dns_servers(gc, dns);
 
+	if (gcd->active_context == ublox_data.default_context_id) {
+		/*
+		 * Only for automatic default context: the APN set by the user
+		 * might not be the correct one because the default context was
+		 * used instead.
+		 */
+		ofono_gprs_context_set_apn(gc, apn);
+		strcpy(gcd->apn, apn);
+	}
+
 	CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
 }
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 14/19] plugins/ublox: give names to model ids
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (12 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 13/19] ubloxmodem: push back APN into gprs context Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 15/19] plugins/ublox: enable ubloxmodem driver when possible Dragos Tatulea
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1740 bytes --]

To make it easier to understand the code.
---
 plugins/ublox.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index 0965ad1..bdc0fa1 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -44,9 +44,18 @@
 
 static const char *none_prefix[] = { NULL };
 
+enum supported_models {
+	UNKNOWN				= 0,
+	SARA_G270			= 1102,
+	TOBYL2_COMPATIBLE_MODE 		= 1141,
+	TOBYL2_MEDIUM_THROUGHPUT_MODE 	= 1143,
+	TOBYL2_HIGH_THROUGHPUT_MODE 	= 1146,
+};
+
 struct ublox_data {
 	GAtChat *modem;
 	GAtChat *aux;
+	int model_id;
 	enum ofono_vendor vendor_family;
 };
 
@@ -140,7 +149,6 @@ static int ublox_enable(struct ofono_modem *modem)
 {
 	struct ublox_data *data = ofono_modem_get_data(modem);
 	const char *model_str = NULL;
-	int model_id;
 
 	DBG("%p", modem);
 
@@ -152,19 +160,19 @@ static int ublox_enable(struct ofono_modem *modem)
 	 * Toby L2 devices are more complex and special than previously
 	 * supported U-Blox devices. So they need a vendor of their own.
 	 */
-	model_id = atoi(model_str);
-	switch (model_id) {
-		case 1102:
+	data->model_id = atoi(model_str);
+	switch (data->model_id) {
+		case SARA_G270:
 			data->vendor_family = OFONO_VENDOR_UBLOX;
 			break;
-		case 1141:
-		case 1146:
+		case TOBYL2_COMPATIBLE_MODE:
+		case TOBYL2_HIGH_THROUGHPUT_MODE:
 			data->vendor_family = OFONO_VENDOR_UBLOX_TOBY_L2;
 			break;
-		case 1143:
+		case TOBYL2_MEDIUM_THROUGHPUT_MODE:
 			DBG("low/medium throughtput profile unsupported");
 		default:
-			DBG("unknown ublox model id %d", model_id);
+			DBG("unknown ublox model id %d", data->model_id);
 			return -EINVAL;
 	}
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 15/19] plugins/ublox: enable ubloxmodem driver when possible
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (13 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 14/19] plugins/ublox: give names to model ids Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 16/19] plugins/ublox: support more internet contexts Dragos Tatulea
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1418 bytes --]

Where possible means Toby L2 in high speed mode.

The bridge mode is set before enabling the modem because the
driver requires this.
---
 plugins/ublox.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index bdc0fa1..032a3c4 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -142,6 +142,11 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 		return;
 	}
 
+	if (data->model_id == TOBYL2_HIGH_THROUGHPUT_MODE)
+		/* use bridged mode until routed mode support is added */
+		g_at_chat_send(data->aux, "AT+UBMCONF=2", none_prefix,
+						NULL, NULL, NULL);
+
 	ofono_modem_set_powered(modem, TRUE);
 }
 
@@ -295,8 +300,15 @@ static void ublox_post_sim(struct ofono_modem *modem)
 
 	gprs = ofono_gprs_create(modem, data->vendor_family, "atmodem",
 					data->aux);
-	gc = ofono_gprs_context_create(modem, data->vendor_family, "atmodem",
-					data->modem ? data->modem : data->aux);
+	if (data->model_id == TOBYL2_HIGH_THROUGHPUT_MODE)
+		gc = ofono_gprs_context_create(modem, data->vendor_family,
+						"ubloxmodem",
+						data->modem ? data->modem : data->aux);
+
+	else
+		gc = ofono_gprs_context_create(modem, data->vendor_family,
+						"atmodem",
+						data->modem ? data->modem : data->aux);
 
 	if (gprs && gc)
 		ofono_gprs_add_context(gprs, gc);
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 16/19] plugins/ublox: support more internet contexts
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (14 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 15/19] plugins/ublox: enable ubloxmodem driver when possible Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 17/19] ubloxmodem: support authentication Dragos Tatulea
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]

Create multiple gprs-context instances and let the gprs core use
them as it sees fit.

Only for Toby L2.
---
 plugins/ublox.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index 032a3c4..76f7fcf 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -295,23 +295,26 @@ static void ublox_post_sim(struct ofono_modem *modem)
 	struct ublox_data *data = ofono_modem_get_data(modem);
 	struct ofono_gprs *gprs;
 	struct ofono_gprs_context *gc;
+	GAtChat *chat = data->modem ? data->modem : data->aux;
+	const char *driver = data->model_id == TOBYL2_HIGH_THROUGHPUT_MODE ?
+							"ubloxmodem":"atmodem";
+	/* Toby L2: Create same number of contexts as supported PDP contexts. */
+	int ncontexts = data->model_id == TOBYL2_HIGH_THROUGHPUT_MODE ? 8:1;
 
 	DBG("%p", modem);
 
 	gprs = ofono_gprs_create(modem, data->vendor_family, "atmodem",
 					data->aux);
-	if (data->model_id == TOBYL2_HIGH_THROUGHPUT_MODE)
-		gc = ofono_gprs_context_create(modem, data->vendor_family,
-						"ubloxmodem",
-						data->modem ? data->modem : data->aux);
 
-	else
+	while (ncontexts) {
 		gc = ofono_gprs_context_create(modem, data->vendor_family,
-						"atmodem",
-						data->modem ? data->modem : data->aux);
+						driver, chat);
 
-	if (gprs && gc)
-		ofono_gprs_add_context(gprs, gc);
+		if (gprs && gc)
+			ofono_gprs_add_context(gprs, gc);
+
+		--ncontexts;
+	}
 }
 
 static void ublox_post_online(struct ofono_modem *modem)
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 17/19] ubloxmodem: support authentication
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (15 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 16/19] plugins/ublox: support more internet contexts Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:44 ` [PATCH 18/19] plugins/ublox: read network mode Dragos Tatulea
  2016-03-09 15:45 ` [PATCH 19/19] ubloxmodem: add routed mode support Dragos Tatulea
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3251 bytes --]

If username and password specified, issue an UAUTHREQ
command with the configured authentication method, selected cid
and credentials.
---
 drivers/ubloxmodem/gprs-context.c | 61 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/drivers/ubloxmodem/gprs-context.c b/drivers/ubloxmodem/gprs-context.c
index b6eaa5e..bc100d6 100644
--- a/drivers/ubloxmodem/gprs-context.c
+++ b/drivers/ubloxmodem/gprs-context.c
@@ -49,6 +49,9 @@ struct gprs_context_data {
 	unsigned int active_context;
 	unsigned int gprs_cid;
 	char apn[OFONO_GPRS_MAX_APN_LENGTH + 1];
+	char username[OFONO_GPRS_MAX_USERNAME_LENGTH + 1];
+	char password[OFONO_GPRS_MAX_PASSWORD_LENGTH + 1];
+	enum ofono_gprs_auth_method auth_method;
 	ofono_gprs_context_cb_t cb;
 	void *cb_data;
 };
@@ -326,9 +329,58 @@ static void ublox_activate_ctx(struct ofono_gprs_context *gc)
 	CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
 }
 
+static void uauthreq_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+
+	DBG("ok %d", ok);
+
+	if (!ok) {
+		ofono_error("can't authenticate");
+		release_context_id(gcd->active_context);
+		callback_with_error(gcd, result);
+
+		return;
+	}
+
+	ublox_activate_ctx(gc);
+}
+
 #define UBLOX_MAX_USER_LEN 50
 #define UBLOX_MAX_PASS_LEN 50
 
+static void ublox_authenticate(struct ofono_gprs_context *gc)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	char buf[UBLOX_MAX_USER_LEN + UBLOX_MAX_PASS_LEN + 32];
+	unsigned auth_method;
+
+	switch (gcd->auth_method) {
+	case OFONO_GPRS_AUTH_METHOD_PAP:
+		auth_method = 1;
+		break;
+	case OFONO_GPRS_AUTH_METHOD_CHAP:
+		auth_method = 2;
+		break;
+	default:
+		ofono_error("Unsupported auth type %u", gcd->auth_method);
+		goto error;
+	}
+
+	snprintf(buf, sizeof(buf), "AT+UAUTHREQ=%u,%u,\"%s\",\"%s\"",
+			gcd->active_context, auth_method,
+			gcd->username, gcd->password);
+
+	/* If this failed, we will see it during context activation. */
+	if (g_at_chat_send(gcd->chat, buf, none_prefix,
+				uauthreq_cb, gc, NULL) > 0)
+		return;
+
+error:
+	CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
 static void ublox_gprs_activate_primary(struct ofono_gprs_context *gc,
 				const struct ofono_gprs_primary_context *ctx,
 				ofono_gprs_context_cb_t cb, void *data)
@@ -352,13 +404,18 @@ static void ublox_gprs_activate_primary(struct ofono_gprs_context *gc,
 
 	gcd->cb = cb;
 	gcd->cb_data = data;
+	gcd->auth_method = ctx->auth_method;
 	gcd->gprs_cid = ctx->cid;
 	memcpy(gcd->apn, ctx->apn, sizeof(ctx->apn));
 
-	if (gcd->active_context == ublox_data.default_context_id)
+	if (gcd->active_context == ublox_data.default_context_id) {
 		/* Default context already active, only read details. */
 		ublox_post_activation(gc);
-	else
+	} else if (strlen(ctx->username) && strlen(ctx->password)) {
+		memcpy(gcd->username, ctx->username, sizeof(ctx->username));
+		memcpy(gcd->password, ctx->password, sizeof(ctx->password));
+		ublox_authenticate(gc);
+	} else
 		ublox_activate_ctx(gc);
 }
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 18/19] plugins/ublox: read network mode
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (16 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 17/19] ubloxmodem: support authentication Dragos Tatulea
@ 2016-03-09 15:44 ` Dragos Tatulea
  2016-03-09 15:45 ` [PATCH 19/19] ubloxmodem: add routed mode support Dragos Tatulea
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2830 bytes --]

From: Dongsu Park <dongsu@endocode.com>

Read network mode into modem string. This will let the gprs-context
drive know what to do.
---
 plugins/ublox.c | 47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index 76f7fcf..9cfba33 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -42,6 +42,7 @@
 #include <drivers/atmodem/atutil.h>
 #include <drivers/atmodem/vendor.h>
 
+static const char *ubmconf_prefix[] = { "+UBMCONF:", NULL };
 static const char *none_prefix[] = { NULL };
 
 enum supported_models {
@@ -52,11 +53,17 @@ enum supported_models {
 	TOBYL2_HIGH_THROUGHPUT_MODE 	= 1146,
 };
 
+enum ublox_net_mode {
+	UBLOX_TOBYL2_NET_MODE_ROUTER = 1,
+	UBLOX_TOBYL2_NET_MODE_BRIDGE = 2,
+};
+
 struct ublox_data {
 	GAtChat *modem;
 	GAtChat *aux;
 	int model_id;
 	enum ofono_vendor vendor_family;
+	enum ublox_net_mode net_mode;
 };
 
 static void ublox_debug(const char *str, void *user_data)
@@ -93,6 +100,39 @@ static void ublox_remove(struct ofono_modem *modem)
 	g_free(data);
 }
 
+static void read_ubmconf_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = (struct ofono_modem *) user_data;
+	struct ublox_data *data = ofono_modem_get_data(modem);
+	int mode = 0;
+	GAtResultIter iter;
+
+	g_at_result_iter_init(&iter, result);
+
+	while (!g_at_result_iter_next(&iter, "+UBMCONF:"))
+		;	/* skip every other line that is not UBMCONF */
+
+	g_at_result_iter_next_number(&iter, &mode);
+
+	data->net_mode = mode;
+	DBG("mode=%d", mode);
+	if (mode == 1)
+		ofono_modem_set_string(modem, "NetworkMode", "routed");
+	else if (mode == 2)
+		ofono_modem_set_string(modem, "NetworkMode", "bridged");
+}
+
+static void read_net_mode(struct ofono_modem *modem)
+{
+	struct ublox_data *data = ofono_modem_get_data(modem);
+
+	if (!data->aux)
+		return;
+
+	g_at_chat_send(data->aux, "AT+UBMCONF?",
+			ubmconf_prefix, read_ubmconf_cb, modem, NULL);
+}
+
 static GAtChat *open_device(struct ofono_modem *modem,
 				const char *key, char *debug)
 {
@@ -142,11 +182,6 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 		return;
 	}
 
-	if (data->model_id == TOBYL2_HIGH_THROUGHPUT_MODE)
-		/* use bridged mode until routed mode support is added */
-		g_at_chat_send(data->aux, "AT+UBMCONF=2", none_prefix,
-						NULL, NULL, NULL);
-
 	ofono_modem_set_powered(modem, TRUE);
 }
 
@@ -207,6 +242,8 @@ static int ublox_enable(struct ofono_modem *modem)
 	g_at_chat_send(data->aux, "ATE0 +CMEE=1", none_prefix,
 					NULL, NULL, NULL);
 
+	read_net_mode(modem);
+
 	g_at_chat_send(data->aux, "AT+CFUN=4", none_prefix,
 					cfun_enable, modem, NULL);
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 19/19] ubloxmodem: add routed mode support
  2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
                   ` (17 preceding siblings ...)
  2016-03-09 15:44 ` [PATCH 18/19] plugins/ublox: read network mode Dragos Tatulea
@ 2016-03-09 15:45 ` Dragos Tatulea
  18 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-09 15:45 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 5510 bytes --]

From: Dongsu Park <dongsu@endocode.com>

Routed mode needs a different treatment than bridged mode:

* UIPCONF needs to be used for reading the interface ip configuratuion.
The spec says that DHCP should work on that interface but it doesn't. So
we read the first ip in the dhcp range and use that.

* CGCONTRDP: only APN and DNS configuration is read
---
 drivers/ubloxmodem/gprs-context.c | 151 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/ubloxmodem/gprs-context.c b/drivers/ubloxmodem/gprs-context.c
index bc100d6..4040a07 100644
--- a/drivers/ubloxmodem/gprs-context.c
+++ b/drivers/ubloxmodem/gprs-context.c
@@ -43,6 +43,7 @@
 
 static const char *none_prefix[] = { NULL };
 static const char *cgcontrdp_prefix[] = { "+CGCONTRDP:", NULL };
+static const char *uipconf_prefix[] = { "+UIPCONF:", NULL };
 
 struct gprs_context_data {
 	GAtChat *chat;
@@ -250,6 +251,65 @@ static void cgcontrdp_bridge_cb(gboolean ok, GAtResult *result, gpointer user_da
 	CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
 }
 
+static void cgcontrdp_router_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	GAtResultIter iter;
+
+	const char *dns[2+1] = { NULL, NULL, NULL };
+	const char *apn = NULL;
+
+	DBG("ok %d", ok);
+
+	if (!ok) {
+		callback_with_error(gcd, result);
+
+		return;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+	while (g_at_result_iter_next(&iter, "+CGCONTRDP:")) {
+		/* skip cid, bearer_id */
+		g_at_result_iter_skip_next(&iter);
+		g_at_result_iter_skip_next(&iter);
+
+		/* read apn */
+		if (!g_at_result_iter_next_string(&iter, &apn))
+			break;
+
+		/* skip laddrnetmask, gw */
+		g_at_result_iter_skip_next(&iter);
+		g_at_result_iter_skip_next(&iter);
+
+		/* read dns servers */
+		if (!g_at_result_iter_next_string(&iter, &dns[0]))
+			break;
+
+		if (!g_at_result_iter_next_string(&iter, &dns[1]))
+			break;
+	}
+
+	set_gprs_context_interface(gc);
+
+	if (dns[0])
+		ofono_gprs_context_set_ipv4_dns_servers(gc, dns);
+
+	if (gcd->active_context == ublox_data.default_context_id) {
+		/*
+		 * Only for automatic default context: the APN set by the user
+		 * might not be the correct one because the default context was
+		 * used instead.
+		 */
+		ofono_gprs_context_set_apn(gc, apn);
+		strcpy(gcd->apn, apn);
+	}
+
+	CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
+	return;
+}
+
 static int ublox_read_ip_config_bridge(struct ofono_gprs_context *gc)
 {
 	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
@@ -262,11 +322,100 @@ static int ublox_read_ip_config_bridge(struct ofono_gprs_context *gc)
 
 }
 
+static void read_uipconf_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	GAtResultIter iter;
+	const char *gw, *netmask, *ipaddr, *dhcp_range_start, *dhcp_range_end;
+	gboolean found = FALSE;
+	char buf[64];
+
+	DBG("ok %d", ok);
+
+	if (!ok) {
+		release_context_id(gcd->active_context);
+		callback_with_error(gcd, result);
+
+		return;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+	/* for example, +UIPCONF: entry looks like:
+	 * +UIPCONF: "192.168.1.1","255.255.255.0","192.168.1.100",
+	 *           "192.168.1.100","fe80::48a5:b2ff:fe6f:5f86/64"
+	 */
+	while (g_at_result_iter_next(&iter, "+UIPCONF:")) {
+		if (!g_at_result_iter_next_string(&iter, &gw))
+			continue;
+
+		if (!g_at_result_iter_next_string(&iter, &netmask))
+			continue;
+
+		if (!g_at_result_iter_next_string(&iter, &dhcp_range_start))
+			continue;
+
+		if (!g_at_result_iter_next_string(&iter, &dhcp_range_end))
+			continue;
+
+		/* skip other entries like IPv6 networks */
+		found = TRUE;
+		break;
+	}
+
+	if (!found)
+		goto error;
+
+	if (dhcp_range_start && dhcp_range_end) {
+		ipaddr = dhcp_range_start;
+		ofono_gprs_context_set_ipv4_address(gc, ipaddr, 1);
+	}
+
+	if (netmask)
+		ofono_gprs_context_set_ipv4_netmask(gc, netmask);
+
+	if (gw)
+		ofono_gprs_context_set_ipv4_gateway(gc, gw);
+
+	/* read ip configuration info */
+	snprintf(buf, sizeof(buf), "AT+CGCONTRDP");
+	if (g_at_chat_send(gcd->chat, buf, cgcontrdp_prefix,
+				cgcontrdp_router_cb, gc, NULL) > 0)
+		return;
+
+error:
+	CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
+static int ublox_read_ip_config_router(struct ofono_gprs_context *gc)
+{
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	char buf[64];
+
+	/* read ip configuration info */
+	snprintf(buf, sizeof(buf), "AT+UIPCONF?");
+	return g_at_chat_send(gcd->chat, buf, uipconf_prefix,
+				read_uipconf_cb, gc, NULL);
+
+}
+
 static void ublox_post_activation(struct ofono_gprs_context *gc)
 {
+	struct ofono_modem *modem;
+	const char *network_mode;
 	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	int ret = 0;
+
+	modem = ofono_gprs_context_get_modem(gc);
+	network_mode = ofono_modem_get_string(modem, "NetworkMode");
+
+	if (g_str_equal(network_mode, "routed"))
+		ret = ublox_read_ip_config_router(gc) ;
+	else
+		ret = ublox_read_ip_config_bridge(gc);
 
-	if (ublox_read_ip_config_bridge(gc) < 0)
+	if (ret <= 0)
 		CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
 }
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH 01/19] plugins/udevng: support the U-Blox TOBY-L2 series
  2016-03-09 15:44 ` [PATCH 01/19] plugins/udevng: support the U-Blox TOBY-L2 series Dragos Tatulea
@ 2016-03-10 14:00   ` Denis Kenzior
  0 siblings, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:00 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

Hi Dongsu,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> From: Dongsu Park <dongsu@endocode.com>
>
> The newest generation of U-Blox TOBY-L2 series can be detected with
> VID 0x1546 (the same as before), and one of the following PIDs:
>
> * "0x1146" : high throughput profile
> * "0x1141" : fairly back-compatible profile
> * "0x1143" : low/medium throughput profile
>
> This patch adds detection for high throughput mode.
> ---
>   plugins/udevng.c | 2 ++
>   1 file changed, 2 insertions(+)
>

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 02/19] plugins/udevng: support different interface strings to detect TOBY series
  2016-03-09 15:44 ` [PATCH 02/19] plugins/udevng: support different interface strings to detect TOBY series Dragos Tatulea
@ 2016-03-10 14:01   ` Denis Kenzior
  0 siblings, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:01 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2845 bytes --]

Hi Dongsu,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> From: Dongsu Park <dongsu@endocode.com>
>
> Each modem expresses their interfaces with its own interface string,
> which is composed of 3 different USB attributes:
> "bInterfaceClass/bInterfaceSubClass/bInterfaceProtocol".
> While the old models like LISA support only "2/2/1" for modem
> interfaces, TOBY-L2 also supports an unique string for NetworkInterface
> for each profile.
>
> * low-medium throughput profile : 2/6/0
> * fairly backward-compatible profile : 10/0/0
> * high throughput profile : 224/1/3
>
> Besides the condition for checking NULL for mdm/aux/net should be relaxed
> a little bit.
> ---
>   plugins/udevng.c | 22 +++++++++++++++++++---
>   1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/plugins/udevng.c b/plugins/udevng.c
> index 52b667e..2170c90 100644
> --- a/plugins/udevng.c
> +++ b/plugins/udevng.c
> @@ -838,7 +838,7 @@ static gboolean setup_quectel(struct modem_info *modem)
>
>   static gboolean setup_ublox(struct modem_info *modem)
>   {
> -	const char *aux = NULL, *mdm = NULL;
> +	const char *aux = NULL, *mdm = NULL, *net = NULL;
>   	GSList *list;
>
>   	DBG("%s", modem->syspath);
> @@ -857,21 +857,37 @@ static gboolean setup_ublox(struct modem_info *modem)
>   			mdm = info->devnode;
>   			if (aux != NULL)
>   				break;
> +		/*
> +		 * "2/2/1"
> +		 *  - a common modem interface both for older models like LISA,
> +		 *    and for newer models like TOBY.
> +		 * For TOBY-L2, NetworkInterface can be detected for each profile:
> +		 *  - low-medium throughput profile : 2/6/0
> +		 *  - fairly backward-compatible profile : 10/0/0
> +		 *  - high throughput profile : 224/1/3
> +		 * */
>   		} else if (g_strcmp0(info->interface, "2/2/1") == 0) {
>   			if (g_strcmp0(info->number, "02") == 0)
>   				aux = info->devnode;
>   			else if (g_strcmp0(info->number, "00") == 0)
>   				mdm = info->devnode;
> +		} else if (g_strcmp0(info->interface, "2/6/0") == 0 ||
> +			   g_strcmp0(info->interface, "10/0/0") == 0 ||
> +			   g_strcmp0(info->interface, "224/1/3") == 0) {
> +			net = info->devnode;
>   		}
>   	}
>
> -	if (aux == NULL || mdm == NULL)
> +	/* Abort only if both interfaces are NULL, as it's highly possible that
> +	 * only one of 2 interfaces is available for U-blox modem. */

Not our comment style, please look at doc/coding-style.txt item M2

> +	if (aux == NULL && mdm == NULL)
>   		return FALSE;
>
> -	DBG("aux=%s modem=%s", aux, mdm);
> +	DBG("aux=%s modem=%s net=%s", aux, mdm, net);
>
>   	ofono_modem_set_string(modem->modem, "Aux", aux);
>   	ofono_modem_set_string(modem->modem, "Modem", mdm);
> +	ofono_modem_set_string(modem->modem, "NetworkInterface", net);
>
>   	return TRUE;
>   }
>

Regards,
-Denis

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 03/19] plugins/udevng: ublox: set model string
  2016-03-09 15:44 ` [PATCH 03/19] plugins/udevng: ublox: set model string Dragos Tatulea
@ 2016-03-10 14:04   ` Denis Kenzior
  0 siblings, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:04 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

Hi Dragos,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> Necessary for supporting the ublox TOBY L2 modem.
> ---
>   plugins/udevng.c | 1 +
>   1 file changed, 1 insertion(+)
>

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 04/19] include: vendor.h: add vendor for ublox toby
  2016-03-09 15:44 ` [PATCH 04/19] include: vendor.h: add vendor for ublox toby Dragos Tatulea
@ 2016-03-10 14:05   ` Denis Kenzior
  0 siblings, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:05 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

Hi Dragos,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> Required to differentiate between the old LISA family
> of supported devices and future TOBY L2 devices.
> ---
>   drivers/atmodem/vendor.h | 1 +
>   1 file changed, 1 insertion(+)
>

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 05/19] plugins/ublox: allow enabling of TOBY L2 modems
  2016-03-09 15:44 ` [PATCH 05/19] plugins/ublox: allow enabling of TOBY L2 modems Dragos Tatulea
@ 2016-03-10 14:11   ` Denis Kenzior
  0 siblings, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:11 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2991 bytes --]

Hi Dragos,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> For this we need to:
> * Set the vendor family based on model id.
> * Not use modem interface for the TOBY L2 family.
> ---
>   plugins/ublox.c | 53 ++++++++++++++++++++++++++++++++++++++++++++---------
>   1 file changed, 44 insertions(+), 9 deletions(-)
>
> diff --git a/plugins/ublox.c b/plugins/ublox.c
> index 89ca709..171d59d 100644
> --- a/plugins/ublox.c
> +++ b/plugins/ublox.c
> @@ -47,6 +47,7 @@ static const char *none_prefix[] = { NULL };
>   struct ublox_data {
>   	GAtChat *modem;
>   	GAtChat *aux;
> +	enum ofono_vendor vendor_family;
>   };
>
>   static void ublox_debug(const char *str, void *user_data)
> @@ -138,24 +139,58 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
>   static int ublox_enable(struct ofono_modem *modem)
>   {
>   	struct ublox_data *data = ofono_modem_get_data(modem);
> +	const char *model_str = NULL;
> +	int model_id;
>
>   	DBG("%p", modem);
>
> -	data->modem = open_device(modem, "Modem", "Modem: ");
> -	if (data->modem == NULL)
> +	model_str = ofono_modem_get_string(modem, "Model");
> +	if (model_str == NULL)
>   		return -EINVAL;
>
> +	/*
> +	 * Toby L2 devices are more complex and special than previously
> +	 * supported U-Blox devices. So they need a vendor of their own.
> +	 */
> +	model_id = atoi(model_str);
> +	switch (model_id) {
> +		case 1102:
> +			data->vendor_family = OFONO_VENDOR_UBLOX;
> +			break;
> +		case 1141:
> +		case 1146:
> +			data->vendor_family = OFONO_VENDOR_UBLOX_TOBY_L2;
> +			break;
> +		case 1143:
> +			DBG("low/medium throughtput profile unsupported");
> +		default:
> +			DBG("unknown ublox model id %d", model_id);
> +			return -EINVAL;
> +	}
> +
>   	data->aux = open_device(modem, "Aux", "Aux: ");
> -	if (data->aux == NULL) {
> -		g_at_chat_unref(data->modem);
> -		data->modem = NULL;
> -		return -EIO;
> +	if (data->aux == NULL)
> +		return -EINVAL;
> +
> +	if (data->vendor_family == OFONO_VENDOR_UBLOX) {
> +

No empty line here please

> +		data->modem = open_device(modem, "Modem", "Modem: ");
> +		if (data->modem == NULL) {
> +			g_at_chat_unref(data->aux);
> +			data->aux = NULL;
> +			return -EIO;
> +		}
> +
> +		g_at_chat_set_slave(data->modem, data->aux);
> +
> +		g_at_chat_send(data->modem, "ATE0 +CMEE=1", none_prefix,
> +						NULL, NULL, NULL);
> +

No unneeded whitespace here please

>   	}
>
> -	g_at_chat_set_slave(data->modem, data->aux);
> +	/* The modem can take a while to wake up if just powered on. */
> +	g_at_chat_set_wakeup_command(data->aux, "AT\r", 1000, 11000);

This is a pretty nasty hack specific for TI Calypso.  I wouldn't use it 
unless you really need it.

>
> -	g_at_chat_send(data->modem, "ATE0 +CMEE=1", none_prefix,
> -					NULL, NULL, NULL);
>   	g_at_chat_send(data->aux, "ATE0 +CMEE=1", none_prefix,
>   					NULL, NULL, NULL);
>
>

Regards,
-Denis

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox
  2016-03-09 15:44 ` [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox Dragos Tatulea
@ 2016-03-10 14:29   ` Denis Kenzior
  2016-03-10 14:43   ` Denis Kenzior
  1 sibling, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:29 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 903 bytes --]

Hi Dragos,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> Based on UBX-13002752 R33
> ---
>   drivers/atmodem/gprs.c | 4 ----
>   1 file changed, 4 deletions(-)
>

Applying: atmodem: ublox: EPS now supported by newer ublox
error: patch failed: drivers/atmodem/gprs.c:303
error: drivers/atmodem/gprs.c: patch does not apply
Patch failed at 0001 atmodem: ublox: EPS now supported by newer ublox

> diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
> index 5551316..0165253 100644
> --- a/drivers/atmodem/gprs.c
> +++ b/drivers/atmodem/gprs.c
> @@ -303,10 +303,6 @@ static void ublox_ureg_notify(GAtResult *result, gpointer user_data)
>   	case 5:
>   		bearer = 4;
>   		break;
> -	case 7:
> -		/* XXX: reserved - assume none. */
> -		bearer = 0;
> -		break;

I don't see this code upstream.

>   	case 8:
>   		bearer = 1;
>   		break;
>

Regards,
-Denis

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 08/19] atmodem: add support for U-Blox TOBY L2 modems
  2016-03-09 15:44 ` [PATCH 08/19] atmodem: add support for U-Blox TOBY L2 modems Dragos Tatulea
@ 2016-03-10 14:34   ` Denis Kenzior
  2016-03-10 14:38     ` Dragos Tatulea
  0 siblings, 1 reply; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:34 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4429 bytes --]

Hi Dragos,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> Besides exceptions below, act like normal U-Blox devices.
>
> gprs-context: don't set auth for TOBY L2. U-Blox Toby L2
> doesn't support PAP/CHAP APN auth method.
>
> atmodem: TOBY L2 supports only CMER mode 1. Also chaged original
> mode variable to ind, which is a more appropriate name.
> mode is what is being set first.
> ---
>   drivers/atmodem/gprs-context.c         |  2 ++
>   drivers/atmodem/gprs.c                 |  1 +
>   drivers/atmodem/network-registration.c | 12 +++++++-----
>   drivers/atmodem/sim.c                  |  1 +
>   4 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/atmodem/gprs-context.c b/drivers/atmodem/gprs-context.c
> index f6e6c2e..ab47b25 100644
> --- a/drivers/atmodem/gprs-context.c
> +++ b/drivers/atmodem/gprs-context.c
> @@ -304,6 +304,8 @@ static void at_gprs_activate_primary(struct ofono_gprs_context *gc,
>   				break;
>   			}
>   			break;
> +		case OFONO_VENDOR_UBLOX_TOBY_L2:
> +			/* Above not true for Toby L2 family, default is ok. */

Why is this needed?

>   		default:
>   			snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
>   					ctx->apn);
> diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
> index 0165253..4505477 100644
> --- a/drivers/atmodem/gprs.c
> +++ b/drivers/atmodem/gprs.c
> @@ -351,6 +351,7 @@ static void gprs_initialized(gboolean ok, GAtResult *result, gpointer user_data)
>   						FALSE, gprs, NULL);
>   		break;
>   	case OFONO_VENDOR_UBLOX:
> +	case OFONO_VENDOR_UBLOX_TOBY_L2:
>   		g_at_chat_register(gd->chat, "+UREG:", ublox_ureg_notify,
>   						FALSE, gprs, NULL);
>   		g_at_chat_send(gd->chat, "AT+UREG=1", none_prefix,
> diff --git a/drivers/atmodem/network-registration.c b/drivers/atmodem/network-registration.c
> index 7cfd6b2..81e8b8d 100644
> --- a/drivers/atmodem/network-registration.c
> +++ b/drivers/atmodem/network-registration.c
> @@ -1580,8 +1580,10 @@ static inline ofono_bool_t append_cmer_element(char *buf, int *len, int cap,
>   static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>   					struct netreg_data *nd)
>   {
> -	const char *mode;
> +	const char *ind;
>   	int len = sprintf(buf, "AT+CMER=");
> +	/* UBX-13002752 R33: TOBY L2 doesn't support mode 2 and 3 */
> +	const char *mode = nd->vendor == OFONO_VENDOR_UBLOX_TOBY_L2 ? "1":"3";

Lets make this into a switch/case statement.

e.g. const char *mode;

>
>   	DBG("");

switch (nd->vendor) {
case OFONO_VENDOR_UBLOX_TOBY_L2:
	mode = 1;
	break;
default:
	mode = 3;
	break;
}

>
> @@ -1590,7 +1592,7 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>   	 * TA‑TE link specific inband technique used to embed result codes and
>   	 * data when TA is in on‑line data mode
>   	 */
> -	if (!append_cmer_element(buf, &len, cmer_opts[0], "3", FALSE))
> +	if (!append_cmer_element(buf, &len, cmer_opts[0], mode, FALSE))
>   		return FALSE;
>
>   	/* No keypad event reporting */
> @@ -1607,14 +1609,14 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>   		 * Telit does not support mode 1.
>   		 * All indicator events shall be directed from TA to TE.
>   		 */
> -		mode = "2";
> +		ind = "2";
>   		break;
>   	default:
>   		/*
>   		 * Only those indicator events, which are not caused by +CIND
>   		 * shall be indicated by the TA to the TE.
>   		 */
> -		mode = "1";
> +		ind = "1";
>   		break;
>   	}
>
> @@ -1623,7 +1625,7 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>   	 * <ind> indicates the indicator order number (as specified for +CIND)
>   	 * and <value> is the new value of indicator.
>   	 */
> -	if (!append_cmer_element(buf, &len, cmer_opts[3], mode, TRUE))
> +	if (!append_cmer_element(buf, &len, cmer_opts[3], ind, TRUE))
>   		return FALSE;
>
>   	return TRUE;
> diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
> index d6a0dcf..081d342 100644
> --- a/drivers/atmodem/sim.c
> +++ b/drivers/atmodem/sim.c
> @@ -1120,6 +1120,7 @@ static void at_pin_retries_query(struct ofono_sim *sim,
>   			return;
>   		break;
>   	case OFONO_VENDOR_UBLOX:
> +	case OFONO_VENDOR_UBLOX_TOBY_L2:
>   		if (g_at_chat_send(sd->chat, "AT+UPINCNT", upincnt_prefix,
>   					upincnt_cb, cbd, g_free) > 0)
>   			return;
>

Regards,
-Denis

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 08/19] atmodem: add support for U-Blox TOBY L2 modems
  2016-03-10 14:34   ` Denis Kenzior
@ 2016-03-10 14:38     ` Dragos Tatulea
  0 siblings, 0 replies; 30+ messages in thread
From: Dragos Tatulea @ 2016-03-10 14:38 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 5611 bytes --]

Hi,

On 03/10/2016 03:34 PM, Denis Kenzior wrote:
> Hi Dragos,
> 
> On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
>> Besides exceptions below, act like normal U-Blox devices.
>>
>> gprs-context: don't set auth for TOBY L2. U-Blox Toby L2
>> doesn't support PAP/CHAP APN auth method.
>>
>> atmodem: TOBY L2 supports only CMER mode 1. Also chaged original
>> mode variable to ind, which is a more appropriate name.
>> mode is what is being set first.
>> ---
>>   drivers/atmodem/gprs-context.c         |  2 ++
>>   drivers/atmodem/gprs.c                 |  1 +
>>   drivers/atmodem/network-registration.c | 12 +++++++-----
>>   drivers/atmodem/sim.c                  |  1 +
>>   4 files changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/atmodem/gprs-context.c b/drivers/atmodem/gprs-context.c
>> index f6e6c2e..ab47b25 100644
>> --- a/drivers/atmodem/gprs-context.c
>> +++ b/drivers/atmodem/gprs-context.c
>> @@ -304,6 +304,8 @@ static void at_gprs_activate_primary(struct ofono_gprs_context *gc,
>>                   break;
>>               }
>>               break;
>> +        case OFONO_VENDOR_UBLOX_TOBY_L2:
>> +            /* Above not true for Toby L2 family, default is ok. */
> 
> Why is this needed?
> 
It was needed in an older version of the code. Not needed anymore.

>>           default:
>>               snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
>>                       ctx->apn);
>> diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
>> index 0165253..4505477 100644
>> --- a/drivers/atmodem/gprs.c
>> +++ b/drivers/atmodem/gprs.c
>> @@ -351,6 +351,7 @@ static void gprs_initialized(gboolean ok, GAtResult *result, gpointer user_data)
>>                           FALSE, gprs, NULL);
>>           break;
>>       case OFONO_VENDOR_UBLOX:
>> +    case OFONO_VENDOR_UBLOX_TOBY_L2:
>>           g_at_chat_register(gd->chat, "+UREG:", ublox_ureg_notify,
>>                           FALSE, gprs, NULL);
>>           g_at_chat_send(gd->chat, "AT+UREG=1", none_prefix,
>> diff --git a/drivers/atmodem/network-registration.c b/drivers/atmodem/network-registration.c
>> index 7cfd6b2..81e8b8d 100644
>> --- a/drivers/atmodem/network-registration.c
>> +++ b/drivers/atmodem/network-registration.c
>> @@ -1580,8 +1580,10 @@ static inline ofono_bool_t append_cmer_element(char *buf, int *len, int cap,
>>   static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>>                       struct netreg_data *nd)
>>   {
>> -    const char *mode;
>> +    const char *ind;
>>       int len = sprintf(buf, "AT+CMER=");
>> +    /* UBX-13002752 R33: TOBY L2 doesn't support mode 2 and 3 */
>> +    const char *mode = nd->vendor == OFONO_VENDOR_UBLOX_TOBY_L2 ? "1":"3";
> 
> Lets make this into a switch/case statement.
> 
> e.g. const char *mode;
> 
>>
>>       DBG("");
> 
> switch (nd->vendor) {
> case OFONO_VENDOR_UBLOX_TOBY_L2:
>     mode = 1;
>     break;
> default:
>     mode = 3;
>     break;
> }
> 
Will do.

>>
>> @@ -1590,7 +1592,7 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>>        * TA‑TE link specific inband technique used to embed result codes and
>>        * data when TA is in on‑line data mode
>>        */
>> -    if (!append_cmer_element(buf, &len, cmer_opts[0], "3", FALSE))
>> +    if (!append_cmer_element(buf, &len, cmer_opts[0], mode, FALSE))
>>           return FALSE;
>>
>>       /* No keypad event reporting */
>> @@ -1607,14 +1609,14 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>>            * Telit does not support mode 1.
>>            * All indicator events shall be directed from TA to TE.
>>            */
>> -        mode = "2";
>> +        ind = "2";
>>           break;
>>       default:
>>           /*
>>            * Only those indicator events, which are not caused by +CIND
>>            * shall be indicated by the TA to the TE.
>>            */
>> -        mode = "1";
>> +        ind = "1";
>>           break;
>>       }
>>
>> @@ -1623,7 +1625,7 @@ static ofono_bool_t build_cmer_string(char *buf, int *cmer_opts,
>>        * <ind> indicates the indicator order number (as specified for +CIND)
>>        * and <value> is the new value of indicator.
>>        */
>> -    if (!append_cmer_element(buf, &len, cmer_opts[3], mode, TRUE))
>> +    if (!append_cmer_element(buf, &len, cmer_opts[3], ind, TRUE))
>>           return FALSE;
>>
>>       return TRUE;
>> diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
>> index d6a0dcf..081d342 100644
>> --- a/drivers/atmodem/sim.c
>> +++ b/drivers/atmodem/sim.c
>> @@ -1120,6 +1120,7 @@ static void at_pin_retries_query(struct ofono_sim *sim,
>>               return;
>>           break;
>>       case OFONO_VENDOR_UBLOX:
>> +    case OFONO_VENDOR_UBLOX_TOBY_L2:
>>           if (g_at_chat_send(sd->chat, "AT+UPINCNT", upincnt_prefix,
>>                       upincnt_cb, cbd, g_free) > 0)
>>               return;
>>
> 
> Regards,
> -Denis
> _______________________________________________
> ofono mailing list
> ofono(a)ofono.org
> https://lists.ofono.org/mailman/listinfo/ofono

Thanks
-- 
Dragos Tatulea
Software Developer @ Endocode AG
dragos(a)endocode.com

Endocode AG, Brückenstraße 5A, 10179 Berlin
+49 30 1206 4472 | info(a)endocode.com | www.endocode.com

Vorstandsvorsitzender: Mirko Boehm
Vorstände: Dr. Thomas Fricke, Sebastian Sucker
Aufsichtsratsvorsitzende: Alexandra Boehm

Registergericht: Amtsgericht Charlottenburg - HRB 150748 B

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 09/19] atmodem: work around CGREG issues in UBlox Toby L2
  2016-03-09 15:44 ` [PATCH 09/19] atmodem: work around CGREG issues in UBlox Toby L2 Dragos Tatulea
@ 2016-03-10 14:40   ` Denis Kenzior
  0 siblings, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:40 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2403 bytes --]

Hi Dragos,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> Don't use CGREG for network notifications. It will return
> 4 both when registered in LTE and in unknown state.
>
> For the CGREG? query, interpret 4 as registered.
> ---
>   drivers/atmodem/gprs.c | 24 +++++++++++++++++++++---
>   1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
> index 4505477..0b4bce8 100644
> --- a/drivers/atmodem/gprs.c
> +++ b/drivers/atmodem/gprs.c
> @@ -101,6 +101,17 @@ static void at_cgreg_cb(gboolean ok, GAtResult *result, gpointer user_data)
>   		return;
>   	}
>
> +	if (gd->vendor == OFONO_VENDOR_UBLOX_TOBY_L2 && status == 4) {
> +		/*
> +		 * UBX-13002752-R33 says:
> +		 * If the module is registered to E-UTRAN the <stat> parameter is 4.
> +		 * So this means we are actually registered.
> +		 * It could also mean that state is unknown, but if we are
> +		 * here we know we already registered.
> +		 */
> +		 status = 1;
> +	}
> +

Does ublox support AT+UREG? ?  Perhaps that would be easier than making 
this hack.  The core polls gprs_driver->attached_status in various 
cases, so assuming that 4==1 here seems unsafe.

>   	cb(&error, status, cbd->data);
>   }
>
> @@ -342,16 +353,23 @@ static void gprs_initialized(gboolean ok, GAtResult *result, gpointer user_data)
>   	struct gprs_data *gd = ofono_gprs_get_data(gprs);
>
>   	g_at_chat_register(gd->chat, "+CGEV:", cgev_notify, FALSE, gprs, NULL);
> -	g_at_chat_register(gd->chat, "+CGREG:", cgreg_notify,
> -						FALSE, gprs, NULL);
> +
> +	/*
> +	 * You really don't want to get CGREG notifications on Toby l2.
> +	 * It sends 4 when BOTH for unknown state and for registered in LTE.
> +	 * +UREG usage is recommended by them.
> +	 */
> +	if (gd->vendor != OFONO_VENDOR_UBLOX_TOBY_L2)
> +		g_at_chat_register(gd->chat, "+CGREG:", cgreg_notify,
> +							FALSE, gprs, NULL);
>
>   	switch (gd->vendor) {
>   	case OFONO_VENDOR_HUAWEI:
>   		g_at_chat_register(gd->chat, "^MODE:", huawei_mode_notify,
>   						FALSE, gprs, NULL);
>   		break;
> -	case OFONO_VENDOR_UBLOX:
>   	case OFONO_VENDOR_UBLOX_TOBY_L2:
> +	case OFONO_VENDOR_UBLOX:
>   		g_at_chat_register(gd->chat, "+UREG:", ublox_ureg_notify,
>   						FALSE, gprs, NULL);
>   		g_at_chat_send(gd->chat, "AT+UREG=1", none_prefix,
>

Regards,
-Denis

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox
  2016-03-09 15:44 ` [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox Dragos Tatulea
  2016-03-10 14:29   ` Denis Kenzior
@ 2016-03-10 14:43   ` Denis Kenzior
  1 sibling, 0 replies; 30+ messages in thread
From: Denis Kenzior @ 2016-03-10 14:43 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 248 bytes --]

Hi Dragos,

On 03/09/2016 09:44 AM, Dragos Tatulea wrote:
> Based on UBX-13002752 R33
> ---
>   drivers/atmodem/gprs.c | 4 ----
>   1 file changed, 4 deletions(-)
>

Ignore my previous message, this was applied now.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2016-03-10 14:43 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09 15:44 [PATCH 00/19] Support for U-Blox Toby L2 modems Dragos Tatulea
2016-03-09 15:44 ` [PATCH 01/19] plugins/udevng: support the U-Blox TOBY-L2 series Dragos Tatulea
2016-03-10 14:00   ` Denis Kenzior
2016-03-09 15:44 ` [PATCH 02/19] plugins/udevng: support different interface strings to detect TOBY series Dragos Tatulea
2016-03-10 14:01   ` Denis Kenzior
2016-03-09 15:44 ` [PATCH 03/19] plugins/udevng: ublox: set model string Dragos Tatulea
2016-03-10 14:04   ` Denis Kenzior
2016-03-09 15:44 ` [PATCH 04/19] include: vendor.h: add vendor for ublox toby Dragos Tatulea
2016-03-10 14:05   ` Denis Kenzior
2016-03-09 15:44 ` [PATCH 05/19] plugins/ublox: allow enabling of TOBY L2 modems Dragos Tatulea
2016-03-10 14:11   ` Denis Kenzior
2016-03-09 15:44 ` [PATCH 06/19] plugins/ublox: use vendor from structure instead of fixed Dragos Tatulea
2016-03-09 15:44 ` [PATCH 07/19] atmodem: ublox: EPS now supported by newer ublox Dragos Tatulea
2016-03-10 14:29   ` Denis Kenzior
2016-03-10 14:43   ` Denis Kenzior
2016-03-09 15:44 ` [PATCH 08/19] atmodem: add support for U-Blox TOBY L2 modems Dragos Tatulea
2016-03-10 14:34   ` Denis Kenzior
2016-03-10 14:38     ` Dragos Tatulea
2016-03-09 15:44 ` [PATCH 09/19] atmodem: work around CGREG issues in UBlox Toby L2 Dragos Tatulea
2016-03-10 14:40   ` Denis Kenzior
2016-03-09 15:44 ` [PATCH 10/19] ubloxmodem: add Toby L2 gprs context driver Dragos Tatulea
2016-03-09 15:44 ` [PATCH 11/19] gprs-context.h: add function for setting APN Dragos Tatulea
2016-03-09 15:44 ` [PATCH 12/19] gprs: allow APN updates from gprs-context driver Dragos Tatulea
2016-03-09 15:44 ` [PATCH 13/19] ubloxmodem: push back APN into gprs context Dragos Tatulea
2016-03-09 15:44 ` [PATCH 14/19] plugins/ublox: give names to model ids Dragos Tatulea
2016-03-09 15:44 ` [PATCH 15/19] plugins/ublox: enable ubloxmodem driver when possible Dragos Tatulea
2016-03-09 15:44 ` [PATCH 16/19] plugins/ublox: support more internet contexts Dragos Tatulea
2016-03-09 15:44 ` [PATCH 17/19] ubloxmodem: support authentication Dragos Tatulea
2016-03-09 15:44 ` [PATCH 18/19] plugins/ublox: read network mode Dragos Tatulea
2016-03-09 15:45 ` [PATCH 19/19] ubloxmodem: add routed mode support Dragos Tatulea

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.