[PATCH] gemalto: radio-settings: cleanup

2021-07-23 Thread Sergey Matyukevich
Enum ofono_radio_access_mode has been replaced by unsigned int.
This change allows to move handling of all the modes into
'switch' in the function gemalto_set_rat_mode.
---
 drivers/gemaltomodem/radio-settings.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/gemaltomodem/radio-settings.c 
b/drivers/gemaltomodem/radio-settings.c
index 738a6908..50764f83 100644
--- a/drivers/gemaltomodem/radio-settings.c
+++ b/drivers/gemaltomodem/radio-settings.c
@@ -171,21 +171,18 @@ static void gemalto_set_rat_mode(struct 
ofono_radio_settings *rs,
case OFONO_RADIO_ACCESS_MODE_LTE:
val = 3;
break;
-   }
-
-   if (m == (OFONO_RADIO_ACCESS_MODE_UMTS|OFONO_RADIO_ACCESS_MODE_GSM)) {
+   case OFONO_RADIO_ACCESS_MODE_UMTS|OFONO_RADIO_ACCESS_MODE_GSM:
val = 1;
p1 = 2;
-   }
-
-   if (m == (OFONO_RADIO_ACCESS_MODE_LTE|OFONO_RADIO_ACCESS_MODE_UMTS)) {
+   break;
+   case OFONO_RADIO_ACCESS_MODE_LTE|OFONO_RADIO_ACCESS_MODE_UMTS:
val = 4;
p1 = 3;
-   }
-
-   if (m == (OFONO_RADIO_ACCESS_MODE_LTE|OFONO_RADIO_ACCESS_MODE_GSM)) {
+   break;
+   case OFONO_RADIO_ACCESS_MODE_LTE|OFONO_RADIO_ACCESS_MODE_GSM:
val = 5;
p1 = 3;
+   break;
}
 
if (val == 6)
-- 
2.32.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [PATCH 1/3] gemalto: add radio-settings driver

2021-07-15 Thread Sergey Matyukevich
Hello Denis,

> > Add support for Gemalto specific radio settings.
> > 
> > ---
> >   Makefile.am   |   1 +
> >   drivers/gemaltomodem/gemaltomodem.c   |   2 +
> >   drivers/gemaltomodem/gemaltomodem.h   |   3 +
> >   drivers/gemaltomodem/radio-settings.c | 267 ++
> >   4 files changed, 273 insertions(+)
> >   create mode 100644 drivers/gemaltomodem/radio-settings.c
> > 
> 
> I went ahead and applied this with a 2 lines amended: changing 'enum
> ofono_access_mode' to 'unsigned int'.  I recently updated all the drivers in
> commit 1d86dbc6 ("radio-settings: Do not use enum ofono_access_mode").  So I
> did a similar amend here for consistency.

Ok, thanks. After enum ofono_access_mode has been removed, it is possible
to convert all the 'ifs' into 'switch' branches in the function
gemalto_set_rat_mode. I will test and send a cleanup patch.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 1/3] gemalto: add radio-settings driver

2021-07-04 Thread Sergey Matyukevich
Add support for Gemalto specific radio settings.

---
 Makefile.am   |   1 +
 drivers/gemaltomodem/gemaltomodem.c   |   2 +
 drivers/gemaltomodem/gemaltomodem.h   |   3 +
 drivers/gemaltomodem/radio-settings.c | 267 ++
 4 files changed, 273 insertions(+)
 create mode 100644 drivers/gemaltomodem/radio-settings.c

diff --git a/Makefile.am b/Makefile.am
index 0159fcb0..6f6e71ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -487,6 +487,7 @@ builtin_sources += drivers/atmodem/atutil.h \
drivers/gemaltomodem/location-reporting.c \
drivers/gemaltomodem/voicecall.c \
drivers/gemaltomodem/gprs-context.c \
+   drivers/gemaltomodem/radio-settings.c \
drivers/gemaltomodem/netmon.c
 
 builtin_modules += xmm7modem
diff --git a/drivers/gemaltomodem/gemaltomodem.c 
b/drivers/gemaltomodem/gemaltomodem.c
index f7e4ff3e..bcf37e5e 100644
--- a/drivers/gemaltomodem/gemaltomodem.c
+++ b/drivers/gemaltomodem/gemaltomodem.c
@@ -36,6 +36,7 @@
 static int gemaltomodem_init(void)
 {
gemalto_location_reporting_init();
+   gemalto_radio_settings_init();
gemalto_gprs_context_init();
gemalto_voicecall_init();
gemalto_netmon_init();
@@ -46,6 +47,7 @@ static int gemaltomodem_init(void)
 static void gemaltomodem_exit(void)
 {
gemalto_location_reporting_exit();
+   gemalto_radio_settings_exit();
gemalto_gprs_context_exit();
gemalto_voicecall_exit();
gemalto_netmon_exit();
diff --git a/drivers/gemaltomodem/gemaltomodem.h 
b/drivers/gemaltomodem/gemaltomodem.h
index ae8f2141..91a70baa 100644
--- a/drivers/gemaltomodem/gemaltomodem.h
+++ b/drivers/gemaltomodem/gemaltomodem.h
@@ -33,3 +33,6 @@ extern void gemalto_gprs_context_exit();
 
 extern void gemalto_netmon_init(void);
 extern void gemalto_netmon_exit(void);
+
+extern void gemalto_radio_settings_init(void);
+extern void gemalto_radio_settings_exit(void);
diff --git a/drivers/gemaltomodem/radio-settings.c 
b/drivers/gemaltomodem/radio-settings.c
new file mode 100644
index ..d2de89cf
--- /dev/null
+++ b/drivers/gemaltomodem/radio-settings.c
@@ -0,0 +1,267 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2017 Intel Corporation. All rights reserved.
+ *  Copyright (C) 2021 Sergey Matyukevich. 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 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "gemaltomodem.h"
+
+static const char *none_prefix[] = { NULL };
+static const char *sxrat_prefix[] = { "^SXRAT:", NULL };
+
+struct radio_settings_data {
+   GAtChat *chat;
+};
+
+static void sxrat_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+   struct cb_data *cbd = user_data;
+   ofono_radio_settings_rat_mode_query_cb_t cb = cbd->cb;
+   enum ofono_radio_access_mode mode;
+   struct ofono_error error;
+   int value, pref1, pref2;
+   GAtResultIter iter;
+
+   DBG("ok %d", ok);
+
+   decode_at_error(&error, g_at_result_final_response(result));
+
+   if (!ok) {
+   cb(&error, -1, cbd->data);
+   return;
+   }
+
+   g_at_result_iter_init(&iter, result);
+
+   if (!g_at_result_iter_next(&iter, "^SXRAT:"))
+   goto error;
+
+   if (!g_at_result_iter_next_number(&iter, &value))
+   goto error;
+
+   g_at_result_iter_next_number_default(&iter, -1, &pref1);
+   g_at_result_iter_next_number_default(&iter, -1, &pref2);
+
+   DBG("mode %d pref1 %d pref2 %d", value, pref1, pref2);
+
+   switch (value) {
+   case 0:
+   mode = OFONO_RADIO_ACCESS_MODE_GSM;
+   break;
+   case 1:
+   mode = OFONO_RADIO_ACCESS_MODE_GSM |
+   OFONO_RADIO_ACCESS_MODE_UMTS;
+   break;
+   case 2:
+   mode = OFONO_RADIO_ACCESS_MODE_UMTS;
+   break;
+   case 3:
+   mode = OFO

[PATCH 3/3] plugins: gemalto: move ussd atom to post_online

2021-07-04 Thread Sergey Matyukevich
Gemalto modem does not allow to enable Supplementary Service
during post_sim stage. So move ussd atom to post_online stage.

---
 plugins/gemalto.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index a2e8a39c..d1962ab8 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -614,8 +614,6 @@ static void gemalto_post_sim(struct ofono_modem *modem)
if (gprs && gc)
ofono_gprs_add_context(gprs, gc);
 
-   ofono_ussd_create(modem, 0, "atmodem", data->app);
-
if (!g_strcmp0(model, GEMALTO_MODEL_ALS3_PLS8x) ||
!g_strcmp0(model, GEMALTO_MODEL_ELS81x))
ofono_lte_create(modem, OFONO_VENDOR_GEMALTO,
@@ -639,6 +637,8 @@ static void gemalto_post_online(struct ofono_modem *modem)
ofono_call_meter_create(modem, 0, "atmodem", data->app);
ofono_call_barring_create(modem, 0, "atmodem", data->app);
 
+   ofono_ussd_create(modem, 0, "atmodem", data->app);
+
if (!g_strcmp0(model, GEMALTO_MODEL_ELS81x))
ofono_netmon_create(modem, OFONO_VENDOR_GEMALTO,
"gemaltomodem", data->app);
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 2/3] plugins: gemalto: add radio-settings atom

2021-07-04 Thread Sergey Matyukevich
Instantiate Gemalto radio-settings atom in post_sim.

---
 plugins/gemalto.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 135e2d26..a2e8a39c 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -597,6 +598,7 @@ static void gemalto_post_sim(struct ofono_modem *modem)
ofono_phonebook_create(modem, 0, "atmodem", data->app);
 
ofono_sms_create(modem, OFONO_VENDOR_GEMALTO, "atmodem", data->app);
+   ofono_radio_settings_create(modem, 0, "gemaltomodem", data->app);
 
gprs = ofono_gprs_create(modem, 0, "atmodem", data->app);
 
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 0/3] gemalto: radio-setings driver

2021-07-04 Thread Sergey Matyukevich
Hi all,

This patch series includes Gemalto specific radio-settings driver
and minor ussd fix.

Regards,
Sergey

Sergey Matyukevich (3):
  gemalto: add radio-settings driver
  plugins: gemalto: add radio-settings atom
  plugins: gemalto: move ussd atom to post_online

 Makefile.am   |   1 +
 drivers/gemaltomodem/gemaltomodem.c   |   2 +
 drivers/gemaltomodem/gemaltomodem.h   |   3 +
 drivers/gemaltomodem/radio-settings.c | 267 ++
 plugins/gemalto.c |   6 +-
 5 files changed, 277 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gemaltomodem/radio-settings.c
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v3 3/3] unit: add validate_utf8_tlv tests

2021-01-16 Thread Sergey Matyukevich
---
 unit/test-simutil.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/unit/test-simutil.c b/unit/test-simutil.c
index 083bd4b2..6f8419b4 100644
--- a/unit/test-simutil.c
+++ b/unit/test-simutil.c
@@ -86,6 +86,27 @@ static void test_ber_tlv_iter(void)
test_buffer(valid_mms_params, sizeof(valid_mms_params));
 }
 
