All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] gemalto: radio-setings driver
@ 2021-07-04 15:53 Sergey Matyukevich
  2021-07-04 15:53 ` [PATCH 1/3] gemalto: add radio-settings driver Sergey Matyukevich
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sergey Matyukevich @ 2021-07-04 15:53 UTC (permalink / raw)
  To: ofono

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

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

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

* [PATCH 1/3] gemalto: add radio-settings driver
  2021-07-04 15:53 [PATCH 0/3] gemalto: radio-setings driver Sergey Matyukevich
@ 2021-07-04 15:53 ` Sergey Matyukevich
  2021-07-15 18:12   ` Denis Kenzior
  2021-07-04 15:53 ` [PATCH 2/3] plugins: gemalto: add radio-settings atom Sergey Matyukevich
  2021-07-04 15:53 ` [PATCH 3/3] plugins: gemalto: move ussd atom to post_online Sergey Matyukevich
  2 siblings, 1 reply; 7+ messages in thread
From: Sergey Matyukevich @ 2021-07-04 15:53 UTC (permalink / raw)
  To: ofono

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

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 00000000..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 <config.h>
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/radio-settings.h>
+
+#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 = OFONO_RADIO_ACCESS_MODE_LTE;
+		break;
+	case 4:
+		mode = OFONO_RADIO_ACCESS_MODE_UMTS |
+			OFONO_RADIO_ACCESS_MODE_LTE;
+		break;
+	case 5:
+		mode = OFONO_RADIO_ACCESS_MODE_GSM |
+			OFONO_RADIO_ACCESS_MODE_LTE;
+		break;
+	case 6:
+		mode = OFONO_RADIO_ACCESS_MODE_ANY;
+		break;
+	default:
+		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+		return;
+	}
+
+	cb(&error, mode, cbd->data);
+
+	return;
+
+error:
+	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+}
+
+static void gemalto_query_rat_mode(struct ofono_radio_settings *rs,
+				ofono_radio_settings_rat_mode_query_cb_t cb,
+				void *data)
+{
+	struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
+	struct cb_data *cbd = cb_data_new(cb, data);
+
+	DBG("");
+
+	if (g_at_chat_send(rsd->chat, "AT^SXRAT?", sxrat_prefix,
+				sxrat_query_cb, cbd, g_free) == 0) {
+		CALLBACK_WITH_FAILURE(cb, -1, data);
+		g_free(cbd);
+	}
+}
+
+static void sxrat_modify_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_radio_settings_rat_mode_set_cb_t cb = cbd->cb;
+	struct ofono_error error;
+
+	DBG("ok %d", ok);
+
+	decode_at_error(&error, g_at_result_final_response(result));
+	cb(&error, cbd->data);
+}
+
+static void gemalto_set_rat_mode(struct ofono_radio_settings *rs,
+				enum ofono_radio_access_mode m,
+				ofono_radio_settings_rat_mode_set_cb_t cb,
+				void *data)
+{
+	struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	int val= 6, p1 = 3, p2 = 2;
+	char buf[20];
+
+	DBG("mode %d", m);
+
+	switch (m) {
+	case OFONO_RADIO_ACCESS_MODE_ANY:
+		val = 6;
+		p1 = 3;
+		p2 = 2;
+		break;
+	case OFONO_RADIO_ACCESS_MODE_GSM:
+		val = 0;
+		break;
+	case OFONO_RADIO_ACCESS_MODE_UMTS:
+		val = 2;
+		break;
+	case OFONO_RADIO_ACCESS_MODE_LTE:
+		val = 3;
+		break;
+	}
+
+	if (m == (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)) {
+		val = 4;
+		p1 = 3;
+	}
+
+	if (m == (OFONO_RADIO_ACCESS_MODE_LTE|OFONO_RADIO_ACCESS_MODE_GSM)) {
+		val = 5;
+		p1 = 3;
+	}
+
+	if (val == 6)
+		snprintf(buf, sizeof(buf), "AT^SXRAT=%u,%u,%u", val, p1, p2);
+	else if (val == 1 || val == 4 || val == 5)
+		snprintf(buf, sizeof(buf), "AT^SXRAT=%u,%u", val, p1);
+	else
+		snprintf(buf, sizeof(buf), "AT^SXRAT=%u", val);
+
+	if (g_at_chat_send(rsd->chat, buf, none_prefix,
+				sxrat_modify_cb, cbd, g_free) > 0)
+		return;
+
+	CALLBACK_WITH_FAILURE(cb, data);
+	g_free(cbd);
+}
+
+static void sxrat_support_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_radio_settings *rs = user_data;
+
+	DBG("ok %d", ok);
+
+	if (!ok) {
+		ofono_radio_settings_remove(rs);
+		return;
+	}
+
+	ofono_radio_settings_register(rs);
+}
+
+static int gemalto_radio_settings_probe(struct ofono_radio_settings *rs,
+					unsigned int vendor, void *data)
+{
+	GAtChat *chat = data;
+	struct radio_settings_data *rsd;
+
+	DBG("");
+
+	rsd = g_new0(struct radio_settings_data, 1);
+
+	rsd->chat = g_at_chat_clone(chat);
+
+	ofono_radio_settings_set_data(rs, rsd);
+
+	g_at_chat_send(rsd->chat, "AT^SXRAT=?", sxrat_prefix,
+			sxrat_support_cb, rs, NULL);
+
+	return 0;
+}
+
+static void gemalto_radio_settings_remove(struct ofono_radio_settings *rs)
+{
+	struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
+
+	DBG("");
+
+	ofono_radio_settings_set_data(rs, NULL);
+	g_at_chat_unref(rsd->chat);
+	g_free(rsd);
+}
+
+static const struct ofono_radio_settings_driver driver = {
+	.name			= "gemaltomodem",
+	.probe			= gemalto_radio_settings_probe,
+	.remove			= gemalto_radio_settings_remove,
+	.query_rat_mode		= gemalto_query_rat_mode,
+	.set_rat_mode		= gemalto_set_rat_mode
+};
+
+void gemalto_radio_settings_init(void)
+{
+	ofono_radio_settings_driver_register(&driver);
+}
+
+void gemalto_radio_settings_exit(void)
+{
+	ofono_radio_settings_driver_unregister(&driver);
+}

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

* [PATCH 2/3] plugins: gemalto: add radio-settings atom
  2021-07-04 15:53 [PATCH 0/3] gemalto: radio-setings driver Sergey Matyukevich
  2021-07-04 15:53 ` [PATCH 1/3] gemalto: add radio-settings driver Sergey Matyukevich
