api,dbus: new `Command' method in the API to send arbitrary AT commands
BUG=chromium-os:25348 TEST="mmcli -m 0 --command='E0'" Change-Id: I320587560fde5780f9d5a4998e32364d36a71ed7
This commit is contained in:
committed by
Aleksander Morgado
parent
54c2daf937
commit
3c41ce5d8b
@@ -1861,6 +1861,35 @@ modem_power_up (MMIfaceModem *self,
|
||||
g_object_unref (result);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Sending a command to the modem (Modem interface) */
|
||||
|
||||
static const gchar *
|
||||
modem_command_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return mm_base_modem_at_command_finish (MM_BASE_MODEM (self),
|
||||
res,
|
||||
error);
|
||||
}
|
||||
|
||||
static void
|
||||
modem_command (MMIfaceModem *self,
|
||||
const gchar *cmd,
|
||||
guint timeout,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (self), cmd, timeout,
|
||||
FALSE,
|
||||
NULL, /* cancellable */
|
||||
callback,
|
||||
user_data);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Initializing the modem (Modem interface) */
|
||||
|
||||
@@ -6668,6 +6697,8 @@ iface_modem_init (MMIfaceModem *iface)
|
||||
iface->load_signal_quality_finish = modem_load_signal_quality_finish;
|
||||
iface->create_bearer = modem_create_bearer;
|
||||
iface->create_bearer_finish = modem_create_bearer_finish;
|
||||
iface->command = modem_command;
|
||||
iface->command_finish = modem_command_finish;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-iface-modem.h"
|
||||
#include "mm-base-modem.h"
|
||||
#include "mm-base-modem-at.h"
|
||||
#include "mm-sim.h"
|
||||
#include "mm-bearer-list.h"
|
||||
#include "mm-log.h"
|
||||
@@ -302,6 +303,57 @@ handle_create_bearer (MmGdbusModem *skeleton,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
command_done (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
DbusCallContext *ctx)
|
||||
{
|
||||
GError *error = NULL;
|
||||
const gchar *result;
|
||||
|
||||
result = MM_IFACE_MODEM_GET_INTERFACE (self)->command_finish (self,
|
||||
res,
|
||||
&error);
|
||||
if (error)
|
||||
g_dbus_method_invocation_take_error (ctx->invocation,
|
||||
error);
|
||||
else
|
||||
mm_gdbus_modem_complete_command (ctx->skeleton,
|
||||
ctx->invocation,
|
||||
result);
|
||||
dbus_call_context_free (ctx);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_command (MmGdbusModem *skeleton,
|
||||
GDBusMethodInvocation *invocation,
|
||||
const gchar *cmd,
|
||||
guint timeout,
|
||||
MMIfaceModem *self)
|
||||
{
|
||||
|
||||
/* If command is not implemented, report an error */
|
||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->command ||
|
||||
!MM_IFACE_MODEM_GET_INTERFACE (self)->command_finish) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Cannot send AT command to modem: "
|
||||
"operation not supported");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
MM_IFACE_MODEM_GET_INTERFACE (self)->command (self,
|
||||
cmd,
|
||||
timeout,
|
||||
(GAsyncReadyCallback)command_done,
|
||||
dbus_call_context_new (skeleton,
|
||||
invocation,
|
||||
self));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
@@ -2920,6 +2972,10 @@ interface_initialization_step (InitializationContext *ctx)
|
||||
"handle-create-bearer",
|
||||
G_CALLBACK (handle_create_bearer),
|
||||
ctx->self);
|
||||
g_signal_connect (ctx->skeleton,
|
||||
"handle-command",
|
||||
G_CALLBACK (handle_command),
|
||||
ctx->self);
|
||||
g_signal_connect (ctx->skeleton,
|
||||
"handle-delete-bearer",
|
||||
G_CALLBACK (handle_delete_bearer),
|
||||
|
||||
@@ -163,6 +163,16 @@ struct _MMIfaceModem {
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
/* Asynchronous command operation */
|
||||
void (*command) (MMIfaceModem *self,
|
||||
const gchar *cmd,
|
||||
guint timeout,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
const gchar * (*command_finish) (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
/* Asynchronous allowed band setting operation */
|
||||
void (*set_allowed_bands) (MMIfaceModem *self,
|
||||
GArray *bands_array,
|
||||
|
||||
Reference in New Issue
Block a user