diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ublox/mm-broadband-modem-ublox.c | 40 | ||||
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.c | 105 | ||||
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.h | 6 | ||||
-rw-r--r-- | plugins/ublox/tests/test-modem-helpers-ublox.c | 112 |
4 files changed, 263 insertions, 0 deletions
diff --git a/plugins/ublox/mm-broadband-modem-ublox.c b/plugins/ublox/mm-broadband-modem-ublox.c index 66056c04..8c7b2ef5 100644 --- a/plugins/ublox/mm-broadband-modem-ublox.c +++ b/plugins/ublox/mm-broadband-modem-ublox.c @@ -75,6 +75,44 @@ release_power_operation (MMBroadbandModemUblox *self) } /*****************************************************************************/ +/* Load supported bands (Modem interface) */ + +static GArray * +load_supported_bands_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return (GArray *) g_task_propagate_pointer (G_TASK (res), error); +} + +static void +load_supported_bands (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + GError *error = NULL; + GArray *bands; + + task = g_task_new (self, NULL, callback, user_data); + + /* The list of supported tasks we give here must include not only the bands + * allowed in the current AcT, but the whole list of bands allowed in all + * AcTs. This is because the list of supported bands is loaded only once + * during modem initialization. Not ideal, but the current API is like that. + * + * So, we give a predefined list of supported bands and we filter them in the + * same way we filter the allowed AcTs. + */ + bands = mm_ublox_get_supported_bands (mm_iface_modem_get_model (self), &error); + if (!bands) + g_task_return_error (task, error); + else + g_task_return_pointer (task, bands, (GDestroyNotify) g_array_unref); + g_object_unref (task); +} + +/*****************************************************************************/ /* Set allowed modes (Modem interface) */ typedef enum { @@ -850,6 +888,8 @@ iface_modem_init (MMIfaceModem *iface) iface->load_current_modes_finish = load_current_modes_finish; iface->set_current_modes = set_current_modes; iface->set_current_modes_finish = set_current_modes_finish; + iface->load_supported_bands = load_supported_bands; + iface->load_supported_bands_finish = load_supported_bands_finish; } static void diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c index 01172de4..ece45fe5 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.c +++ b/plugins/ublox/mm-modem-helpers-ublox.c @@ -540,6 +540,111 @@ mm_ublox_filter_supported_modes (const gchar *model, } /*****************************************************************************/ +/* Supported bands loading */ + +typedef struct { + guint ubandsel_value; + MMModemBand bands_2g[2]; + MMModemBand bands_3g[2]; + MMModemBand bands_4g[2]; +} BandConfiguration; + +static const BandConfiguration band_configuration[] = { + { + .ubandsel_value = 700, + .bands_4g = { MM_MODEM_BAND_EUTRAN_XIII, MM_MODEM_BAND_EUTRAN_XVII } + }, + { + .ubandsel_value = 800, + .bands_3g = { MM_MODEM_BAND_U800 }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_XX } + }, + { + .ubandsel_value = 850, + .bands_2g = { MM_MODEM_BAND_G850 }, + .bands_3g = { MM_MODEM_BAND_U850 }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_V } + }, + { + .ubandsel_value = 900, + .bands_2g = { MM_MODEM_BAND_EGSM }, + .bands_3g = { MM_MODEM_BAND_U900 }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_VIII } + }, + { + .ubandsel_value = 1500, + .bands_4g = { MM_MODEM_BAND_EUTRAN_XI } + }, + { + .ubandsel_value = 1700, + .bands_3g = { MM_MODEM_BAND_U17IV }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_IV } + }, + { + .ubandsel_value = 1800, + .bands_2g = { MM_MODEM_BAND_DCS }, + .bands_3g = { MM_MODEM_BAND_U1800 }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_III } + }, + { + .ubandsel_value = 1900, + .bands_2g = { MM_MODEM_BAND_PCS }, + .bands_3g = { MM_MODEM_BAND_U1900 }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_II } + }, + { + .ubandsel_value = 2100, + .bands_3g = { MM_MODEM_BAND_U2100 }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_I } + }, + { + .ubandsel_value = 2600, + .bands_3g = { MM_MODEM_BAND_U2600 }, + .bands_4g = { MM_MODEM_BAND_EUTRAN_VII } + }, +}; + +GArray * +mm_ublox_get_supported_bands (const gchar *model, + GError **error) +{ + MMModemMode mode; + GArray *bands; + guint i; + + mode = supported_modes_per_model (model); + + bands = g_array_new (FALSE, FALSE, sizeof (MMModemBand)); + + for (i = 0; i < G_N_ELEMENTS (band_configuration); i++) { + if ((mode & MM_MODEM_MODE_2G) && band_configuration[i].bands_2g[0]) { + bands = g_array_append_val (bands, band_configuration[i].bands_2g[0]); + if (band_configuration[i].bands_2g[1]) + bands = g_array_append_val (bands, band_configuration[i].bands_2g[1]); + } + if ((mode & MM_MODEM_MODE_3G) && band_configuration[i].bands_3g[0]) { + bands = g_array_append_val (bands, band_configuration[i].bands_3g[0]); + if (band_configuration[i].bands_3g[1]) + bands = g_array_append_val (bands, band_configuration[i].bands_3g[1]); + } + if ((mode & MM_MODEM_MODE_4G) && band_configuration[i].bands_4g[0]) { + bands = g_array_append_val (bands, band_configuration[i].bands_4g[0]); + if (band_configuration[i].bands_4g[1]) + bands = g_array_append_val (bands, band_configuration[i].bands_4g[1]); + } + } + + if (bands->len == 0) { + g_array_unref (bands); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "No valid supported bands loaded"); + return NULL; + } + + return bands; +} + +/*****************************************************************************/ /* Get mode to apply when ANY */ MMModemMode diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h index ba264a39..97a0c797 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.h +++ b/plugins/ublox/mm-modem-helpers-ublox.h @@ -89,6 +89,12 @@ GArray *mm_ublox_filter_supported_modes (const gchar *model, GError **error); /*****************************************************************************/ +/* Model-based supported bands loading */ + +GArray *mm_ublox_get_supported_bands (const gchar *model, + GError **error); + +/*****************************************************************************/ /* Get mode to apply when ANY */ MMModemMode mm_ublox_get_modem_mode_any (const GArray *combinations); diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c index 2f3994c3..497b56f7 100644 --- a/plugins/ublox/tests/test-modem-helpers-ublox.c +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -484,6 +484,114 @@ test_urat_write_command (void) } /*****************************************************************************/ +/* Supported bands */ + +static void +common_validate_supported_bands (const gchar *model, + const MMModemBand *expected_bands, + guint n_expected_bands) +{ + GError *error = NULL; + GArray *bands; + gchar *bands_str; + GArray *expected_bands_array; + gchar *expected_bands_str; + + bands = mm_ublox_get_supported_bands (model, &error); + g_assert_no_error (error); + g_assert (bands); + mm_common_bands_garray_sort (bands); + bands_str = mm_common_build_bands_string ((MMModemBand *)(bands->data), bands->len); + g_array_unref (bands); + + expected_bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), n_expected_bands); + g_array_append_vals (expected_bands_array, expected_bands, n_expected_bands); + mm_common_bands_garray_sort (expected_bands_array); + expected_bands_str = mm_common_build_bands_string ((MMModemBand *)(expected_bands_array->data), expected_bands_array->len); + g_array_unref (expected_bands_array); + + g_assert_cmpstr (bands_str, ==, expected_bands_str); + g_free (bands_str); + g_free (expected_bands_str); +} + +static void +test_supported_bands_all (void) +{ + /* All 2G, 3G and 4G bands */ + const MMModemBand expected_bands[] = { + /* 700 */ MM_MODEM_BAND_EUTRAN_XIII, MM_MODEM_BAND_EUTRAN_XVII, + /* 800 */ MM_MODEM_BAND_U800, MM_MODEM_BAND_EUTRAN_XX, + /* 850 */ MM_MODEM_BAND_G850, MM_MODEM_BAND_U850, MM_MODEM_BAND_EUTRAN_V, + /* 900 */ MM_MODEM_BAND_EGSM, MM_MODEM_BAND_U900, MM_MODEM_BAND_EUTRAN_VIII, + /* 1500 */ MM_MODEM_BAND_EUTRAN_XI, + /* 1700 */ MM_MODEM_BAND_U17IV, MM_MODEM_BAND_EUTRAN_IV, + /* 1800 */ MM_MODEM_BAND_DCS, MM_MODEM_BAND_U1800, MM_MODEM_BAND_EUTRAN_III, + /* 1900 */ MM_MODEM_BAND_PCS, MM_MODEM_BAND_U1900, MM_MODEM_BAND_EUTRAN_II, + /* 2100 */ MM_MODEM_BAND_U2100, MM_MODEM_BAND_EUTRAN_I, + /* 2600 */ MM_MODEM_BAND_U2600, MM_MODEM_BAND_EUTRAN_VII, + }; + + common_validate_supported_bands (NULL, expected_bands, G_N_ELEMENTS (expected_bands)); +} + +static void +test_supported_bands_toby_l201 (void) +{ + /* Only 3G and 4G bands */ + const MMModemBand expected_bands[] = { + /* 700 */ MM_MODEM_BAND_EUTRAN_XIII, MM_MODEM_BAND_EUTRAN_XVII, + /* 800 */ MM_MODEM_BAND_U800, MM_MODEM_BAND_EUTRAN_XX, + /* 850 */ MM_MODEM_BAND_U850, MM_MODEM_BAND_EUTRAN_V, + /* 900 */ MM_MODEM_BAND_U900, MM_MODEM_BAND_EUTRAN_VIII, + /* 1500 */ MM_MODEM_BAND_EUTRAN_XI, + /* 1700 */ MM_MODEM_BAND_U17IV, MM_MODEM_BAND_EUTRAN_IV, + /* 1800 */ MM_MODEM_BAND_U1800, MM_MODEM_BAND_EUTRAN_III, + /* 1900 */ MM_MODEM_BAND_U1900, MM_MODEM_BAND_EUTRAN_II, + /* 2100 */ MM_MODEM_BAND_U2100, MM_MODEM_BAND_EUTRAN_I, + /* 2600 */ MM_MODEM_BAND_U2600, MM_MODEM_BAND_EUTRAN_VII, + }; + + common_validate_supported_bands ("TOBY-L201", expected_bands, G_N_ELEMENTS (expected_bands)); +} + +static void +test_supported_bands_lisa_u200 (void) +{ + /* Only 2G and 3G bands */ + const MMModemBand expected_bands[] = { + /* 800 */ MM_MODEM_BAND_U800, + /* 850 */ MM_MODEM_BAND_G850, MM_MODEM_BAND_U850, + /* 900 */ MM_MODEM_BAND_EGSM, MM_MODEM_BAND_U900, + /* 1700 */ MM_MODEM_BAND_U17IV, + /* 1800 */ MM_MODEM_BAND_DCS, MM_MODEM_BAND_U1800, + /* 1900 */ MM_MODEM_BAND_PCS, MM_MODEM_BAND_U1900, + /* 2100 */ MM_MODEM_BAND_U2100, + /* 2600 */ MM_MODEM_BAND_U2600, + }; + + common_validate_supported_bands ("LISA-U200", expected_bands, G_N_ELEMENTS (expected_bands)); +} + +static void +test_supported_bands_sara_u280 (void) +{ + /* Only 3G bands */ + const MMModemBand expected_bands[] = { + /* 800 */ MM_MODEM_BAND_U800, + /* 850 */ MM_MODEM_BAND_U850, + /* 900 */ MM_MODEM_BAND_U900, + /* 1700 */ MM_MODEM_BAND_U17IV, + /* 1800 */ MM_MODEM_BAND_U1800, + /* 1900 */ MM_MODEM_BAND_U1900, + /* 2100 */ MM_MODEM_BAND_U2100, + /* 2600 */ MM_MODEM_BAND_U2600, + }; + + common_validate_supported_bands ("SARA-U280", expected_bands, G_N_ELEMENTS (expected_bands)); +} + +/*****************************************************************************/ void _mm_log (const char *loc, @@ -525,6 +633,10 @@ int main (int argc, char **argv) g_test_add_func ("/MM/ublox/urat/test/response/sara-u280", test_mode_filtering_sara_u280); g_test_add_func ("/MM/ublox/urat/read/response", test_urat_read_response); g_test_add_func ("/MM/ublox/urat/write/command", test_urat_write_command); + g_test_add_func ("/MM/ublox/supported-bands/all", test_supported_bands_all); + g_test_add_func ("/MM/ublox/supported-bands/toby-l201", test_supported_bands_toby_l201); + g_test_add_func ("/MM/ublox/supported-bands/lisa-u200", test_supported_bands_lisa_u200); + g_test_add_func ("/MM/ublox/supported-bands/sara-u280", test_supported_bands_sara_u280); return g_test_run (); } |