Files
ModemManager/plugins/mbm/tests/test-modem-helpers-mbm.c
T
Aleksander Morgado 0ebf6d5da5 mbm: query supported modes to the modem with +CFUN=?
We were trying to load the generic modes supported reported by either *CNTI=2 or
AT+WS46=?, so that then we could filter out the MBM-specific modes unsupported.

But, this may not be ideal, as both these two commands may fail:

    [mm-broadband-modem.c:1612] modem_load_supported_modes(): loading supported modes...
    [mm-port-serial.c:1237] mm_port_serial_open(): (ttyACM1) device open count is 3 (open)
    [mm-port-serial.c:1294] _close_internal(): (ttyACM1) device open count is 2 (close)
    [mm-port-serial-at.c:440] debug_log(): (ttyACM1): --> 'AT*CNTI=2<CR>'
    [mm-port-serial-at.c:440] debug_log(): (ttyACM1): <-- '<CR><LF>ERROR<CR><LF>'
    [mm-serial-parsers.c:364] mm_serial_parser_v1_parse(): Got failure code 100: Unknown error
    [mm-broadband-modem.c:1546] supported_modes_cnti_ready(): Generic query of supported 3GPP networks with *CNTI failed: 'Unknown error'
    [mm-port-serial.c:1237] mm_port_serial_open(): (ttyACM1) device open count is 3 (open)
    [mm-port-serial.c:1294] _close_internal(): (ttyACM1) device open count is 2 (close)
    [mm-port-serial-at.c:440] debug_log(): (ttyACM1): --> 'AT+WS46=?<CR>'
    [mm-port-serial-at.c:440] debug_log(): (ttyACM1): <-- '<CR><LF>ERROR<CR><LF>'
    [mm-serial-parsers.c:364] mm_serial_parser_v1_parse(): Got failure code 100: Unknown error
    [mm-broadband-modem.c:1494] supported_modes_ws46_test_ready(): Generic query of supported 3GPP networks with WS46=? failed: 'Unknown error'
    [mm-iface-modem.c:3974] load_supported_modes_ready(): couldn't load Supported Modes: 'Couldn't retrieve supported modes'

Instead, we'll ask the modem for the list of modes supported, and return that
directly.
2016-01-10 17:46:12 +01:00

