All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Lucas <gabriel.lucas@smile.fr>
To: ofono@ofono.org
Subject: [PATCH 2/6] gemalto: support ALS3 in gemalto's plugin
Date: Fri, 16 Mar 2018 17:08:05 +0100	[thread overview]
Message-ID: <1521216485-20499-1-git-send-email-gabriel.lucas@smile.fr> (raw)
In-Reply-To: <1521215975-19944-1-git-send-email-gabriel.lucas@smile.fr>

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

Force serial port opening options
Wait for modem to be ready to start
initializing it
Handle LTE
---
 plugins/gemalto.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 95 insertions(+), 12 deletions(-)

diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 3739d7b..3fb2904 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -53,6 +53,10 @@
 
 #define HARDWARE_MONITOR_INTERFACE OFONO_SERVICE ".cinterion.HardwareMonitor"
 
+/* Supported gemalto's modem */
+#define GEMALTO_MODEL_PHS8P 	"0053"
+#define GEMALTO_MODEL_ALS3 		"0061"
+
 static const char *none_prefix[] = { NULL };
 static const char *sctm_prefix[] = { "^SCTM:", NULL };
 static const char *sbv_prefix[] = { "^SBV:", NULL };
@@ -70,6 +74,8 @@ struct gemalto_data {
 	gboolean have_sim;
 	struct at_util_sim_state_query *sim_state_query;
 	struct gemalto_hardware_monitor *hm;
+	guint modem_ready_id;
+	guint trial_cmd_id;
 };
 
 static int gemalto_probe(struct ofono_modem *modem)
@@ -107,10 +113,26 @@ static GAtChat *open_device(const char *device)
 	GAtSyntax *syntax;
 	GIOChannel *channel;
 	GAtChat *chat;
+	GHashTable *options;
+
+	options = g_hash_table_new(g_str_hash, g_str_equal);
+	if (options == NULL)
+		return NULL;
+
+	g_hash_table_insert(options, "Baud", "115200");
+	g_hash_table_insert(options, "StopBits", "1");
+	g_hash_table_insert(options, "DataBits", "8");
+	g_hash_table_insert(options, "Parity", "none");
+	g_hash_table_insert(options, "XonXoff", "off");
+	g_hash_table_insert(options, "RtsCts", "on");
+	g_hash_table_insert(options, "Local", "on");
+	g_hash_table_insert(options, "Read", "on");
 
 	DBG("Opening device %s", device);
 
-	channel = g_at_tty_open(device, NULL);
+	channel = g_at_tty_open(device, options);
+	g_hash_table_destroy(options);
+
 	if (channel == NULL)
 		return NULL;
 
@@ -300,29 +322,24 @@ static int gemalto_hardware_monitor_enable(struct ofono_modem *modem)
 	return 0;
 }
 
-static int gemalto_enable(struct ofono_modem *modem)
+static void gemalto_initialize(struct ofono_modem *modem)
 {
 	struct gemalto_data *data = ofono_modem_get_data(modem);
-	const char *app, *mdm;
+	const char *mdm;
 
-	DBG("%p", modem);
+	DBG("");
 
-	app = ofono_modem_get_string(modem, "Application");
 	mdm = ofono_modem_get_string(modem, "Modem");
 
-	if (app == NULL || mdm == NULL)
-		return -EINVAL;
+	if (mdm == NULL)
+		return;
 
 	/* Open devices */
-	data->app = open_device(app);
-	if (data->app == NULL)
-		return -EINVAL;
-
 	data->mdm = open_device(mdm);
 	if (data->mdm == NULL) {
 		g_at_chat_unref(data->app);
 		data->app = NULL;
-		return -EINVAL;
+		return;
 	}
 
 	if (getenv("OFONO_AT_DEBUG")) {
@@ -340,6 +357,67 @@ static int gemalto_enable(struct ofono_modem *modem)
 			cfun_enable, modem, NULL);
 
 	gemalto_hardware_monitor_enable(modem);
+}
+
+static void gemalto_modem_ready(GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct gemalto_data *data = ofono_modem_get_data(modem);
+	const char *app = ofono_modem_get_string(modem, "Application");
+
+	DBG("");
+
+	g_at_chat_unregister(data->app, data->modem_ready_id);
+	g_at_chat_cancel(data->app, data->trial_cmd_id);
+
+	/*!
+	 * As the modem wasn't ready to handle AT commands when we opened
+	 * it, we have to close and reopen the device app.
+	 */
+	g_at_chat_unref(data->app);
+
+	if(app == NULL)
+		return;
+
+	data->app = open_device(app);
+	if (data->app == NULL)
+		return;
+
+	gemalto_initialize(modem);
+}
+
+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);
+
+	g_at_chat_unregister(data->app, data->modem_ready_id);
+	gemalto_initialize(modem);
+}
+
+static int gemalto_enable(struct ofono_modem *modem)
+{
+	struct gemalto_data *data = ofono_modem_get_data(modem);
+	const char *app, *mdm;
+
+	DBG("%p", modem);
+
+	app = ofono_modem_get_string(modem, "Application");
+	mdm = ofono_modem_get_string(modem, "Modem");
+
+	if (app == NULL || mdm == NULL)
+		return -EINVAL;
+
+	/* Open devices */
+	data->app = open_device(app);
+	if (data->app == NULL)
+		return -EINVAL;
+
+	/* Try the AT command. If it doesn't work, wait for ^SYSSTART */
+	data->modem_ready_id = g_at_chat_register(data->app, "^SYSSTART",
+				gemalto_modem_ready, FALSE, modem, NULL);
+	data->trial_cmd_id = g_at_chat_send(data->app, "ATE0 AT",
+				none_prefix, gemalto_at_cb, modem, NULL);
 
 	return -EINPROGRESS;
 }
