core: add modem reset/power-cycle command

Based on a patch by Elly Jones from Google.
This commit is contained in:
Dan Williams
2011-01-14 12:17:02 -06:00
parent 12b144e120
commit d908389aff
5 changed files with 109 additions and 1 deletions

View File

@@ -63,9 +63,20 @@
</arg>
</method>
<method name="Reset">
<tp:docstring>
Clear non-persistent configuration and state, and return the device to
a newly-powered-on state. This command may power-cycle the device.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_reset"/>
</method>
<method name="FactoryReset">
<tp:docstring>
Reset the modem to as close to factory state as possible.
Clear the modem's configuration (including persistent configuration and
state), and return the device to a factory-default state. This command
may or may not power-cycle the device.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_factory_reset"/>

View File

@@ -272,6 +272,24 @@ query_registration_state (MMGenericCdma *cdma,
/*****************************************************************************/
static void
reset (MMModem *modem,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
MMAtSerialPort *port;
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
/* Ensure we have a usable port to use for the command */
port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error);
if (port)
mm_at_serial_port_queue_command (port, "*RESET", 3, NULL, NULL);
mm_callback_info_schedule (info);
}
static gboolean
grab_port (MMModem *modem,
const char *subsys,
@@ -333,6 +351,7 @@ static void
modem_init (MMModem *modem_class)
{
modem_class->grab_port = grab_port;
modem_class->reset = reset;
}
static void

View File

@@ -509,6 +509,24 @@ do_disconnect (MMGenericGsm *gsm,
MM_GENERIC_GSM_CLASS (mm_modem_mbm_parent_class)->do_disconnect (gsm, cid, callback, user_data);
}
static void
reset (MMModem *modem,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
MMAtSerialPort *port;
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
/* Ensure we have a usable port to use for the command */
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error);
if (port)
mm_at_serial_port_queue_command (port, "*E2RESET", 3, NULL, NULL);
mm_callback_info_schedule (info);
}
static void
factory_reset_done (MMAtSerialPort *port,
GString *response,
@@ -940,6 +958,7 @@ modem_init (MMModem *modem_class)
modem_class->grab_port = grab_port;
modem_class->disable = disable;
modem_class->connect = do_connect;
modem_class->reset = reset;
modem_class->factory_reset = factory_reset;
}

View File

@@ -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_reset (MMModem *modem, DBusGMethodInvocation *context);
static void impl_modem_factory_reset (MMModem *modem, const char *code, DBusGMethodInvocation *context);
#include "mm-modem-glue.h"
@@ -477,6 +478,56 @@ impl_modem_get_info (MMModem *modem,
/*****************************************************************************/
static void
reset_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModem *self = MM_MODEM (owner);
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_reset (self, async_call_done, context);
}
static void
impl_modem_reset (MMModem *modem, 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,
reset_auth_cb,
NULL, NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
void
mm_modem_reset (MMModem *self,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->reset)
MM_MODEM_GET_INTERFACE (self)->reset (self, callback, user_data);
else
async_op_not_supported (self, callback, user_data);
}
/*****************************************************************************/
static void
factory_reset_auth_cb (MMAuthRequest *req,
GObject *owner,

View File

@@ -194,6 +194,10 @@ struct _MMModem {
MMAuthRequest *req,
GError **error);
void (*reset) (MMModem *self,
MMModemFn callback,
gpointer user_data);
void (*factory_reset) (MMModem *self,
const char *code,
MMModemFn callback,
@@ -257,6 +261,10 @@ void mm_modem_set_charset (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_reset (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_factory_reset (MMModem *self,
const char *code,
MMModemFn callback,