[PATCH] [PATCH v2] [TELIT] implemented set current bands

Carlo Lobrano c.lobrano at gmail.com
Thu Mar 10 11:41:10 UTC 2016


---

Hello,

I fixed the usage of mm_base_at_command_finish and the other changes
required in the previous code review. Hope everything is fine now.

Thanks,
Carlo

---
 data/ModemManager.service.in                      |   2 +-
 plugins/telit/mm-broadband-modem-telit.c          | 294 +++++++++++++++-------
 plugins/telit/mm-modem-helpers-telit.c            |  85 +++++++
 plugins/telit/mm-modem-helpers-telit.h            |   1 +
 plugins/telit/tests/test-mm-modem-helpers-telit.c | 191 ++++++++++++++
 5 files changed, 484 insertions(+), 89 deletions(-)

diff --git a/data/ModemManager.service.in b/data/ModemManager.service.in
index 9fe3a3b..81923e8 100644
--- a/data/ModemManager.service.in
+++ b/data/ModemManager.service.in
@@ -5,7 +5,7 @@ After=syslog.target
 [Service]
 Type=dbus
 BusName=org.freedesktop.ModemManager1
-ExecStart=@sbindir@/ModemManager
+ExecStart=@sbindir@/ModemManager --debug --log-level=DEBUG --log-file=/tmp/modemmanager.log
 StandardError=null
 Restart=on-abort
 
diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c
index 0127314..47a4d7b 100644
--- a/plugins/telit/mm-broadband-modem-telit.c
+++ b/plugins/telit/mm-broadband-modem-telit.c
@@ -30,6 +30,7 @@
 #include "mm-base-modem-at.h"
 #include "mm-iface-modem.h"
 #include "mm-iface-modem-3gpp.h"
+#include "mm-common-helpers.h"
 #include "mm-broadband-modem-telit.h"
 #include "mm-modem-helpers-telit.h"
 
@@ -43,6 +44,121 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemTelit, mm_broadband_modem_telit, MM_TYPE
                         G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init));
 
 /*****************************************************************************/