@@ -432,6 +510,7 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 	struct gemalto_data *data = ofono_modem_get_data(modem);
 	struct ofono_gprs *gprs;
 	struct ofono_gprs_context *gc;
+	const char *model = ofono_modem_get_string(modem, "Model");
 
 	DBG("%p", modem);
 
@@ -444,6 +523,10 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 
 	if (gprs && gc)
 		ofono_gprs_add_context(gprs, gc);
+
+	if (!g_strcmp0(model, GEMALTO_MODEL_ALS3))
+		ofono_lte_create(modem, OFONO_VENDOR_CINTERION,
+						"atmodem", data->app);
 }
 
 static void gemalto_post_online(struct ofono_modem *modem)
-- 
1.9.1


  reply	other threads:[~2018-03-16 16:08 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-15 12:49 [PATCH 0/6] gemalto's ALS3 and PHS8P support Gabriel Lucas
2018-03-15 12:49 ` [PATCH 1/6] gemalto: add detection of ALS3 modem Gabriel Lucas
2018-03-15 17:22   ` Denis Kenzior
2018-03-15 12:49 ` [PATCH 2/6] gemalto: support ALS3 in gemalto's plugin Gabriel Lucas
2018-03-15 17:11   ` Denis Kenzior
2018-03-16 10:30     ` Gabriel Lucas
2018-03-16 14:23       ` Denis Kenzior
2018-03-16 15:53         ` Gabriel Lucas
2018-03-16 15:59           ` Gabriel Lucas
2018-03-16 16:08             ` Gabriel Lucas [this message]
2018-03-16 16:08             ` Denis Kenzior
2018-03-19  9:45               ` Gabriel Lucas
2018-03-19 13:50                 ` Denis Kenzior
2018-03-19 15:15                   ` Gabriel Lucas
2018-03-19 15:24                     ` Denis Kenzior
2018-03-15 12:49 ` [PATCH 3/6] gemalto: acquire the network technology Gabriel Lucas
2018-03-15 17:19   ` Denis Kenzior
2018-03-16 12:04     ` Gabriel Lucas
2018-03-16 12:59     ` Gabriel Lucas
2018-03-16 14:27       ` Denis Kenzior
2018-03-16 15:30         ` Gabriel LUCAS
2018-03-15 12:49 ` [PATCH 4/6] gemalto: handle sim is inserted or removed URCs Gabriel Lucas
2018-03-15 17:26   ` Denis Kenzior
2018-03-16 13:28     ` Gabriel Lucas
2018-03-16 14:03       ` Denis Kenzior
2018-03-19 15:57         ` Gabriel Lucas
2018-03-19 16:08           ` Denis Kenzior
2018-03-19 16:26             ` Gabriel Lucas
2018-03-19 17:10               ` Denis Kenzior
2018-03-20  8:37                 ` Gabriel Lucas
2018-03-15 12:49 ` [PATCH 5/6] sim: give access to the driver Gabriel Lucas
2018-03-15 17:27   ` Denis Kenzior
2018-03-15 12:49 ` [PATCH 6/6] gemalto: fix sim reinsertion issue Gabriel Lucas
2018-03-15 17:29   ` Denis Kenzior
2018-03-16 13:30     ` Gabriel Lucas
2018-03-19 16:01     ` Gabriel Lucas
  -- strict thread matches above, loose matches on Subject: below --
2018-03-12 12:57 [PATCH 0/6] gemalto's ALS3 and PHS8P support Gabriel Lucas
2018-03-12 12:57 ` [PATCH 2/6] gemalto: support ALS3 in gemalto's plugin Gabriel Lucas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1521216485-20499-1-git-send-email-gabriel.lucas@smile.fr \
    --to=gabriel.lucas@smile.fr \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.