All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 2/6] gemalto: support ALS3 in gemalto's plugin
Date: Thu, 15 Mar 2018 12:11:14 -0500	[thread overview]
Message-ID: <ede1a470-9930-352a-be94-3501f298974b@gmail.com> (raw)
In-Reply-To: <1521118170-23722-3-git-send-email-gabriel.lucas@smile.fr>

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

Hi Gabriel,

On 03/15/2018 07:49 AM, Gabriel Lucas wrote:
> Force serial port opening options
> Wait for modem to be ready to start
> initializing it
> Handle LTE
> ---
>   plugins/gemalto.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++----
>   1 file changed, 99 insertions(+), 6 deletions(-)
> 
> diff --git a/plugins/gemalto.c b/plugins/gemalto.c
> index 3739d7b..16ca463 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

No // please, use /* */.  This is C code ;)

> +#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,24 @@ 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);
>   	if (channel == NULL)
>   		return NULL;

You leak options here in case channel == NULL.  The typical pattern is 
to call g_hash_table_destroy(options) right after g_at_tty_open.  See 
other plugins for details.

>   
> @@ -118,6 +138,7 @@ static GAtChat *open_device(const char *device)
>   	chat = g_at_chat_new(channel, syntax);
>   	g_at_syntax_unref(syntax);
>   	g_io_channel_unref(channel);
> +	g_hash_table_destroy(options);
>   
>   	if (chat == NULL)
>   		return NULL;
> @@ -300,29 +321,33 @@ 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;
>   
> -	DBG("%p", modem);
> +	/* Close devices */
> +	g_at_chat_unref(data->mdm);
> +	g_at_chat_unref(data->app);
> +

Why would you close both devices?  It is unnecessary, especially in the 
case that the modem is already up and responding to commands.

> +	DBG("");
>   
>   	app = ofono_modem_get_string(modem, "Application");
>   	mdm = ofono_modem_get_string(modem, "Modem");
>   
>   	if (app == NULL || mdm == NULL)
> -		return -EINVAL;
> +		return;
>   
>   	/* Open devices */
>   	data->app = open_device(app);
>   	if (data->app == NULL)
> -		return -EINVAL;
> +		return;
>   
>   	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 +365,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);
> +
> +	DBG("");
> +
> +	g_at_chat_unregister(data->app, data->modem_ready_id);
> +	g_at_chat_cancel(data->app, data->trial_cmd_id);
> +
> +	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 gboolean gemalto_at_timeout(gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +	struct gemalto_data *data = ofono_modem_get_data(modem);
> +
> +	data->trial_cmd_id = g_at_chat_send(data->app, "AT+CFUN?", none_prefix, gemalto_at_cb, modem, NULL);

What does this do?

> +
> +	return FALSE;
> +}

Where is the timeout started?

> +
> +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;
> +
> +	data->mdm = open_device(mdm);
> +	if (data->mdm == NULL) {
> +		g_at_chat_unref(data->app);
> +		data->app = NULL;
> +		return -EINVAL;
> +	}
> +
> +	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);

We use the Linux Kernel coding style with house rules documented in 
doc/coding-style.txt.  No lines over 80 characters please.

Why do you open both ports only to close them in gemalto_initialize? 
One port here would be sufficient.

>   
>   	return -EINPROGRESS;
>   }
> @@ -449,10 +535,17 @@ 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;
>   
>   	DBG("%p", modem);
>   
>   	ofono_netreg_create(modem, OFONO_VENDOR_CINTERION, "atmodem", data->app);
> +
> +	model = ofono_modem_get_string(modem, "Model");

You might as well perform this assignment at variable declaration.

> +
> +	if(!strncmp(model, GEMALTO_MODEL_ALS3, 4)) {
> +		ofono_lte_create(modem, "atmodem", data->app);
> +	}

Why strncmp?  No need for {} and there should be a space between if and '('

Also, you most likely need the LTE atom in post_sim.

You also now have to little arguments to ofono_lte_create.  Please git 
pull --rebase first.

>   }
>   
>   static struct ofono_modem_driver gemalto_driver = {
> 

Regards,
-Denis

  reply	other threads:[~2018-03-15 17:11 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 [this message]
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
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=ede1a470-9930-352a-be94-3501f298974b@gmail.com \
    --to=denkenz@gmail.com \
    --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.