+static void test_validate_tlv(void)
+{
+   unsigned char impi_none[] = { 0x80, 0x0 };
+   unsigned char impi_empty[] = { 0x80, 0x1, '\0' };
+   unsigned char impi_term1[] = { 0x80, 0x3, 'F', 'O', 'O' };
+   unsigned char impi_term2[] = { 0x80, 0x4, 'F', 'O', 'O', '\0' };
+   unsigned char impi_term3[] = { 0x80, 0x3, 'F', 'O', 'O', 0xff, 0xff };
+   unsigned char impi_term4[] = { 0x80, 0x4, 'F', 'O', 'O', '\0', 0xff };
+   unsigned char impi_invalid1[] = { 0x80, 0x4, 'F', '\0', 'O', '\0' };
+   unsigned char impi_invalid2[] = { 0x80, 0x4, 0xff, 0xff, 0xff, 0xff };
+
+   g_assert(validate_utf8_tlv(impi_none) == FALSE);
+   g_assert(validate_utf8_tlv(impi_empty) == TRUE);
+   g_assert(validate_utf8_tlv(impi_term1) == TRUE);
+   g_assert(validate_utf8_tlv(impi_term2) == TRUE);
+   g_assert(validate_utf8_tlv(impi_term3) == TRUE);
+   g_assert(validate_utf8_tlv(impi_term4) == TRUE);
+   g_assert(validate_utf8_tlv(impi_invalid1) == FALSE);
+   g_assert(validate_utf8_tlv(impi_invalid2) == FALSE);
+}
+
 static void test_ber_tlv_builder_mms(void)
 {
struct ber_tlv_iter top_iter, nested_iter;
@@ -610,6 +631,7 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
 
g_test_add_func("/testsimutil/ber tlv iter", test_ber_tlv_iter);
+   g_test_add_func("/testsimutil/ber tlv validate utf8", 
test_validate_tlv);
g_test_add_func("/testsimutil/ber tlv encode MMS",
test_ber_tlv_builder_mms);
g_test_add_func("/testsimutil/ber tlv encode EFpnn",
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v3 2/3] sim: validate IMS private identity

2021-01-16 Thread Sergey Matyukevich
Make sure that IMS private identity is a valid UTF8 string before
setting sim->impi field. Otherwise ofono may crash on dbus assert
when SIM properties are reported via org.ofono.SimManager interface.
---
 src/sim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/sim.c b/src/sim.c
index 33e1245f..793ff64a 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, int 
record,
return;
}
 
-   sim->impi = g_strndup((const char *)data + 2, data[1]);
+   if (validate_utf8_tlv(data))
+   sim->impi = g_strndup((const char *)data + 2, data[1]);
 }
 
 static void discover_apps_cb(const struct ofono_error *error,
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v3 1/3] simutil: add validate_utf8_tlv

2021-01-16 Thread Sergey Matyukevich
Add helper to validate if TLV value is a valid UTF8 string.
Note that both null-terminated and non null-terminated UTF8
strings are considered valid.
---
 src/simutil.c | 14 ++
 src/simutil.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/src/simutil.c b/src/simutil.c
index 4e0d3311..5808b14e 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -765,6 +765,20 @@ unsigned char *comprehension_tlv_builder_get_data(
return tlv + tag_size + len_size;
 }
 
+gboolean validate_utf8_tlv(const unsigned char *tlv)
+{
+   int len = tlv[1];
+
+   if (len == 0)
+   return FALSE;
+
+   /* support both null-termiated and non null-terminated UTF8 TLV value */
+   if (tlv[len + 1] == '\0')
+   len -= 1;
+
+   return g_utf8_validate_len((const char *)tlv + 2, len, NULL);
+}
+
 static char *sim_network_name_parse(const unsigned char *buffer, int length,
gboolean *add_ci)
 {
diff --git a/src/simutil.h b/src/simutil.h
index 14a39957..33b775a7 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -403,6 +403,7 @@ gboolean comprehension_tlv_builder_set_length(
unsigned int len);
 unsigned char *comprehension_tlv_builder_get_data(
struct comprehension_tlv_builder *builder);
+gboolean validate_utf8_tlv(const unsigned char *data);
 
 void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu,
unsigned int len);
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v3 0/3] sim: validate IMS private identity

2021-01-16 Thread Sergey Matyukevich
Hello Denis and all,

These patches add UTF8 validation for IMS private identity. Without
this check ofono may crash on dbus assert when SIM properties are
reported via org.ofono.SimManager interface.

Regards,
Sergey

v2 -> v3

- support both null-terminated and non-null terminated TLV values
- move validation helper into simutil.c
- add unit tests

Sergey Matyukevich (3):
  simutil: add validate_utf8_tlv
  sim: validate IMS private identity
  unit: add validate_utf8_tlv tests

 src/sim.c   |  3 ++-
 src/simutil.c   | 14 ++
 src/simutil.h   |  1 +
 unit/test-simutil.c | 22 ++
 4 files changed, 39 insertions(+), 1 deletion(-)
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [PATCH v2] sim: validate IMS private identity

2021-01-15 Thread Sergey Matyukevich
Hi Denis,

> > > > Make sure that IMS private identity is a valid UTF8 string before
> > > > setting sim->impi field. Otherwise ofono may crash on dbus assert
> > > > when SIM properties are reported via org.ofono.SimManager interface.
> > > > ---
> > > >src/sim.c | 3 ++-
> > > >1 file changed, 2 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/src/sim.c b/src/sim.c
> > > > index 33e1245f..2a663e2d 100644
> > > > --- a/src/sim.c
> > > > +++ b/src/sim.c
> > > > @@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int 
> > > > total_length, int record,
> > > > return;
> > > > }
> > > > -   sim->impi = g_strndup((const char *)data + 2, data[1]);
> > > > +   if (g_utf8_validate((const char *)data + 2, data[1], NULL))
> > > > +   sim->impi = g_strndup((const char *)data + 2, data[1]);
> > > 
> > > I assume this code path was tested with a file containing embedded NULs as
> > > that is the only way it would have worked.
> 
> Ignore the last part of the above sentence.  What I'm trying to say is that:
> 
> We in theory have two possibilities:
> 
> 1. file with a string 'foo', no null:
> 0x80 0x03 'f' 'o' 'o'
> 
> 2. file with  a string 'foo' and null:
> 0x80 0x04 'f' 'o' 'o'
> 
> I suspect the spec really wants 1, but maybe it can be interpreted that 2 is
> also a possibility?
> 
> The present logic should work for either of the above, but not what you have, 
> i.e.:
> 
> 0x80 0x03 0xff 0xff 0xff
> 
> > > 
> > > glib docs [1] say:
> > > "Note that g_utf8_validate() returns FALSE if max_len is positive and any 
> > > of
> > > the max_len bytes are nul."
> > > 
> > > So I think the above logic would flag such a file as invalid, no?
> > 
> 
> ...but g_utf8_validate as invoked in this patch would flag possibility 2 as
> invalid...

True. Thanks for detailed clarification. Indeed, both cases needs to be
supported. Let me double-check and come back with v3.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [PATCH v2] sim: validate IMS private identity

2021-01-15 Thread Sergey Matyukevich
> > Make sure that IMS private identity is a valid UTF8 string before
> > setting sim->impi field. Otherwise ofono may crash on dbus assert
> > when SIM properties are reported via org.ofono.SimManager interface.
> > ---
> >   src/sim.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/sim.c b/src/sim.c
> > index 33e1245f..2a663e2d 100644
> > --- a/src/sim.c
> > +++ b/src/sim.c
> > @@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, 
> > int record,
> > return;
> > }
> > -   sim->impi = g_strndup((const char *)data + 2, data[1]);
> > +   if (g_utf8_validate((const char *)data + 2, data[1], NULL))
> > +   sim->impi = g_strndup((const char *)data + 2, data[1]);
> 
> I assume this code path was tested with a file containing embedded NULs as
> that is the only way it would have worked.
> 
> glib docs [1] say:
> "Note that g_utf8_validate() returns FALSE if max_len is positive and any of
> the max_len bytes are nul."
> 
> So I think the above logic would flag such a file as invalid, no?

No, I tested using modem with attached SIM/eSIM. TLV data object appears
to be well-formed, but the contents is all padding 0xff bytes. Could you
please clarify your concern ? I assume we can not rely on the content
being properly null terminated string.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2] sim: validate IMS private identity

2021-01-15 Thread Sergey Matyukevich
Make sure that IMS private identity is a valid UTF8 string before
setting sim->impi field. Otherwise ofono may crash on dbus assert
when SIM properties are reported via org.ofono.SimManager interface.
---
 src/sim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/sim.c b/src/sim.c
index 33e1245f..2a663e2d 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, int 
record,
return;
}
 