225 lines
6.8 KiB
C

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2013 Aleksander Morgado <aleksander@gnu.org>
* Copyright (C) 2014 Dan Williams <dcbw@redhat.com>
*/
#include <glib.h>
#include <glib-object.h>
#include <locale.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ModemManager.h>
#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include "mm-log.h"
#include "mm-modem-helpers.h"
#include "mm-modem-helpers-mbm.h"
#define ENABLE_TEST_MESSAGE_TRACES
/*****************************************************************************/
/* Test *E2IPCFG responses */
typedef struct {
const gchar *str;
/* IPv4 */
const gchar *ipv4_addr;
const gchar *ipv4_gw;
const gchar *ipv4_dns1;
const gchar *ipv4_dns2;
/* IPv6 */
const gchar *ipv6_addr;
const gchar *ipv6_dns1;
const gchar *ipv6_dns2;
} E2ipcfgTest;
static const E2ipcfgTest tests[] = {
{ "*E2IPCFG: (1,\"46.157.32.246\")(2,\"46.157.32.243\")(3,\"193.213.112.4\")(3,\"130.67.15.198\")\r\n",
"46.157.32.246", "46.157.32.243", "193.213.112.4", "130.67.15.198",
NULL, NULL },
{ "*E2IPCFG: (1,\"fe80:0000:0000:0000:0000:0000:e537:1801\")(3,\"2001:4600:0004:0fff:0000:0000:0000:0054\")(3,\"2001:4600:0004:1fff:0000:0000:0000:0054\")\r\n",
NULL, NULL, NULL, NULL,
"fe80:0000:0000:0000:0000:0000:e537:1801", "2001:4600:0004:0fff:0000:0000:0000:0054", "2001:4600:0004:1fff:0000:0000:0000:0054" },
{ "*E2IPCFG: (1,\"fe80:0000:0000:0000:0000:0027:b7fe:9401\")(3,\"fd00:976a:0000:0000:0000:0000:0000:0009\")\r\n",
NULL, NULL, NULL, NULL,
"fe80:0000:0000:0000:0000:0027:b7fe:9401", "fd00:976a:0000:0000:0000:0000:0000:0009", NULL },
{ NULL }
};
static void
test_e2ipcfg (void)
{
guint i;
for (i = 0; tests[i].str; i++) {
gboolean success;
GError *error = NULL;
MMBearerIpConfig *ipv4 = NULL;
MMBearerIpConfig *ipv6 = NULL;
const gchar **dns;
guint dnslen;
success = mm_mbm_parse_e2ipcfg_response (tests[i].str, &ipv4, &ipv6, &error);
g_assert_no_error (error);
g_assert (success);
/* IPv4 */
if (tests[i].ipv4_addr) {
g_assert (ipv4);
g_assert_cmpint (mm_bearer_ip_config_get_method (ipv4), ==, MM_BEARER_IP_METHOD_STATIC);
g_assert_cmpstr (mm_bearer_ip_config_get_address (ipv4), ==, tests[i].ipv4_addr);
g_assert_cmpint (mm_bearer_ip_config_get_prefix (ipv4), ==, 28);
g_assert_cmpstr (mm_bearer_ip_config_get_gateway (ipv4), ==, tests[i].ipv4_gw);
dns = mm_bearer_ip_config_get_dns (ipv4);
g_assert (dns);
dnslen = g_strv_length ((gchar **) dns);
if (tests[i].ipv4_dns2 != NULL)
g_assert_cmpint (dnslen, ==, 2);
else
g_assert_cmpint (dnslen, ==, 1);
g_assert_cmpstr (dns[0], ==, tests[i].ipv4_dns1);
g_assert_cmpstr (dns[1], ==, tests[i].ipv4_dns2);
g_object_unref (ipv4);
} else
g_assert (ipv4 == NULL);
/* IPv6 */
if (tests[i].ipv6_addr) {
struct in6_addr a6;
g_assert (ipv6);
g_assert_cmpstr (mm_bearer_ip_config_get_address (ipv6), ==, tests[i].ipv6_addr);
g_assert_cmpint (mm_bearer_ip_config_get_prefix (ipv6), ==, 64);
g_assert (inet_pton (AF_INET6, mm_bearer_ip_config_get_address (ipv6), &a6));
if (IN6_IS_ADDR_LINKLOCAL (&a6))
g_assert_cmpint (mm_bearer_ip_config_get_method (ipv6), ==, MM_BEARER_IP_METHOD_DHCP);
else
g_assert_cmpint (mm_bearer_ip_config_get_method (ipv6), ==, MM_BEARER_IP_METHOD_STATIC);
dns = mm_bearer_ip_config_get_dns (ipv6);
g_assert (dns);
dnslen = g_strv_length ((gchar **) dns);
if (tests[i].ipv6_dns2 != NULL)
g_assert_cmpint (dnslen, ==, 2);
else
g_assert_cmpint (dnslen, ==, 1);
g_assert_cmpstr (dns[0], ==, tests[i].ipv6_dns1);
g_assert_cmpstr (dns[1], ==, tests[i].ipv6_dns2);
g_object_unref (ipv6);
} else
g_assert (ipv6 == NULL);
}
}
/*****************************************************************************/
/* Test +CFUN test responses */
#define MAX_MODES 32
typedef struct {
const gchar *str;
guint32 expected_mask;
} CfunTest;
static const CfunTest cfun_tests[] = {
{
"+CFUN: (0,1,4-6),(1-0)\r\n",
((1 << MBM_NETWORK_MODE_OFFLINE) |
(1 << MBM_NETWORK_MODE_ANY) |
(1 << MBM_NETWORK_MODE_LOW_POWER) |
(1 << MBM_NETWORK_MODE_2G) |
(1 << MBM_NETWORK_MODE_3G))
},
{
"+CFUN: (0,1,4-6)\r\n",
((1 << MBM_NETWORK_MODE_OFFLINE) |
(1 << MBM_NETWORK_MODE_ANY) |
(1 << MBM_NETWORK_MODE_LOW_POWER) |
(1 << MBM_NETWORK_MODE_2G) |
(1 << MBM_NETWORK_MODE_3G))
},
{
"+CFUN: (0,1,4)\r\n",
((1 << MBM_NETWORK_MODE_OFFLINE) |
(1 << MBM_NETWORK_MODE_ANY) |
(1 << MBM_NETWORK_MODE_LOW_POWER))
},
{
"+CFUN: (0,1)\r\n",
((1 << MBM_NETWORK_MODE_OFFLINE) |
(1 << MBM_NETWORK_MODE_ANY))
},
};
static void
test_cfun (void)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (cfun_tests); i++) {
guint32 mask;
gboolean success;
GError *error = NULL;
success = mm_mbm_parse_cfun_test (cfun_tests[i].str, &mask, &error);
g_assert_no_error (error);
g_assert (success);
g_assert_cmpuint (mask, ==, cfun_tests[i].expected_mask);
}
}
/*****************************************************************************/
void
_mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{
#if defined ENABLE_TEST_MESSAGE_TRACES
/* Dummy log function */
va_list args;
gchar *msg;
va_start (args, fmt);
msg = g_strdup_vprintf (fmt, args);
va_end (args);
g_print ("%s\n", msg);
g_free (msg);
#endif
}
int main (int argc, char **argv)
{
setlocale (LC_ALL, "");
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/MM/mbm/e2ipcfg", test_e2ipcfg);
g_test_add_func ("/MM/mbm/cfun", test_cfun);
return g_test_run ();
}