[PATCH 5/5] add plugin for the Thuraya XT satellite phone modem
Thomas Sailer
sailer at sailer.dynip.lugs.ch
Thu Feb 11 12:45:12 UTC 2016
From: Thomas Sailer <t.sailer at alumni.ethz.ch>
Signed-off-by: Thomas Sailer <t.sailer at alumni.ethz.ch>
---
plugins/Makefile.am | 25 ++
plugins/thuraya/mm-broadband-modem-thuraya.c | 295 +++++++++++++++++++++
plugins/thuraya/mm-broadband-modem-thuraya.h | 50 ++++
plugins/thuraya/mm-modem-helpers-thuraya.c | 156 +++++++++++
plugins/thuraya/mm-modem-helpers-thuraya.h | 27 ++
plugins/thuraya/mm-plugin-thuraya.c | 85 ++++++
plugins/thuraya/mm-plugin-thuraya.h | 48 ++++
.../thuraya/tests/test-mm-modem-helpers-thuraya.c | 131 +++++++++
8 files changed, 817 insertions(+)
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 3cc5e2f..f79ce9a 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -125,6 +125,7 @@ pkglib_LTLIBRARIES = \
libmm-plugin-nokia-icera.la \
libmm-plugin-cinterion.la \
libmm-plugin-iridium.la \
+ libmm-plugin-thuraya.la \
libmm-plugin-motorola.la \
libmm-plugin-novatel.la \
libmm-plugin-novatel-lte.la \
@@ -461,6 +462,30 @@ libmm_plugin_iridium_la_SOURCES = \
libmm_plugin_iridium_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
libmm_plugin_iridium_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
+# Thuraya XT
+libmm_plugin_thuraya_la_SOURCES = \
+ thuraya/mm-plugin-thuraya.c \
+ thuraya/mm-plugin-thuraya.h \
+ thuraya/mm-broadband-modem-thuraya.c \
+ thuraya/mm-broadband-modem-thuraya.h \
+ thuraya/mm-modem-helpers-thuraya.c \
+ thuraya/mm-modem-helpers-thuraya.h
+libmm_plugin_thuraya_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
+libmm_plugin_thuraya_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
+
+noinst_PROGRAMS += test-modem-helpers-thuraya
+test_modem_helpers_thuraya_SOURCES = \
+ thuraya/mm-modem-helpers-thuraya.c \
+ thuraya/mm-modem-helpers-thuraya.h \
+ thuraya/tests/test-mm-modem-helpers-thuraya.c
+test_modem_helpers_thuraya_CPPFLAGS = \
+ -I$(top_srcdir)/plugins/thuraya \
+ $(PLUGIN_COMMON_COMPILER_FLAGS)
+test_modem_helpers_thuraya_LDADD = \
+ $(top_builddir)/libmm-glib/libmm-glib.la \
+ $(top_builddir)/src/libmodem-helpers.la
+test_modem_helpers_thuraya_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
+
# Common Novatel modem support library
noinst_LTLIBRARIES += libmm-utils-novatel.la
libmm_utils_novatel_la_SOURCES = \
diff --git a/plugins/thuraya/mm-broadband-modem-thuraya.c b/plugins/thuraya/mm-broadband-modem-thuraya.c
new file mode 100644
index 0000000..3fc77f2
--- /dev/null
+++ b/plugins/thuraya/mm-broadband-modem-thuraya.c
@@ -0,0 +1,295 @@
+/* -*- 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) 2011 - 2012 Ammonit Measurement GmbH
+ * Author: Aleksander Morgado <aleksander at lanedo.com>
+ * Copyright (C) 2016 Thomas Sailer <t.sailer at alumni.ethz.ch>
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "ModemManager.h"
+#include "mm-log.h"
+#include "mm-errors-types.h"
+#include "mm-base-modem-at.h"
+#include "mm-iface-modem.h"
+#include "mm-iface-modem-3gpp.h"
+#include "mm-iface-modem-messaging.h"
+#include "mm-broadband-modem-thuraya.h"
+#include "mm-broadband-bearer.h"
+#include "mm-modem-helpers.h"
+#include "mm-modem-helpers-thuraya.h"
+
+static void iface_modem_init (MMIfaceModem *iface);
+static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface);
+static void iface_modem_messaging_init (MMIfaceModemMessaging *iface);
+
+G_DEFINE_TYPE_EXTENDED (MMBroadbandModemThuraya, mm_broadband_modem_thuraya, MM_TYPE_BROADBAND_MODEM, 0,
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_MESSAGING, iface_modem_messaging_init) );
+
+/*****************************************************************************/
+/* Operator Code and Name loading (3GPP interface) */
+
+static gchar *
+load_operator_code_finish (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ /* Only "90103" operator code is assumed */
+ return g_strdup ("90106");
+}
+
+static gchar *
+load_operator_name_finish (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ /* Only "THURAYA" operator name is assumed */
+ return g_strdup ("THURAYA");
+}
+
+static void
+load_operator_name_or_code (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_operator_name_or_code);
+ g_simple_async_result_set_op_res_gboolean (result, TRUE);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+/*****************************************************************************/
+/* Load supported modes (Modem inteface) */
+
+static GArray *
+load_supported_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return g_array_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+load_supported_modes (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GArray *combinations;
+ MMModemModeCombination mode;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_supported_modes);
+
+ /* Build list of combinations */
+ combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 1);
+
+ /* Report any, Thuraya connections are packet-switched */
+ mode.allowed = MM_MODEM_MODE_ANY;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+
+ g_simple_async_result_set_op_res_gpointer (result, combinations, (GDestroyNotify) g_array_unref);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+/*****************************************************************************/
+/* Load supported SMS storages (Messaging interface) */
+
+typedef struct {
+ GArray *mem1;
+ GArray *mem2;
+ GArray *mem3;
+} SupportedStoragesResult;
+
+static void
+supported_storages_result_free (SupportedStoragesResult *result)
+{
+ if (result->mem1)
+ g_array_unref (result->mem1);
+ if (result->mem2)
+ g_array_unref (result->mem2);
+ if (result->mem3)
+ g_array_unref (result->mem3);
+ g_free (result);
+}
+
+static gboolean
+modem_messaging_load_supported_storages_finish (MMIfaceModemMessaging *self,
+ GAsyncResult *res,
+ GArray **mem1,
+ GArray **mem2,
+ GArray **mem3,
+ GError **error)
+{
+ SupportedStoragesResult *result;
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return FALSE;
+
+ result = (SupportedStoragesResult *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+ *mem1 = g_array_ref (result->mem1);
+ *mem2 = g_array_ref (result->mem2);
+ *mem3 = g_array_ref (result->mem3);
+
+ return TRUE;
+}
+
+static void
+cpms_format_check_ready (MMBroadbandModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ const gchar *response;
+ GError *error = NULL;
+ SupportedStoragesResult *result;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (error) {
+ g_simple_async_result_take_error (simple, error);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ result = g_new0 (SupportedStoragesResult, 1);
+
+ /* Parse reply */
+ if (!mm_thuraya_3gpp_parse_cpms_test_response (response,
+ &result->mem1,
+ &result->mem2,
+ &result->mem3)) {
+ g_simple_async_result_set_error (simple,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't parse supported storages reply: '%s'",
+ response);
+ supported_storages_result_free (result);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ g_simple_async_result_set_op_res_gpointer (simple,
+ result,
+ (GDestroyNotify)supported_storages_result_free);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+modem_messaging_load_supported_storages (MMIfaceModemMessaging *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_messaging_load_supported_storages);
+
+ /* Check support storages */
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ "+CPMS=?",
+ 3,
+ TRUE,
+ (GAsyncReadyCallback)cpms_format_check_ready,
+ result);
+}
+
+/*****************************************************************************/
+
+MMBroadbandModemThuraya *
+mm_broadband_modem_thuraya_new (const gchar *device,
+ const gchar **drivers,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id)
+{
+ return g_object_new (MM_TYPE_BROADBAND_MODEM_THURAYA,
+ 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,
+ NULL);
+}
+
+static void
+mm_broadband_modem_thuraya_init (MMBroadbandModemThuraya *self)
+{
+}
+
+static void
+iface_modem_init (MMIfaceModem *iface)
+{
+ /* No need to power-up/power-down the modem */
+ iface->load_power_state = NULL;
+ iface->load_power_state_finish = NULL;
+ iface->modem_power_up = NULL;
+ iface->modem_power_up_finish = NULL;
+ iface->modem_power_down = NULL;
+ iface->modem_power_down_finish = NULL;
+
+ /* Supported modes cannot be queried */
+ iface->load_supported_modes = load_supported_modes;
+ iface->load_supported_modes_finish = load_supported_modes_finish;
+}
+
+static void
+iface_modem_3gpp_init (MMIfaceModem3gpp *iface)
+{
+ /* Fixed operator code and name to be reported */
+ iface->load_operator_name = load_operator_name_or_code;
+ iface->load_operator_name_finish = load_operator_name_finish;
+ iface->load_operator_code = load_operator_name_or_code;
+ iface->load_operator_code_finish = load_operator_code_finish;
+
+ /* Don't try to scan networks with AT+COPS=?.
+ * The Thuraya XT does not seem to properly support AT+COPS=?.
+ * When issuing this command, it seems to get sufficiently confused
+ * to drop the signal. Furthermore, it is useless anyway as there is only
+ * one network supported, Thuraya.
+ */
+ iface->scan_networks = NULL;
+ iface->scan_networks_finish = NULL;
+}
+
+static void
+iface_modem_messaging_init (MMIfaceModemMessaging *iface)
+{
+ iface->load_supported_storages = modem_messaging_load_supported_storages;
+ iface->load_supported_storages_finish = modem_messaging_load_supported_storages_finish;
+}
+
+static void
+mm_broadband_modem_thuraya_class_init (MMBroadbandModemThurayaClass *klass)
+{
+}
diff --git a/plugins/thuraya/mm-broadband-modem-thuraya.h b/plugins/thuraya/mm-broadband-modem-thuraya.h
new file mode 100644
index 0000000..42df9b9
--- /dev/null
+++ b/plugins/thuraya/mm-broadband-modem-thuraya.h
@@ -0,0 +1,50 @@
+/* -*- 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 - 2011 Red Hat, Inc.
+ * Copyright (C) 2011 Google Inc.
+ * Copyright (C) 2016 Thomas Sailer <t.sailer at alumni.ethz.ch>
+ */
+
+#ifndef MM_BROADBAND_MODEM_THURAYA_H
+#define MM_BROADBAND_MODEM_THURAYA_H
+
+#include "mm-broadband-modem.h"
+
+#define MM_TYPE_BROADBAND_MODEM_THURAYA (mm_broadband_modem_thuraya_get_type ())
+#define MM_BROADBAND_MODEM_THURAYA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_THURAYA, MMBroadbandModemThuraya))
+#define MM_BROADBAND_MODEM_THURAYA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_THURAYA, MMBroadbandModemThurayaClass))
+#define MM_IS_BROADBAND_MODEM_THURAYA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_THURAYA))
+#define MM_IS_BROADBAND_MODEM_THURAYA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_THURAYA))
+#define MM_BROADBAND_MODEM_THURAYA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_THURAYA, MMBroadbandModemThurayaClass))
+
+typedef struct _MMBroadbandModemThuraya MMBroadbandModemThuraya;
+typedef struct _MMBroadbandModemThurayaClass MMBroadbandModemThurayaClass;
+
+struct _MMBroadbandModemThuraya {
+ MMBroadbandModem parent;
+};
+
+struct _MMBroadbandModemThurayaClass{
+ MMBroadbandModemClass parent;
+};
+
+GType mm_broadband_modem_thuraya_get_type (void);
+
+MMBroadbandModemThuraya *mm_broadband_modem_thuraya_new (const gchar *device,
+ const gchar **drivers,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id);
+
+#endif /* MM_BROADBAND_MODEM_THURAYA_H */
diff --git a/plugins/thuraya/mm-modem-helpers-thuraya.c b/plugins/thuraya/mm-modem-helpers-thuraya.c
new file mode 100644
index 0000000..b940e63
--- /dev/null
+++ b/plugins/thuraya/mm-modem-helpers-thuraya.c
@@ -0,0 +1,156 @@
+/* -*- 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 Thomas Sailer <t.sailer at alumni.ethz.ch>
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <ModemManager.h>
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mm-log.h"
+#include "mm-modem-helpers.h"
+#include "mm-modem-helpers-thuraya.h"
+
+/*************************************************************************/
+
+static MMSmsStorage
+storage_from_str (const gchar *str)
+{
+ if (g_str_equal (str, "SM"))
+ return MM_SMS_STORAGE_SM;
+ if (g_str_equal (str, "ME"))
+ return MM_SMS_STORAGE_ME;
+ if (g_str_equal (str, "MT"))
+ return MM_SMS_STORAGE_MT;
+ if (g_str_equal (str, "SR"))
+ return MM_SMS_STORAGE_SR;
+ if (g_str_equal (str, "BM"))
+ return MM_SMS_STORAGE_BM;
+ if (g_str_equal (str, "TA"))
+ return MM_SMS_STORAGE_TA;
+ return MM_SMS_STORAGE_UNKNOWN;
+}
+
+gboolean
+mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply,
+ GArray **mem1,
+ GArray **mem2,
+ GArray **mem3)
+{
+#define N_EXPECTED_GROUPS 3
+
+ GRegex *r;
+ gchar **split;
+ gchar **splitp;
+ const gchar *splita[N_EXPECTED_GROUPS];
+ guint i;
+ GArray *tmp1 = NULL;
+ GArray *tmp2 = NULL;
+ GArray *tmp3 = NULL;
+
+ g_assert (mem1 != NULL);
+ g_assert (mem2 != NULL);
+ g_assert (mem3 != NULL);
+
+ split = g_strsplit (mm_strip_tag (reply, "+CPMS:"), " ", -1);
+ if (!split)
+ return FALSE;
+
+ /* remove empty strings, and count non-empty strings */
+ i = 0;
+ for (splitp = split; *splitp; ++splitp) {
+ if (!**splitp)
+ continue;
+ if (i < N_EXPECTED_GROUPS)
+ splita[i] = *splitp;
+ ++i;
+ }
+
+ if (i != N_EXPECTED_GROUPS) {
+ mm_warn ("Cannot parse +CPMS test response: invalid number of groups (%u != %u)",
+ i, N_EXPECTED_GROUPS);
+ g_strfreev (split);
+ return FALSE;
+ }
+
+ r = g_regex_new ("\\s*\"([^,\\)]+)\"\\s*", 0, 0, NULL);
+ g_assert (r);
+
+ for (i = 0; i < N_EXPECTED_GROUPS; i++) {
+ GMatchInfo *match_info = NULL;
+ GArray *array;
+
+ /* We always return a valid array, even if it may be empty */
+ array = g_array_new (FALSE, FALSE, sizeof (MMSmsStorage));
+
+ /* Got a range group to match */
+ if (g_regex_match_full (r, splita[i], strlen (splita[i]), 0, 0, &match_info, NULL)) {
+ while (g_match_info_matches (match_info)) {
+ gchar *str;
+
+ str = g_match_info_fetch (match_info, 1);
+ if (str) {
+ MMSmsStorage storage;
+
+ storage = storage_from_str (str);
+ g_array_append_val (array, storage);
+ g_free (str);
+ }
+
+ g_match_info_next (match_info, NULL);
+ }
+ }
+ g_match_info_free (match_info);
+
+ if (!tmp1)
+ tmp1 = array;
+ else if (!tmp2)
+ tmp2 = array;
+ else if (!tmp3)
+ tmp3 = array;
+ else
+ g_assert_not_reached ();
+ }
+
+ g_strfreev (split);
+ g_regex_unref (r);
+
+ g_warn_if_fail (tmp1 != NULL);
+ g_warn_if_fail (tmp2 != NULL);
+ g_warn_if_fail (tmp3 != NULL);
+
+ /* Only return TRUE if all sets have been parsed correctly
+ * (even if the arrays may be empty) */
+ if (tmp1 && tmp2 && tmp3) {
+ *mem1 = tmp1;
+ *mem2 = tmp2;
+ *mem3 = tmp3;
+ return TRUE;
+ }
+
+ /* Otherwise, cleanup and return FALSE */
+ if (tmp1)
+ g_array_unref (tmp1);
+ if (tmp2)
+ g_array_unref (tmp2);
+ if (tmp3)
+ g_array_unref (tmp3);
+ return FALSE;
+}
+
+/*****************************************************************************/
diff --git a/plugins/thuraya/mm-modem-helpers-thuraya.h b/plugins/thuraya/mm-modem-helpers-thuraya.h
new file mode 100644
index 0000000..454baf4
--- /dev/null
+++ b/plugins/thuraya/mm-modem-helpers-thuraya.h
@@ -0,0 +1,27 @@
+/* -*- 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 Thomas Sailer <t.sailer at alumni.ethz.ch>
+ *
+ */
+#ifndef MM_MODEM_HELPERS_THURAYA_H
+#define MM_MODEM_HELPERS_THURAYA_H
+
+#include <glib.h>
+
+/* AT+CPMS=? (Preferred SMS storage) response parser */
+gboolean mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply,
+ GArray **mem1,
+ GArray **mem2,
+ GArray **mem3);
+
+#endif /* MM_MODEM_HELPERS_THURAYA_H */
diff --git a/plugins/thuraya/mm-plugin-thuraya.c b/plugins/thuraya/mm-plugin-thuraya.c
new file mode 100644
index 0000000..df8a6aa
--- /dev/null
+++ b/plugins/thuraya/mm-plugin-thuraya.c
@@ -0,0 +1,85 @@
+/* -*- 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2011 - 2012 Ammonit Measurement GmbH
+ * Author: Aleksander Morgado <aleksander at lanedo.com>
+ * Copyright (C) 2016 Thomas Sailer <t.sailer at alumni.ethz.ch>
+ */
+
+#include <string.h>
+#include <gmodule.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-plugin-thuraya.h"
+#include "mm-broadband-modem.h"
+#include "mm-broadband-modem-thuraya.h"
+#include "mm-private-boxed-types.h"
+#include "mm-log.h"
+
+G_DEFINE_TYPE (MMPluginThuraya, mm_plugin_thuraya, MM_TYPE_PLUGIN)
+
+int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
+int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
+
+static MMBaseModem *
+create_modem (MMPlugin *self,
+ const gchar *sysfs_path,
+ const gchar **drivers,
+ guint16 vendor,
+ guint16 product,
+ GList *probes,
+ GError **error)
+{
+ return MM_BASE_MODEM (mm_broadband_modem_thuraya_new (sysfs_path,
+ drivers,
+ mm_plugin_get_name (self),
+ vendor,
+ product));
+}
+
+/*****************************************************************************/
+
+G_MODULE_EXPORT MMPlugin *
+mm_plugin_create (void)
+{
+ static const gchar *subsystems[] = { "tty", NULL };
+ static const gchar *vendor_strings[] = { "manufacturer apsi", NULL };
+
+ return MM_PLUGIN (
+ g_object_new (MM_TYPE_PLUGIN_THURAYA,
+ MM_PLUGIN_NAME, "Thuraya",
+ MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems,
+ MM_PLUGIN_ALLOWED_VENDOR_STRINGS, vendor_strings,
+ MM_PLUGIN_ALLOWED_AT, TRUE,
+ NULL));
+}
+
+static void
+mm_plugin_thuraya_init (MMPluginThuraya *self)
+{
+}
+
+static void
+mm_plugin_thuraya_class_init (MMPluginThurayaClass *klass)
+{
+ MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass);
+
+ plugin_class->create_modem = create_modem;
+}
diff --git a/plugins/thuraya/mm-plugin-thuraya.h b/plugins/thuraya/mm-plugin-thuraya.h
new file mode 100644
index 0000000..fb86090
--- /dev/null
+++ b/plugins/thuraya/mm-plugin-thuraya.h
@@ -0,0 +1,48 @@
+/* -*- 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2011 - 2012 Ammonit Measurement GmbH
+ * Author: Aleksander Morgado <aleksander at lanedo.com>
+ * Copyright (C) 2016 Thomas Sailer <t.sailer at alumni.ethz.ch>
+ */
+
+#ifndef MM_PLUGIN_THURAYA_H
+#define MM_PLUGIN_THURAYA_H
+
+#include "mm-plugin.h"
+
+#define MM_TYPE_PLUGIN_THURAYA (mm_plugin_thuraya_get_type ())
+#define MM_PLUGIN_THURAYA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_THURAYA, MMPluginThuraya))
+#define MM_PLUGIN_THURAYA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_THURAYA, MMPluginThurayaClass))
+#define MM_IS_PLUGIN_THURAYA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_THURAYA))
+#define MM_IS_PLUGIN_THURAYA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_THURAYA))
+#define MM_PLUGIN_THURAYA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_THURAYA, MMPluginThurayaClass))
+
+typedef struct {
+ MMPlugin parent;
+} MMPluginThuraya;
+
+typedef struct {
+ MMPluginClass parent;
+} MMPluginThurayaClass;
+
+GType mm_plugin_thuraya_get_type (void);
+
+G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
+
+#endif /* MM_PLUGIN_THURAYA_H */
diff --git a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c
new file mode 100644
index 0000000..f3a7ea4
--- /dev/null
+++ b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c
@@ -0,0 +1,131 @@
+/* -*- 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 Thomas Sailer <t.sailer at alumni.ethz.ch>
+ *
+ */
+#include <stdio.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <locale.h>
+
+#include <ModemManager.h>
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-modem-helpers.h"
+#include "mm-modem-helpers-thuraya.h"
+#include "mm-log.h"
+
+#if defined ENABLE_TEST_MESSAGE_TRACES
+#define trace(message, ...) g_print (message, ##__VA_ARGS__)
+#else
+#define trace(...)
+#endif
+
+/*****************************************************************************/
+/* Test CPMS response */
+
+static gboolean
+is_storage_supported (GArray *supported,
+ MMSmsStorage storage)
+{
+ guint i;
+
+ for (i = 0; i < supported->len; i++) {
+ if (storage == g_array_index (supported, MMSmsStorage, i))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+test_cpms_response_thuraya (void *f, gpointer d)
+{
+ /*
+ * First: ("ME","MT") 2-item group
+ * Second: "ME" 1 item
+ * Third: ("SM") 1-item group
+ */
+ const gchar *reply = "+CPMS: \"MT\",\"SM\",\"BM\",\"ME\",\"SR\", \"MT\",\"SM\",\"BM\",\"ME\",\"SR\", \"MT\",\"SM\",\"BM\",\"ME\",\"SR\" ";
+ GArray *mem1 = NULL;
+ GArray *mem2 = NULL;
+ GArray *mem3 = NULL;
+
+ trace ("\nTesting thuraya +CPMS=? response...\n");
+
+ g_assert (mm_thuraya_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
+ g_assert_cmpuint (mem1->len, ==, 5);
+ g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
+ g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_SM));
+ g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_BM));
+ g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
+ g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_SR));
+ g_assert_cmpuint (mem2->len, ==, 5);
+ g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_MT));
+ g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_SM));
+ g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_BM));
+ g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_ME));
+ g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_SR));
+ g_assert_cmpuint (mem3->len, ==, 5);
+ g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_MT));
+ g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_SM));
+ g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_BM));
+ g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_ME));
+ g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_SR));
+
+ g_array_unref (mem1);
+ g_array_unref (mem2);
+ g_array_unref (mem3);
+}
+
+/*****************************************************************************/
+
+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
+}
+
+#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (GTestFixtureFunc) t, NULL)
+
+int main (int argc, char **argv)
+{
+ GTestSuite *suite;
+ gint result;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ suite = g_test_get_root ();
+
+ g_test_suite_add (suite, TESTCASE (test_cpms_response_thuraya, NULL));
+
+ result = g_test_run ();
+
+ return result;
+}
--
2.5.0
More information about the ModemManager-devel
mailing list