-   sim->impi = g_strndup((const char *)data + 2, data[1]);
+   if (g_utf8_validate((const char *)data + 2, data[1], NULL))
+   sim->impi = g_strndup((const char *)data + 2, data[1]);
 }
 
 static void discover_apps_cb(const struct ofono_error *error,
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [PATCH] sim: validate IMS private identity

2021-01-15 Thread Sergey Matyukevich
Hi Denis,

> > Make sure that IMPI is a valid UTF8 string before attempting
> > to report it via DBus. Otherwise ofono may crash on dbus assert.
> > This field may not be defined for ISIM in use. In this case the
> > field still can be read from ISIM, though it will not contain
> > a valid UTF8 string. For instance, it may contain 255 0xFF bytes.
> 
> Ugh, seems like the SIM vendor can't follow RFC's either?  31.103 Section
> 4.2.2 says:
> 
> "For contents and syntax of NAI TLV data object values see IETF RFC 2486
> [24]. The NAI shall be encoded to an octet string according to UTF-8
> encoding rules as specified in IETF RFC 3629 [27]. The tag value of the NAI
> TLV data object shall be '80'. "

This crash occured during my experiments with eSIM. As I mentioned, the
content of that TLV data object was 0xff bytes. IIUC it looks like vendor
could just skip initialization of that particular TLV data object during
bootstrap. Though I am not yet familiar with eSIM init procedure...

> > ---
> >   src/sim.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/src/sim.c b/src/sim.c
> > index 33e1245f..f60f5d1b 100644
> > --- a/src/sim.c
> > +++ b/src/sim.c
> > @@ -423,7 +423,7 @@ static DBusMessage *sim_get_properties(DBusConnection 
> > *conn,
> > ofono_dbus_dict_append(&dict, "ServiceProviderName",
> > DBUS_TYPE_STRING, &sim->spn);
> > -   if (sim->impi)
> > +   if (sim->impi && g_utf8_validate(sim->impi, 255, NULL))
> 
> Hmm, this would imply that we're setting sim->impi incorrectly..  Also,
> since we have __ofono_sim_get_impi() API, the better fix would be to make
> sure sim->impi is set correctly in impi_read_cb()

Ok. I will set sim->impi in impi_read_cb only if it is a valid UTF8 string.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [PATCH v2 3/3] gemalto: netmon measurements scaling

2021-01-15 Thread Sergey Matyukevich
Hello Denis,

> > Gemalto modem reports raw measurements in dBm. Reported values may
> > include negative numbers. Meanwhile oFono follows ETSI TS 27.007,
> > so negative numbers do not really exist at the API level.
> > 
> > Modify gemalto netmon driver to report measurements according to
> > 27.007. For this purpose re-scale from what Gemalto firmware
> > reports into something that 27.007 recommends.
> > ---
> >   drivers/gemaltomodem/netmon.c | 52 ---
> >   1 file changed, 48 insertions(+), 4 deletions(-)
> > 
> 
> I went ahead and applied all three patches after making minor tweaks in this 
> one:

Thanks!

> > +static int gemalto_rscp_scale(int value)
> > +{
> > +   if (value < -120)
> > +   return 0;
> > +
> > +   if (value > -24)
> > +   return 96;
> > +
> > +   return (value + 120);
> 
> The ()s weren't needed here..

Well, I did check coding style document for arithmetic expressions,
but I did not find anything other than spaces around operators. 
So I made a wrong guess...

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH] sim: validate IMS private identity

2021-01-15 Thread Sergey Matyukevich
Make sure that IMPI is a valid UTF8 string before attempting
to report it via DBus. Otherwise ofono may crash on dbus assert.
This field may not be defined for ISIM in use. In this case the
field still can be read from ISIM, though it will not contain
a valid UTF8 string. For instance, it may contain 255 0xFF bytes.
---
 src/sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sim.c b/src/sim.c
index 33e1245f..f60f5d1b 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -423,7 +423,7 @@ static DBusMessage *sim_get_properties(DBusConnection *conn,
ofono_dbus_dict_append(&dict, "ServiceProviderName",
DBUS_TYPE_STRING, &sim->spn);
 
-   if (sim->impi)
+   if (sim->impi && g_utf8_validate(sim->impi, 255, NULL))
ofono_dbus_dict_append(&dict, "ImsPrivateIdentity",
DBUS_TYPE_STRING, &sim->impi);
 
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 3/3] gemalto: netmon measurements scaling

2021-01-15 Thread Sergey Matyukevich
Gemalto modem reports raw measurements in dBm. Reported values may
include negative numbers. Meanwhile oFono follows ETSI TS 27.007,
so negative numbers do not really exist at the API level.

Modify gemalto netmon driver to report measurements according to
27.007. For this purpose re-scale from what Gemalto firmware
reports into something that 27.007 recommends.
---
 drivers/gemaltomodem/netmon.c | 52 ---
 1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/drivers/gemaltomodem/netmon.c b/drivers/gemaltomodem/netmon.c
index ddaebf1a..c3a0498d 100644
--- a/drivers/gemaltomodem/netmon.c
+++ b/drivers/gemaltomodem/netmon.c
@@ -128,6 +128,50 @@ static gboolean gemalto_delayed_register(gpointer 
user_data)
return FALSE;
 }
 
+static int gemalto_ecno_scale(int value)
+{
+   if (value < -24)
+   return 0;
+
+   if (value > 0)
+   return 49;
+
+   return 49 * (value + 24) / 24;
+}
+
+static int gemalto_rscp_scale(int value)
+{
+   if (value < -120)
+   return 0;
+
+   if (value > -24)
+   return 96;
+
+   return (value + 120);
+}
+
+static int gemalto_rsrp_scale(int value)
+{
+   if (value < -140)
+   return 0;
+
+   if (value > -43)
+   return 97;
+
+   return (value + 140);
+}
+
+static int gemalto_rsrq_scale(int value)
+{
+   if (2 * value < -39)
+   return 0;
+
+   if (2 * value > -5)
+   return 34;
+
+   return (2 * value + 39);
+}
+
 static int gemalto_parse_smoni_gsm(GAtResultIter *iter,
struct req_cb_data *cbd)
 {
@@ -273,13 +317,13 @@ static int gemalto_parse_smoni_umts(GAtResultIter *iter,
case SMONI_UMTS_ECN0:
if (g_at_result_iter_next_unquoted_string(iter, &str)) {
if (sscanf(str, "%f", &fnumber) == 1)
-   cbd->t.umts.ecno = (int)fnumber;
+   cbd->t.umts.ecno = 
gemalto_ecno_scale((int)fnumber);
}
break;
case SMONI_UMTS_RSCP:
if (g_at_result_iter_next_unquoted_string(iter, &str)) {
if (sscanf(str, "%d", &number) == 1)
-   cbd->t.umts.rscp = number;
+   cbd->t.umts.rscp = 
gemalto_rscp_scale(number);
}
break;
case SMONI_UMTS_MCC:
@@ -368,12 +412,12 @@ static int gemalto_parse_smoni_lte(GAtResultIter *iter,
 
if (g_at_result_iter_next_unquoted_string(iter, &str)) {
if (sscanf(str, "%d", &number) == 1)
-   cbd->t.lte.rsrp = number;
+   cbd->t.lte.rsrp = gemalto_rsrp_scale(number);
}
 
if (g_at_result_iter_next_unquoted_string(iter, &str)) {
if (sscanf(str, "%d", &number) == 1)
-   cbd->t.lte.rsrq = number;
+   cbd->t.lte.rsrq = gemalto_rsrq_scale(number);
}
 
DBG(" %-15s %s", "LTE.MCC", cbd->op.mcc);
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 2/3] plugin: gemalto: enable netmon

2021-01-15 Thread Sergey Matyukevich
Enable netmon functionality for Gemalto ELS81x modems.
---
 plugins/gemalto.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 28ee3aff..135e2d26 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -622,6 +623,7 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 static void gemalto_post_online(struct ofono_modem *modem)
 {
struct gemalto_data *data = ofono_modem_get_data(modem);
+   const char *model = ofono_modem_get_string(modem, "Model");
 
DBG("%p", modem);
 
@@ -634,6 +636,10 @@ static void gemalto_post_online(struct ofono_modem *modem)
ofono_call_settings_create(modem, 0, "atmodem", data->app);
ofono_call_meter_create(modem, 0, "atmodem", data->app);
ofono_call_barring_create(modem, 0, "atmodem", data->app);
+
+   if (!g_strcmp0(model, GEMALTO_MODEL_ELS81x))
+   ofono_netmon_create(modem, OFONO_VENDOR_GEMALTO,
+   "gemaltomodem", data->app);
 }
 
 static struct ofono_modem_driver gemalto_driver = {
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 1/3] gemalto: add netmon driver

2021-01-15 Thread Sergey Matyukevich
Implement network monitoring driver for gemalto modems that
are able to provide serving cell information and basic
measurements using AT+CQS and AT^SMONI commands.
---
 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   2 +
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/netmon.c   | 605 
 4 files changed, 612 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gemaltomodem/netmon.c

diff --git a/Makefile.am b/Makefile.am
index c0631081..5e7614c1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -483,7 +483,8 @@ builtin_sources += drivers/atmodem/atutil.h \
drivers/gemaltomodem/gemaltomodem.c \
drivers/gemaltomodem/location-reporting.c \
drivers/gemaltomodem/voicecall.c \
-   drivers/gemaltomodem/gprs-context.c
+   drivers/gemaltomodem/gprs-context.c \
+   drivers/gemaltomodem/netmon.c
 
 builtin_modules += xmm7modem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/gemaltomodem/gemaltomodem.c 
b/drivers/gemaltomodem/gemaltomodem.c
index 4b20dd1b..f7e4ff3e 100644
--- a/drivers/gemaltomodem/gemaltomodem.c
+++ b/drivers/gemaltomodem/gemaltomodem.c
@@ -38,6 +38,7 @@ static int gemaltomodem_init(void)
gemalto_location_reporting_init();
gemalto_gprs_context_init();
gemalto_voicecall_init();
+   gemalto_netmon_init();
 
return 0;
 }
@@ -47,6 +48,7 @@ static void gemaltomodem_exit(void)
gemalto_location_reporting_exit();
gemalto_gprs_context_exit();
gemalto_voicecall_exit();
+   gemalto_netmon_exit();
 }
 
 OFONO_PLUGIN_DEFINE(gemaltomodem, "Gemalto modem driver", VERSION,
diff --git a/drivers/gemaltomodem/gemaltomodem.h 
b/drivers/gemaltomodem/gemaltomodem.h
index dc0d346b..ae8f2141 100644
--- a/drivers/gemaltomodem/gemaltomodem.h
+++ b/drivers/gemaltomodem/gemaltomodem.h
@@ -30,3 +30,6 @@ extern void gemalto_voicecall_exit();
 
 extern void gemalto_gprs_context_init();
 extern void gemalto_gprs_context_exit();
+
+extern void gemalto_netmon_init(void);
+extern void gemalto_netmon_exit(void);
diff --git a/drivers/gemaltomodem/netmon.c b/drivers/gemaltomodem/netmon.c
new file mode 100644
index ..ddaebf1a
--- /dev/null
+++ b/drivers/gemaltomodem/netmon.c
@@ -0,0 +1,605 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  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 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "common.h"
+#include "gemaltomodem.h"
+#include "drivers/atmodem/vendor.h"
+
+static const char *smoni_prefix[] = { "^SMONI:", NULL };
+static const char *csq_prefix[] = { "+CSQ:", NULL };
+
+struct netmon_driver_data {
+   GAtChat *chat;
+};
+
+struct req_cb_data {
+   gint ref_count; /* Ref count */
+
+   struct ofono_netmon *netmon;
+   ofono_netmon_cb_t cb;
+   void *data;
+
+   struct ofono_network_operator op;
+
+   int rssi;   /* CSQ: received signal strength indicator (RSSI) */
+
+   union {
+   struct {
+   int arfcn;  /* SMONI: Absolute Radio Frequency 
Channel Number */
+   int bcch;   /* SMONI: Receiving level of the BCCH 
carrier in dBm */
+   int lac;/* SMONI: Location Area Code */
+   int ci; /* SMONI: Cell ID */
+   } gsm;
+   struct {
+   int uarfcn; /* SMONI: UTRAN Absolute Radio 
Frequency Channel Number */
+   int psc;/* SMONI: Primary Scrambling Code */
+   int ecno;   /* SMONI: Carrier to noise ratio in dB 
*/
+   int rscp;   /* SMONI: Received Signal Code Power in 
dBm */
+   int lac;/* SMONI: Location Area Code */
+   int ci; /* SMONI: Cell ID */
+   } umts;
+   struct {
+   int euarfcn;/* SMONI: E-UTRA Absolute Radio 
Frequency Channel Number */
+   int rsrp;   /* SMONI: Reference Signal Received

[PATCH v2 0/3] gemalto: netmon driver

2021-01-15 Thread Sergey Matyukevich
Hello Denis and all,

This patch series implements netmon driver for gemalto modems that are
able to provide basic measurements using AT+CQS and AT^SMONI commands.
For now netmon driver is enabled for ELS81x modems.

Regards,
Sergey

v1 -> v2

- use g_new0 instead of g_try_new0
- remove rssi scaling: keep using 27.007 range
- scale modem measurement reports to ranges recommended by 27.007

Sergey Matyukevich (3):
  gemalto: add netmon driver
  plugin: gemalto: enable netmon
  gemalto: netmon measurements scaling

 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   2 +
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/netmon.c   | 649 
 plugins/gemalto.c   |   6 +
 5 files changed, 662 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gemaltomodem/netmon.c
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [RFC PATCH 0/2] gemalto: netmon driver

2021-01-11 Thread Sergey Matyukevich
Hello Denis,

> > This patch series implements netmon driver for gemalto modems that are
> > able to provide basic measurements using AT+CQS and AT^SMONI commands.
> > 
> > This patch series is intendedly marked as RFC. In addition to general
> 
> I guess you mean intentionally here...
> 
> > feedback for this v1 I would like to clarify the right way to handle
> > negative values that can be returned by modem. For instance, this
> 
> So the short answer is: You're not supposed to even have negative numbers in
> AT commands.  And since oFono follows 27.007, which is itself based on AT
> commands, negative numbers do not really exist at the API level.
> 
> Refer to ITU v.250 Section 5.4.2.1 "Numeric constants".  Strings are also
> supposed to be formatted in a certain way, which the firmware isn't doing
> properly either...  The fact that you have to resort to using
> next_unquoted_string is kind of telling.
> 
> > is the case for the values measured in dBm including EC/n0 and RSCP.
> > Currently such values are discarded by CELL_INFO_DICT_APPEND macro.
> 
> I would guess your best bet would be to re-scale from what Gemalto firmware
> reports into something that 27.007 recommends.  You may have to refer to
> 27.007, Section 8.69 to see what the scale is according to 3GPP.

Thanks a lot for pointing me in the right direction. I will get back
with v2 once I introduce the suggested changes.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[RFC PATCH 2/2] plugin: gemalto: enable netmon

2021-01-10 Thread Sergey Matyukevich
Enable netmon functionality for Gemalto ELS81x modems.
---
 plugins/gemalto.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 28ee3aff..135e2d26 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -622,6 +623,7 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 static void gemalto_post_online(struct ofono_modem *modem)
 {
struct gemalto_data *data = ofono_modem_get_data(modem);
+   const char *model = ofono_modem_get_string(modem, "Model");
 
DBG("%p", modem);
 
@@ -634,6 +636,10 @@ static void gemalto_post_online(struct ofono_modem *modem)
ofono_call_settings_create(modem, 0, "atmodem", data->app);
ofono_call_meter_create(modem, 0, "atmodem", data->app);
ofono_call_barring_create(modem, 0, "atmodem", data->app);
+
+   if (!g_strcmp0(model, GEMALTO_MODEL_ELS81x))
+   ofono_netmon_create(modem, OFONO_VENDOR_GEMALTO,
+   "gemaltomodem", data->app);
 }
 
 static struct ofono_modem_driver gemalto_driver = {
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[RFC PATCH 1/2] gemalto: add netmon driver

2021-01-10 Thread Sergey Matyukevich
Implement network monitoring driver for gemalto modems that
are able to provide serving cell information and basic
measurements using AT+CQS and AT^SMONI commands.
---
 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   2 +
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/netmon.c   | 609 
 4 files changed, 616 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gemaltomodem/netmon.c

diff --git a/Makefile.am b/Makefile.am
index c0631081..5e7614c1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -483,7 +483,8 @@ builtin_sources += drivers/atmodem/atutil.h \
drivers/gemaltomodem/gemaltomodem.c \
drivers/gemaltomodem/location-reporting.c \
drivers/gemaltomodem/voicecall.c \
-   drivers/gemaltomodem/gprs-context.c
+   drivers/gemaltomodem/gprs-context.c \
+   drivers/gemaltomodem/netmon.c
 
 builtin_modules += xmm7modem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/gemaltomodem/gemaltomodem.c 
b/drivers/gemaltomodem/gemaltomodem.c
index 4b20dd1b..f7e4ff3e 100644
--- a/drivers/gemaltomodem/gemaltomodem.c
+++ b/drivers/gemaltomodem/gemaltomodem.c
@@ -38,6 +38,7 @@ static int gemaltomodem_init(void)
gemalto_location_reporting_init();
gemalto_gprs_context_init();
gemalto_voicecall_init();
+   gemalto_netmon_init();
 
return 0;
 }
@@ -47,6 +48,7 @@ static void gemaltomodem_exit(void)
gemalto_location_reporting_exit();
gemalto_gprs_context_exit();
gemalto_voicecall_exit();
+   gemalto_netmon_exit();
 }
 
 OFONO_PLUGIN_DEFINE(gemaltomodem, "Gemalto modem driver", VERSION,
diff --git a/drivers/gemaltomodem/gemaltomodem.h 
b/drivers/gemaltomodem/gemaltomodem.h
index dc0d346b..ae8f2141 100644
--- a/drivers/gemaltomodem/gemaltomodem.h
+++ b/drivers/gemaltomodem/gemaltomodem.h
@@ -30,3 +30,6 @@ extern void gemalto_voicecall_exit();
 
 extern void gemalto_gprs_context_init();
 extern void gemalto_gprs_context_exit();
+
+extern void gemalto_netmon_init(void);
+extern void gemalto_netmon_exit(void);
diff --git a/drivers/gemaltomodem/netmon.c b/drivers/gemaltomodem/netmon.c
new file mode 100644
index ..93e6d02f
--- /dev/null
+++ b/drivers/gemaltomodem/netmon.c
@@ -0,0 +1,609 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  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 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "common.h"
+#include "gemaltomodem.h"
+#include "drivers/atmodem/vendor.h"
+
+static const char *smoni_prefix[] = { "^SMONI:", NULL };
+static const char *csq_prefix[] = { "+CSQ:", NULL };
+
+struct netmon_driver_data {
+   GAtChat *chat;
+};
+
+struct req_cb_data {
+   gint ref_count; /* Ref count */
+
+   struct ofono_netmon *netmon;
+   ofono_netmon_cb_t cb;
+   void *data;
+
+   struct ofono_network_operator op;
+
+   int rssi;   /* CSQ: received signal strength indicator (RSSI) */
+
+   union {
+   struct {
+   int arfcn;  /* SMONI: Absolute Radio Frequency 
Channel Number */
+   int bcch;   /* SMONI: Receiving level of the BCCH 
carrier in dBm */
+   int lac;/* SMONI: Location Area Code */
+   int ci; /* SMONI: Cell ID */
+   } gsm;
+   struct {
+   int uarfcn; /* SMONI: UTRAN Absolute Radio 
Frequency Channel Number */
+   int psc;/* SMONI: Primary Scrambling Code */
+   int ecn0;   /* SMONI: Carrier to noise ratio in dB 
*/
+   int rscp;   /* SMONI: Received Signal Code Power in 
dBm */
+   int lac;/* SMONI: Location Area Code */
+   int ci; /* SMONI: Cell ID */
+   } umts;
+   struct {
+   int euarfcn;/* SMONI: E-UTRA Absolute Radio 
Frequency Channel Number */
+   int rsrp;   /* SMONI: Reference Signal Received

[RFC PATCH 0/2] gemalto: netmon driver

2021-01-10 Thread Sergey Matyukevich
Hello Denis and all,

This patch series implements netmon driver for gemalto modems that are
able to provide basic measurements using AT+CQS and AT^SMONI commands.

This patch series is intendedly marked as RFC. In addition to general
feedback for this v1 I would like to clarify the right way to handle
negative values that can be returned by modem. For instance, this
is the case for the values measured in dBm including EC/n0 and RSCP.
Currently such values are discarded by CELL_INFO_DICT_APPEND macro.

Regards,
Sergey


Sergey Matyukevich (2):
  gemalto: add netmon driver
  plugin: gemalto: enable netmon

 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   2 +
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/netmon.c   | 609 
 plugins/gemalto.c   |   6 +
 5 files changed, 622 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gemaltomodem/netmon.c
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 2/2] gemalto: gprs: support authentication settings

2020-12-26 Thread Sergey Matyukevich
Add support for gprs contexts with username, password,
and specific authentication type.
---
 drivers/gemaltomodem/gprs-context.c | 53 -
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
index 99cb4114..c0837bed 100644
--- a/drivers/gemaltomodem/gprs-context.c
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -46,6 +46,9 @@ static const char *none_prefix[] = { NULL };
 struct gprs_context_data {
GAtChat *chat;
unsigned int active_context;
+   char username[OFONO_GPRS_MAX_USERNAME_LENGTH + 1];
+   char password[OFONO_GPRS_MAX_PASSWORD_LENGTH + 1];
+   int auth_type;
enum ofono_gprs_proto proto;
ofono_gprs_context_cb_t cb;
void *cb_data;
@@ -82,7 +85,7 @@ static void swwan_cb(gboolean ok, GAtResult *result, gpointer 
user_data)
}
 }
 
-static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
+static void sgauth_enable_cb(gboolean ok, GAtResult *result,
gpointer user_data)
 {
struct ofono_gprs_context *gc = user_data;
@@ -111,6 +114,38 @@ static void cgdcont_enable_cb(gboolean ok, GAtResult 
*result,
CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
 }
 
+static void cgdcont_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);
+   struct ofono_error error;
+   char buf[384];
+
+   DBG("ok %d", ok);
+
+   if (!ok) {
+   gcd->active_context = 0;
+   decode_at_error(&error, g_at_result_final_response(result));
+   gcd->cb(&error, gcd->cb_data);
+   return;
+   }
+
+   if (gcd->username[0] && gcd->password[0])
+   sprintf(buf, "AT^SGAUTH=%u,%u,\"%s\",\"%s\"",
+   gcd->active_context, gcd->auth_type,
+   gcd->username, gcd->password);
+   else
+   sprintf(buf, "AT^SGAUTH=%u,%u,\"\",\"\"",
+   gcd->active_context, gcd->auth_type);
+
+   if (g_at_chat_send(gcd->chat, buf, none_prefix,
+   sgauth_enable_cb, gc, NULL) > 0)
+   return;
+
+   CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
 static void gemalto_gprs_activate_primary(struct ofono_gprs_context *gc,
const struct ofono_gprs_primary_context *ctx,
ofono_gprs_context_cb_t cb, void *data)
@@ -125,6 +160,22 @@ static void gemalto_gprs_activate_primary(struct 
ofono_gprs_context *gc,
gcd->cb_data = data;
gcd->cb = cb;
 
+   memcpy(gcd->username, ctx->username, sizeof(ctx->username));
+   memcpy(gcd->password, ctx->password, sizeof(ctx->password));
+   gcd->proto = ctx->proto;
+
+   switch (ctx->auth_method) {
+   case OFONO_GPRS_AUTH_METHOD_PAP:
+   gcd->auth_type = 1;
+   break;
+   case OFONO_GPRS_AUTH_METHOD_CHAP:
+   gcd->auth_type = 2;
+   break;
+   case OFONO_GPRS_AUTH_METHOD_NONE:
+   default:
+   gcd->auth_type = 0;
+   break;
+   }
 
switch (ctx->proto) {
case OFONO_GPRS_PROTO_IP:
-- 
2.29.2
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 1/2] gemalto: gprs: support automatic context activation

2020-12-26 Thread Sergey Matyukevich
Implement read_settings function to get configuration for automatic
contexts. AT^SWWAN command activates PDP context unless it has been
already activated automatically, and then starts DHCP server in the
ME. So AT^SWWAN command should be run for automatic context as well
in order to obtain IP settings from the ME.

This commit also fixes the issue uncovered by the added support for
automatic contexts: as per modem specs, AT+CGACT context should not
be reused for AT^SWWAN. Though that worked for some reason when
automatic context was reactivated without proper deactivation.

Note that in both cases success code is reported to the core before
AT^SWWAN response. This is because the ME waits until DHCP negotiation
has finished before sending the "OK" or "ERROR" result code.
---
 drivers/gemaltomodem/gprs-context.c | 116 +---
 1 file changed, 69 insertions(+), 47 deletions(-)

diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
index 13a858d4..99cb4114 100644
--- a/drivers/gemaltomodem/gprs-context.c
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -51,70 +51,63 @@ struct gprs_context_data {
void *cb_data;
 };
 
-static void cgact_enable_cb(gboolean ok, GAtResult *result,
-   gpointer user_data)
+static void set_gprs_context_interface(struct ofono_gprs_context *gc)
 {
-   struct ofono_gprs_context *gc = user_data;
-   struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
struct ofono_modem *modem;
const char *interface;
-   char buf[64];
+
+   modem = ofono_gprs_context_get_modem(gc);
+   interface = ofono_modem_get_string(modem, "NetworkInterface");
+   ofono_gprs_context_set_interface(gc, interface);
+
+   /* Use DHCP */
+   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
+}
+
+static void swwan_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);
+   struct ofono_error error;
 
DBG("ok %d", ok);
 
if (!ok) {
-   struct ofono_error error;
-
+   ofono_error("Unable to activate context");
+   ofono_gprs_context_deactivated(gc, gcd->active_context);
gcd->active_context = 0;
-
decode_at_error(&error, g_at_result_final_response(result));
gcd->cb(&error, gcd->cb_data);
-
return;
}
-
-   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
-   g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
-
-   modem = ofono_gprs_context_get_modem(gc);
-   interface = ofono_modem_get_string(modem, "NetworkInterface");
-   ofono_gprs_context_set_interface(gc, interface);
-
-   /* Use DHCP */
-   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
-
-   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
 }
 
 static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
-   gpointer user_data)
+   gpointer user_data)
 {
struct ofono_gprs_context *gc = user_data;
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+   struct ofono_error error;
char buf[64];
 
DBG("ok %d", ok);
 
if (!ok) {
-   struct ofono_error error;
-
gcd->active_context = 0;
-
decode_at_error(&error, g_at_result_final_response(result));
gcd->cb(&error, gcd->cb_data);
-
return;
}
 
-   snprintf(buf, sizeof(buf), "AT+CGACT=1,%u", gcd->active_context);
+   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
 
-   if (g_at_chat_send(gcd->chat, buf, none_prefix,
-   cgact_enable_cb, gc, NULL) == 0)
-   goto error;
+   if (g_at_chat_send(gcd->chat, buf, none_prefix, swwan_cb, gc, NULL)) {
+   set_gprs_context_interface(gc);
 
-   return;
+   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
+   return;
+   }
 
-error:
CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
 }
 
@@ -152,31 +145,27 @@ static void gemalto_gprs_activate_primary(struct 
ofono_gprs_context *gc,
snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"", ctx->apn);
 
if (g_at_chat_send(gcd->chat, buf, none_prefix,
-   cgdcont_enable_cb, gc, NULL) > 0)
+   cgdcont_enable_cb, gc, NULL))
return;
 
