diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2022-12-08 13:37:55 +0000 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2023-01-03 13:56:25 +0000 |
commit | e14b904cbd6816cb0227d519d308ae71ddaf6e07 (patch) | |
tree | 4997ab68cc606fdf4d72a571e821cec0c8df42ef /src/plugins/linktop | |
parent | 072d7ac9065f444e83b390a1e2af5471ac0d48f6 (diff) |
build: move plugins directory to src/plugins
We are going to allow including the plugin sources built within the
ModemManager daemon binary; moving the sources within the daemon
sources directory makes it easier.
Diffstat (limited to 'src/plugins/linktop')
-rw-r--r-- | src/plugins/linktop/77-mm-linktop-port-types.rules | 16 | ||||
-rw-r--r-- | src/plugins/linktop/mm-broadband-modem-linktop.c | 269 | ||||
-rw-r--r-- | src/plugins/linktop/mm-broadband-modem-linktop.h | 49 | ||||
-rw-r--r-- | src/plugins/linktop/mm-modem-helpers-linktop.c | 54 | ||||
-rw-r--r-- | src/plugins/linktop/mm-modem-helpers-linktop.h | 40 | ||||
-rw-r--r-- | src/plugins/linktop/mm-plugin-linktop.c | 79 | ||||
-rw-r--r-- | src/plugins/linktop/mm-plugin-linktop.h | 42 | ||||
-rw-r--r-- | src/plugins/linktop/tests/test-modem-helpers-linktop.c | 71 |
8 files changed, 620 insertions, 0 deletions
diff --git a/src/plugins/linktop/77-mm-linktop-port-types.rules b/src/plugins/linktop/77-mm-linktop-port-types.rules new file mode 100644 index 00000000..dc2ef0d6 --- /dev/null +++ b/src/plugins/linktop/77-mm-linktop-port-types.rules @@ -0,0 +1,16 @@ +# do not edit this file, it will be overwritten on update + +ACTION!="add|change|move|bind", GOTO="mm_linktop_end" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="230d", GOTO="mm_linktop_generic" +GOTO="mm_linktop_end" + +LABEL="mm_linktop_generic" +SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInterfaceNumber}" + +# Linktop HSPADataCard +# ttyACM0 (if #1): Data port +# ttyACM1 (if #3): Primary AT port +ATTRS{idVendor}=="230d", ATTRS{idProduct}=="0001", ENV{.MM_USBIFNUM}=="01", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_AT_PPP}="1" +ATTRS{idVendor}=="230d", ATTRS{idProduct}=="0001", ENV{.MM_USBIFNUM}=="03", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" + +LABEL="mm_linktop_end" diff --git a/src/plugins/linktop/mm-broadband-modem-linktop.c b/src/plugins/linktop/mm-broadband-modem-linktop.c new file mode 100644 index 00000000..a83682c8 --- /dev/null +++ b/src/plugins/linktop/mm-broadband-modem-linktop.c @@ -0,0 +1,269 @@ +/* -*- 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) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2012 Red Hat, Inc. + * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org> + */ + +#include <config.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <ctype.h> + +#define _LIBMM_INSIDE_MM +#include <libmm-glib.h> + +#include "ModemManager.h" +#include "mm-serial-parsers.h" +#include "mm-modem-helpers.h" +#include "mm-iface-modem.h" +#include "mm-base-modem-at.h" +#include "mm-broadband-modem-linktop.h" +#include "mm-modem-helpers-linktop.h" + +static void iface_modem_init (MMIfaceModem *iface); + +static MMIfaceModem *iface_modem_parent; + +G_DEFINE_TYPE_EXTENDED (MMBroadbandModemLinktop, mm_broadband_modem_linktop, MM_TYPE_BROADBAND_MODEM, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)) + +/*****************************************************************************/ +/* Load supported modes (Modem interface) */ + +static GArray * +load_supported_modes_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_pointer (G_TASK (res), error); +} + +static void +parent_load_supported_modes_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) +{ + 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_task_return_error (task, error); + g_object_unref (task); + return; + } + + /* Build list of combinations */ + combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 3); + + /* 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); + + /* Filter out those unsupported modes */ + filtered = mm_filter_supported_modes (all, combinations, self); + g_array_unref (all); + g_array_unref (combinations); + + g_task_return_pointer (task, filtered, (GDestroyNotify) g_array_unref); + g_object_unref (task); +} + +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_task_new (self, NULL, callback, user_data)); +} + +/*****************************************************************************/ +/* Load initial allowed/preferred modes (Modem interface) */ + +static gboolean +load_current_modes_finish (MMIfaceModem *self, + GAsyncResult *res, + MMModemMode *allowed, + MMModemMode *preferred, + GError **error) +{ + const gchar *response; + + response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error); + if (!response || !mm_linktop_parse_cfun_query_current_modes (response, allowed, error)) + return FALSE; + + /* None preferred always */ + *preferred = MM_MODEM_MODE_NONE; + + return TRUE; +} + +static void +load_current_modes (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + mm_base_modem_at_command (MM_BASE_MODEM (self), + "+CFUN?", + 3, + FALSE, + callback, + user_data); +} + +/*****************************************************************************/ +/* Set allowed modes (Modem interface) */ + +static gboolean +set_current_modes_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +allowed_mode_update_ready (MMBroadbandModemLinktop *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); + if (error) + /* Let the error be critical. */ + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + + g_object_unref (task); +} + +static void +set_current_modes (MMIfaceModem *self, + MMModemMode allowed, + MMModemMode preferred, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + gchar *command; + gint linktop_mode = -1; + + task = g_task_new (self, NULL, callback, user_data); + + if (allowed == MM_MODEM_MODE_2G) + linktop_mode = LINKTOP_MODE_2G; + else if (allowed == MM_MODEM_MODE_3G) + linktop_mode = LINKTOP_MODE_3G; + else if ((allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) && + (preferred == MM_MODEM_MODE_NONE)) + linktop_mode = LINKTOP_MODE_ANY; + else if ((allowed == MM_MODEM_MODE_ANY && + preferred == MM_MODEM_MODE_NONE)) + linktop_mode = LINKTOP_MODE_ANY; + + if (linktop_mode < 0) { + gchar *allowed_str; + gchar *preferred_str; + + allowed_str = mm_modem_mode_build_string_from_mask (allowed); + preferred_str = mm_modem_mode_build_string_from_mask (preferred); + g_task_return_new_error (task, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Requested mode (allowed: '%s', preferred: '%s') not " + "supported by the modem.", + allowed_str, + preferred_str); + g_object_unref (task); + g_free (allowed_str); + g_free (preferred_str); + return; + } + + command = g_strdup_printf ("AT+CFUN=%d", linktop_mode); + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + command, + 3, + FALSE, + (GAsyncReadyCallback)allowed_mode_update_ready, + task); + g_free (command); +} + +/*****************************************************************************/ + +MMBroadbandModemLinktop * +mm_broadband_modem_linktop_new (const gchar *device, + const gchar **drivers, + const gchar *plugin, + guint16 vendor_id, + guint16 product_id) +{ + return g_object_new (MM_TYPE_BROADBAND_MODEM_LINKTOP, + MM_BASE_MODEM_DEVICE, device, + MM_BASE_MODEM_DRIVERS, drivers, + MM_BASE_MODEM_PLUGIN, plugin, + MM_BASE_MODEM_VENDOR_ID, vendor_id, + MM_BASE_MODEM_PRODUCT_ID, product_id, + /* Generic bearer supports AT only */ + MM_BASE_MODEM_DATA_NET_SUPPORTED, FALSE, + MM_BASE_MODEM_DATA_TTY_SUPPORTED, TRUE, + NULL); +} + +static void +mm_broadband_modem_linktop_init (MMBroadbandModemLinktop *self) +{ +} + +static void +iface_modem_init (MMIfaceModem *iface) +{ + iface_modem_parent = g_type_interface_peek_parent (iface); + + iface->load_supported_modes = load_supported_modes; + iface->load_supported_modes_finish = load_supported_modes_finish; + iface->load_current_modes = load_current_modes; + 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; +} + +static void +mm_broadband_modem_linktop_class_init (MMBroadbandModemLinktopClass *klass) +{ +} diff --git a/src/plugins/linktop/mm-broadband-modem-linktop.h b/src/plugins/linktop/mm-broadband-modem-linktop.h new file mode 100644 index 00000000..385a20b8 --- /dev/null +++ b/src/plugins/linktop/mm-broadband-modem-linktop.h @@ -0,0 +1,49 @@ +/* -*- 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) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2012 Red Hat, Inc. + * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org> + */ + +#ifndef MM_BROADBAND_MODEM_LINKTOP_H +#define MM_BROADBAND_MODEM_LINKTOP_H + +#include "mm-broadband-modem.h" + +#define MM_TYPE_BROADBAND_MODEM_LINKTOP (mm_broadband_modem_linktop_get_type ()) +#define MM_BROADBAND_MODEM_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_LINKTOP, MMBroadbandModemLinktop)) +#define MM_BROADBAND_MODEM_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_LINKTOP, MMBroadbandModemLinktopClass)) +#define MM_IS_BROADBAND_MODEM_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_LINKTOP)) +#define MM_IS_BROADBAND_MODEM_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_LINKTOP)) +#define MM_BROADBAND_MODEM_LINKTOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_LINKTOP, MMBroadbandModemLinktopClass)) + +typedef struct _MMBroadbandModemLinktop MMBroadbandModemLinktop; +typedef struct _MMBroadbandModemLinktopClass MMBroadbandModemLinktopClass; + +struct _MMBroadbandModemLinktop { + MMBroadbandModem parent; +}; + +struct _MMBroadbandModemLinktopClass{ + MMBroadbandModemClass parent; +}; + +GType mm_broadband_modem_linktop_get_type (void); + +MMBroadbandModemLinktop *mm_broadband_modem_linktop_new (const gchar *device, + const gchar **drivers, + const gchar *plugin, + guint16 vendor_id, + guint16 product_id); + +#endif /* MM_BROADBAND_MODEM_LINKTOP_H */ diff --git a/src/plugins/linktop/mm-modem-helpers-linktop.c b/src/plugins/linktop/mm-modem-helpers-linktop.c new file mode 100644 index 00000000..2ca46bb6 --- /dev/null +++ b/src/plugins/linktop/mm-modem-helpers-linktop.c @@ -0,0 +1,54 @@ +/* -*- 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) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2016 Red Hat, Inc. + * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es> + */ + +#include "mm-modem-helpers.h" +#include "mm-modem-helpers-linktop.h" + +/*****************************************************************************/ + +gboolean +mm_linktop_parse_cfun_query_current_modes (const gchar *response, + MMModemMode *allowed, + GError **error) +{ + guint state; + + g_assert (allowed); + + if (!mm_3gpp_parse_cfun_query_response (response, &state, error)) + return FALSE; + + switch (state) { + case LINKTOP_MODE_OFFLINE: + case LINKTOP_MODE_LOW_POWER: + *allowed = MM_MODEM_MODE_NONE; + return TRUE; + case LINKTOP_MODE_2G: + *allowed = MM_MODEM_MODE_2G; + return TRUE; + case LINKTOP_MODE_3G: + *allowed = MM_MODEM_MODE_3G; + return TRUE; + case LINKTOP_MODE_ANY: + *allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); + return TRUE; + default: + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Unknown linktop +CFUN current mode: %u", state); + return FALSE; + } +} diff --git a/src/plugins/linktop/mm-modem-helpers-linktop.h b/src/plugins/linktop/mm-modem-helpers-linktop.h new file mode 100644 index 00000000..69fa7ee2 --- /dev/null +++ b/src/plugins/linktop/mm-modem-helpers-linktop.h @@ -0,0 +1,40 @@ +/* -*- 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) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2016 Red Hat, Inc. + * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es> + */ + +#ifndef MM_MODEM_HELPERS_LINKTOP_H +#define MM_MODEM_HELPERS_LINKTOP_H + +#include <glib.h> + +#include <ModemManager.h> +#define _LIBMM_INSIDE_MM +#include <libmm-glib.h> + +typedef enum { + LINKTOP_MODE_OFFLINE = 0, + LINKTOP_MODE_ANY = 1, + LINKTOP_MODE_LOW_POWER = 4, + LINKTOP_MODE_2G = 5, + LINKTOP_MODE_3G = 6, +} MMLinktopMode; + +/* AT+CFUN? response parsers */ +gboolean mm_linktop_parse_cfun_query_current_modes (const gchar *response, + MMModemMode *allowed, + GError **error); + +#endif /* MM_MODEM_HELPERS_LINKTOP_H */ diff --git a/src/plugins/linktop/mm-plugin-linktop.c b/src/plugins/linktop/mm-plugin-linktop.c new file mode 100644 index 00000000..8276e59f --- /dev/null +++ b/src/plugins/linktop/mm-plugin-linktop.c @@ -0,0 +1,79 @@ +/* -*- 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) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2012 Red Hat, Inc. + * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org> + */ + +#include <string.h> +#include <gmodule.h> + +#define _LIBMM_INSIDE_MM +#include <libmm-glib.h> + +#include "mm-plugin-linktop.h" +#include "mm-broadband-modem-linktop.h" + +G_DEFINE_TYPE (MMPluginLinktop, mm_plugin_linktop, MM_TYPE_PLUGIN) + +MM_PLUGIN_DEFINE_MAJOR_VERSION +MM_PLUGIN_DEFINE_MINOR_VERSION + +/*****************************************************************************/ + +static MMBaseModem * +create_modem (MMPlugin *self, + const gchar *uid, + const gchar **drivers, + guint16 vendor, + guint16 product, + guint16 subsystem_vendor, + GList *probes, + GError **error) +{ + return MM_BASE_MODEM (mm_broadband_modem_linktop_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); +} + +/*****************************************************************************/ + +G_MODULE_EXPORT MMPlugin * +mm_plugin_create (void) +{ + static const gchar *subsystems[] = { "tty", NULL }; + static const guint16 vendor_ids[] = { 0x230d, 0 }; + + return MM_PLUGIN ( + g_object_new (MM_TYPE_PLUGIN_LINKTOP, + MM_PLUGIN_NAME, MM_MODULE_NAME, + MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, + MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, + MM_PLUGIN_ALLOWED_AT, TRUE, + NULL)); +} + +static void +mm_plugin_linktop_init (MMPluginLinktop *self) +{ +} + +static void +mm_plugin_linktop_class_init (MMPluginLinktopClass *klass) +{ + MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass); + + plugin_class->create_modem = create_modem; +} diff --git a/src/plugins/linktop/mm-plugin-linktop.h b/src/plugins/linktop/mm-plugin-linktop.h new file mode 100644 index 00000000..6c8e5789 --- /dev/null +++ b/src/plugins/linktop/mm-plugin-linktop.h @@ -0,0 +1,42 @@ +/* -*- 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) 2008 - 2009 Novell, Inc. + * Copyright (C) 2009 - 2012 Red Hat, Inc. + * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org> + */ + +#ifndef MM_PLUGIN_LINKTOP_H +#define MM_PLUGIN_LINKTOP_H + +#include "mm-plugin.h" + +#define MM_TYPE_PLUGIN_LINKTOP (mm_plugin_linktop_get_type ()) +#define MM_PLUGIN_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktop)) +#define MM_PLUGIN_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktopClass)) +#define MM_IS_PLUGIN_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_LINKTOP)) +#define MM_IS_PLUGIN_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_LINKTOP)) +#define MM_PLUGIN_LINKTOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktopClass)) + +typedef struct { + MMPlugin parent; +} MMPluginLinktop; + +typedef struct { + MMPluginClass parent; +} MMPluginLinktopClass; + +GType mm_plugin_linktop_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_LINKTOP_H */ diff --git a/src/plugins/linktop/tests/test-modem-helpers-linktop.c b/src/plugins/linktop/tests/test-modem-helpers-linktop.c new file mode 100644 index 00000000..07aa8378 --- /dev/null +++ b/src/plugins/linktop/tests/test-modem-helpers-linktop.c @@ -0,0 +1,71 @@ +/* -*- 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) 2016 Aleksander Morgado <aleksander@aleksander.es> + */ + +#include <glib.h> +#include <glib-object.h> +#include <locale.h> + +#include <ModemManager.h> +#define _LIBMM_INSIDE_MM +#include <libmm-glib.h> + +#include "mm-log-test.h" +#include "mm-modem-helpers.h" +#include "mm-modem-helpers-linktop.h" + +/*****************************************************************************/ + +typedef struct { + const gchar *str; + MMModemMode allowed; +} CfunQueryCurrentModeTest; + +static const CfunQueryCurrentModeTest cfun_query_current_mode_tests[] = { + { "+CFUN: 0", MM_MODEM_MODE_NONE }, + { "+CFUN: 1", MM_MODEM_MODE_2G | MM_MODEM_MODE_3G }, + { "+CFUN: 4", MM_MODEM_MODE_NONE }, + { "+CFUN: 5", MM_MODEM_MODE_2G }, + { "+CFUN: 6", MM_MODEM_MODE_3G }, +}; + +static void +test_cfun_query_current_modes (void) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (cfun_query_current_mode_tests); i++) { + GError *error = NULL; + gboolean success; + MMModemMode allowed = MM_MODEM_MODE_NONE; + + success = mm_linktop_parse_cfun_query_current_modes (cfun_query_current_mode_tests[i].str, &allowed, &error); + g_assert_no_error (error); + g_assert (success); + g_assert_cmpuint (cfun_query_current_mode_tests[i].allowed, ==, allowed); + } +} + +/*****************************************************************************/ + +int main (int argc, char **argv) +{ + setlocale (LC_ALL, ""); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/MM/linktop/cfun/query/current-modes", test_cfun_query_current_modes); + + return g_test_run (); +} |