+/* Set current bands (Modem interface) */
+
+static gboolean
+modem_set_current_bands_finish (MMIfaceModem *self,
+                                GAsyncResult *res,
+                                GError **error)
+{
+    return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+modem_set_current_bands_ready (MMIfaceModem *self,
+                               GAsyncResult *res,
+                               GSimpleAsyncResult *simple)
+{
+    GError *error = NULL;
+
+    mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+    if (error) {
+        g_simple_async_result_take_error (simple, error);
+    } else {
+        g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+    }
+
+    g_simple_async_result_complete (simple);
+    g_object_unref (simple);
+}
+
+static void
+modem_set_current_bands (MMIfaceModem *self,
+                         GArray *bands_array,
+                         GAsyncReadyCallback callback,
+                         gpointer user_data)
+{
+    gchar *cmd;
+    gint flag2g;
+    gint flag3g;
+    gint flag4g;
+    gboolean is_2g;
+    gboolean is_3g;
+    gboolean is_4g;
+    GSimpleAsyncResult *res;
+
+    mm_telit_get_band_flag (bands_array, &flag2g, &flag3g, &flag4g);
+
+    is_2g = mm_iface_modem_is_2g (self);
+    is_3g = mm_iface_modem_is_3g (self);
+    is_4g = mm_iface_modem_is_4g (self);
+
+    if (is_2g && flag2g == -1) {
+        g_simple_async_report_error_in_idle (G_OBJECT (self),
+                                             callback,
+                                             user_data,
+                                             MM_CORE_ERROR,
+                                             MM_CORE_ERROR_NOT_FOUND,
+                                             "None or invalid 2G bands combination in the provided list");
+        return;
+    }
+
+    if (is_3g && flag3g == -1) {
+        g_simple_async_report_error_in_idle (G_OBJECT (self),
+                                             callback,
+                                             user_data,
+                                             MM_CORE_ERROR,
+                                             MM_CORE_ERROR_NOT_FOUND,
+                                             "None or invalid 3G bands combination in the provided list");
+        return;
+    }
+
+    if (is_4g && flag4g == -1) {
+        g_simple_async_report_error_in_idle (G_OBJECT (self),
+                                             callback,
+                                             user_data,
+                                             MM_CORE_ERROR,
+                                             MM_CORE_ERROR_NOT_FOUND,
+                                             "None or invalid 4G bands combination in the provided list");
+        return;
+    }
+
+    cmd = NULL;
+    if (is_2g && !is_3g && !is_4g)
+        cmd = g_strdup_printf ("AT#BND=%d", flag2g);
+    else if (is_2g && is_3g && !is_4g)
+        cmd = g_strdup_printf ("AT#BND=%d,%d", flag2g, flag3g);
+    else if (is_2g && is_3g && is_4g)
+        cmd = g_strdup_printf ("AT#BND=%d,%d,%d", flag2g, flag3g, flag4g);
+    else if (!is_2g && !is_3g && is_4g)
+        cmd = g_strdup_printf ("AT#BND=0,0,%d", flag4g);
+    else if (!is_2g && is_3g && is_4g)
+        cmd = g_strdup_printf ("AT#BND=0,%d,%d", flag3g, flag4g);
+    else if (is_2g && !is_3g && is_4g)
+        cmd = g_strdup_printf ("AT#BND=%d,0,%d", flag2g, flag4g);
+    else {
+        g_simple_async_report_error_in_idle (G_OBJECT (self),
+                                             callback,
+                                             user_data,
+                                             MM_CORE_ERROR,
+                                             MM_CORE_ERROR_FAILED,
+                                             "Unexpectd error: could not compose AT#BND command");
+        return;
+    }
+    res = g_simple_async_result_new (G_OBJECT (self),
+                                     callback,
+                                     user_data,
+                                     modem_set_current_bands);
+    mm_base_modem_at_command (MM_BASE_MODEM (self),
+                              cmd,
+                              20,
+                              FALSE,
+                              (GAsyncReadyCallback)modem_set_current_bands_ready,
+                              res);
+    g_free (cmd);
+}
+
+/*****************************************************************************/
 /* Load current bands (Modem interface) */
 
 typedef struct {
@@ -72,7 +188,7 @@ modem_load_bands_finish (MMIfaceModem *self,
         return NULL;
 
     return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
-                                       G_SIMPLE_ASYNC_RESULT (res)));
+                                                                              G_SIMPLE_ASYNC_RESULT (res)));
 }
 
 static void
@@ -209,7 +325,7 @@ modem_load_unlock_retries_finish (MMIfaceModem *self,
         return NULL;
 
     return (MMUnlockRetries*) g_object_ref (g_simple_async_result_get_op_res_gpointer (
-                                                G_SIMPLE_ASYNC_RESULT (res)));
+                                                                                       G_SIMPLE_ASYNC_RESULT (res)));
 }
 
 static void
@@ -436,20 +552,20 @@ response_processor_psnt_ignore_at_errors (MMBaseModem *self,
     mode = strchr (psnt, ',');
     if (mode) {
         switch (atoi (++mode)) {
-        case 0:
-            *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_GPRS);
-            return TRUE;
-        case 1:
-            *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EDGE);
-            return TRUE;
-        case 2:
-            *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_UMTS);
-            return TRUE;
-        case 3:
-            *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_HSDPA);
-            return TRUE;
-        default:
-            break;
+            case 0:
+                *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_GPRS);
+                return TRUE;
+            case 1:
+                *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EDGE);
+                return TRUE;
+            case 2:
+                *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_UMTS);
+                return TRUE;
+            case 3:
+                *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_HSDPA);
+                return TRUE;
+            default:
+                break;
         }
     }
 
@@ -484,17 +600,17 @@ response_processor_service_ignore_at_errors (MMBaseModem *self,
     mode = strchr (service, ',');
     if (mode) {
         switch (atoi (++mode)) {
-        case 1:
-            *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
-            return TRUE;
-        case 2:
-            *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0);
-            return TRUE;
-        case 3:
-            *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EVDOA);
-            return TRUE;
-        default:
-            break;
+            case 1:
+                *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
+                return TRUE;
+            case 2:
+                *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0);
+                return TRUE;
+            case 3:
+                *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EVDOA);
+                return TRUE;
+            default:
+                break;
         }
     }
 