CALLBACK_WITH_FAILURE(cb, data);
 }
 
-static void cgact_disable_cb(gboolean ok, GAtResult *result,
-   gpointer user_data)
+static void deactivate_cb(gboolean ok, GAtResult *result,
+   gpointer user_data)
 {
struct ofono_gprs_context *gc = user_data;
struct gprs_context_data *gcd = ofono_gprs_context_get

[PATCH v2 0/2] gemalto: gprs context driver updates

2020-12-26 Thread Sergey Matyukevich
Hi Denis and all,

This is the second version of the patches updating gemalto gprs context
driver. Major changes include support for automatic context activation
and support for gprs context authentication settings.

Regards,
Sergey

v1 -> v2

- drop patches 1, 2, 4 that has been already applied
- add detailed comment on AT^SWWAN patch
- address review comments


Sergey Matyukevich (2):
  gemalto: gprs: support automatic context activation
  gemalto: gprs: support authentication settings

 drivers/gemaltomodem/gprs-context.c | 155 
 1 file changed, 114 insertions(+), 41 deletions(-)

-- 
2.29.2
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [PATCH 3/5] gemalto: gprs: support automatic context activation

2020-12-24 Thread Sergey Matyukevich
Hi Denis,

> > > Are you sure you don't want to wait until swwan_cb to return success to 
> > > the
> > > core?  AT^SWWAN can still fail...?
> > 
> > AT^SWWAN command is yet another way to activate a PDP context. AT commands
> > spec for this modem is a bit vague about SWWAN details, but according to
> > other materials from Gemalto as well as my experiments, this command
> > activates internal DHCP server, so DHCP client can be started for modem
> > USB ethernet interfaces. Based on my observations, SWWAN command does
> > not return until DHCP flow is completed.
> 
> Ugh.  I'd 'window.throw(modem)'...

Well, suggested revision works fairly well in conjunction with ConnMan.
So I would give it a chance )
 
