diff options
-rw-r--r-- | introspection/mm-modem.xml | 11 | ||||
-rw-r--r-- | src/mm-modem.c | 57 | ||||
-rw-r--r-- | src/mm-modem.h | 10 |
3 files changed, 78 insertions, 0 deletions
diff --git a/introspection/mm-modem.xml b/introspection/mm-modem.xml index 35b679689..7d54dd30e 100644 --- a/introspection/mm-modem.xml +++ b/introspection/mm-modem.xml @@ -81,6 +81,17 @@ </arg> </method> + <method name="FactoryReset"> + <tp:docstring> + Reset the modem to as close to factory state as possible. + </tp:docstring> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_factory_reset"/> + <arg name="code" type="s" direction="in"> + Carrier-supplied code required to reset the modem. Ignored if not required. + </arg> + </method> + <property name="Device" type="s" access="read"> <tp:docstring> The modem port to use for IP configuration and traffic. diff --git a/src/mm-modem.c b/src/mm-modem.c index 8d25e483d..221c9eabc 100644 --- a/src/mm-modem.c +++ b/src/mm-modem.c @@ -28,6 +28,7 @@ static void impl_modem_connect (MMModem *modem, const char *number, DBusGMethodI static void impl_modem_disconnect (MMModem *modem, DBusGMethodInvocation *context); static void impl_modem_get_ip4_config (MMModem *modem, DBusGMethodInvocation *context); static void impl_modem_get_info (MMModem *modem, DBusGMethodInvocation *context); +static void impl_modem_factory_reset (MMModem *modem, const char *code, DBusGMethodInvocation *context); #include "mm-modem-glue.h" @@ -476,6 +477,62 @@ impl_modem_get_info (MMModem *modem, /*****************************************************************************/ +static void +factory_reset_auth_cb (MMAuthRequest *req, + GObject *owner, + DBusGMethodInvocation *context, + gpointer user_data) +{ + MMModem *self = MM_MODEM (owner); + const char *code = user_data; + GError *error = NULL; + + /* Return any authorization error, otherwise try to reset the modem */ + if (!mm_modem_auth_finish (self, req, &error)) { + dbus_g_method_return_error (context, error); + g_error_free (error); + } else + mm_modem_factory_reset (self, code, async_call_done, context); +} + +static void +impl_modem_factory_reset (MMModem *modem, + const char *code, + DBusGMethodInvocation *context) +{ + GError *error = NULL; + + /* Make sure the caller is authorized to reset the device */ + if (!mm_modem_auth_request (MM_MODEM (modem), + MM_AUTHORIZATION_DEVICE_CONTROL, + context, + factory_reset_auth_cb, + g_strdup (code), + g_free, + &error)) { + dbus_g_method_return_error (context, error); + g_error_free (error); + } +} + +void +mm_modem_factory_reset (MMModem *self, + const char *code, + MMModemFn callback, + gpointer user_data) +{ + g_return_if_fail (MM_IS_MODEM (self)); + g_return_if_fail (callback != NULL); + g_return_if_fail (code != NULL); + + if (MM_MODEM_GET_INTERFACE (self)->factory_reset) + MM_MODEM_GET_INTERFACE (self)->factory_reset (self, code, callback, user_data); + else + async_op_not_supported (self, callback, user_data); +} + +/*****************************************************************************/ + void mm_modem_get_supported_charsets (MMModem *self, MMModemUIntFn callback, diff --git a/src/mm-modem.h b/src/mm-modem.h index 154de87c3..0915180bc 100644 --- a/src/mm-modem.h +++ b/src/mm-modem.h @@ -188,6 +188,11 @@ struct _MMModem { MMAuthRequest *req, GError **error); + void (*factory_reset) (MMModem *self, + const char *code, + MMModemFn callback, + gpointer user_data); + /* Signals */ void (*state_changed) (MMModem *self, MMModemState new_state, @@ -246,6 +251,11 @@ void mm_modem_set_charset (MMModem *self, MMModemFn callback, gpointer user_data); +void mm_modem_factory_reset (MMModem *self, + const char *code, + MMModemFn callback, + gpointer user_data); + gboolean mm_modem_get_valid (MMModem *self); char *mm_modem_get_device (MMModem *self); |