@@ -519,12 +635,12 @@ load_access_technologies (MMIfaceModem *self,
 {
     mm_dbg ("loading access technology (Telit)...");
     mm_base_modem_at_sequence (
-        MM_BASE_MODEM (self),
-        access_tech_commands,
-        NULL, /* response_processor_context */
-        NULL, /* response_processor_context_free */
-        callback,
-        user_data);
+                               MM_BASE_MODEM (self),
+                               access_tech_commands,
+                               NULL, /* response_processor_context */
+                               NULL, /* response_processor_context_free */
+                               callback,
+                               user_data);
 }
 
 /*****************************************************************************/
@@ -549,11 +665,11 @@ setup_flow_control (MMIfaceModem *self,
     guint flow_control = 1; /* Default flow control: XON/XOFF */
 
     switch (mm_base_modem_get_product_id (MM_BASE_MODEM (self)) & 0xFFFF) {
-    case 0x0021:
-        flow_control = 2; /* Telit IMC modems support only RTS/CTS mode */
-        break;
-    default:
-        break;
+        case 0x0021:
+            flow_control = 2; /* Telit IMC modems support only RTS/CTS mode */
+            break;
+        default:
+            break;
     }
 
     cmd = g_strdup_printf ("+IFC=%u,%u", flow_control, flow_control);
@@ -604,32 +720,32 @@ load_current_modes_finish (MMIfaceModem *self,
 
     *preferred = MM_MODEM_MODE_NONE;
     switch (a) {
-    case 12:
-        *allowed = MM_MODEM_MODE_2G;
-        return TRUE;
-    case 22:
-        *allowed = MM_MODEM_MODE_3G;
-        return TRUE;
-    case 25:
-        if (mm_iface_modem_is_3gpp_lte (self))
-            *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G);
-        else
+        case 12:
+            *allowed = MM_MODEM_MODE_2G;
+            return TRUE;
+        case 22:
+            *allowed = MM_MODEM_MODE_3G;
+            return TRUE;
+        case 25:
+            if (mm_iface_modem_is_3gpp_lte (self))
+                *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G);
+            else
+                *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
+            return TRUE;
+        case 28:
+            *allowed = MM_MODEM_MODE_4G;
+            return TRUE;
+        case 29:
             *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
-        return TRUE;
-    case 28:
-        *allowed = MM_MODEM_MODE_4G;
-        return TRUE;
-    case 29:
-        *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
-        return TRUE;
-    case 30:
-        *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_4G);
-        return TRUE;
-    case 31:
-        *allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_4G);
-        return TRUE;
-    default:
-        break;
+            return TRUE;
+        case 30:
+            *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_4G);
+            return TRUE;
+        case 31:
+            *allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_4G);
+            return TRUE;
+        default:
+            break;
     }
 
     g_set_error (error,
@@ -740,12 +856,12 @@ set_current_modes (MMIfaceModem *self,
 
     command = g_strdup_printf ("AT+WS46=%d", ws46_mode);
     mm_base_modem_at_command (
-        MM_BASE_MODEM (self),
-        command,
-        10,
-        FALSE,
-        (GAsyncReadyCallback)ws46_set_ready,
-        result);
+                              MM_BASE_MODEM (self),
+                              command,
+                              10,
+                              FALSE,
+                              (GAsyncReadyCallback)ws46_set_ready,
+                              result);
     g_free (command);
 }
 
