aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mm-broadband-modem-mbim.c2
-rw-r--r--src/mm-broadband-modem-qmi.c94
-rw-r--r--src/mm-iface-modem.c78
-rw-r--r--src/mm-iface-modem.h14
-rw-r--r--src/mm-modem-helpers.c28
-rw-r--r--src/mm-modem-helpers.h3
-rw-r--r--src/tests/test-modem-helpers.c94
7 files changed, 252 insertions, 61 deletions
diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c
index 5c9f3478..15b93d93 100644
--- a/src/mm-broadband-modem-mbim.c
+++ b/src/mm-broadband-modem-mbim.c
@@ -2169,8 +2169,6 @@ 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;
iface->load_manufacturer = modem_load_manufacturer;
iface->load_manufacturer_finish = modem_load_manufacturer_finish;
iface->load_model = modem_load_model;
diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c
index 3e4ced73..8091c036 100644
--- a/src/mm-broadband-modem-qmi.c
+++ b/src/mm-broadband-modem-qmi.c
@@ -555,46 +555,37 @@ modem_load_current_capabilities (MMIfaceModem *self,
}
/*****************************************************************************/
-/* Modem Capabilities loading (Modem interface) */
+/* Supported capabilities loading (Modem interface) */
typedef struct {
MMBroadbandModemQmi *self;
GSimpleAsyncResult *result;
-} LoadModemCapabilitiesContext;
+} LoadSupportedCapabilitiesContext;
static void
-load_modem_capabilities_context_complete_and_free (LoadModemCapabilitiesContext *ctx)
+load_supported_capabilities_context_complete_and_free (LoadSupportedCapabilitiesContext *ctx)
{
g_simple_async_result_complete (ctx->result);
g_object_unref (ctx->result);
g_object_unref (ctx->self);
- g_slice_free (LoadModemCapabilitiesContext, ctx);
+ g_slice_free (LoadSupportedCapabilitiesContext, ctx);
}
-static MMModemCapability
-modem_load_modem_capabilities_finish (MMIfaceModem *self,
- GAsyncResult *res,
- GError **error)
+static GArray *
+modem_load_supported_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;
+ return NULL;
- 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;
+ return g_array_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
}
static void
dms_get_capabilities_ready (QmiClientDms *client,
GAsyncResult *res,
- LoadModemCapabilitiesContext *ctx)
+ LoadSupportedCapabilitiesContext *ctx)
{
QmiMessageDmsGetCapabilitiesOutput *output = NULL;
GError *error = NULL;
@@ -604,12 +595,15 @@ dms_get_capabilities_ready (QmiClientDms *client,
g_prefix_error (&error, "QMI operation failed: ");
g_simple_async_result_take_error (ctx->result, error);
} else if (!qmi_message_dms_get_capabilities_output_get_result (output, &error)) {
- g_prefix_error (&error, "Couldn't get modem capabilities: ");
+ g_prefix_error (&error, "Couldn't get supported capabilities: ");
g_simple_async_result_take_error (ctx->result, error);
} else {
guint i;
- guint mask = MM_MODEM_CAPABILITY_NONE;
+ MMModemCapability mask = MM_MODEM_CAPABILITY_NONE;
+ MMModemCapability single;
GArray *radio_interface_list;
+ GArray *supported_combinations;
+ GArray *filtered_combinations;
qmi_message_dms_get_capabilities_output_get_info (
output,
@@ -631,23 +625,55 @@ dms_get_capabilities_ready (QmiClientDms *client,
g_array_unref (ctx->self->priv->supported_radio_interfaces);
ctx->self->priv->supported_radio_interfaces = g_array_ref (radio_interface_list);
+ supported_combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 7);
+
+ /* Add all possible supported capability combinations, we will filter
+ * them out afterwards */
+
+ /* GSM/UMTS */
+ single = MM_MODEM_CAPABILITY_GSM_UMTS;
+ g_array_append_val (supported_combinations, single);
+ /* CDMA/EVDO */
+ single = MM_MODEM_CAPABILITY_CDMA_EVDO;
+ g_array_append_val (supported_combinations, single);
+ /* LTE only */
+ single = MM_MODEM_CAPABILITY_LTE;
+ g_array_append_val (supported_combinations, single);
+ /* GSM/UMTS + CDMA/EVDO */
+ single = (MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_GSM_UMTS);
+ g_array_append_val (supported_combinations, single);
+ /* GSM/UMTS + LTE */
+ single = (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_LTE);
+ g_array_append_val (supported_combinations, single);
+ /* CDMA/EVDO + LTE */
+ single = (MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_LTE);
+ g_array_append_val (supported_combinations, single);
+ /* GSM/UMTS + CDMA/EVDO + LTE */
+ single = (MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_LTE);
+ g_array_append_val (supported_combinations, single);
+
+ /* Now filter out based on the real capabilities of the modem */
+ filtered_combinations = mm_filter_supported_capabilities (mask,
+ supported_combinations);
+ g_array_unref (supported_combinations);
+
g_simple_async_result_set_op_res_gpointer (ctx->result,
- GUINT_TO_POINTER (mask),
- NULL);
+ filtered_combinations,
+ (GDestroyNotify) g_array_unref);
}
if (output)
qmi_message_dms_get_capabilities_output_unref (output);
- load_modem_capabilities_context_complete_and_free (ctx);
+ load_supported_capabilities_context_complete_and_free (ctx);
}
static void
-modem_load_modem_capabilities (MMIfaceModem *self,
- GAsyncReadyCallback callback,
- gpointer user_data)
+modem_load_supported_capabilities (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- LoadModemCapabilitiesContext *ctx;
+ LoadSupportedCapabilitiesContext *ctx;
QmiClient *client = NULL;
if (!ensure_qmi_client (MM_BROADBAND_MODEM_QMI (self),
@@ -655,14 +681,14 @@ modem_load_modem_capabilities (MMIfaceModem *self,
callback, user_data))
return;
- ctx = g_slice_new (LoadModemCapabilitiesContext);
+ ctx = g_slice_new (LoadSupportedCapabilitiesContext);
ctx->self = g_object_ref (self);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
- modem_load_modem_capabilities);
+ modem_load_supported_capabilities);
- mm_dbg ("loading modem capabilities...");
+ mm_dbg ("loading supported capabilities...");
qmi_client_dms_get_capabilities (QMI_CLIENT_DMS (client),
NULL,
5,
@@ -8182,8 +8208,8 @@ 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 = modem_load_modem_capabilities;
- iface->load_modem_capabilities_finish = modem_load_modem_capabilities_finish;
+ iface->load_supported_capabilities = modem_load_supported_capabilities;
+ iface->load_supported_capabilities_finish = modem_load_supported_capabilities_finish;
iface->load_manufacturer = modem_load_manufacturer;
iface->load_manufacturer_finish = modem_load_manufacturer_finish;
iface->load_model = modem_load_model;
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c
index 59be9e67..9f9ad50d 100644
--- a/src/mm-iface-modem.c
+++ b/src/mm-iface-modem.c
@@ -3501,7 +3501,7 @@ static void interface_initialization_step (InitializationContext *ctx);
typedef enum {
INITIALIZATION_STEP_FIRST,
INITIALIZATION_STEP_CURRENT_CAPABILITIES,
- INITIALIZATION_STEP_MODEM_CAPABILITIES,
+ INITIALIZATION_STEP_SUPPORTED_CAPABILITIES,
INITIALIZATION_STEP_BEARERS,
INITIALIZATION_STEP_MANUFACTURER,
INITIALIZATION_STEP_MODEL,
@@ -3681,7 +3681,33 @@ load_current_capabilities_ready (MMIfaceModem *self,
interface_initialization_step (ctx);
}
-UINT_REPLY_READY_FN (modem_capabilities, "Modem Capabilities")
+static void
+load_supported_capabilities_ready (MMIfaceModem *self,
+ GAsyncResult *res,
+ InitializationContext *ctx)
+{
+ GArray *supported_capabilities;
+ GError *error = NULL;
+
+ supported_capabilities = MM_IFACE_MODEM_GET_INTERFACE (self)->load_supported_capabilities_finish (self, res, &error);
+ if (error) {
+ g_propagate_error (&ctx->fatal_error, error);
+ g_prefix_error (&ctx->fatal_error, "couldn't load supported capabilities: ");
+ /* Jump to the last step */
+ ctx->step = INITIALIZATION_STEP_LAST;
+ interface_initialization_step (ctx);
+ return;
+ }
+
+ /* Update supported caps */
+ mm_gdbus_modem_set_supported_capabilities (ctx->skeleton,
+ mm_common_capability_combinations_garray_to_variant (supported_capabilities));
+ g_array_unref (supported_capabilities);
+
+ ctx->step++;
+ interface_initialization_step (ctx);
+}
+
STR_REPLY_READY_FN (manufacturer, "Manufacturer")
STR_REPLY_READY_FN (model, "Model")
STR_REPLY_READY_FN (revision, "Revision")
@@ -3935,26 +3961,42 @@ interface_initialization_step (InitializationContext *ctx)
/* Fall down to next step */
ctx->step++;
- case INITIALIZATION_STEP_MODEM_CAPABILITIES:
- /* Modem capabilities are meant to be loaded only once during the whole
+ case INITIALIZATION_STEP_SUPPORTED_CAPABILITIES: {
+ GArray *supported_capabilities;
+
+ supported_capabilities = (mm_common_capability_combinations_variant_to_garray (
+ mm_gdbus_modem_get_supported_capabilities (ctx->skeleton)));
+
+ /* Supported capabilities are meant to be loaded only once during the whole
* lifetime of the modem. Therefore, if we already have them loaded,
* don't try to load them again. */
- if (mm_gdbus_modem_get_modem_capabilities (ctx->skeleton) == MM_MODEM_CAPABILITY_NONE &&
- MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_modem_capabilities &&
- MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_modem_capabilities_finish) {
- MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_modem_capabilities (
- ctx->self,
- (GAsyncReadyCallback)load_modem_capabilities_ready,
- ctx);
- return;
+ if (supported_capabilities->len == 0 ||
+ g_array_index (supported_capabilities, MMModemCapability, 0) == MM_MODEM_CAPABILITY_NONE) {
+ MMModemCapability current;
+
+ if (MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_supported_capabilities &&
+ MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_supported_capabilities_finish) {
+ MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_supported_capabilities (
+ ctx->self,
+ (GAsyncReadyCallback)load_supported_capabilities_ready,
+ ctx);
+ return;
+ }
+
+ /* If no specific way of getting modem capabilities, default to the current ones */
+ g_array_unref (supported_capabilities);
+ supported_capabilities = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 1);
+ current = mm_gdbus_modem_get_current_capabilities (ctx->skeleton);
+ g_array_append_val (supported_capabilities, current);
+ mm_gdbus_modem_set_supported_capabilities (
+ ctx->skeleton,
+ mm_common_capability_combinations_garray_to_variant (supported_capabilities));
}
- /* If no specific way of getting modem capabilities, assume they are
- * equal to the current capabilities */
- mm_gdbus_modem_set_modem_capabilities (
- ctx->skeleton,
- mm_gdbus_modem_get_current_capabilities (ctx->skeleton));
+ g_array_unref (supported_capabilities);
+
/* Fall down to next step */
ctx->step++;
+ }
case INITIALIZATION_STEP_BEARERS: {
MMBearerList *list = NULL;
@@ -4318,8 +4360,8 @@ mm_iface_modem_initialize (MMIfaceModem *self,
/* Set all initial property defaults */
mm_gdbus_modem_set_sim (skeleton, NULL);
+ mm_gdbus_modem_set_supported_capabilities (skeleton, mm_common_build_capability_combinations_none ());
mm_gdbus_modem_set_current_capabilities (skeleton, MM_MODEM_CAPABILITY_NONE);
- mm_gdbus_modem_set_modem_capabilities (skeleton, MM_MODEM_CAPABILITY_NONE);
mm_gdbus_modem_set_max_bearers (skeleton, 0);
mm_gdbus_modem_set_max_active_bearers (skeleton, 0);
mm_gdbus_modem_set_manufacturer (skeleton, NULL);
diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h
index 8ba1da66..8f87bc6b 100644
--- a/src/mm-iface-modem.h
+++ b/src/mm-iface-modem.h
@@ -42,13 +42,13 @@ typedef struct _MMIfaceModem MMIfaceModem;
struct _MMIfaceModem {
GTypeInterface g_iface;
- /* Loading of the ModemCapabilities property */
- void (*load_modem_capabilities) (MMIfaceModem *self,
- GAsyncReadyCallback callback,
- gpointer user_data);
- MMModemCapability (*load_modem_capabilities_finish) (MMIfaceModem *self,
- GAsyncResult *res,
- GError **error);
+ /* Loading of the SupportedCapabilities property */
+ void (*load_supported_capabilities) (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ GArray * (*load_supported_capabilities_finish) (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error);
/* Loading of the CurrentCapabilities property */
void (*load_current_capabilities) (MMIfaceModem *self,
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 6d0acb20..cd4ef763 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -295,6 +295,34 @@ mm_filter_supported_modes (const GArray *all,
/*****************************************************************************/
+GArray *
+mm_filter_supported_capabilities (MMModemCapability all,
+ const GArray *supported_combinations)
+{
+ guint i;
+ GArray *filtered_combinations;
+
+ g_return_val_if_fail (all != MM_MODEM_CAPABILITY_NONE, NULL);
+ g_return_val_if_fail (supported_combinations != NULL, NULL);
+
+ /* We will filter out all combinations which have modes not listed in 'all' */
+ filtered_combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), supported_combinations->len);
+ for (i = 0; i < supported_combinations->len; i++) {
+ MMModemCapability capability;
+
+ capability = g_array_index (supported_combinations, MMModemCapability, i);
+ if (!(capability & ~all))
+ g_array_append_val (filtered_combinations, capability);
+ }
+
+ if (filtered_combinations->len == 0)
+ mm_warn ("All supported capability combinations were filtered out.");
+
+ return filtered_combinations;
+}
+
+/*****************************************************************************/
+
/* +CREG: <stat> (GSM 07.07 CREG=1 unsolicited) */
#define CREG1 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9])"
diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h
index ce7c66d1..a1f12329 100644
--- a/src/mm-modem-helpers.h
+++ b/src/mm-modem-helpers.h
@@ -76,6 +76,9 @@ gchar *mm_new_iso8601_time (guint year,
GArray *mm_filter_supported_modes (const GArray *all,
const GArray *supported_combinations);
+GArray *mm_filter_supported_capabilities (MMModemCapability all,
+ const GArray *supported_combinations);
+
/*****************************************************************************/
/* 3GPP specific helpers and utilities */
/*****************************************************************************/
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index c61f190c..f988dfaa 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -2053,6 +2053,98 @@ test_supported_mode_filter (void *f, gpointer d)
/*****************************************************************************/
+static gboolean
+find_capability_combination (GArray *capabilities,
+ MMModemCapability capability)
+{
+ guint i;
+
+ for (i = 0; i < capabilities->len; i++) {
+ MMModemCapability capability_i;
+
+ capability_i = g_array_index (capabilities, MMModemCapability, i);
+ if (capability_i == capability)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+test_supported_capability_filter (void *f, gpointer d)
+{
+ MMModemCapability capability;
+ GArray *combinations;
+ GArray *filtered;
+
+ combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 6);
+
+ /* GSM/UMTS only */
+ capability = MM_MODEM_CAPABILITY_GSM_UMTS;
+ g_array_append_val (combinations, capability);
+ /* CDMA/EVDO only */
+ capability = MM_MODEM_CAPABILITY_CDMA_EVDO;
+ g_array_append_val (combinations, capability);
+ /* GSM/UMTS and CDMA/EVDO */
+ capability = (MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_GSM_UMTS);
+ g_array_append_val (combinations, capability);
+ /* GSM/UMTS+LTE */
+ capability = (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_LTE);
+ g_array_append_val (combinations, capability);
+ /* CDMA/EVDO+LTE */
+ capability = (MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_LTE);
+ g_array_append_val (combinations, capability);
+ /* GSM/UMTS+CDMA/EVDO+LTE */
+ capability = (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_LTE);
+ g_array_append_val (combinations, capability);
+
+ /* Only GSM-UMTS supported */
+ filtered = mm_filter_supported_capabilities (MM_MODEM_CAPABILITY_GSM_UMTS, combinations);
+ g_assert_cmpuint (filtered->len, ==, 1);
+ g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_GSM_UMTS));
+ g_array_unref (filtered);
+
+ /* Only CDMA-EVDO supported */
+ filtered = mm_filter_supported_capabilities (MM_MODEM_CAPABILITY_CDMA_EVDO, combinations);
+ g_assert_cmpuint (filtered->len, ==, 1);
+ g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_CDMA_EVDO));
+ g_array_unref (filtered);
+
+ /* GSM-UMTS and CDMA-EVDO supported */
+ filtered = mm_filter_supported_capabilities ((MM_MODEM_CAPABILITY_CDMA_EVDO |
+ MM_MODEM_CAPABILITY_GSM_UMTS),
+ combinations);
+ g_assert_cmpuint (filtered->len, ==, 3);
+ g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_CDMA_EVDO));
+ g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_GSM_UMTS));
+ g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS |
+ MM_MODEM_CAPABILITY_CDMA_EVDO)));
+ g_array_unref (filtered);
+
+ /* GSM-UMTS, CDMA-EVDO and LTE supported */
+ filtered = mm_filter_supported_capabilities ((MM_MODEM_CAPABILITY_CDMA_EVDO |
+ MM_MODEM_CAPABILITY_GSM_UMTS |
+ MM_MODEM_CAPABILITY_LTE),
+ combinations);
+ g_assert_cmpuint (filtered->len, ==, 6);
+ g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_CDMA_EVDO));
+ g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_GSM_UMTS));
+ g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS |
+ MM_MODEM_CAPABILITY_CDMA_EVDO)));
+ g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS |
+ MM_MODEM_CAPABILITY_LTE)));
+ g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_CDMA_EVDO |
+ MM_MODEM_CAPABILITY_LTE)));
+ g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS |
+ MM_MODEM_CAPABILITY_CDMA_EVDO |
+ MM_MODEM_CAPABILITY_LTE)));
+ g_array_unref (filtered);
+
+ g_array_unref (combinations);
+}
+
+/*****************************************************************************/
+
void
_mm_log (const char *loc,
const char *func,
@@ -2184,6 +2276,8 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_supported_mode_filter, NULL));
+ g_test_suite_add (suite, TESTCASE (test_supported_capability_filter, NULL));
+
result = g_test_run ();
reg_test_data_free (reg_data);