@ 2021-07-04 15:53 ` Sergey Matyukevich
  2021-07-15 18:12   ` Denis Kenzior
  2021-07-04 15:53 ` [PATCH 3/3] plugins: gemalto: move ussd atom to post_online Sergey Matyukevich
  2 siblings, 1 reply; 7+ messages in thread
From: Sergey Matyukevich @ 2021-07-04 15:53 UTC (permalink / raw)
  To: ofono

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

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 <ofono/gprs-context.h>
 #include <ofono/location-reporting.h>
 #include <ofono/netmon.h>
+#include <ofono/radio-settings.h>
 
 #include <drivers/atmodem/atutil.h>
 #include <drivers/atmodem/vendor.h>
@@ -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);
 

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

* [PATCH 3/3] plugins: gemalto: move ussd atom to post_online
  2021-07-04 15:53 [PATCH 0/3] gemalto: radio-setings driver Sergey Matyukevich
  2021-07-04 15:53 ` [PATCH 1/3] gemalto: add radio-settings driver Sergey Matyukevich
  2021-07-04 15:53 ` [PATCH 2/3] plugins: gemalto: add radio-settings atom Sergey Matyukevich
@ 2021-07-04 15:53 ` Sergey Matyukevich
  2 siblings, 0 replies; 7+ messages in thread
From: Sergey Matyukevich @ 2021-07-04 15:53 UTC (permalink / raw)
  To: ofono

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

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);

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

* Re: [PATCH 1/3] gemalto: add radio-settings driver
  2021-07-04 15:53 ` [PATCH 1/3] gemalto: add radio-settings driver Sergey Matyukevich
@ 2021-07-15 18:12   ` Denis Kenzior
  2021-07-15 19:01     ` Sergey Matyukevich
  0 siblings, 1 reply; 7+ messages in thread
From: Denis Kenzior @ 2021-07-15 18:12 UTC (permalink / raw)
  To: ofono

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

Hi Sergey,

On 7/4/21 10:53 AM, Sergey Matyukevich wrote:
> 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.

Regards,
-Denis

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

* Re: [PATCH 2/3] plugins: gemalto: add radio-settings atom
  2021-07-04 15:53 ` [PATCH 2/3] plugins: gemalto: add radio-settings atom Sergey Matyukevich
@ 2021-07-15 18:12   ` Denis Kenzior
  0 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2021-07-15 18:12 UTC (permalink / raw)
  To: ofono

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

Hi Sergey,

On 7/4/21 10:53 AM, Sergey Matyukevich wrote:
> Instantiate Gemalto radio-settings atom in post_sim.
> 
> ---
>   plugins/gemalto.c | 2 ++
>   1 file changed, 2 insertions(+)
> 

Patch 2 & 3 applied, thanks.

Regards,
-Denis

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

* Re: [PATCH 1/3] gemalto: add radio-settings driver
  2021-07-15 18:12   ` Denis Kenzior
@ 2021-07-15 19:01     ` Sergey Matyukevich
  0 siblings, 0 replies; 7+ messages in thread
From: Sergey Matyukevich @ 2021-07-15 19:01 UTC (permalink / raw)
  To: ofono

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

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

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

end of thread, other threads:[~2021-07-15 19:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-04 15:53 [PATCH 0/3] gemalto: radio-setings driver Sergey Matyukevich
2021-07-04 15:53 ` [PATCH 1/3] gemalto: add radio-settings driver Sergey Matyukevich
2021-07-15 18:12   ` Denis Kenzior
2021-07-15 19:01     ` Sergey Matyukevich
2021-07-04 15:53 ` [PATCH 2/3] plugins: gemalto: add radio-settings atom Sergey Matyukevich
2021-07-15 18:12   ` Denis Kenzior
2021-07-04 15:53 ` [PATCH 3/3] plugins: gemalto: move ussd atom to post_online Sergey Matyukevich

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