@@ -839,12 +955,12 @@ load_supported_modes (MMIfaceModem *self,
 {
     /* 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));
+                                              MM_IFACE_MODEM (self),
+                                              (GAsyncReadyCallback)parent_load_supported_modes_ready,
+                                              g_simple_async_result_new (G_OBJECT (self),
+                                                                         callback,
+                                                                         user_data,
+                                                                         load_supported_modes));
 }
 
 /*****************************************************************************/
@@ -855,7 +971,7 @@ modem_3gpp_enable_unsolicited_events_finish (MMIfaceModem3gpp *self,
                                              GAsyncResult *res,
                                              GError **error)
 {
-   /* Ignore errors */
+    /* Ignore errors */
     mm_base_modem_at_sequence_full_finish (MM_BASE_MODEM (self),
                                            res,
                                            NULL,
@@ -877,24 +993,24 @@ modem_3gpp_enable_unsolicited_events (MMIfaceModem3gpp *self,
                                       gpointer user_data)
 {
     mm_base_modem_at_sequence_full (
-        MM_BASE_MODEM (self),
-        mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)),
-        unsolicited_enable_sequence,
-        NULL,  /* response_processor_context */
-        NULL,  /* response_processor_context_free */
-        NULL,  /* cancellable */
-        callback,
-        user_data);
+                                    MM_BASE_MODEM (self),
+                                    mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)),
+                                    unsolicited_enable_sequence,
+                                    NULL,  /* response_processor_context */
+                                    NULL,  /* response_processor_context_free */
+                                    NULL,  /* cancellable */
+                                    callback,
+                                    user_data);
 }
 
 /*****************************************************************************/
 
 MMBroadbandModemTelit *
 mm_broadband_modem_telit_new (const gchar *device,
-                             const gchar **drivers,
-                             const gchar *plugin,
-                             guint16 vendor_id,
-                             guint16 product_id)
+                              const gchar **drivers,
+                              const gchar *plugin,
+                              guint16 vendor_id,
+                              guint16 product_id)
 {
     return g_object_new (MM_TYPE_BROADBAND_MODEM_TELIT,
                          MM_BASE_MODEM_DEVICE, device,
@@ -915,6 +1031,8 @@ iface_modem_init (MMIfaceModem *iface)
 {
     iface_modem_parent = g_type_interface_peek_parent (iface);
 
+    iface->set_current_bands = modem_set_current_bands;
+    iface->set_current_bands_finish = modem_set_current_bands_finish;
     iface->load_current_bands = modem_load_current_bands;
     iface->load_current_bands_finish = modem_load_bands_finish;
     iface->load_supported_bands = modem_load_supported_bands;
diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c
index ae7f8e7..80065fb 100644
--- a/plugins/telit/mm-modem-helpers-telit.c
+++ b/plugins/telit/mm-modem-helpers-telit.c
@@ -26,6 +26,91 @@
 #include "mm-modem-helpers.h"
 #include "mm-modem-helpers-telit.h"
 
+
+/*****************************************************************************/
+/* Set current bands helpers */
+
+void
+mm_telit_get_band_flag (GArray *bands_array,
+                        gint *flag2g,
+                        gint *flag3g,
+                        gint *flag4g)
+{
+    guint mask_2g = 0;
+    guint mask3g = 0;
+    guint mask4g = 0;
+    guint found4g = FALSE;
+    guint i;
+
+    for (i = 0; i < bands_array->len; i++) {
+        MMModemBand band = g_array_index(bands_array, MMModemBand, i);
+
+        if (flag2g != NULL &&
+            band > MM_MODEM_BAND_UNKNOWN && band <= MM_MODEM_BAND_G850) {
+            mask_2g += 1 << band;
+        }
+
+        if (flag3g != NULL &&
+            band >= MM_MODEM_BAND_U2100 && band <= MM_MODEM_BAND_U2600) {
+            mask3g += 1 << band;
+        }
+
+         if (flag4g != NULL &&
+             band >= MM_MODEM_BAND_EUTRAN_I && band <= MM_MODEM_BAND_EUTRAN_XLIV) {
+             mask4g += 1 << (band - MM_MODEM_BAND_EUTRAN_I);
+             found4g = TRUE;
+        }
+    }
+
+    /* Get 2G flag */
+    if (flag2g != NULL) {
+        if (mask_2g == ((1 << MM_MODEM_BAND_EGSM) + (1 << MM_MODEM_BAND_DCS)))
+            *flag2g = 0;
+        else if (mask_2g == ((1 << MM_MODEM_BAND_EGSM) + (1 << MM_MODEM_BAND_PCS)))
+            *flag2g = 1;
+        else if (mask_2g == ((1 << MM_MODEM_BAND_G850) + (1 << MM_MODEM_BAND_DCS)))
+            *flag2g = 2;
+        else if (mask_2g == ((1 << MM_MODEM_BAND_G850) + (1 << MM_MODEM_BAND_PCS)))
+            *flag2g = 3;
+        else
+            *flag2g = -1;
+    }
+
+    /* Get 3G flag */
+    if (flag3g != NULL) {
+        if (mask3g == (1 << MM_MODEM_BAND_U2100))
+            *flag3g = 0;
+        else if (mask3g == (1 << MM_MODEM_BAND_U1900))
+            *flag3g = 1;
+        else if (mask3g == (1 << MM_MODEM_BAND_U850))
+            *flag3g = 2;
+        else if (mask3g == ((1 << MM_MODEM_BAND_U2100) +
+                            (1 << MM_MODEM_BAND_U1900) +
+                            (1 << MM_MODEM_BAND_U850)))
+            *flag3g = 3;
+        else if (mask3g == ((1 << MM_MODEM_BAND_U1900) +
+                            (1 << MM_MODEM_BAND_U850)))
+            *flag3g = 4;
+        else if (mask3g == (1 << MM_MODEM_BAND_U900))
+            *flag3g = 5;
+        else if (mask3g == ((1 << MM_MODEM_BAND_U2100) +
+                            (1 << MM_MODEM_BAND_U900)))
+            *flag3g = 6;
+        else if (mask3g == (1 << MM_MODEM_BAND_U17IV))
+            *flag3g = 7;
+        else
+            *flag3g = -1;
+    }
+
+    /* 4G flag correspond to the mask */
+    if (flag4g != NULL) {
+        if (found4g)
+            *flag4g = mask4g;
+        else
+            *flag4g = -1;
+    }
+}
+
 /*****************************************************************************/
 /* +CSIM response parser */
 
diff --git a/plugins/telit/mm-modem-helpers-telit.h b/plugins/telit/mm-modem-helpers-telit.h
index a7e250e..75bd6ad 100644
--- a/plugins/telit/mm-modem-helpers-telit.h
+++ b/plugins/telit/mm-modem-helpers-telit.h
@@ -97,4 +97,5 @@ gboolean mm_telit_update_2g_bands(gchar *band_list, GMatchInfo **match_info, GAr
 gboolean mm_telit_update_3g_bands(gchar *band_list, GMatchInfo **match_info, GArray **bands, GError **error);
 gboolean mm_telit_update_4g_bands(GArray** bands, GMatchInfo *match_info, GError **error);
 
+void mm_telit_get_band_flag (GArray *bands_array, gint *flag_2g, gint *flag_3g, gint *flag_4g);
 #endif  /* MM_MODEM_HELPERS_TELIT_H */
diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c
index cac10fb..bfdde89 100644
--- a/plugins/telit/tests/test-mm-modem-helpers-telit.c
+++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c
@@ -313,8 +313,196 @@ test_parse_current_bands_response (void) {
     }
 }
 
+static void
+test_telit_get_2g_bnd_flag (void)
+{
+    GArray *bands_array;
+    gint flag2g;
+    MMModemBand egsm = MM_MODEM_BAND_EGSM;
+    MMModemBand dcs = MM_MODEM_BAND_DCS;
+    MMModemBand pcs = MM_MODEM_BAND_PCS;
+    MMModemBand g850 = MM_MODEM_BAND_G850;
+
+    /* Test Flag 0 */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, egsm);
+    g_array_append_val (bands_array, dcs);
+
+    mm_telit_get_band_flag (bands_array, &flag2g, NULL, NULL);
+    g_assert_cmpuint (flag2g, ==, 0);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 1 */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, egsm);
+    g_array_append_val (bands_array, pcs);
+
+    mm_telit_get_band_flag (bands_array, &flag2g, NULL, NULL);
+    g_assert_cmpuint (flag2g, ==, 1);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 2 */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, g850);
+    g_array_append_val (bands_array, dcs);
+
+    mm_telit_get_band_flag (bands_array, &flag2g, NULL, NULL);
+    g_assert_cmpuint (flag2g, ==, 2);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 3 */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, g850);
+    g_array_append_val (bands_array, pcs);
+
+    mm_telit_get_band_flag (bands_array, &flag2g, NULL, NULL);
+    g_assert_cmpuint (flag2g, ==, 3);
+    g_array_free (bands_array, TRUE);
+
+    /* Test invalid band array */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, g850);
+    g_array_append_val (bands_array, egsm);
+
+    mm_telit_get_band_flag (bands_array, &flag2g, NULL, NULL);
+    g_assert_cmpuint (flag2g, ==, -1);
+    g_array_free (bands_array, TRUE);
+}
 
 
+static void
+test_telit_get_3g_bnd_flag (void)
+{
+    GArray *bands_array;
+    MMModemBand u2100 = MM_MODEM_BAND_U2100;
+    MMModemBand u1900 = MM_MODEM_BAND_U1900;
+    MMModemBand u850 = MM_MODEM_BAND_U850;
+    MMModemBand u900 = MM_MODEM_BAND_U900;
+    MMModemBand u17iv = MM_MODEM_BAND_U17IV;
+    MMModemBand u17ix = MM_MODEM_BAND_U17IX;
+    gint flag;
+
+    /* Test flag 0 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, u2100);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 0);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 1 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, u1900);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 1);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 2 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, u850);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 2);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 3 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 3);
+    g_array_append_val (bands_array, u2100);
+    g_array_append_val (bands_array, u1900);
+    g_array_append_val (bands_array, u850);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 3);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 4 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, u1900);
+    g_array_append_val (bands_array, u850);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 4);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 5 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, u900);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 5);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 6 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, u2100);
+    g_array_append_val (bands_array, u900);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 6);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 7 */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, u17iv);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, 7);
+    g_array_free (bands_array, TRUE);
+
+    /* Test invalid band array */
+    flag = -1;
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, u17ix);
+
+    mm_telit_get_band_flag (bands_array, NULL, &flag, NULL);
+    g_assert_cmpint (flag, ==, -1);
+    g_array_free (bands_array, TRUE);
+}
+
+static void
+test_telit_get_4g_bnd_flag (void)
+{
+    GArray *bands_array;
+    MMModemBand eutran_i = MM_MODEM_BAND_EUTRAN_I;
+    MMModemBand eutran_ii = MM_MODEM_BAND_EUTRAN_II;
+    MMModemBand egsm = MM_MODEM_BAND_EGSM;
+    gint flag = -1;
+
+    /* Test flag 1 */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, eutran_i);
+
+    mm_telit_get_band_flag (bands_array, NULL, NULL, &flag);
+    g_assert_cmpint (flag, ==, 1);
+    g_array_free (bands_array, TRUE);
+
+    /* Test flag 3 */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 2);
+    g_array_append_val (bands_array, eutran_i);
+    g_array_append_val (bands_array, eutran_ii);
+
+    mm_telit_get_band_flag (bands_array, NULL, NULL, &flag);
+    g_assert_cmpint (flag, ==, 3);
+    g_array_free (bands_array, TRUE);
+
+    /* Test invalid bands array */
+    bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 1);
+    g_array_append_val (bands_array, egsm);
+
+    mm_telit_get_band_flag (bands_array, NULL, NULL, &flag);
+    g_assert_cmpint (flag, ==, -1);
+    g_array_free (bands_array, TRUE);
+}
+
 int main (int argc, char **argv)
 {
     setlocale (LC_ALL, "");
@@ -327,5 +515,8 @@ int main (int argc, char **argv)
     g_test_add_func ("/MM/telit/bands/supported/parse_band_flag", test_parse_band_flag_str);
     g_test_add_func ("/MM/telit/bands/supported/parse_bands_response", test_parse_supported_bands_response);
     g_test_add_func ("/MM/telit/bands/current/parse_bands_response", test_parse_current_bands_response);
+    g_test_add_func ("/MM/telit/bands/current/set_bands/2g", test_telit_get_2g_bnd_flag);
+    g_test_add_func ("/MM/telit/bands/current/set_bands/3g", test_telit_get_3g_bnd_flag);
+    g_test_add_func ("/MM/telit/bands/current/set_bands/4g", test_telit_get_4g_bnd_flag);
     return g_test_run ();
 }
-- 
2.1.4



More information about the ModemManager-devel mailing list