> > 
> > So the idea is to send SWWAN command to modem and make it possible to
> > start DHCP flow right away. I assume that I need both things: mark
> > interface for DHCP and signal success to the core. Callback swwan_cb is
> 
> So the problem with this is that you've now blocked the app/modem port until
> that DHCP negotiation happens.  Maybe it does, maybe it doesn't.  It is less
> than ideal to depend on some external component; there are frequently
> situations where people would be running without ConnMan for example.
> 
> > supposed to handle the case when SWWAN command fails: mark context as
> > deactivated and let oFono proceed with further connection attempts.
> > 
> 
> Another thing to consider is to just run dhcp yourself.  ell has had a
> DHCPv4 client for a while now.  So you could just run l_dhcp_client to
> obtain the address and signal it to the core, leaving the app port in a
> known state...
> 
> Or better yet, don't use SWWAN if you can help it...

I guess that can be done as well. As I mentioned previously, SWWAN is
just one possible option. I assume that another option is to use
CGDCONT/CGACT and then to retrieve IP settings from modem. There were
earlier patches on the mail list for PLS8x modem, IIRC at least one
of them suggested both CGACT and SWWAN. I think I will take a look
and update those patches as soon as I am done with this SWWAN part.
Though at the moment I have no idea how to make configurable gprs
driver selection in gemalto plugin...

> 
> 
> > Sure, I can add a comment. What whould be better: to add a comment in
> > driver or to write a more detailed commit message ?
> 
> Given how unusual this behavior is, I'd add a comment directly in the code.

Ok, I will do both in v2: clarify commit message and add a comment into
the driver.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [PATCH 3/5] gemalto: gprs: support automatic context activation

2020-12-23 Thread Sergey Matyukevich
Hello Denis,

> > Implement read_settings function to get configuration for automatic
> > contexts. Fix the issue uncovered by added support for automatic
> > context activation: do not use AT+CGACT for the contexts handled
> > by AT^SWWAN. As per modem specs, CGACT context can not be reused
> > for SWWAN. Though that worked for some reason when automatic
> > context was reactivated without proper deactivation.
> > ---
> >   drivers/gemaltomodem/gprs-context.c | 110 +++-
> >   1 file changed, 59 insertions(+), 51 deletions(-)



> > +static void swwan_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);
> > +   struct ofono_error error;
> > DBG("ok %d", ok);
> > if (!ok) {
> > -   struct ofono_error error;
> > -
> > +   ofono_error("Unable to activate context");
> > +   ofono_gprs_context_deactivated(gc, gcd->active_context);
> > gcd->active_context = 0;
> 
> This seems a bit strange.  Are you signaling success to the core too early

Correct, this is intended behavior. See my further comments regarding
SWWAN command and its processing.
 
> > -
> > decode_at_error(&error, g_at_result_final_response(result));
> > gcd->cb(&error, gcd->cb_data);
> > -
> > return;
> > }
> > -
> > -   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
> > -   g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
> > -
> > -   modem = ofono_gprs_context_get_modem(gc);
> > -   interface = ofono_modem_get_string(modem, "NetworkInterface");
> > -   ofono_gprs_context_set_interface(gc, interface);
> > -
> > -   /* Use DHCP */
> > -   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
> > -
> > -   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
> >   }
> >   static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
> > -   gpointer user_data)
> > +   gpointer user_data)
> 
> nit: This is superfluous and also see doc/coding-style.txt item M4

Fixed in v2.



> > -   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) == 0)
> > -   goto error;
> > +   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
> > +   if (g_at_chat_send(gcd->chat, buf, none_prefix, swwan_cb, gc, NULL)) {
> 
> Note, this returns > 0 when the command has been queued, not that it has
> been sent or replied to yet...
> 
> > +   set_gprs_context_interface(gc);
> > +   /* Use DHCP */
> > +   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
> 
> If these modems can only do DHCP, then might be cleaner to move the 'Use
> DHCP' bits into set_gprs_context_interface.  And maybe rename it to make
> things clearer, if needed.

Good point, fixed in v2.

> 
> > -   return;
> > +   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
> 
> Are you sure you don't want to wait until swwan_cb to return success to the
> core?  AT^SWWAN can still fail...?

AT^SWWAN command is yet another way to activate a PDP context. AT commands
spec for this modem is a bit vague about SWWAN details, but according to
other materials from Gemalto as well as my experiments, this command
activates internal DHCP server, so DHCP client can be started for modem
USB ethernet interfaces. Based on my observations, SWWAN command does
not return until DHCP flow is completed.

So the idea is to send SWWAN command to modem and make it possible to
start DHCP flow right away. I assume that I need both things: mark
interface for DHCP and signal success to the core. Callback swwan_cb is
supposed to handle the case when SWWAN command fails: mark context as
deactivated and let oFono proceed with further connection attempts.

> > +   return;
> > +   }
> > -error:
> > CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
> >   }
> 
> 
> 
> > @@ -185,17 +170,39 @@ static void gemalto_gprs_deactivate_primary(struct 
> > ofono_gprs_context *gc,
> > gcd->cb = cb;
> > gcd->cb_data = data;
> > -   snprintf(buf, sizeof(buf), "AT+CGACT=0,%u", cid);
> > +   snprintf(buf, sizeof(buf), "AT^SWWAN=0,%u", gcd->active_context);
> > if (g_at_chat_send(gcd->chat, buf, none_prefix,
> > -   cgact_disable_cb, gc, NULL) == 0)
> > -   goto error;
> > -
> > -   return;
> > +   deactivate_cb, gc, NULL))
> > +   return;
> > -error:
> > CALLBACK_WITH_FAILURE(cb, data);
> > +}
> > +
> > +static void gemalto_gprs_read_settings(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 

[PATCH 5/5] gemalto: gprs: support authentication settings

2020-12-21 Thread Sergey Matyukevich
From: Sergey Matyukevich 

Add support for gprs contexts with username, password, as well as
specific authentication type.
---
 drivers/gemaltomodem/gprs-context.c | 54 -
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
index bb09f0b0..da68e959 100644
--- a/drivers/gemaltomodem/gprs-context.c
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -46,6 +46,9 @@ static const char *none_prefix[] = { NULL };
 struct gprs_context_data {
GAtChat *chat;
unsigned int active_context;
+   char username[OFONO_GPRS_MAX_USERNAME_LENGTH + 1];
+   char password[OFONO_GPRS_MAX_PASSWORD_LENGTH + 1];
+   int auth_type;
enum ofono_gprs_proto proto;
ofono_gprs_context_cb_t cb;
void *cb_data;
@@ -79,7 +82,7 @@ static void swwan_cb(gboolean ok, GAtResult *result, gpointer 
user_data)
}
 }
 
