diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-05-29 12:41:49 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-06-05 19:15:14 +0200 |
commit | 45ceba76924f184ed9e12ba3d35e00a55ad3a197 (patch) | |
tree | c413d3e29a64eb86340e964ec48e67d8a66c6f76 /plugins/simtech/mm-broadband-modem-simtech.c | |
parent | 212d00c529ee07131bf3b71a8759dca49292c059 (diff) |
api,introspection: 'SupportedModes' is now a list of possible combinations
Instead of just a mask of MMModemMode values, we now provide a list of the
allowed and preferred mode combinations supported by the modem. E.g.:
$> sudo mmcli -m 0
-------------------------
Modes | supported: 'allowed: 2g; preferred: none
| allowed: 3g; preferred: none
| allowed: 2g, 3g; preferred: none
| allowed: 2g, 3g; preferred: 2g
| allowed: 2g, 3g; preferred: 3g
| allowed: 4g; preferred: none
| allowed: 2g, 3g, 4g; preferred: none'
Diffstat (limited to 'plugins/simtech/mm-broadband-modem-simtech.c')
-rw-r--r-- | plugins/simtech/mm-broadband-modem-simtech.c | 109 |
1 files changed, 102 insertions, 7 deletions
diff --git a/plugins/simtech/mm-broadband-modem-simtech.c b/plugins/simtech/mm-broadband-modem-simtech.c index 359dde50..f7353d88 100644 --- a/plugins/simtech/mm-broadband-modem-simtech.c +++ b/plugins/simtech/mm-broadband-modem-simtech.c @@ -37,11 +37,12 @@ static void iface_modem_init (MMIfaceModem *iface); static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface); +static MMIfaceModem *iface_modem_parent; static MMIfaceModem3gpp *iface_modem_3gpp_parent; G_DEFINE_TYPE_EXTENDED (MMBroadbandModemSimtech, mm_broadband_modem_simtech, MM_TYPE_BROADBAND_MODEM, 0, G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init)); + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init)) /*****************************************************************************/ /* Setup/Cleanup unsolicited events (3GPP interface) */ @@ -445,6 +446,87 @@ load_access_technologies (MMIfaceModem *self, } /*****************************************************************************/ +/* Load supported modes (Modem interface) */ + +static GArray * +load_supported_modes_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) + return NULL; + + return g_array_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); +} + +static void +parent_load_supported_modes_ready (MMIfaceModem *self, + GAsyncResult *res, + GSimpleAsyncResult *simple) +{ + GError *error = NULL; + GArray *all; + GArray *combinations; + GArray *filtered; + MMModemModeCombination mode; + + all = iface_modem_parent->load_supported_modes_finish (self, res, &error); + if (!all) { + g_simple_async_result_take_error (simple, error); + g_simple_async_result_complete (simple); + g_object_unref (simple); + return; + } + + /* Build list of combinations */ + combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 5); + /* 2G only */ + mode.allowed = MM_MODEM_MODE_2G; + mode.preferred = MM_MODEM_MODE_NONE; + g_array_append_val (combinations, mode); + /* 3G only */ + mode.allowed = MM_MODEM_MODE_3G; + mode.preferred = MM_MODEM_MODE_NONE; + g_array_append_val (combinations, mode); + /* 2G and 3G */ + mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); + mode.preferred = MM_MODEM_MODE_NONE; + g_array_append_val (combinations, mode); + /* 2G and 3G, 2G preferred */ + mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); + mode.preferred = MM_MODEM_MODE_2G; + g_array_append_val (combinations, mode); + /* 2G and 3G, 3G preferred */ + mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); + mode.preferred = MM_MODEM_MODE_3G; + g_array_append_val (combinations, mode); + + /* Filter out those unsupported modes */ + filtered = mm_filter_supported_modes (all, combinations); + g_array_unref (all); + g_array_unref (combinations); + + g_simple_async_result_set_op_res_gpointer (simple, filtered, (GDestroyNotify) g_array_unref); + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +static void +load_supported_modes (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + /* Run parent's loading */ + iface_modem_parent->load_supported_modes ( + MM_IFACE_MODEM (self), + (GAsyncReadyCallback)parent_load_supported_modes_ready, + g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + load_supported_modes)); +} + +/*****************************************************************************/ /* Load initial allowed/preferred modes (Modem interface) */ typedef struct { @@ -731,19 +813,28 @@ set_allowed_modes (MMIfaceModem *self, user_data, set_allowed_modes); - ctx->nmp = 2; /* automatic mode preference */ - ctx->naop = 0; /* automatic acquisition order */ + /* Defaults: automatic search */ + ctx->nmp = 2; + ctx->naop = 0; - if (allowed == MM_MODEM_MODE_2G) + if (allowed == MM_MODEM_MODE_ANY && + preferred == MM_MODEM_MODE_NONE) { + /* defaults nmp and naop */ + } else if (allowed == MM_MODEM_MODE_2G) { ctx->nmp = 13; - else if (allowed == MM_MODEM_MODE_3G) + ctx->naop = 0; + } else if (allowed == MM_MODEM_MODE_3G) { ctx->nmp = 14; - else if (allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) { + ctx->naop = 0; + } else if (allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) { + /* default nmp */ if (preferred == MM_MODEM_MODE_2G) ctx->naop = 3; else if (preferred == MM_MODEM_MODE_3G) ctx->naop = 2; - /* else, auto */ + else + /* default naop */ + ctx->naop = 0; } else { gchar *allowed_str; gchar *preferred_str; @@ -830,8 +921,12 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface) static void iface_modem_init (MMIfaceModem *iface) { + iface_modem_parent = g_type_interface_peek_parent (iface); + iface->load_access_technologies = load_access_technologies; iface->load_access_technologies_finish = load_access_technologies_finish; + iface->load_supported_modes = load_supported_modes; + iface->load_supported_modes_finish = load_supported_modes_finish; iface->load_allowed_modes = load_allowed_modes; iface->load_allowed_modes_finish = load_allowed_modes_finish; iface->set_allowed_modes = set_allowed_modes; |