iface-modem: allow setting allowed modes and bands internally, not just via DBus
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include <ModemManager.h>
|
#include <ModemManager.h>
|
||||||
#include <libmm-common.h>
|
#include <libmm-common.h>
|
||||||
|
|
||||||
|
#include "mm-modem-helpers.h"
|
||||||
#include "mm-iface-modem.h"
|
#include "mm-iface-modem.h"
|
||||||
#include "mm-base-modem.h"
|
#include "mm-base-modem.h"
|
||||||
#include "mm-sim.h"
|
#include "mm-sim.h"
|
||||||
@@ -563,8 +564,61 @@ handle_factory_reset (MmGdbusModem *skeleton,
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mm_iface_modem_set_allowed_bands_finish (MMIfaceModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_allowed_bands_ready (MMIfaceModem *self,
|
set_allowed_bands_ready (MMIfaceModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GSimpleAsyncResult *simple)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish (self, res, &error))
|
||||||
|
g_simple_async_result_take_error (simple, error);
|
||||||
|
else
|
||||||
|
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
|
||||||
|
g_simple_async_result_complete (simple);
|
||||||
|
g_object_unref (simple);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mm_iface_modem_set_allowed_bands (MMIfaceModem *self,
|
||||||
|
MMModemBand bands,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *result;
|
||||||
|
|
||||||
|
/* If setting allowed bands is not implemented, report an error */
|
||||||
|
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands ||
|
||||||
|
!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish) {
|
||||||
|
g_simple_async_report_error_in_idle (G_OBJECT (self),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
MM_CORE_ERROR,
|
||||||
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
|
"Setting allowed bands not supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
mm_iface_modem_set_allowed_bands);
|
||||||
|
MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands (self,
|
||||||
|
bands,
|
||||||
|
(GAsyncReadyCallback)set_allowed_bands_ready,
|
||||||
|
result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_set_allowed_bands_ready (MMIfaceModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
DbusCallContext *ctx)
|
DbusCallContext *ctx)
|
||||||
{
|
{
|
||||||
@@ -573,8 +627,7 @@ set_allowed_bands_ready (MMIfaceModem *self,
|
|||||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish (self,
|
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish (self,
|
||||||
res,
|
res,
|
||||||
&error))
|
&error))
|
||||||
g_dbus_method_invocation_take_error (ctx->invocation,
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
error);
|
|
||||||
else
|
else
|
||||||
mm_gdbus_modem_complete_set_allowed_bands (ctx->skeleton,
|
mm_gdbus_modem_complete_set_allowed_bands (ctx->skeleton,
|
||||||
ctx->invocation);
|
ctx->invocation);
|
||||||
@@ -584,22 +637,11 @@ set_allowed_bands_ready (MMIfaceModem *self,
|
|||||||
static gboolean
|
static gboolean
|
||||||
handle_set_allowed_bands (MmGdbusModem *skeleton,
|
handle_set_allowed_bands (MmGdbusModem *skeleton,
|
||||||
GDBusMethodInvocation *invocation,
|
GDBusMethodInvocation *invocation,
|
||||||
guint64 arg_bands,
|
guint64 bands,
|
||||||
MMIfaceModem *self)
|
MMIfaceModem *self)
|
||||||
{
|
{
|
||||||
MMModemState modem_state;
|
MMModemState modem_state = MM_MODEM_STATE_UNKNOWN;
|
||||||
|
|
||||||
/* If setting allowed bands is not implemented, report an error */
|
|
||||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands ||
|
|
||||||
!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish) {
|
|
||||||
g_dbus_method_invocation_return_error (invocation,
|
|
||||||
MM_CORE_ERROR,
|
|
||||||
MM_CORE_ERROR_UNSUPPORTED,
|
|
||||||
"Setting allowed bands not supported");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
modem_state = MM_MODEM_STATE_UNKNOWN;
|
|
||||||
g_object_get (self,
|
g_object_get (self,
|
||||||
MM_IFACE_MODEM_STATE, &modem_state,
|
MM_IFACE_MODEM_STATE, &modem_state,
|
||||||
NULL);
|
NULL);
|
||||||
@@ -610,7 +652,7 @@ handle_set_allowed_bands (MmGdbusModem *skeleton,
|
|||||||
g_dbus_method_invocation_return_error (invocation,
|
g_dbus_method_invocation_return_error (invocation,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_WRONG_STATE,
|
MM_CORE_ERROR_WRONG_STATE,
|
||||||
"Cannot reset the modem to factory defaults: "
|
"Cannot set allowed bands: "
|
||||||
"not initialized/unlocked yet");
|
"not initialized/unlocked yet");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -623,9 +665,9 @@ handle_set_allowed_bands (MmGdbusModem *skeleton,
|
|||||||
case MM_MODEM_STATE_DISCONNECTING:
|
case MM_MODEM_STATE_DISCONNECTING:
|
||||||
case MM_MODEM_STATE_CONNECTING:
|
case MM_MODEM_STATE_CONNECTING:
|
||||||
case MM_MODEM_STATE_CONNECTED:
|
case MM_MODEM_STATE_CONNECTED:
|
||||||
MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands (self,
|
mm_iface_modem_set_allowed_bands (self,
|
||||||
arg_bands,
|
bands,
|
||||||
(GAsyncReadyCallback)set_allowed_bands_ready,
|
(GAsyncReadyCallback)handle_set_allowed_bands_ready,
|
||||||
dbus_call_context_new (skeleton,
|
dbus_call_context_new (skeleton,
|
||||||
invocation,
|
invocation,
|
||||||
self));
|
self));
|
||||||
@@ -636,19 +678,72 @@ handle_set_allowed_bands (MmGdbusModem *skeleton,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
/* ALLOWED MODES */
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mm_iface_modem_set_allowed_modes_finish (MMIfaceModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_allowed_modes_ready (MMIfaceModem *self,
|
set_allowed_modes_ready (MMIfaceModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GSimpleAsyncResult *simple)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish (self, res, &error))
|
||||||
|
g_simple_async_result_take_error (simple, error);
|
||||||
|
else
|
||||||
|
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
|
||||||
|
g_simple_async_result_complete (simple);
|
||||||
|
g_object_unref (simple);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mm_iface_modem_set_allowed_modes (MMIfaceModem *self,
|
||||||
|
MMModemMode allowed,
|
||||||
|
MMModemMode preferred,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *result;
|
||||||
|
|
||||||
|
/* If setting allowed modes is not implemented, report an error */
|
||||||
|
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes ||
|
||||||
|
!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish) {
|
||||||
|
g_simple_async_report_error_in_idle (G_OBJECT (self),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
MM_CORE_ERROR,
|
||||||
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
|
"Setting allowed modes not supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
mm_iface_modem_set_allowed_modes);
|
||||||
|
MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes (self,
|
||||||
|
allowed,
|
||||||
|
preferred,
|
||||||
|
(GAsyncReadyCallback)set_allowed_modes_ready,
|
||||||
|
result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_set_allowed_modes_ready (MMIfaceModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
DbusCallContext *ctx)
|
DbusCallContext *ctx)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish (self,
|
if (mm_iface_modem_set_allowed_modes_finish (self, res, &error))
|
||||||
res,
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
&error))
|
|
||||||
g_dbus_method_invocation_take_error (ctx->invocation,
|
|
||||||
error);
|
|
||||||
else
|
else
|
||||||
mm_gdbus_modem_complete_set_allowed_modes (ctx->skeleton,
|
mm_gdbus_modem_complete_set_allowed_modes (ctx->skeleton,
|
||||||
ctx->invocation);
|
ctx->invocation);
|
||||||
@@ -658,24 +753,12 @@ set_allowed_modes_ready (MMIfaceModem *self,
|
|||||||
static gboolean
|
static gboolean
|
||||||
handle_set_allowed_modes (MmGdbusModem *skeleton,
|
handle_set_allowed_modes (MmGdbusModem *skeleton,
|
||||||
GDBusMethodInvocation *invocation,
|
GDBusMethodInvocation *invocation,
|
||||||
guint arg_modes,
|
guint modes,
|
||||||
guint arg_preferred,
|
guint preferred,
|
||||||
MMIfaceModem *self)
|
MMIfaceModem *self)
|
||||||
{
|
{
|
||||||
MMModemState modem_state;
|
MMModemState modem_state = MM_MODEM_STATE_UNKNOWN;
|
||||||
|
|
||||||
/* If setting allowed modes is not implemented, report an error */
|
|
||||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes ||
|
|
||||||
!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish) {
|
|
||||||
g_dbus_method_invocation_return_error (invocation,
|
|
||||||
MM_CORE_ERROR,
|
|
||||||
MM_CORE_ERROR_UNSUPPORTED,
|
|
||||||
"Setting allowed modes not supported");
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
modem_state = MM_MODEM_STATE_UNKNOWN;
|
|
||||||
g_object_get (self,
|
g_object_get (self,
|
||||||
MM_IFACE_MODEM_STATE, &modem_state,
|
MM_IFACE_MODEM_STATE, &modem_state,
|
||||||
NULL);
|
NULL);
|
||||||
@@ -686,7 +769,7 @@ handle_set_allowed_modes (MmGdbusModem *skeleton,
|
|||||||
g_dbus_method_invocation_return_error (invocation,
|
g_dbus_method_invocation_return_error (invocation,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_WRONG_STATE,
|
MM_CORE_ERROR_WRONG_STATE,
|
||||||
"Cannot reset the modem to factory defaults: "
|
"Cannot set allowed modes: "
|
||||||
"not initialized/unlocked yet");
|
"not initialized/unlocked yet");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -699,10 +782,10 @@ handle_set_allowed_modes (MmGdbusModem *skeleton,
|
|||||||
case MM_MODEM_STATE_DISCONNECTING:
|
case MM_MODEM_STATE_DISCONNECTING:
|
||||||
case MM_MODEM_STATE_CONNECTING:
|
case MM_MODEM_STATE_CONNECTING:
|
||||||
case MM_MODEM_STATE_CONNECTED:
|
case MM_MODEM_STATE_CONNECTED:
|
||||||
MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes (self,
|
mm_iface_modem_set_allowed_modes (self,
|
||||||
arg_modes,
|
modes,
|
||||||
arg_preferred,
|
preferred,
|
||||||
(GAsyncReadyCallback)set_allowed_modes_ready,
|
(GAsyncReadyCallback)handle_set_allowed_modes_ready,
|
||||||
dbus_call_context_new (skeleton,
|
dbus_call_context_new (skeleton,
|
||||||
invocation,
|
invocation,
|
||||||
self));
|
self));
|
||||||
@@ -2187,6 +2270,19 @@ mm_iface_modem_shutdown (MMIfaceModem *self)
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mm_iface_modem_is_3gpp (MMIfaceModem *self)
|
||||||
|
{
|
||||||
|
MMModemCapability capabilities = MM_MODEM_CAPABILITY_NONE;
|
||||||
|
|
||||||
|
g_object_get (self,
|
||||||
|
MM_IFACE_MODEM_CURRENT_CAPABILITIES, &capabilities,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return (capabilities & MM_MODEM_CAPABILITY_3GPP);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
@@ -242,6 +242,9 @@ struct _MMIfaceModem {
|
|||||||
|
|
||||||
GType mm_iface_modem_get_type (void);
|
GType mm_iface_modem_get_type (void);
|
||||||
|
|
||||||
|
/* Check whether this modem has 3GPP capabilities */
|
||||||
|
gboolean mm_iface_modem_is_3gpp (MMIfaceModem *self);
|
||||||
|
|
||||||
/* Initialize Modem interface (async) */
|
/* Initialize Modem interface (async) */
|
||||||
void mm_iface_modem_initialize (MMIfaceModem *self,
|
void mm_iface_modem_initialize (MMIfaceModem *self,
|
||||||
MMAtSerialPort *port,
|
MMAtSerialPort *port,
|
||||||
@@ -301,4 +304,23 @@ void mm_iface_modem_update_access_tech (MMIfaceModem *self,
|
|||||||
MMModemAccessTechnology access_tech,
|
MMModemAccessTechnology access_tech,
|
||||||
guint32 mask);
|
guint32 mask);
|
||||||
|
|
||||||
|
/* Allow setting allowed modes */
|
||||||
|
void mm_iface_modem_set_allowed_modes (MMIfaceModem *self,
|
||||||
|
MMModemMode allowed,
|
||||||
|
MMModemMode preferred,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
gboolean mm_iface_modem_set_allowed_modes_finish (MMIfaceModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
/* Allow setting allowed bands */
|
||||||
|
void mm_iface_modem_set_allowed_bands (MMIfaceModem *self,
|
||||||
|
MMModemBand bands,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
gboolean mm_iface_modem_set_allowed_bands_finish (MMIfaceModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
#endif /* MM_IFACE_MODEM_H */
|
#endif /* MM_IFACE_MODEM_H */
|
||||||
|
Reference in New Issue
Block a user