aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/generic
diff options
context:
space:
mode:
authorAleksander Morgado <aleksandermj@chromium.org>2022-12-08 13:37:55 +0000
committerAleksander Morgado <aleksander@aleksander.es>2023-01-03 13:56:25 +0000
commite14b904cbd6816cb0227d519d308ae71ddaf6e07 (patch)
tree4997ab68cc606fdf4d72a571e821cec0c8df42ef /src/plugins/generic
parent072d7ac9065f444e83b390a1e2af5471ac0d48f6 (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/generic')
-rw-r--r--src/plugins/generic/mm-plugin-generic.c120
-rw-r--r--src/plugins/generic/mm-plugin-generic.h40
-rw-r--r--src/plugins/generic/tests/test-service-generic.c90
3 files changed, 250 insertions, 0 deletions
diff --git a/src/plugins/generic/mm-plugin-generic.c b/src/plugins/generic/mm-plugin-generic.c
new file mode 100644
index 00000000..6dd37d59
--- /dev/null
+++ b/src/plugins/generic/mm-plugin-generic.c
@@ -0,0 +1,120 @@
+/* -*- 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 - 2010 Dan Williams <dcbw@redhat.com>
+ */
+
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <time.h>
+
+#include <gmodule.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-plugin-generic.h"
+#include "mm-broadband-modem.h"
+#include "mm-serial-parsers.h"
+#include "mm-log-object.h"
+
+#if defined WITH_QMI
+#include "mm-broadband-modem-qmi.h"
+#endif
+
+#if defined WITH_MBIM
+#include "mm-broadband-modem-mbim.h"
+#endif
+
+G_DEFINE_TYPE (MMPluginGeneric, mm_plugin_generic, 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)
+{
+#if defined WITH_QMI
+ if (mm_port_probe_list_has_qmi_port (probes)) {
+ mm_obj_dbg (self, "QMI-powered generic modem found...");
+ return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid,
+ drivers,
+ mm_plugin_get_name (self),
+ vendor,
+ product));
+ }
+#endif
+
+#if defined WITH_MBIM
+ if (mm_port_probe_list_has_mbim_port (probes)) {
+ mm_obj_dbg (self, "MBIM-powered generic modem found...");
+ return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid,
+ drivers,
+ mm_plugin_get_name (self),
+ vendor,
+ product));
+ }
+#endif
+
+ return MM_BASE_MODEM (mm_broadband_modem_new (uid,
+ drivers,
+ mm_plugin_get_name (self),
+ vendor,
+ product));
+}
+
+/*****************************************************************************/
+
+G_MODULE_EXPORT MMPlugin *
+mm_plugin_create (void)
+{
+ static const gchar *subsystems[] = { "tty", "net", "usbmisc", "wwan", NULL };
+
+ return MM_PLUGIN (
+ g_object_new (MM_TYPE_PLUGIN_GENERIC,
+ MM_PLUGIN_NAME, MM_MODULE_NAME,
+ MM_PLUGIN_IS_GENERIC, TRUE,
+ MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems,
+ MM_PLUGIN_ALLOWED_AT, TRUE,
+ MM_PLUGIN_REQUIRED_QCDM, TRUE,
+ MM_PLUGIN_ALLOWED_QMI, TRUE,
+ MM_PLUGIN_ALLOWED_MBIM, TRUE,
+ NULL));
+}
+
+static void
+mm_plugin_generic_init (MMPluginGeneric *self)
+{
+}
+
+static void
+mm_plugin_generic_class_init (MMPluginGenericClass *klass)
+{
+ MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass);
+
+ plugin_class->create_modem = create_modem;
+}
diff --git a/src/plugins/generic/mm-plugin-generic.h b/src/plugins/generic/mm-plugin-generic.h
new file mode 100644
index 00000000..12f9dd9d
--- /dev/null
+++ b/src/plugins/generic/mm-plugin-generic.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) 2009 Red Hat, Inc.
+ */
+
+#ifndef MM_PLUGIN_GENERIC_H
+#define MM_PLUGIN_GENERIC_H
+
+#include "mm-plugin.h"
+
+#define MM_TYPE_PLUGIN_GENERIC (mm_plugin_generic_get_type ())
+#define MM_PLUGIN_GENERIC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_GENERIC, MMPluginGeneric))
+#define MM_PLUGIN_GENERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_GENERIC, MMPluginGenericClass))
+#define MM_IS_PLUGIN_GENERIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_GENERIC))
+#define MM_IS_PLUGIN_GENERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_GENERIC))
+#define MM_PLUGIN_GENERIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_GENERIC, MMPluginGenericClass))
+
+typedef struct {
+ MMPlugin parent;
+} MMPluginGeneric;
+
+typedef struct {
+ MMPluginClass parent;
+} MMPluginGenericClass;
+
+GType mm_plugin_generic_get_type (void);
+
+G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
+
+#endif /* MM_PLUGIN_GENERIC_H */
diff --git a/src/plugins/generic/tests/test-service-generic.c b/src/plugins/generic/tests/test-service-generic.c
new file mode 100644
index 00000000..d7bc4e01
--- /dev/null
+++ b/src/plugins/generic/tests/test-service-generic.c
@@ -0,0 +1,90 @@
+/* -*- 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@gnu.org>
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <libmm-glib.h>
+
+#include "test-port-context.h"
+#include "test-fixture.h"
+
+/*****************************************************************************/
+
+static void
+test_enable_disable (TestFixture *fixture)
+{
+ GError *error = NULL;
+ MMObject *obj;
+ MMModem *modem;
+ TestPortContext *port0;
+ gchar *ports [] = { NULL, NULL };
+
+ /* Create port name, and add process ID so that multiple runs of this test
+ * in the same system don't clash with each other */
+ ports[0] = g_strdup_printf ("abstract:port0:%ld", (glong) getpid ());
+ g_debug ("test service generic: using abstract port at '%s'", ports[0]);
+
+ /* Setup new port context */
+ port0 = test_port_context_new (ports[0]);
+ test_port_context_load_commands (port0, COMMON_GSM_PORT_CONF);
+ test_port_context_start (port0);
+
+ /* Ensure no modem is modem exported */
+ test_fixture_no_modem (fixture);
+
+ /* Set the test profile */
+ test_fixture_set_profile (fixture,
+ "test-enable-disable",
+ "generic",
+ (const gchar *const *)ports);
+
+ /* Wait and get the modem object */
+ obj = test_fixture_get_modem (fixture);
+
+ /* Get Modem interface, and enable */
+ modem = mm_object_get_modem (obj);
+ g_assert (modem != NULL);
+ mm_modem_enable_sync (modem, NULL, &error);
+ g_assert_no_error (error);
+
+ /* And disable */
+ mm_modem_disable_sync (modem, NULL, &error);
+ g_assert_no_error (error);
+
+ g_object_unref (modem);
+ g_object_unref (obj);
+
+ /* Stop port context */
+ test_port_context_stop (port0);
+ test_port_context_free (port0);
+
+ g_free (ports[0]);
+}
+
+/*****************************************************************************/
+
+int main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ TEST_ADD ("/MM/Service/Generic/enable-disable", test_enable_disable);
+
+ return g_test_run ();
+}