port-serial-at: use GIO Async API like methods

This commit is contained in:
Aleksander Morgado
2014-02-13 13:40:21 +01:00
parent 81ee07832d
commit d4dfd661b9
10 changed files with 276 additions and 211 deletions
+15 -16
View File
@@ -76,25 +76,23 @@ cinterion_custom_init_finish (MMPortProbe *probe,
static void
sqport_ready (MMPortSerialAt *port,
GString *response,
GError *error,
GAsyncResult *res,
CinterionCustomInitContext *ctx)
{
const gchar *response;
/* Ignore errors, just avoid tagging */
if (error) {
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
cinterion_custom_init_context_complete_and_free (ctx);
return;
response = mm_port_serial_at_command_finish (port, res, NULL);
if (response) {
/* A valid reply to AT^SQPORT tells us this is an AT port already */
mm_port_probe_set_result_at (ctx->probe, TRUE);
if (strstr (response, "Application"))
g_object_set_data (G_OBJECT (ctx->probe), TAG_CINTERION_APP_PORT, GUINT_TO_POINTER (TRUE));
else if (strstr (response, "Modem"))
g_object_set_data (G_OBJECT (ctx->probe), TAG_CINTERION_MODEM_PORT, GUINT_TO_POINTER (TRUE));
}
/* A valid reply to AT^SQPORT tells us this is an AT port already */
mm_port_probe_set_result_at (ctx->probe, TRUE);
if (strstr (response->str, "Application"))
g_object_set_data (G_OBJECT (ctx->probe), TAG_CINTERION_APP_PORT, GUINT_TO_POINTER (TRUE));
else if (strstr (response->str, "Modem"))
g_object_set_data (G_OBJECT (ctx->probe), TAG_CINTERION_MODEM_PORT, GUINT_TO_POINTER (TRUE));
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
cinterion_custom_init_context_complete_and_free (ctx);
}
@@ -117,13 +115,14 @@ cinterion_custom_init (MMPortProbe *probe,
ctx->port = g_object_ref (port);
ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
mm_port_serial_at_queue_command (
mm_port_serial_at_command (
ctx->port,
"AT^SQPORT?",
3,
FALSE, /* raw */
FALSE, /* allow cached */
ctx->cancellable,
(MMPortSerialAtResponseFn)sqport_ready,
(GAsyncReadyCallback)sqport_ready,
ctx);
}
+34 -21
View File
@@ -128,10 +128,13 @@ cache_port_mode (MMDevice *device,
static void
getportmode_ready (MMPortSerialAt *port,
GString *response,
GError *error,
GAsyncResult *res,
HuaweiCustomInitContext *ctx)
{
const gchar *response;
GError *error = NULL;
response = mm_port_serial_at_command_finish (port, res, &error);
if (error) {
mm_dbg ("(Huawei) couldn't get port mode: '%s'",
error->message);
@@ -141,11 +144,8 @@ getportmode_ready (MMPortSerialAt *port,
*/
if (!g_error_matches (error,
MM_MOBILE_EQUIPMENT_ERROR,
MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN)) {
/* Retry */
huawei_custom_init_step (ctx);
return;
}
MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN))
goto out;
/* Port mode not supported */
} else {
@@ -155,10 +155,10 @@ getportmode_ready (MMPortSerialAt *port,
/* Results are cached in the parent device object */
device = mm_port_probe_peek_device (ctx->probe);
cache_port_mode (device, response->str, "PCUI:", TAG_HUAWEI_PCUI_PORT);
cache_port_mode (device, response->str, "MDM:", TAG_HUAWEI_MODEM_PORT);
cache_port_mode (device, response->str, "NDIS:", TAG_HUAWEI_NDIS_PORT);
cache_port_mode (device, response->str, "DIAG:", TAG_HUAWEI_DIAG_PORT);
cache_port_mode (device, response, "PCUI:", TAG_HUAWEI_PCUI_PORT);
cache_port_mode (device, response, "MDM:", TAG_HUAWEI_MODEM_PORT);
cache_port_mode (device, response, "NDIS:", TAG_HUAWEI_NDIS_PORT);
cache_port_mode (device, response, "DIAG:", TAG_HUAWEI_DIAG_PORT);
g_object_set_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED, GUINT_TO_POINTER (TRUE));
/* Mark port as being AT already */
@@ -166,23 +166,29 @@ getportmode_ready (MMPortSerialAt *port,
}
ctx->getportmode_done = TRUE;
out:
if (error)
g_error_free (error);
huawei_custom_init_step (ctx);
}
static void
curc_ready (MMPortSerialAt *port,
GString *response,
GError *error,
GAsyncResult *res,
HuaweiCustomInitContext *ctx)
{
const gchar *response;
GError *error = NULL;
response = mm_port_serial_at_command_finish (port, res, &error);
if (error) {
/* Retry if we get a timeout error */
if (g_error_matches (error,
MM_SERIAL_ERROR,
MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
huawei_custom_init_step (ctx);
return;
}
MM_SERIAL_ERROR_RESPONSE_TIMEOUT))
goto out;
mm_dbg ("(Huawei) couldn't turn off unsolicited messages in"
"secondary ports: '%s'",
@@ -192,6 +198,11 @@ curc_ready (MMPortSerialAt *port,
mm_dbg ("(Huawei) unsolicited messages in secondary ports turned off");
ctx->curc_done = TRUE;
out:
if (error)
g_error_free (error);
huawei_custom_init_step (ctx);
}
@@ -263,13 +274,14 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
ctx->curc_retries--;
/* Turn off unsolicited messages on secondary ports until needed */
mm_port_serial_at_queue_command (
mm_port_serial_at_command (
ctx->port,
"AT^CURC=0",
3,
FALSE, /* raw */
FALSE, /* allow_cached */
ctx->cancellable,
(MMPortSerialAtResponseFn)curc_ready,
(GAsyncReadyCallback)curc_ready,
ctx);
return;
}
@@ -283,13 +295,14 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
}
ctx->getportmode_retries--;
mm_port_serial_at_queue_command (
mm_port_serial_at_command (
ctx->port,
"AT^GETPORTMODE",
3,
FALSE, /* raw */
FALSE, /* allow_cached */
ctx->cancellable,
(MMPortSerialAtResponseFn)getportmode_ready,
(GAsyncReadyCallback)getportmode_ready,
ctx);
return;
}
+13 -6
View File
@@ -67,20 +67,22 @@ static void longcheer_custom_init_step (LongcheerCustomInitContext *ctx);
static void
gmr_ready (MMPortSerialAt *port,
GString *response,
GError *error,
GAsyncResult *res,
LongcheerCustomInitContext *ctx)
{
const gchar *p;
const gchar *response;
GError *error = NULL;
response = mm_port_serial_at_command_finish (port, res, &error);
if (error) {
/* Just retry... */
longcheer_custom_init_step (ctx);
return;
goto out;
}
/* Note the lack of a ':' on the GMR; the X200 doesn't send one */
p = mm_strip_tag (response->str, "AT+GMR");
p = mm_strip_tag (response, "AT+GMR");
if (p && *p == 'L') {
/* X200 modems have a GMR firmware revision that starts with 'L', and
* as far as I can tell X060s devices have a revision starting with 'C'.
@@ -98,6 +100,10 @@ gmr_ready (MMPortSerialAt *port,
}
longcheer_custom_init_context_complete_and_free (ctx);
out:
if (error)
g_error_free (error);
}
static void
@@ -124,13 +130,14 @@ longcheer_custom_init_step (LongcheerCustomInitContext *ctx)
}
ctx->retries--;
mm_port_serial_at_queue_command (
mm_port_serial_at_command (
ctx->port,
"AT+GMR",
3,
FALSE, /* raw */
FALSE, /* allow_cached */
ctx->cancellable,
(MMPortSerialAtResponseFn)gmr_ready,
(GAsyncReadyCallback)gmr_ready,
ctx);
}
+18 -10
View File
@@ -91,16 +91,19 @@ static void custom_init_step (CustomInitContext *ctx);
static void
nwdmat_ready (MMPortSerialAt *port,
GString *response,
GError *error,
GAsyncResult *res,
CustomInitContext *ctx)
{
const gchar *response;
GError *error = NULL;
response = mm_port_serial_at_command_finish (port, res, &error);
if (error) {
if (g_error_matches (error,
MM_SERIAL_ERROR,
MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
custom_init_step (ctx);
return;
goto out;
}
mm_dbg ("(Novatel) Error flipping secondary ports to AT mode: %s", error->message);
@@ -109,6 +112,10 @@ nwdmat_ready (MMPortSerialAt *port,
/* Finish custom_init */
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
custom_init_context_complete_and_free (ctx);
out:
if (error)
g_error_free (error);
}
static gboolean
@@ -147,13 +154,14 @@ custom_init_step (CustomInitContext *ctx)
if (ctx->nwdmat_retries > 0) {
ctx->nwdmat_retries--;
mm_port_serial_at_queue_command (ctx->port,
"$NWDMAT=1",
3,
FALSE, /* raw */
ctx->cancellable,
(MMPortSerialAtResponseFn)nwdmat_ready,
ctx);
mm_port_serial_at_command (ctx->port,
"$NWDMAT=1",
3,
FALSE, /* raw */
FALSE, /* allow_cached */
ctx->cancellable,
(GAsyncReadyCallback)nwdmat_ready,
ctx);
return;
}
+21 -11
View File
@@ -79,10 +79,13 @@ static void sierra_custom_init_step (SierraCustomInitContext *ctx);
static void
gcap_ready (MMPortSerialAt *port,
GString *response,
GError *error,
GAsyncResult *res,
SierraCustomInitContext *ctx)
{
const gchar *response;
GError *error = NULL;
response = mm_port_serial_at_command_finish (port, res, &error);
if (error) {
/* If consumed all tries and the last error was a timeout, assume the
* port is not AT */
@@ -106,7 +109,7 @@ gcap_ready (MMPortSerialAt *port,
/* Just retry... */
sierra_custom_init_step (ctx);
return;
goto out;
}
/* A valid reply to ATI tells us this is an AT port already */
@@ -118,23 +121,25 @@ gcap_ready (MMPortSerialAt *port,
* or fail PPP. So we whitelist modems that are known to allow PPP on the
* secondary APP ports.
*/
if (strstr (response->str, "APP1")) {
if (strstr (response, "APP1")) {
g_object_set_data (G_OBJECT (ctx->probe), TAG_SIERRA_APP_PORT, GUINT_TO_POINTER (TRUE));
/* PPP-on-APP1-port whitelist */
if (strstr (response->str, "C885") || strstr (response->str, "USB 306") || strstr (response->str, "MC8790"))
if (strstr (response, "C885") ||
strstr (response, "USB 306") ||
strstr (response, "MC8790"))
g_object_set_data (G_OBJECT (ctx->probe), TAG_SIERRA_APP1_PPP_OK, GUINT_TO_POINTER (TRUE));
/* For debugging: let users figure out if their device supports PPP
* on the APP1 port or not.
*/
if (getenv ("MM_SIERRA_APP1_PPP_OK")) {
mm_dbg ("Sierra: APP1 PPP OK '%s'", response->str);
mm_dbg ("Sierra: APP1 PPP OK '%s'", response);
g_object_set_data (G_OBJECT (ctx->probe), TAG_SIERRA_APP1_PPP_OK, GUINT_TO_POINTER (TRUE));
}
} else if (strstr (response->str, "APP2") ||
strstr (response->str, "APP3") ||
strstr (response->str, "APP4")) {
} else if (strstr (response, "APP2") ||
strstr (response, "APP3") ||
strstr (response, "APP4")) {
/* Additional APP ports don't support most AT commands, so they cannot
* be used as the primary port.
*/
@@ -143,6 +148,10 @@ gcap_ready (MMPortSerialAt *port,
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
sierra_custom_init_context_complete_and_free (ctx);
out:
if (error)
g_error_free (error);
}
static void
@@ -166,13 +175,14 @@ sierra_custom_init_step (SierraCustomInitContext *ctx)
}
ctx->retries--;
mm_port_serial_at_queue_command (
mm_port_serial_at_command (
ctx->port,
"ATI",
3,
FALSE, /* raw */
FALSE, /* allow_cached */
ctx->cancellable,
(MMPortSerialAtResponseFn)gcap_ready,
(GAsyncReadyCallback)gcap_ready,
ctx);
}
+13 -6
View File
@@ -71,20 +71,22 @@ static void x22x_custom_init_step (X22xCustomInitContext *ctx);
static void
gmr_ready (MMPortSerialAt *port,
GString *response,
GError *error,
GAsyncResult *res,
X22xCustomInitContext *ctx)
{
const gchar *p;
const gchar *response;
GError *error = NULL;
response = mm_port_serial_at_command_finish (port, res, &error);
if (error) {
/* Just retry... */
x22x_custom_init_step (ctx);
return;
goto out;
}
/* Note the lack of a ':' on the GMR; the X200 doesn't send one */
p = mm_strip_tag (response->str, "AT+GMR");
p = mm_strip_tag (response, "AT+GMR");
if (p && *p != 'L') {
/* X200 modems have a GMR firmware revision that starts with 'L', and
* as far as I can tell X060s devices have a revision starting with 'C'.
@@ -101,6 +103,10 @@ gmr_ready (MMPortSerialAt *port,
}
x22x_custom_init_context_complete_and_free (ctx);
out:
if (error)
g_error_free (error);
}
static void
@@ -127,13 +133,14 @@ x22x_custom_init_step (X22xCustomInitContext *ctx)
}
ctx->retries--;
mm_port_serial_at_queue_command (
mm_port_serial_at_command (
ctx->port,
"AT+GMR",
3,
FALSE, /* raw */
FALSE, /* allow_cached */
ctx->cancellable,
(MMPortSerialAtResponseFn)gmr_ready,
(GAsyncReadyCallback)gmr_ready,
ctx);
}