aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-04-03 12:26:24 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-04-04 19:26:51 +0200
commitf24fc68e04fbe225de162f57e3cbd254f8f03df4 (patch)
tree441589ebf3f7003402f62fceb9c7adaa3ac82db3
parent4e4d139e309c890b2c5c44b747aeaf9a5deac9bc (diff)
port-probe: add a new serial parser filter to detect non-AT strings
We will check each string with our custom filter before even trying to parse them. A MM_SERIAL_ERROR_PARSE_FAILED error will be issued whenever the string doesn't match the filter.
-rw-r--r--include/ModemManager-errors.h2
-rw-r--r--src/mm-port-probe-at.c11
-rw-r--r--src/mm-port-probe.c25
3 files changed, 33 insertions, 5 deletions
diff --git a/include/ModemManager-errors.h b/include/ModemManager-errors.h
index 0be24abb..ed714573 100644
--- a/include/ModemManager-errors.h
+++ b/include/ModemManager-errors.h
@@ -209,6 +209,7 @@ typedef enum { /*< underscore_name=mm_connection_error >*/
* @MM_SERIAL_ERROR_OPEN_FAILED_NO_DEVICE: Could not open the serial port, no device.
* @MM_SERIAL_ERROR_FLASH_FAILED: Could not flash the device.
* @MM_SERIAL_ERROR_NOT_OPEN: The serial port is not open.
+ * @MM_SERIAL_ERROR_PARSE_FAILED: The serial port specific parsing failed.
*
* Serial errors that may be reported by ModemManager.
*/
@@ -220,6 +221,7 @@ typedef enum { /*< underscore_name=mm_serial_error >*/
MM_SERIAL_ERROR_OPEN_FAILED_NO_DEVICE = 4, /*< nick=OpenFailedNoDevice >*/
MM_SERIAL_ERROR_FLASH_FAILED = 5, /*< nick=FlashFailed >*/
MM_SERIAL_ERROR_NOT_OPEN = 6, /*< nick=NotOpen >*/
+ MM_SERIAL_ERROR_PARSE_FAILED = 7, /*< nick=ParseFailed >*/
} MMSerialError;
/**
diff --git a/src/mm-port-probe-at.c b/src/mm-port-probe-at.c
index d7e6fefe..10cce9e5 100644
--- a/src/mm-port-probe-at.c
+++ b/src/mm-port-probe-at.c
@@ -50,11 +50,15 @@ mm_port_probe_response_processor_is_at (const gchar *command,
return FALSE;
}
- /* If error is NOT known by the parser, request to abort */
- if (!mm_serial_parser_v1_is_known_error (error)) {
+ /* If error is NOT known by the parser, or if the error is actually
+ * the generic parsing filter error, request to abort */
+ if (!mm_serial_parser_v1_is_known_error (error) ||
+ g_error_matches (error,
+ MM_SERIAL_ERROR,
+ MM_SERIAL_ERROR_PARSE_FAILED)) {
*result_error = g_error_copy (error);
g_prefix_error (result_error,
- "Fatal error parsing AT reply. ");
+ "Fatal error parsing AT reply: ");
return FALSE;
}
@@ -91,4 +95,3 @@ mm_port_probe_response_processor_string (const gchar *command,
return TRUE;
}
-
diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c
index 6c36e6ba..33f0be86 100644
--- a/src/mm-port-probe.c
+++ b/src/mm-port-probe.c
@@ -955,6 +955,23 @@ serial_buffer_full (MMSerialPort *serial,
}
static gboolean
+serial_parser_filter_cb (gpointer filter,
+ gpointer user_data,
+ GString *response,
+ GError **error)
+{
+ if (is_non_at_response ((const guint8 *) response->str, response->len)) {
+ g_set_error (error,
+ MM_SERIAL_ERROR,
+ MM_SERIAL_ERROR_PARSE_FAILED,
+ "Not an AT response");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
serial_open_at (MMPortProbe *self)
{
PortProbeRunTask *task = self->priv->task;
@@ -968,6 +985,8 @@ serial_open_at (MMPortProbe *self)
/* Create AT serial port if not done before */
if (!task->serial) {
+ gpointer parser;
+
task->serial = MM_SERIAL_PORT (mm_at_serial_port_new (g_udev_device_get_name (self->priv->port)));
if (!task->serial) {
port_probe_run_task_complete (
@@ -989,9 +1008,13 @@ serial_open_at (MMPortProbe *self)
MM_SERIAL_PORT_SPEW_CONTROL, TRUE,
NULL);
+ parser = mm_serial_parser_v1_new ();
+ mm_serial_parser_v1_add_filter (parser,
+ serial_parser_filter_cb,
+ NULL);
mm_at_serial_port_set_response_parser (MM_AT_SERIAL_PORT (task->serial),
mm_serial_parser_v1_parse,
- mm_serial_parser_v1_new (),
+ parser,
mm_serial_parser_v1_destroy);
}