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.
This commit is contained in:
@@ -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_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_FLASH_FAILED: Could not flash the device.
|
||||||
* @MM_SERIAL_ERROR_NOT_OPEN: The serial port is not open.
|
* @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.
|
* 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_OPEN_FAILED_NO_DEVICE = 4, /*< nick=OpenFailedNoDevice >*/
|
||||||
MM_SERIAL_ERROR_FLASH_FAILED = 5, /*< nick=FlashFailed >*/
|
MM_SERIAL_ERROR_FLASH_FAILED = 5, /*< nick=FlashFailed >*/
|
||||||
MM_SERIAL_ERROR_NOT_OPEN = 6, /*< nick=NotOpen >*/
|
MM_SERIAL_ERROR_NOT_OPEN = 6, /*< nick=NotOpen >*/
|
||||||
|
MM_SERIAL_ERROR_PARSE_FAILED = 7, /*< nick=ParseFailed >*/
|
||||||
} MMSerialError;
|
} MMSerialError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -50,11 +50,15 @@ mm_port_probe_response_processor_is_at (const gchar *command,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If error is NOT known by the parser, request to abort */
|
/* If error is NOT known by the parser, or if the error is actually
|
||||||
if (!mm_serial_parser_v1_is_known_error (error)) {
|
* 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);
|
*result_error = g_error_copy (error);
|
||||||
g_prefix_error (result_error,
|
g_prefix_error (result_error,
|
||||||
"Fatal error parsing AT reply. ");
|
"Fatal error parsing AT reply: ");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,4 +95,3 @@ mm_port_probe_response_processor_string (const gchar *command,
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -954,6 +954,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
|
static gboolean
|
||||||
serial_open_at (MMPortProbe *self)
|
serial_open_at (MMPortProbe *self)
|
||||||
{
|
{
|
||||||
@@ -968,6 +985,8 @@ serial_open_at (MMPortProbe *self)
|
|||||||
|
|
||||||
/* Create AT serial port if not done before */
|
/* Create AT serial port if not done before */
|
||||||
if (!task->serial) {
|
if (!task->serial) {
|
||||||
|
gpointer parser;
|
||||||
|
|
||||||
task->serial = MM_SERIAL_PORT (mm_at_serial_port_new (g_udev_device_get_name (self->priv->port)));
|
task->serial = MM_SERIAL_PORT (mm_at_serial_port_new (g_udev_device_get_name (self->priv->port)));
|
||||||
if (!task->serial) {
|
if (!task->serial) {
|
||||||
port_probe_run_task_complete (
|
port_probe_run_task_complete (
|
||||||
@@ -989,9 +1008,13 @@ serial_open_at (MMPortProbe *self)
|
|||||||
MM_SERIAL_PORT_SPEW_CONTROL, TRUE,
|
MM_SERIAL_PORT_SPEW_CONTROL, TRUE,
|
||||||
NULL);
|
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_at_serial_port_set_response_parser (MM_AT_SERIAL_PORT (task->serial),
|
||||||
mm_serial_parser_v1_parse,
|
mm_serial_parser_v1_parse,
|
||||||
mm_serial_parser_v1_new (),
|
parser,
|
||||||
mm_serial_parser_v1_destroy);
|
mm_serial_parser_v1_destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user