diff options
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.c | 170 | ||||
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.h | 6 | ||||
-rw-r--r-- | plugins/ublox/tests/test-modem-helpers-ublox.c | 69 |
3 files changed, 242 insertions, 3 deletions
diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c index 9df85dc3..f60a1459 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.c +++ b/plugins/ublox/mm-modem-helpers-ublox.c @@ -819,6 +819,176 @@ mm_ublox_get_modem_mode_any (const GArray *combinations) } /*****************************************************************************/ +/* UACT common config */ + +typedef struct { + guint num; + MMModemBand band; +} UactBandConfig; + +static const UactBandConfig uact_band_config[] = { + /* GSM bands */ + { .num = 900, .band = MM_MODEM_BAND_EGSM }, + { .num = 1800, .band = MM_MODEM_BAND_DCS }, + { .num = 1900, .band = MM_MODEM_BAND_PCS }, + { .num = 850, .band = MM_MODEM_BAND_G850 }, + { .num = 450, .band = MM_MODEM_BAND_G450 }, + { .num = 480, .band = MM_MODEM_BAND_G480 }, + { .num = 750, .band = MM_MODEM_BAND_G750 }, + { .num = 380, .band = MM_MODEM_BAND_G380 }, + { .num = 410, .band = MM_MODEM_BAND_G410 }, + { .num = 710, .band = MM_MODEM_BAND_G710 }, + { .num = 810, .band = MM_MODEM_BAND_G810 }, + /* UMTS bands */ + { .num = 1, .band = MM_MODEM_BAND_UTRAN_1 }, + { .num = 2, .band = MM_MODEM_BAND_UTRAN_2 }, + { .num = 3, .band = MM_MODEM_BAND_UTRAN_3 }, + { .num = 4, .band = MM_MODEM_BAND_UTRAN_4 }, + { .num = 5, .band = MM_MODEM_BAND_UTRAN_5 }, + { .num = 6, .band = MM_MODEM_BAND_UTRAN_6 }, + { .num = 7, .band = MM_MODEM_BAND_UTRAN_7 }, + { .num = 8, .band = MM_MODEM_BAND_UTRAN_8 }, + { .num = 9, .band = MM_MODEM_BAND_UTRAN_9 }, + { .num = 10, .band = MM_MODEM_BAND_UTRAN_10 }, + { .num = 11, .band = MM_MODEM_BAND_UTRAN_11 }, + { .num = 12, .band = MM_MODEM_BAND_UTRAN_12 }, + { .num = 13, .band = MM_MODEM_BAND_UTRAN_13 }, + { .num = 14, .band = MM_MODEM_BAND_UTRAN_14 }, + { .num = 19, .band = MM_MODEM_BAND_UTRAN_19 }, + { .num = 20, .band = MM_MODEM_BAND_UTRAN_20 }, + { .num = 21, .band = MM_MODEM_BAND_UTRAN_21 }, + { .num = 22, .band = MM_MODEM_BAND_UTRAN_22 }, + { .num = 25, .band = MM_MODEM_BAND_UTRAN_25 }, + /* LTE bands */ + { .num = 101, .band = MM_MODEM_BAND_EUTRAN_1 }, + { .num = 102, .band = MM_MODEM_BAND_EUTRAN_2 }, + { .num = 103, .band = MM_MODEM_BAND_EUTRAN_3 }, + { .num = 104, .band = MM_MODEM_BAND_EUTRAN_4 }, + { .num = 105, .band = MM_MODEM_BAND_EUTRAN_5 }, + { .num = 106, .band = MM_MODEM_BAND_EUTRAN_6 }, + { .num = 107, .band = MM_MODEM_BAND_EUTRAN_7 }, + { .num = 108, .band = MM_MODEM_BAND_EUTRAN_8 }, + { .num = 109, .band = MM_MODEM_BAND_EUTRAN_9 }, + { .num = 110, .band = MM_MODEM_BAND_EUTRAN_10 }, + { .num = 111, .band = MM_MODEM_BAND_EUTRAN_11 }, + { .num = 112, .band = MM_MODEM_BAND_EUTRAN_12 }, + { .num = 113, .band = MM_MODEM_BAND_EUTRAN_13 }, + { .num = 114, .band = MM_MODEM_BAND_EUTRAN_14 }, + { .num = 117, .band = MM_MODEM_BAND_EUTRAN_17 }, + { .num = 118, .band = MM_MODEM_BAND_EUTRAN_18 }, + { .num = 119, .band = MM_MODEM_BAND_EUTRAN_19 }, + { .num = 120, .band = MM_MODEM_BAND_EUTRAN_20 }, + { .num = 121, .band = MM_MODEM_BAND_EUTRAN_21 }, + { .num = 122, .band = MM_MODEM_BAND_EUTRAN_22 }, + { .num = 123, .band = MM_MODEM_BAND_EUTRAN_23 }, + { .num = 124, .band = MM_MODEM_BAND_EUTRAN_24 }, + { .num = 125, .band = MM_MODEM_BAND_EUTRAN_25 }, + { .num = 126, .band = MM_MODEM_BAND_EUTRAN_26 }, + { .num = 127, .band = MM_MODEM_BAND_EUTRAN_27 }, + { .num = 128, .band = MM_MODEM_BAND_EUTRAN_28 }, + { .num = 129, .band = MM_MODEM_BAND_EUTRAN_29 }, + { .num = 130, .band = MM_MODEM_BAND_EUTRAN_30 }, + { .num = 131, .band = MM_MODEM_BAND_EUTRAN_31 }, + { .num = 132, .band = MM_MODEM_BAND_EUTRAN_32 }, + { .num = 133, .band = MM_MODEM_BAND_EUTRAN_33 }, + { .num = 134, .band = MM_MODEM_BAND_EUTRAN_34 }, + { .num = 135, .band = MM_MODEM_BAND_EUTRAN_35 }, + { .num = 136, .band = MM_MODEM_BAND_EUTRAN_36 }, + { .num = 137, .band = MM_MODEM_BAND_EUTRAN_37 }, + { .num = 138, .band = MM_MODEM_BAND_EUTRAN_38 }, + { .num = 139, .band = MM_MODEM_BAND_EUTRAN_39 }, + { .num = 140, .band = MM_MODEM_BAND_EUTRAN_40 }, + { .num = 141, .band = MM_MODEM_BAND_EUTRAN_41 }, + { .num = 142, .band = MM_MODEM_BAND_EUTRAN_42 }, + { .num = 143, .band = MM_MODEM_BAND_EUTRAN_43 }, + { .num = 144, .band = MM_MODEM_BAND_EUTRAN_44 }, + { .num = 145, .band = MM_MODEM_BAND_EUTRAN_45 }, + { .num = 146, .band = MM_MODEM_BAND_EUTRAN_46 }, + { .num = 147, .band = MM_MODEM_BAND_EUTRAN_47 }, + { .num = 148, .band = MM_MODEM_BAND_EUTRAN_48 }, +}; + +static MMModemBand +uact_num_to_band (guint num) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (uact_band_config); i++) { + if (num == uact_band_config[i].num) + return uact_band_config[i].band; + } + return MM_MODEM_BAND_UNKNOWN; +} + +/*****************************************************************************/ +/* UACT? response parser */ + +static GArray * +uact_num_array_to_band_array (GArray *nums) +{ + GArray *bands = NULL; + guint i; + + if (!nums) + return NULL; + + bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), nums->len); + for (i = 0; i < nums->len; i++) { + MMModemBand band; + + band = uact_num_to_band (g_array_index (nums, guint, i)); + g_array_append_val (bands, band); + } + + return bands; +} + +GArray * +mm_ublox_parse_uact_response (const gchar *response, + GError **error) +{ + GRegex *r; + GMatchInfo *match_info; + GError *inner_error = NULL; + GArray *nums = NULL; + GArray *bands = NULL; + + /* + * AT+UACT? + * +UACT: ,,,900,1800,1,8,101,103,107,108,120,138 + */ + r = g_regex_new ("\\+UACT: ([^,]*),([^,]*),([^,]*),(.*)(?:\\r\\n)?", + G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, NULL); + g_assert (r != NULL); + + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); + if (!inner_error && g_match_info_matches (match_info)) { + gchar *bandstr; + + bandstr = mm_get_string_unquoted_from_match_info (match_info, 4); + nums = mm_parse_uint_list (bandstr, &inner_error); + g_free (bandstr); + } + + if (match_info) + g_match_info_free (match_info); + g_regex_unref (r); + + if (inner_error) { + g_propagate_error (error, inner_error); + return NULL; + } + + /* Convert to MMModemBand values */ + if (nums) { + bands = uact_num_array_to_band_array (nums); + g_array_unref (nums); + } + + return bands; +} + +/*****************************************************************************/ /* URAT? response parser */ gboolean diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h index fc25feed..cac11ade 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.h +++ b/plugins/ublox/mm-modem-helpers-ublox.h @@ -107,6 +107,12 @@ gchar *mm_ublox_build_ubandsel_set_command (GArray *bands, GError **error); /*****************************************************************************/ +/* UACT? response parser */ + +GArray *mm_ublox_parse_uact_response (const gchar *response, + 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 76330e69..587b5a38 100644 --- a/plugins/ublox/tests/test-modem-helpers-ublox.c +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -730,6 +730,68 @@ test_ubandsel_request_1800 (void) } /*****************************************************************************/ +/* Test +UACT? response parser */ + +static void +common_validate_uact_response (const gchar *str, + const MMModemBand *expected_bands, + guint n_expected_bands) +{ + GError *error = NULL; + GArray *bands; + + bands = mm_ublox_parse_uact_response (str, &error); + g_assert_no_error (error); + + common_compare_bands (bands, expected_bands, n_expected_bands); +} + +static void +test_uact_response_empty_list (void) +{ + common_validate_uact_response ("+UACT: ,,,\r\n", NULL, 0); +} + +static void +test_uact_response_2g (void) +{ + const MMModemBand expected_bands[] = { + MM_MODEM_BAND_G850, MM_MODEM_BAND_EGSM, MM_MODEM_BAND_DCS, MM_MODEM_BAND_PCS, + }; + + common_validate_uact_response ("+UACT: ,,,900,1800,1900,850\r\n", + expected_bands, G_N_ELEMENTS (expected_bands)); +} + +static void +test_uact_response_2g3g (void) +{ + const MMModemBand expected_bands[] = { + MM_MODEM_BAND_G850, MM_MODEM_BAND_EGSM, MM_MODEM_BAND_DCS, MM_MODEM_BAND_PCS, + MM_MODEM_BAND_UTRAN_1, MM_MODEM_BAND_UTRAN_2, MM_MODEM_BAND_UTRAN_3, MM_MODEM_BAND_UTRAN_4, MM_MODEM_BAND_UTRAN_5, + MM_MODEM_BAND_UTRAN_6, MM_MODEM_BAND_UTRAN_7, MM_MODEM_BAND_UTRAN_8, MM_MODEM_BAND_UTRAN_9, + }; + + common_validate_uact_response ("+UACT: ,,,900,1800,1900,850,1,2,3,4,5,6,7,8,9\r\n", + expected_bands, G_N_ELEMENTS (expected_bands)); +} + +static void +test_uact_response_2g3g4g (void) +{ + const MMModemBand expected_bands[] = { + MM_MODEM_BAND_G850, MM_MODEM_BAND_EGSM, MM_MODEM_BAND_DCS, MM_MODEM_BAND_PCS, + MM_MODEM_BAND_UTRAN_1, MM_MODEM_BAND_UTRAN_2, MM_MODEM_BAND_UTRAN_3, MM_MODEM_BAND_UTRAN_4, MM_MODEM_BAND_UTRAN_5, + MM_MODEM_BAND_UTRAN_6, MM_MODEM_BAND_UTRAN_7, MM_MODEM_BAND_UTRAN_8, MM_MODEM_BAND_UTRAN_9, + MM_MODEM_BAND_EUTRAN_1, MM_MODEM_BAND_EUTRAN_2, MM_MODEM_BAND_EUTRAN_3, MM_MODEM_BAND_EUTRAN_4, MM_MODEM_BAND_EUTRAN_5, + MM_MODEM_BAND_EUTRAN_6, MM_MODEM_BAND_EUTRAN_7, MM_MODEM_BAND_EUTRAN_8, MM_MODEM_BAND_EUTRAN_9, + }; + + common_validate_uact_response ("+UACT: ,,,900,1800,1900,850,1,2,3,4,5,6,7,8,9,101,102,103,104,105,106,107,108,109\r\n", + expected_bands, G_N_ELEMENTS (expected_bands)); +} + +/*****************************************************************************/ /* Test +UGCNTRD responses */ typedef struct { @@ -852,16 +914,17 @@ int main (int argc, char **argv) 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); - g_test_add_func ("/MM/ublox/ubandsel/response/one", test_ubandsel_response_one); g_test_add_func ("/MM/ublox/ubandsel/response/two", test_ubandsel_response_two); g_test_add_func ("/MM/ublox/ubandsel/response/three", test_ubandsel_response_three); g_test_add_func ("/MM/ublox/ubandsel/response/four", test_ubandsel_response_four); - g_test_add_func ("/MM/ublox/ubandsel/request/any", test_ubandsel_request_any); g_test_add_func ("/MM/ublox/ubandsel/request/2g", test_ubandsel_request_2g); g_test_add_func ("/MM/ublox/ubandsel/request/1800", test_ubandsel_request_1800); - + g_test_add_func ("/MM/ublox/uact/response/empty-list", test_uact_response_empty_list); + g_test_add_func ("/MM/ublox/uact/response/2g", test_uact_response_2g); + g_test_add_func ("/MM/ublox/uact/response/2g3g", test_uact_response_2g3g); + g_test_add_func ("/MM/ublox/uact/response/2g3g4g", test_uact_response_2g3g4g); g_test_add_func ("/MM/ublox/ugcntrd/response", test_ugcntrd_response); return g_test_run (); |