broadband-modem-mbim: implement current capabilities loading
This commit is contained in:
@@ -37,9 +37,122 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemMbim, mm_broadband_modem_mbim, MM_TYPE_B
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init))
|
||||
|
||||
struct _MMBroadbandModemMbimPrivate {
|
||||
gpointer dummy;
|
||||
/* Queried and cached capabilities */
|
||||
MbimCellularClass caps_cellular_class;
|
||||
MbimDataClass caps_data_class;
|
||||
MbimSmsCaps caps_sms;
|
||||
guint caps_max_sessions;
|
||||
gchar *caps_device_id;
|
||||
gchar *caps_firmware_info;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Current Capabilities loading (Modem interface) */
|
||||
|
||||
typedef struct {
|
||||
MMBroadbandModemMbim *self;
|
||||
GSimpleAsyncResult *result;
|
||||
} LoadCapabilitiesContext;
|
||||
|
||||
static void
|
||||
load_capabilities_context_complete_and_free (LoadCapabilitiesContext *ctx)
|
||||
{
|
||||
g_simple_async_result_complete (ctx->result);
|
||||
g_object_unref (ctx->result);
|
||||
g_object_unref (ctx->self);
|
||||
g_slice_free (LoadCapabilitiesContext, ctx);
|
||||
}
|
||||
|
||||
static MMModemCapability
|
||||
modem_load_current_capabilities_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
MMModemCapability caps;
|
||||
gchar *caps_str;
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
||||
return MM_MODEM_CAPABILITY_NONE;
|
||||
|
||||
caps = ((MMModemCapability) GPOINTER_TO_UINT (
|
||||
g_simple_async_result_get_op_res_gpointer (
|
||||
G_SIMPLE_ASYNC_RESULT (res))));
|
||||
caps_str = mm_modem_capability_build_string_from_mask (caps);
|
||||
mm_dbg ("loaded modem capabilities: %s", caps_str);
|
||||
g_free (caps_str);
|
||||
return caps;
|
||||
}
|
||||
|
||||
static void
|
||||
device_caps_query_ready (MbimDevice *device,
|
||||
GAsyncResult *res,
|
||||
LoadCapabilitiesContext *ctx)
|
||||
{
|
||||
MMModemCapability mask;
|
||||
MbimMessage *response;
|
||||
GError *error = NULL;
|
||||
|
||||
response = mbim_device_command_finish (device, res, &error);
|
||||
if (!response) {
|
||||
g_simple_async_result_take_error (ctx->result, error);
|
||||
load_capabilities_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Gather and store the results we want */
|
||||
ctx->self->priv->caps_cellular_class = mbim_message_basic_connect_device_caps_query_response_get_cellular_class (response);
|
||||
ctx->self->priv->caps_data_class = mbim_message_basic_connect_device_caps_query_response_get_data_class (response);
|
||||
ctx->self->priv->caps_sms = mbim_message_basic_connect_device_caps_query_response_get_sms_caps (response);
|
||||
ctx->self->priv->caps_max_sessions = mbim_message_basic_connect_device_caps_query_response_get_max_sessions (response);
|
||||
ctx->self->priv->caps_device_id = mbim_message_basic_connect_device_caps_query_response_get_device_id (response);
|
||||
ctx->self->priv->caps_firmware_info = mbim_message_basic_connect_device_caps_query_response_get_firmware_info (response);
|
||||
mbim_message_unref (response);
|
||||
|
||||
/* Build mask of modem capabilities */
|
||||
mask = 0;
|
||||
if (ctx->self->priv->caps_cellular_class & MBIM_CELLULAR_CLASS_GSM)
|
||||
mask |= MM_MODEM_CAPABILITY_GSM_UMTS;
|
||||
if (ctx->self->priv->caps_cellular_class & MBIM_CELLULAR_CLASS_CDMA)
|
||||
mask |= MM_MODEM_CAPABILITY_CDMA_EVDO;
|
||||
if (ctx->self->priv->caps_data_class & MBIM_DATA_CLASS_LTE)
|
||||
mask |= MM_MODEM_CAPABILITY_LTE;
|
||||
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (ctx->result,
|
||||
GUINT_TO_POINTER (mask),
|
||||
NULL);
|
||||
load_capabilities_context_complete_and_free (ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
modem_load_current_capabilities (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
LoadCapabilitiesContext *ctx;
|
||||
MMMbimPort *port;
|
||||
MbimMessage *message;
|
||||
|
||||
ctx = g_slice_new (LoadCapabilitiesContext);
|
||||
ctx->self = g_object_ref (self);
|
||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
modem_load_current_capabilities);
|
||||
|
||||
mm_dbg ("loading current capabilities...");
|
||||
port = mm_base_modem_peek_port_mbim (MM_BASE_MODEM (self));
|
||||
message = (mbim_message_basic_connect_device_caps_query_request_new (
|
||||
mm_mbim_port_get_next_transaction_id (port)));
|
||||
mbim_device_command (mm_mbim_port_peek_device (port),
|
||||
message,
|
||||
10,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)device_caps_query_ready,
|
||||
ctx);
|
||||
mbim_message_unref (message);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Create Bearer (Modem interface) */
|
||||
|
||||
@@ -306,6 +419,9 @@ finalize (GObject *object)
|
||||
MMMbimPort *mbim;
|
||||
MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (object);
|
||||
|
||||
g_free (self->priv->caps_device_id);
|
||||
g_free (self->priv->caps_firmware_info);
|
||||
|
||||
mbim = mm_base_modem_peek_port_mbim (MM_BASE_MODEM (self));
|
||||
/* If we did open the MBIM port during initialization, close it now */
|
||||
if (mbim &&
|
||||
@@ -319,6 +435,12 @@ finalize (GObject *object)
|
||||
static void
|
||||
iface_modem_init (MMIfaceModem *iface)
|
||||
{
|
||||
/* Initialization steps */
|
||||
iface->load_current_capabilities = modem_load_current_capabilities;
|
||||
iface->load_current_capabilities_finish = modem_load_current_capabilities_finish;
|
||||
iface->load_modem_capabilities = NULL;
|
||||
iface->load_modem_capabilities_finish = NULL;
|
||||
|
||||
/* Create MBIM-specific SIM */
|
||||
iface->create_sim = create_sim;
|
||||
iface->create_sim_finish = create_sim_finish;
|
||||
|
||||
Reference in New Issue
Block a user