diff options
author | Dan Williams <dcbw@redhat.com> | 2011-08-02 10:43:54 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-08-02 10:43:54 -0500 |
commit | d3c2228f7b55465f4433bedb36d47744b8d791f1 (patch) | |
tree | 301d3d5ecff9c372b3a11de75ecf42f0f18749b4 /src | |
parent | 18231c9f8df809aacd4534d0a081125e8d6569df (diff) |
core: allow ports to skip flash behavior (bgo #650740)
Flashing is a technique to break out of the data/PPP stream and
re-enter command stream (like +++) and MM uses it in the generic
paths in various cases. But devices that don't need it (ie, ones
with at least one AT capable port that won't be used for data)
now sometimes appear to have side-effects.
The Ericsson F5521gw firmware R2A07 resets port attributes like
echo and &C and such when the port is flashed, leading to
confusion on the part of MM. Since the Ericsson devices will
always have at least one free AT port they don't need flashing
anyway.
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-serial-port.c | 102 | ||||
-rw-r--r-- | src/mm-serial-port.h | 4 |
2 files changed, 68 insertions, 38 deletions
diff --git a/src/mm-serial-port.c b/src/mm-serial-port.c index 116eb611..00d35d5e 100644 --- a/src/mm-serial-port.c +++ b/src/mm-serial-port.c @@ -46,6 +46,7 @@ enum { PROP_FD, PROP_SPEW_CONTROL, PROP_RTS_CTS, + PROP_FLASH_OK, LAST_PROP }; @@ -80,6 +81,7 @@ typedef struct { guint64 send_delay; gboolean spew_control; gboolean rts_cts; + gboolean flash_ok; guint queue_id; guint watch_id; @@ -1068,13 +1070,6 @@ mm_serial_port_queue_command_cached (MMSerialPort *self, internal_queue_command (self, command, take_command, TRUE, timeout_seconds, callback, user_data); } -typedef struct { - MMSerialPort *port; - speed_t current_speed; - MMSerialFlashFn callback; - gpointer user_data; -} FlashInfo; - static gboolean get_speed (MMSerialPort *self, speed_t *speed, GError **error) { @@ -1154,6 +1149,13 @@ set_speed (MMSerialPort *self, speed_t speed, GError **error) return TRUE; } +typedef struct { + MMSerialPort *port; + speed_t current_speed; + MMSerialFlashFn callback; + gpointer user_data; +} FlashInfo; + static gboolean flash_do (gpointer data) { @@ -1163,13 +1165,15 @@ flash_do (gpointer data) priv->flash_id = 0; - if (info->current_speed) { - if (!set_speed (info->port, info->current_speed, &error)) - g_assert (error); - } else { - error = g_error_new_literal (MM_SERIAL_ERROR, - MM_SERIAL_ERROR_FLASH_FAILED, - "Failed to retrieve current speed"); + if (priv->flash_ok) { + if (info->current_speed) { + if (!set_speed (info->port, info->current_speed, &error)) + g_assert (error); + } else { + error = g_error_new_literal (MM_SERIAL_ERROR, + MM_SERIAL_ERROR_FLASH_FAILED, + "Failed to retrieve current speed"); + } } info->callback (info->port, error, info->user_data); @@ -1185,9 +1189,8 @@ mm_serial_port_flash (MMSerialPort *self, MMSerialFlashFn callback, gpointer user_data) { - FlashInfo *info; + FlashInfo *info = NULL; MMSerialPortPrivate *priv; - speed_t cur_speed = 0; GError *error = NULL; gboolean success; @@ -1200,43 +1203,43 @@ mm_serial_port_flash (MMSerialPort *self, error = g_error_new_literal (MM_SERIAL_ERROR, MM_SERIAL_ERROR_NOT_OPEN, "The serial port is not open."); - callback (self, error, user_data); - g_error_free (error); - return FALSE; + goto error; } if (priv->flash_id > 0) { error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_IN_PROGRESS, "Modem is already being flashed."); - callback (self, error, user_data); - g_error_free (error); - return FALSE; - } - - success = get_speed (self, &cur_speed, &error); - if (!success && !ignore_errors) { - callback (self, error, user_data); - g_error_free (error); - return FALSE; + goto error; } - g_clear_error (&error); info = g_slice_new0 (FlashInfo); info->port = self; - info->current_speed = cur_speed; info->callback = callback; info->user_data = user_data; - success = set_speed (self, B0, &error); - if (!success && !ignore_errors) { - callback (self, error, user_data); - g_error_free (error); - return FALSE; - } + if (priv->flash_ok) { + /* Grab current speed so we can reset it after flashing */ + success = get_speed (self, &info->current_speed, &error); + if (!success && !ignore_errors) + goto error; + g_clear_error (&error); + + success = set_speed (self, B0, &error); + if (!success && !ignore_errors) + goto error; + priv->flash_id = g_timeout_add (flash_time, flash_do, info); + } else + priv->flash_id = g_idle_add (flash_do, info); - priv->flash_id = g_timeout_add (flash_time, flash_do, info); return TRUE; + +error: + callback (self, error, user_data); + g_clear_error (&error); + if (info) + g_slice_free (FlashInfo, info); + return FALSE; } void @@ -1254,6 +1257,14 @@ mm_serial_port_flash_cancel (MMSerialPort *self) } } +gboolean +mm_serial_port_get_flash_ok (MMSerialPort *self) +{ + g_return_val_if_fail (MM_IS_SERIAL_PORT (self), TRUE); + + return MM_SERIAL_PORT_GET_PRIVATE (self)->flash_ok; +} + /*****************************************************************************/ MMSerialPort * @@ -1357,6 +1368,9 @@ set_property (GObject *object, guint prop_id, case PROP_RTS_CTS: priv->rts_cts = g_value_get_boolean (value); break; + case PROP_FLASH_OK: + priv->flash_ok = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1394,6 +1408,9 @@ get_property (GObject *object, guint prop_id, case PROP_RTS_CTS: g_value_set_boolean (value, priv->rts_cts); break; + case PROP_FLASH_OK: + g_value_set_boolean (value, priv->flash_ok); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1512,6 +1529,15 @@ mm_serial_port_class_init (MMSerialPortClass *klass) FALSE, G_PARAM_READWRITE)); + g_object_class_install_property + (object_class, PROP_FLASH_OK, + g_param_spec_boolean (MM_SERIAL_PORT_FLASH_OK, + "FlaskOk", + "Flashing the port (0 baud for a short period) " + "is allowed.", + TRUE, + G_PARAM_READWRITE)); + /* Signals */ signals[BUFFER_FULL] = g_signal_new ("buffer-full", diff --git a/src/mm-serial-port.h b/src/mm-serial-port.h index a9f34402..eb12cbbe 100644 --- a/src/mm-serial-port.h +++ b/src/mm-serial-port.h @@ -38,6 +38,7 @@ #define MM_SERIAL_PORT_RTS_CTS "rts-cts" #define MM_SERIAL_PORT_FD "fd" /* Construct-only */ #define MM_SERIAL_PORT_SPEW_CONTROL "spew-control" /* Construct-only */ +#define MM_SERIAL_PORT_FLASH_OK "flash-ok" /* Construct-only */ typedef struct _MMSerialPort MMSerialPort; typedef struct _MMSerialPortClass MMSerialPortClass; @@ -123,8 +124,11 @@ gboolean mm_serial_port_flash (MMSerialPort *self, gboolean ignore_errors, MMSerialFlashFn callback, gpointer user_data); + void mm_serial_port_flash_cancel (MMSerialPort *self); +gboolean mm_serial_port_get_flash_ok (MMSerialPort *self); + void mm_serial_port_queue_command (MMSerialPort *self, GByteArray *command, gboolean take_command, |