-static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
+static void sgauth_enable_cb(gboolean ok, GAtResult *result,
gpointer user_data)
 {
struct ofono_gprs_context *gc = user_data;
@@ -109,6 +112,39 @@ static void cgdcont_enable_cb(gboolean ok, GAtResult 
*result,
CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
 }
 
+static void cgdcont_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);
+   struct ofono_error error;
+   char buf[384];
+
+   DBG("ok %d", ok);
+
+   if (!ok) {
+   gcd->active_context = 0;
+   decode_at_error(&error, g_at_result_final_response(result));
+   gcd->cb(&error, gcd->cb_data);
+   return;
+   }
+
+   if (gcd->username[0] && gcd->password[0])
+   sprintf(buf, "AT^SGAUTH=%u,%u,\"%s\",\"%s\"",
+   gcd->active_context, gcd->auth_type,
+   gcd->username, gcd->password);
+   else
+   sprintf(buf, "AT^SGAUTH=%u,%u,\"\",\"\"",
+   gcd->active_context, gcd->auth_type);
+
+
+   if (g_at_chat_send(gcd->chat, buf, none_prefix,
+   sgauth_enable_cb, gc, NULL) > 0)
+   return;
+
+   CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
 static void gemalto_gprs_activate_primary(struct ofono_gprs_context *gc,
const struct ofono_gprs_primary_context *ctx,
ofono_gprs_context_cb_t cb, void *data)
@@ -123,6 +159,22 @@ static void gemalto_gprs_activate_primary(struct 
ofono_gprs_context *gc,
gcd->cb_data = data;
gcd->cb = cb;
 
+   memcpy(gcd->username, ctx->username, sizeof(ctx->username));
+   memcpy(gcd->password, ctx->password, sizeof(ctx->password));
+   gcd->proto = ctx->proto;
+
+   switch (ctx->auth_method) {
+   case OFONO_GPRS_AUTH_METHOD_PAP:
+   gcd->auth_type = 1;
+   break;
+   case OFONO_GPRS_AUTH_METHOD_CHAP:
+   gcd->auth_type = 2;
+   break;
+   case OFONO_GPRS_AUTH_METHOD_NONE:
+   default:
+   gcd->auth_type = 0;
+   break;
+   }
 
switch (ctx->proto) {
case OFONO_GPRS_PROTO_IP:
-- 
2.29.2
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 4/5] gemalto: gprs: support different gprs protocols

2020-12-21 Thread Sergey Matyukevich
From: Sergey Matyukevich 

Add support for IPv6 and dual mode gprs contexts.
---
 drivers/gemaltomodem/gprs-context.c | 22 --
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
index 680f01ab..bb09f0b0 100644
--- a/drivers/gemaltomodem/gprs-context.c
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -46,6 +46,7 @@ static const char *none_prefix[] = { NULL };
 struct gprs_context_data {
GAtChat *chat;
unsigned int active_context;
+   enum ofono_gprs_proto proto;
ofono_gprs_context_cb_t cb;
void *cb_data;
 };
@@ -118,15 +119,25 @@ static void gemalto_gprs_activate_primary(struct 
ofono_gprs_context *gc,
 
DBG("cid %u", ctx->cid);
 
-   /* IPv6 support not implemented */
-   if (ctx->proto != OFONO_GPRS_PROTO_IP)
-   goto error;
-
gcd->active_context = ctx->cid;
gcd->cb_data = data;
gcd->cb = cb;
 
-   len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IP\"", ctx->cid);
+
+   switch (ctx->proto) {
+   case OFONO_GPRS_PROTO_IP:
+   len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IP\"",
+   ctx->cid);
+   break;
+   case OFONO_GPRS_PROTO_IPV6:
+   len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IPV6\"",
+   ctx->cid);
+   break;
+   case OFONO_GPRS_PROTO_IPV4V6:
+   len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IPV4V6\"",
+   ctx->cid);
+   break;
+   }
 
if (ctx->apn)
snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"", ctx->apn);
@@ -135,7 +146,6 @@ static void gemalto_gprs_activate_primary(struct 
ofono_gprs_context *gc,
cgdcont_enable_cb, gc, NULL))
return;
 
-error:
CALLBACK_WITH_FAILURE(cb, data);
 }
 
-- 
2.29.2
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 3/5] gemalto: gprs: support automatic context activation

2020-12-21 Thread Sergey Matyukevich
From: Sergey Matyukevich 

Implement read_settings function to get configuration for automatic
contexts. Fix the issue uncovered by added support for automatic
context activation: do not use AT+CGACT for the contexts handled
by AT^SWWAN. As per modem specs, CGACT context can not be reused
for SWWAN. Though that worked for some reason when automatic
context was reactivated without proper deactivation.
---
 drivers/gemaltomodem/gprs-context.c | 110 +++-
 1 file changed, 59 insertions(+), 51 deletions(-)

diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
index 322a5f98..680f01ab 100644
--- a/drivers/gemaltomodem/gprs-context.c
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -50,70 +50,61 @@ struct gprs_context_data {
void *cb_data;
 };
 
-static void cgact_enable_cb(gboolean ok, GAtResult *result,
-   gpointer user_data)
+static void set_gprs_context_interface(struct ofono_gprs_context *gc)
 {
-   struct ofono_gprs_context *gc = user_data;
-   struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
struct ofono_modem *modem;
const char *interface;
-   char buf[64];
+
+   modem = ofono_gprs_context_get_modem(gc);
+   interface = ofono_modem_get_string(modem, "NetworkInterface");
+   ofono_gprs_context_set_interface(gc, interface);
+}
+
+static void swwan_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);
+   struct ofono_error error;
 
DBG("ok %d", ok);
 
if (!ok) {
-   struct ofono_error error;
-
+   ofono_error("Unable to activate context");
+   ofono_gprs_context_deactivated(gc, gcd->active_context);
gcd->active_context = 0;
-
decode_at_error(&error, g_at_result_final_response(result));
gcd->cb(&error, gcd->cb_data);
-
return;
}
-
-   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
-   g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
-
-   modem = ofono_gprs_context_get_modem(gc);
-   interface = ofono_modem_get_string(modem, "NetworkInterface");
-   ofono_gprs_context_set_interface(gc, interface);
-
-   /* Use DHCP */
-   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
-
-   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
 }
 
 static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
-   gpointer user_data)
+   gpointer user_data)
 {
struct ofono_gprs_context *gc = user_data;
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+   struct ofono_error error;
char buf[64];
 
DBG("ok %d", ok);
 
if (!ok) {
-   struct ofono_error error;
-
gcd->active_context = 0;
-
decode_at_error(&error, g_at_result_final_response(result));
gcd->cb(&error, gcd->cb_data);
-
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) == 0)
-   goto error;
+   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
+   if (g_at_chat_send(gcd->chat, buf, none_prefix, swwan_cb, gc, NULL)) {
+   set_gprs_context_interface(gc);
+   /* Use DHCP */
+   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
 
-   return;
+   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
+   return;
+   }
 
-error:
CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
 }
 
@@ -141,34 +132,28 @@ static void gemalto_gprs_activate_primary(struct 
ofono_gprs_context *gc,
snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"", ctx->apn);
 
if (g_at_chat_send(gcd->chat, buf, none_prefix,
-   cgdcont_enable_cb, gc, NULL) == 0)
-   goto error;
-
-   return;
+   cgdcont_enable_cb, gc, NULL))
+   return;
 
 error:
CALLBACK_WITH_FAILURE(cb, data);
 }
 
-static void cgact_disable_cb(gboolean ok, GAtResult *result,
-   gpointer user_data)
+static void deactivate_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);
 
+   gcd->active_context = 0

[PATCH 0/5] gemalto: gprs context driver updates

2020-12-21 Thread Sergey Matyukevich
Hi Denis and all,

This patch series includes several updates and fixes for gemalto gprs
context driver based on testing and troubleshooting in several regions.
Major changes include support for automatic context activation and fixes
for gprs context deactivation.

Besides support for automatic context activation uncovered an issue with
normal activation sequence. According to modem specs, AT+CGACT should
not be used for contexts handled by AT^SWWAN. However wrong sequence
used to work when re-activating contexts already activated automatically,
while correct sequence produced incorrect modem DHCP responces.

Regards,
Sergey

Sergey Matyukevich (5):
  plugin: gemalto: fix source of gprs notifications
  gemalto: gprs: cgev gprs context deactivation
  gemalto: gprs: support automatic context activation
  gemalto: gprs: support different gprs protocols
  gemalto: gprs: support authentication settings

 drivers/gemaltomodem/gprs-context.c | 176 
 plugins/gemalto.c   |   2 +-
 2 files changed, 125 insertions(+), 53 deletions(-)

-- 
2.29.2
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 1/5] plugin: gemalto: fix source of gprs notifications

2020-12-21 Thread Sergey Matyukevich
Modem USB interface does not receive certain gprs context notifications.
Fix gprs chat: use Application USB interface to receive all the modem
notifications.
---
 plugins/gemalto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 238c7cc4..28ee3aff 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -606,7 +606,7 @@ static void gemalto_post_sim(struct ofono_modem *modem)
driver = "atmodem";
}
 
-   gc = ofono_gprs_context_create(modem, 0, driver, data->mdm);
+   gc = ofono_gprs_context_create(modem, 0, driver, data->app);
 
if (gprs && gc)
ofono_gprs_add_context(gprs, gc);
-- 
2.29.2
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 2/5] gemalto: gprs: cgev gprs context deactivation

2020-12-21 Thread Sergey Matyukevich
Gemalto ELS81x modems use 'ME PDN DEACT' message to notify about gprs
context deactivation. Process this 'deactivate' event in CGEV handler.
---
 drivers/gemaltomodem/gprs-context.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
index 73cf81a8..322a5f98 100644
--- a/drivers/gemaltomodem/gprs-context.c
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -216,6 +216,8 @@ static void cgev_notify(GAtResult *result, gpointer 
user_data)
 
if (g_str_has_prefix(event, "NW PDN DEACT"))
sscanf(event, "%*s %*s %*s %u", &cid);
+   else if (g_str_has_prefix(event, "ME PDN DEACT"))
+   sscanf(event, "%*s %*s %*s %u", &cid);
else if (g_str_has_prefix(event, "NW DEACT"))
sscanf(event, "%*s %*s %u", &cid);
else
-- 
2.29.2
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 2/3] plugins: udevng: detect gemalto network interfaces

2020-08-18 Thread Sergey Matyukevich
Some gemalto modems, including ELS81x, may provide more than one
USB ethernet interface. Detect and save both network interfaces
rather than only the last one.

