From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 3/4] plugins: add a new driver for Quectel UC15 modules
Date: Tue, 24 Jun 2014 12:41:45 -0500 [thread overview]
Message-ID: <53A9B859.9040007@gmail.com> (raw)
In-Reply-To: <1403604522-22645-4-git-send-email-philip@paeps.cx>
[-- Attachment #1: Type: text/plain, Size: 4441 bytes --]
Hi Philip,
<snip>
> +
> +static void verify_enable(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> + struct quectel_data *data = ofono_modem_get_data(modem);
> +
> + if (ok) {
> + ofono_modem_set_powered(modem, TRUE);
> + g_at_chat_send(data->modem, "AT&C0", NULL, NULL, NULL, NULL);
> + g_at_chat_send(data->aux, "AT&C0", NULL, NULL, NULL, NULL);
Why do you do send AT&C0 here? Can it be done earlier?
Any reason for checking that CFUN succeeded? If so, then it might be a
good idea to document that in comments / commit description.
What if it failed? Are you relying on the core timeout mechanisms?
> + }
> +}
> +
> +static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> + struct quectel_data *data = ofono_modem_get_data(modem);
> +
> + DBG("ok %d (tried %d times)", (int)ok, data->enable_tries);
This cast seems unnecessary
> +
> + if (!ok) {
> + if (data->enable_tries > MAX_RETRIES) {
> + g_at_chat_unref(data->aux);
> + data->aux = NULL;
> + g_at_chat_unref(data->modem);
> + data->modem = NULL;
> + ofono_modem_set_powered(modem, FALSE);
> + DBG("modem won't enable - giving up");
> + }
> + goto retry;
Is the timer still running in case MAX_RETRIES is reached? In general
we prefer using single-shot timers and re-starting them if the command
fails. Certain commands might take several seconds to return on some
hardware.
> + }
> +
> + g_at_chat_send(data->aux, "AT+CPIN?", NULL, verify_enable,
> + modem, NULL);
Using prefixes is a good idea, otherwise any unsolicited notifications
will be missed. git show 35feae07e50f89ea3c42566c765f501ec768bd44 for
an example of what might happen.
> +retry:
> + data->enable_tries++;
> +}
> +
> +static gboolean quectel_start(gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> + struct quectel_data *data = ofono_modem_get_data(modem);
> +
> + if (ofono_modem_get_powered(modem) == FALSE) {
> + g_at_chat_send(data->aux, "AT+CFUN=1", NULL, cfun_enable,
> + modem, NULL);
> + return TRUE;
> + }
> +
> + data->enable_timer = 0;
> +
> + return FALSE;
> +}
> +
> +static int quectel_enable(struct ofono_modem *modem)
> +{
> + struct quectel_data *data = ofono_modem_get_data(modem);
> +
> + DBG("%p", modem);
> +
> + data->modem = open_device(modem, "Modem", "Modem: ");
> + if (data->modem == NULL)
> + return -EINVAL;
> +
> + data->aux = open_device(modem, "Aux", "Aux: ");
> + if (data->aux == NULL) {
> + g_at_chat_unref(data->modem);
> + data->modem = NULL;
> + return -EIO;
> + }
> + g_at_chat_set_slave(data->modem, data->aux);
> +
> + g_at_chat_send(data->modem, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
> + g_at_chat_send(data->aux, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
> +
> + /* Give the modem a bit more time to power up completely. */
> + data->enable_tries = 0;
> + data->enable_timer = g_timeout_add_seconds(RESET_DELAY,
> + quectel_start, modem);
Is this delay always necessary? enable() is called in other situations
besides a hot-plugging...
> +
> + return -EINPROGRESS;
> +}
> +
> +static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> + struct quectel_data *data = ofono_modem_get_data(modem);
> +
> + DBG("");
> +
> + g_at_chat_unref(data->aux);
> + data->aux = NULL;
> +
> + if (ok)
> + ofono_modem_set_powered(modem, FALSE);
> +}
> +
> +static int quectel_disable(struct ofono_modem *modem)
> +{
> + struct quectel_data *data = ofono_modem_get_data(modem);
> +
> + DBG("%p", modem);
> +
> + /* Prevent a race with cfun_start() retries. */
> + if (data->enable_timer)
> + g_source_remove(data->enable_timer);
> +
> + g_at_chat_cancel_all(data->modem);
> + g_at_chat_unregister_all(data->modem);
> +
> + g_at_chat_unref(data->modem);
> + data->modem = NULL;
> +
> + g_at_chat_cancel_all(data->aux);
> + g_at_chat_unregister_all(data->aux);
> +
> + g_at_chat_send(data->aux, "AT+CFUN=0", NULL,
> + cfun_disable, modem, NULL);
What behavior does this modem exhibit when using CFUN=0? Many devices
jump off the USB bus when this is sent. Hence why most drivers use CFUN=4.
> +
> + return -EINPROGRESS;
> +}
> +
Regards,
-Denis
next prev parent reply other threads:[~2014-06-24 17:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 10:08 [PATCH 0/4] Add a driver for Quectel UC15 modules Philip Paeps
2014-06-24 10:08 ` [PATCH 1/4] atmodem: add vendor Quectel Philip Paeps
2014-06-24 10:08 ` [PATCH 2/4] udevng: add setup logic for Quectel UC15 modules Philip Paeps
2014-06-24 10:08 ` [PATCH 3/4] plugins: add a new driver " Philip Paeps
2014-06-24 10:15 ` Philip Paeps
2014-06-24 17:41 ` Denis Kenzior [this message]
2014-06-24 18:34 ` Philip Paeps
2014-06-24 18:44 ` Denis Kenzior
2014-06-24 10:08 ` [PATCH 4/4] sim: query Quectel UC15 PIN retries with AT+QPINQ Philip Paeps
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=53A9B859.9040007@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.