Signed-off-by: Sergey Matyukevich 
---
 plugins/udevng.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 7e6a3ab7..839fabdb 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -1162,7 +1162,7 @@ static gboolean setup_ublox(struct modem_info *modem)
 static gboolean setup_gemalto(struct modem_info* modem)
 {
const char *app = NULL, *gps = NULL, *mdm = NULL,
-   *net = NULL, *qmi = NULL;
+   *net = NULL, *qmi = NULL, *net2 = NULL;
 
GSList *list;
 
@@ -1197,9 +1197,14 @@ static gboolean setup_gemalto(struct modem_info* modem)
else if (g_strcmp0(info->number, "04") == 0)
gps = info->devnode;
}
+
if (g_strcmp0(info->interface, "2/6/0") == 0) {
-   if (g_strcmp0(info->subsystem, "net") == 0)
-   net = info->devnode;
+   if (g_strcmp0(info->subsystem, "net") == 0) {
+   if (g_strcmp0(info->number, "0a") == 0)
+   net = info->devnode;
+   if (g_strcmp0(info->number, "0c") == 0)
+   net2 = info->devnode;
+   }
}
}
 
@@ -1216,6 +1221,9 @@ static gboolean setup_gemalto(struct modem_info* modem)
ofono_modem_set_string(modem->modem, "Model", modem->model);
ofono_modem_set_string(modem->modem, "NetworkInterface", net);
 
+   if (net2)
+   ofono_modem_set_string(modem->modem, "NetworkInterface2", net2);
+
return TRUE;
 }
 
-- 
2.28.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 0/3] gemalto: USB ethernet data path for ELS81x

2020-08-18 Thread Sergey Matyukevich
Hi Denis and all,

This patch series enables USB ethernet data path for gemalto modems
that support this feature, in particular for ELS81x devices.

Regards,
Sergey

v1 -> v2

- replace g_try_new0 by use g_new0
- drop patch with incorrect fix for modem init


Sergey Matyukevich (3):
  drivers: gemalto: add gprs-context driver
  plugins: udevng: detect gemalto network interfaces
  plugins: gemalto: alternative gprs-context driver

 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   4 +-
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/gprs-context.c | 278 
 plugins/gemalto.c   |  12 +-
 plugins/udevng.c|  14 +-
 6 files changed, 308 insertions(+), 6 deletions(-)
 create mode 100644 drivers/gemaltomodem/gprs-context.c

-- 
2.28.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH v2 1/3] drivers: gemalto: add gprs-context driver

2020-08-18 Thread Sergey Matyukevich
Some gemalto modems provide USB ethernet interfaces for data path.
Implement gprs-context driver for such modems to send data via
USB ethernet rather than fallback to PPP.

Signed-off-by: Sergey Matyukevich 
---
 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   4 +-
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/gprs-context.c | 278 
 4 files changed, 286 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gemaltomodem/gprs-context.c

diff --git a/Makefile.am b/Makefile.am
index fbb0eff4..67c3bcbf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -482,7 +482,8 @@ builtin_sources += drivers/atmodem/atutil.h \
drivers/gemaltomodem/gemaltomodem.h \
drivers/gemaltomodem/gemaltomodem.c \
drivers/gemaltomodem/location-reporting.c \
-   drivers/gemaltomodem/voicecall.c
+   drivers/gemaltomodem/voicecall.c \
+   drivers/gemaltomodem/gprs-context.c
 
 builtin_modules += xmm7modem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/gemaltomodem/gemaltomodem.c 
b/drivers/gemaltomodem/gemaltomodem.c
index 4818ac66..4b20dd1b 100644
--- a/drivers/gemaltomodem/gemaltomodem.c
+++ b/drivers/gemaltomodem/gemaltomodem.c
@@ -36,6 +36,7 @@
 static int gemaltomodem_init(void)
 {
gemalto_location_reporting_init();
+   gemalto_gprs_context_init();
gemalto_voicecall_init();
 
return 0;
@@ -43,8 +44,9 @@ static int gemaltomodem_init(void)
 
 static void gemaltomodem_exit(void)
 {
-   gemalto_voicecall_exit();
gemalto_location_reporting_exit();
+   gemalto_gprs_context_exit();
+   gemalto_voicecall_exit();
 }
 
 OFONO_PLUGIN_DEFINE(gemaltomodem, "Gemalto modem driver", VERSION,
diff --git a/drivers/gemaltomodem/gemaltomodem.h 
b/drivers/gemaltomodem/gemaltomodem.h
index 27b1460e..dc0d346b 100644
--- a/drivers/gemaltomodem/gemaltomodem.h
+++ b/drivers/gemaltomodem/gemaltomodem.h
@@ -27,3 +27,6 @@ extern void gemalto_location_reporting_exit();
 
 extern void gemalto_voicecall_init();
 extern void gemalto_voicecall_exit();
+
+extern void gemalto_gprs_context_init();
+extern void gemalto_gprs_context_exit();
diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
new file mode 100644
index ..73cf81a8
--- /dev/null
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -0,0 +1,278 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2020 Sergey Matyukevich. 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 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+
+#include "gatchat.h"
+#include "gatresult.h"
+#include "gattty.h"
+
+#include "gemaltomodem.h"
+
+static const char *none_prefix[] = { NULL };
+
+struct gprs_context_data {
+   GAtChat *chat;
+   unsigned int active_context;
+   ofono_gprs_context_cb_t cb;
+   void *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);
+   struct ofono_modem *modem;
+   const char *interface;
+   char buf[64];
+
+   DBG("ok %d", ok);
+
+   if (!ok) {
+   struct ofono_error error;
+
+   gcd->active_context = 0;
+
+   decode_at_error(&error, g_at_result_final_response(result));
+   gcd->cb(&error, gcd->cb_data);
+
+   return;
+   }
+
+   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
+   g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
+
+   modem = ofono_gprs_context_get_modem(gc);
+   interface = ofono_modem_get_string(modem, "NetworkInterface");
+   ofono_gprs_context_set_interface(gc, interface);
+
+   /* Use DHCP */
+   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
+
+   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
+}
+
+static void cgdcont_enable_cb(gboolean ok

[PATCH v2 3/3] plugins: gemalto: alternative gprs-context driver

2020-08-18 Thread Sergey Matyukevich
Use alternative gprs context driver for gemalto modems
that provide USB ethernet interfaces for data path.

Signed-off-by: Sergey Matyukevich 
---
 plugins/gemalto.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 13950742..238c7cc4 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -588,6 +588,8 @@ static void gemalto_post_sim(struct ofono_modem *modem)
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
const char *model = ofono_modem_get_string(modem, "Model");
+   const char *driver = NULL;
+   const char *iface = NULL;
 
DBG("%p", modem);
 
@@ -596,7 +598,15 @@ static void gemalto_post_sim(struct ofono_modem *modem)
ofono_sms_create(modem, OFONO_VENDOR_GEMALTO, "atmodem", data->app);
 
gprs = ofono_gprs_create(modem, 0, "atmodem", data->app);
-   gc = ofono_gprs_context_create(modem, 0, "atmodem", data->mdm);
+
+   iface = ofono_modem_get_string(modem, "NetworkInterface");
+   if (iface) {
+   driver = "gemaltomodem";
+   } else {
+   driver = "atmodem";
+   }
+
+   gc = ofono_gprs_context_create(modem, 0, driver, data->mdm);
 
if (gprs && gc)
ofono_gprs_add_context(gprs, gc);
-- 
2.28.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

2020-08-17 Thread Sergey Matyukevich
Hello Denis,

> > Function gemalto_modem_ready attempts to restart AT chat data->app
> > after  incomplete shutdown. As a result, new AT chat does not work
> > as expected loosing AT commands.
> > 
> > Signed-off-by: Sergey Matyukevich 
> > ---
> >   plugins/gemalto.c | 8 
> >   1 file changed, 8 insertions(+)
> 
> Patch 2, 3 look good to me.
> 
> For this one, what is it trying to do actually?
> 

Thanks for review. I will re-send second revision of the patches 1-3
with minor changes according to review comments.

Concerning the 4th patch, I thought the problem was in the incomplete
cleanup on data->app re-open in gemalto_modem_ready function. However
this is not the case. Sometimes, in particular on cold start, modem
is not really ready even after it sends ^SYSSTART. As a result,
subsequent AT+CFUN=4 command never completes. I have been experimenting
with the same approach as in ublox plugin with much better results.
So I will complete my experiments and send new fix in a separate patch.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


Re: [RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

2020-08-17 Thread Sergey Matyukevich
> Function gemalto_modem_ready attempts to restart AT chat data->app
> after  incomplete shutdown. As a result, new AT chat does not work
> as expected loosing AT commands.
> 
> Signed-off-by: Sergey Matyukevich 
> ---
>  plugins/gemalto.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/plugins/gemalto.c b/plugins/gemalto.c
> index 238c7cc4..321c8c1b 100644
> --- a/plugins/gemalto.c
> +++ b/plugins/gemalto.c

...

> @@ -451,6 +455,8 @@ static void gemalto_modem_ready(GAtResult *result, 
> gpointer user_data)
>   data->modem_ready_id = 0;
>   data->trial_cmd_id = 0;
>  
> + g_at_chat_cancel_all(data->app);
> + g_at_chat_unregister_all(data->app);
>   g_at_chat_unref(data->app);
>  
>   data->app = open_device(app);

Please disregard this patch in the series. This change does not resolve
the root cause. It looks like when gemalto_modem_ready is called on
^SYSSTART, occasionally modem is not ready to process AT commands.
As a result, the upcoming gemalto_initialize function fails due to
timed out AT commands.

It turns out that the approach implemented in ublox plugin (repeated
probe AT command) provides more reliable results, in particular
in power-off tests. I will do more testing and update this patch
in the next revision of the patch set.

Regards,
Sergey
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

2020-08-15 Thread Sergey Matyukevich
Function gemalto_modem_ready attempts to restart AT chat data->app
after  incomplete shutdown. As a result, new AT chat does not work
as expected loosing AT commands.

Signed-off-by: Sergey Matyukevich 
---
 plugins/gemalto.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 238c7cc4..321c8c1b 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -222,6 +222,8 @@ static void sim_state_cb(gboolean present, gpointer 
user_data)
struct ofono_modem *modem = user_data;
struct gemalto_data *data = ofono_modem_get_data(modem);
 
+   DBG("");
+
at_util_sim_state_query_free(data->sim_state_query);
data->sim_state_query = NULL;
 
@@ -241,6 +243,8 @@ static void cfun_enable(gboolean ok, GAtResult *result, 
gpointer user_data)
struct ofono_modem *modem = user_data;
struct gemalto_data *data = ofono_modem_get_data(modem);
 
+   DBG("");
+
if (!ok) {
g_at_chat_unref(data->app);
data->app = NULL;
@@ -451,6 +455,8 @@ static void gemalto_modem_ready(GAtResult *result, gpointer 
user_data)
data->modem_ready_id = 0;
data->trial_cmd_id = 0;
 
+   g_at_chat_cancel_all(data->app);
+   g_at_chat_unregister_all(data->app);
g_at_chat_unref(data->app);
 
data->app = open_device(app);
@@ -466,6 +472,8 @@ static void gemalto_at_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
struct ofono_modem *modem = user_data;
struct gemalto_data *data = ofono_modem_get_data(modem);
 
+   DBG("");
+
g_at_chat_unregister(data->app, data->modem_ready_id);
data->modem_ready_id = 0;
 
-- 
2.28.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[RFC PATCH 3/4] plugins: gemalto: add optional gprs-context driver

2020-08-15 Thread Sergey Matyukevich
Setup custom gprs context driver for modems that provide
USB ethernet interfaces for data path.

Signed-off-by: Sergey Matyukevich 
---
 plugins/gemalto.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 13950742..238c7cc4 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -588,6 +588,8 @@ static void gemalto_post_sim(struct ofono_modem *modem)
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
const char *model = ofono_modem_get_string(modem, "Model");
+   const char *driver = NULL;
+   const char *iface = NULL;
 
DBG("%p", modem);
 
@@ -596,7 +598,15 @@ static void gemalto_post_sim(struct ofono_modem *modem)
ofono_sms_create(modem, OFONO_VENDOR_GEMALTO, "atmodem", data->app);
 
gprs = ofono_gprs_create(modem, 0, "atmodem", data->app);
-   gc = ofono_gprs_context_create(modem, 0, "atmodem", data->mdm);
+
+   iface = ofono_modem_get_string(modem, "NetworkInterface");
+   if (iface) {
+   driver = "gemaltomodem";
+   } else {
+   driver = "atmodem";
+   }
+
+   gc = ofono_gprs_context_create(modem, 0, driver, data->mdm);
 
if (gprs && gc)
ofono_gprs_add_context(gprs, gc);
-- 
2.28.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[RFC PATCH 0/4] gemalto: USB ethernet data path for ELS81x

2020-08-15 Thread Sergey Matyukevich
Hi Denis and all,

This patch series suggests several updates and fixes for gemalto modems,
in particular for ELS81x device. Major change enables data path via USB
ethernet interface for modems supporting this feature.

Before submitting this patch series, I figured out that similar changes
have been already submitted to ofono mailing list back in 2017. At that
time they were aimed at PLS8 device:

https://lists.syncevolution.org/hyperkitty/list/ofono@ofono.org/thread/CHQZ2LY6D7J75MLYENACM6JDFHNN5GJ5/#3JB3RF5WVW2U6R65UHA6POSRROUNV6ET

It looks like not all the pieces from the original patches finally
landed in the ofono code base. I am not sure why they were not
merged, so I marked this series as RFC.

Regards,
Sergey

Sergey Matyukevich (4):
  drivers: gemalto: add gprs-context driver
  plugins: udevng: detect gemalto network interfaces
  plugins: gemalto: add optional gprs-context driver
  plugins: gemalto: fix incomplete at-chat shutdown

 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   4 +-
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/gprs-context.c | 280 
 plugins/gemalto.c   |  20 +-
 plugins/udevng.c|  14 +-
 6 files changed, 318 insertions(+), 6 deletions(-)
 create mode 100644 drivers/gemaltomodem/gprs-context.c

-- 
2.28.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[RFC PATCH 1/4] drivers: gemalto: add gprs-context driver

2020-08-15 Thread Sergey Matyukevich
Some gemalto modems provide USB ethernet interfaces for data path.
Implement gprs-context driver for such modems to send data via
USB ethernet rather than fallback to PPP.

Signed-off-by: Sergey Matyukevich 
---
 Makefile.am |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   4 +-
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/gprs-context.c | 280 
 4 files changed, 288 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gemaltomodem/gprs-context.c

diff --git a/Makefile.am b/Makefile.am
index fbb0eff4..67c3bcbf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -482,7 +482,8 @@ builtin_sources += drivers/atmodem/atutil.h \
drivers/gemaltomodem/gemaltomodem.h \
drivers/gemaltomodem/gemaltomodem.c \
drivers/gemaltomodem/location-reporting.c \
-   drivers/gemaltomodem/voicecall.c
+   drivers/gemaltomodem/voicecall.c \
+   drivers/gemaltomodem/gprs-context.c
 
 builtin_modules += xmm7modem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/gemaltomodem/gemaltomodem.c 
b/drivers/gemaltomodem/gemaltomodem.c
index 4818ac66..4b20dd1b 100644
--- a/drivers/gemaltomodem/gemaltomodem.c
+++ b/drivers/gemaltomodem/gemaltomodem.c
@@ -36,6 +36,7 @@
 static int gemaltomodem_init(void)
 {
gemalto_location_reporting_init();
+   gemalto_gprs_context_init();
gemalto_voicecall_init();
 
return 0;
@@ -43,8 +44,9 @@ static int gemaltomodem_init(void)
 
 static void gemaltomodem_exit(void)
 {
-   gemalto_voicecall_exit();
gemalto_location_reporting_exit();
+   gemalto_gprs_context_exit();
+   gemalto_voicecall_exit();
 }
 
 OFONO_PLUGIN_DEFINE(gemaltomodem, "Gemalto modem driver", VERSION,
diff --git a/drivers/gemaltomodem/gemaltomodem.h 
b/drivers/gemaltomodem/gemaltomodem.h
index 27b1460e..dc0d346b 100644
--- a/drivers/gemaltomodem/gemaltomodem.h
+++ b/drivers/gemaltomodem/gemaltomodem.h
@@ -27,3 +27,6 @@ extern void gemalto_location_reporting_exit();
 
 extern void gemalto_voicecall_init();
 extern void gemalto_voicecall_exit();
+
+extern void gemalto_gprs_context_init();
+extern void gemalto_gprs_context_exit();
diff --git a/drivers/gemaltomodem/gprs-context.c 
b/drivers/gemaltomodem/gprs-context.c
new file mode 100644
index ..be3de537
--- /dev/null
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -0,0 +1,280 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2020 Sergey Matyukevich. 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 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+
+#include "gatchat.h"
+#include "gatresult.h"
+#include "gattty.h"
+
+#include "gemaltomodem.h"
+
+static const char *none_prefix[] = { NULL };
+
+struct gprs_context_data {
+   GAtChat *chat;
+   unsigned int active_context;
+   ofono_gprs_context_cb_t cb;
+   void *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);
+   struct ofono_modem *modem;
+   const char *interface;
+   char buf[64];
+
+   DBG("ok %d", ok);
+
+   if (!ok) {
+   struct ofono_error error;
+
+   gcd->active_context = 0;
+
+   decode_at_error(&error, g_at_result_final_response(result));
+   gcd->cb(&error, gcd->cb_data);
+
+   return;
+   }
+
+   snprintf(buf, sizeof(buf), "AT^SWWAN=1,%u", gcd->active_context);
+   g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
+
+   modem = ofono_gprs_context_get_modem(gc);
+   interface = ofono_modem_get_string(modem, "NetworkInterface");
+   ofono_gprs_context_set_interface(gc, interface);
+
+   /* Use DHCP */
+   ofono_gprs_context_set_ipv4_address(gc, NULL, 0);
+
+   CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
+}
+
+static void cgdcont_enable_cb(gboolean ok

[RFC PATCH 2/4] plugins: udevng: detect gemalto network interfaces

2020-08-15 Thread Sergey Matyukevich
Some gemalto modems, including ELS81x, may provide more than one
USB ethernet interface. Detect and save both network interfaces
rather than the last one.

Signed-off-by: Sergey Matyukevich 
---
 plugins/udevng.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 7e6a3ab7..839fabdb 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -1162,7 +1162,7 @@ static gboolean setup_ublox(struct modem_info *modem)
 static gboolean setup_gemalto(struct modem_info* modem)
 {
const char *app = NULL, *gps = NULL, *mdm = NULL,
-   *net = NULL, *qmi = NULL;
+   *net = NULL, *qmi = NULL, *net2 = NULL;
 
GSList *list;
 
@@ -1197,9 +1197,14 @@ static gboolean setup_gemalto(struct modem_info* modem)
else if (g_strcmp0(info->number, "04") == 0)
gps = info->devnode;
}
+
if (g_strcmp0(info->interface, "2/6/0") == 0) {
-   if (g_strcmp0(info->subsystem, "net") == 0)
-   net = info->devnode;
+   if (g_strcmp0(info->subsystem, "net") == 0) {
+   if (g_strcmp0(info->number, "0a") == 0)
+   net = info->devnode;
+   if (g_strcmp0(info->number, "0c") == 0)
+   net2 = info->devnode;
+   }
}
}
 
@@ -1216,6 +1221,9 @@ static gboolean setup_gemalto(struct modem_info* modem)
ofono_modem_set_string(modem->modem, "Model", modem->model);
ofono_modem_set_string(modem->modem, "NetworkInterface", net);
 
+   if (net2)
+   ofono_modem_set_string(modem->modem, "NetworkInterface2", net2);
+
return TRUE;
 }
 
-- 
2.28.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 2/2] plugins: gemalto: enable LTE for ELS81x

2020-06-27 Thread Sergey Matyukevich
Enable LTE atom for Cinterion ELS81x modems.

---
 plugins/gemalto.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 297aaea3..13950742 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -58,6 +58,8 @@
 #define GEMALTO_MODEL_PHS8P"0053"
 /* ALS3, PLS8-E, and PLS8-X family */
 #define GEMALTO_MODEL_ALS3_PLS8x   "0061"
+/* ELS81 modem */
+#define GEMALTO_MODEL_ELS81x   "005b"
 
 static const char *none_prefix[] = { NULL };
 static const char *sctm_prefix[] = { "^SCTM:", NULL };
@@ -601,7 +603,8 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 
ofono_ussd_create(modem, 0, "atmodem", data->app);
 
-   if (!g_strcmp0(model, GEMALTO_MODEL_ALS3_PLS8x))
+   if (!g_strcmp0(model, GEMALTO_MODEL_ALS3_PLS8x) ||
+   !g_strcmp0(model, GEMALTO_MODEL_ELS81x))
ofono_lte_create(modem, OFONO_VENDOR_GEMALTO,
"atmodem", data->app);
 }
-- 
2.27.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 0/2] gemalto: enable ELS81x modem

2020-06-27 Thread Sergey Matyukevich
Hi all,

These two simple patches enable oFono support for ELS81x modem using
cdc_ether/cdc_acm drivers. As far as I know, new firmwares for ELS81x
enable support for MBIM as well. But I have not yet tried that.

Regards,
Sergey

Sergey Matyukevich (2):
  plugins: udevng: detect Centirion ELS81x modem
  plugins: gemalto: enable LTE for ELS81x

 plugins/gemalto.c | 5 -
 plugins/udevng.c  | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.27.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org


[PATCH 1/2] plugins: udevng: detect Centirion ELS81x modem

2020-06-27 Thread Sergey Matyukevich
Enable detection of Centirion ELS81x modem.

---
 plugins/udevng.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 4a38621b..30597d2c 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -1807,6 +1807,8 @@ static struct {
{ "gemalto","qmi_wwan", "1e2d", "0053"  },
{ "gemalto","cdc_acm",  "1e2d", "0061"  },
{ "gemalto","cdc_ether","1e2d", "0061"  },
+   { "gemalto","cdc_acm",  "1e2d", "005b"  },
+   { "gemalto","cdc_ether","1e2d", "005b"  },
{ "telit",  "cdc_ncm",  "1bc7", "0036"  },
{ "telit",  "cdc_acm",  "1bc7", "0036"  },
{ "xmm7xxx","cdc_acm",  "8087"  },
-- 
2.27.0
___
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org