aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib
diff options
context:
space:
mode:
Diffstat (limited to 'libmm-glib')
-rw-r--r--libmm-glib/Makefile.am3
-rw-r--r--libmm-glib/libmm-glib.h1
-rw-r--r--libmm-glib/mm-sim-preferred-network.c167
-rw-r--r--libmm-glib/mm-sim-preferred-network.h68
-rw-r--r--libmm-glib/mm-sim.c42
-rw-r--r--libmm-glib/mm-sim.h2
6 files changed, 283 insertions, 0 deletions
diff --git a/libmm-glib/Makefile.am b/libmm-glib/Makefile.am
index 49f1e832..f33836f2 100644
--- a/libmm-glib/Makefile.am
+++ b/libmm-glib/Makefile.am
@@ -89,6 +89,8 @@ libmm_glib_la_SOURCES = \
mm-pco.c \
mm-call-audio-format.h \
mm-call-audio-format.c \
+ mm-sim-preferred-network.h \
+ mm-sim-preferred-network.c \
$(NULL)
libmm_glib_la_CPPFLAGS = \
@@ -160,6 +162,7 @@ include_HEADERS = \
mm-kernel-event-properties.h \
mm-pco.h \
mm-call-audio-format.h \
+ mm-sim-preferred-network.h \
$(NULL)
CLEANFILES =
diff --git a/libmm-glib/libmm-glib.h b/libmm-glib/libmm-glib.h
index e4504894..6572b2d3 100644
--- a/libmm-glib/libmm-glib.h
+++ b/libmm-glib/libmm-glib.h
@@ -80,6 +80,7 @@
#include <mm-signal.h>
#include <mm-kernel-event-properties.h>
#include <mm-pco.h>
+#include <mm-sim-preferred-network.h>
/* generated */
#include <mm-errors-types.h>
diff --git a/libmm-glib/mm-sim-preferred-network.c b/libmm-glib/mm-sim-preferred-network.c
new file mode 100644
index 00000000..c53239dd
--- /dev/null
+++ b/libmm-glib/mm-sim-preferred-network.c
@@ -0,0 +1,167 @@
+/* -*- 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) 2021 UROS Ltd
+ */
+
+#include "mm-sim-preferred-network.h"
+
+struct _MMSimPreferredNetwork {
+ gchar *operator_code;
+ MMModemAccessTechnology access_technology;
+};
+
+static MMSimPreferredNetwork *
+mm_sim_preferred_network_copy (MMSimPreferredNetwork *preferred_network)
+{
+ MMSimPreferredNetwork *preferred_network_copy;
+
+ preferred_network_copy = g_slice_new0 (MMSimPreferredNetwork);
+ preferred_network_copy->operator_code = g_strdup (preferred_network->operator_code);
+ preferred_network_copy->access_technology = preferred_network->access_technology;
+
+ return preferred_network_copy;
+}
+
+G_DEFINE_BOXED_TYPE (MMSimPreferredNetwork, mm_sim_preferred_network, (GBoxedCopyFunc) mm_sim_preferred_network_copy, (GBoxedFreeFunc) mm_sim_preferred_network_free)
+
+/**
+ * mm_sim_preferred_network_free:
+ * @self: A #MMSimPreferredNetwork.
+ *
+ * Frees a #MMSimPreferredNetwork.
+ *
+ * Since: 1.18
+ */
+void
+mm_sim_preferred_network_free (MMSimPreferredNetwork *self)
+{
+ if (!self)
+ return;
+
+ g_free (self->operator_code);
+ g_slice_free (MMSimPreferredNetwork, self);
+}
+
+/**
+ * mm_sim_preferred_network_get_operator_code:
+ * @self: A #MMSimPreferredNetwork.
+ *
+ * Get the operator code (MCCMNC) of the preferred network.
+ *
+ * Returns: (transfer none): The operator code, or %NULL if none available.
+ *
+ * Since: 1.18
+ */
+const gchar *
+mm_sim_preferred_network_get_operator_code (const MMSimPreferredNetwork *self)
+{
+ g_return_val_if_fail (self != NULL, NULL);
+
+ return self->operator_code;
+}
+
+/**
+ * mm_sim_preferred_network_get_access_technology:
+ * @self: A #MMSimPreferredNetwork.
+ *
+ * Get the access technology mask of the preferred network.
+ *
+ * Returns: A #MMModemAccessTechnology.
+ *
+ * Since: 1.18
+ */
+MMModemAccessTechnology
+mm_sim_preferred_network_get_access_technology (const MMSimPreferredNetwork *self)
+{
+ g_return_val_if_fail (self != NULL, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN);
+
+ return self->access_technology;
+}
+
+/**
+ * mm_sim_preferred_network_set_operator_code: (skip)
+ */
+void
+mm_sim_preferred_network_set_operator_code (MMSimPreferredNetwork *self,
+ const gchar *operator_code)
+{
+ g_return_if_fail (self != NULL);
+
+ g_free (self->operator_code);
+ self->operator_code = g_strdup (operator_code);
+}
+
+/**
+ * mm_sim_preferred_network_set_access_technology: (skip)
+ */
+void
+mm_sim_preferred_network_set_access_technology (MMSimPreferredNetwork *self,
+ MMModemAccessTechnology access_technology)
+{
+ g_return_if_fail (self != NULL);
+
+ self->access_technology = access_technology;
+}
+
+/**
+ * mm_sim_preferred_network_new: (skip)
+ */
+MMSimPreferredNetwork *
+mm_sim_preferred_network_new (void)
+{
+ return g_slice_new0 (MMSimPreferredNetwork);
+}
+
+/**
+ * mm_sim_preferred_network_new_from_variant: (skip)
+ */
+MMSimPreferredNetwork *
+mm_sim_preferred_network_new_from_variant (GVariant *variant)
+{
+ MMSimPreferredNetwork *preferred_net;
+
+ g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE ("(su)")),
+ NULL);
+
+ preferred_net = mm_sim_preferred_network_new ();
+ g_variant_get (variant, "(su)", &preferred_net->operator_code, &preferred_net->access_technology);
+ return preferred_net;
+}
+
+/**
+ * mm_sim_preferred_network_get_tuple: (skip)
+ */
+GVariant *
+mm_sim_preferred_network_get_tuple (const MMSimPreferredNetwork *self)
+{
+ return g_variant_new ("(su)",
+ self->operator_code,
+ self->access_technology);
+}
+
+/**
+ * mm_sim_preferred_network_list_get_variant: (skip)
+ */
+GVariant *
+mm_sim_preferred_network_list_get_variant (const GList *preferred_network_list)
+{
+ GVariantBuilder builder;
+ const GList *iter;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(su)"));
+ for (iter = preferred_network_list; iter; iter = g_list_next (iter)) {
+ g_variant_builder_add_value (&builder,
+ mm_sim_preferred_network_get_tuple ((const MMSimPreferredNetwork *) iter->data));
+ }
+ return g_variant_builder_end (&builder);
+}
diff --git a/libmm-glib/mm-sim-preferred-network.h b/libmm-glib/mm-sim-preferred-network.h
new file mode 100644
index 00000000..e6042587
--- /dev/null
+++ b/libmm-glib/mm-sim-preferred-network.h
@@ -0,0 +1,68 @@
+/* -*- 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) 2021 UROS Ltd
+ */
+
+#ifndef MM_SIM_PREFERRED_NETWORK_H
+#define MM_SIM_PREFERRED_NETWORK_H
+
+#if !defined (__LIBMM_GLIB_H_INSIDE__) && !defined (LIBMM_GLIB_COMPILATION)
+#error "Only <libmm-glib.h> can be included directly."
+#endif
+
+#include <ModemManager.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/**
+ * MMSimPreferredNetwork:
+ *
+ * The #MMSimPreferredNetwork structure contains private data and should only be accessed
+ * using the provided API.
+ */
+typedef struct _MMSimPreferredNetwork MMSimPreferredNetwork;
+
+#define MM_TYPE_SIM_PREFERRED_NETWORK (mm_sim_preferred_network_get_type ())
+GType mm_sim_preferred_network_get_type (void);
+
+const gchar *mm_sim_preferred_network_get_operator_code (const MMSimPreferredNetwork *self);
+MMModemAccessTechnology mm_sim_preferred_network_get_access_technology (const MMSimPreferredNetwork *self);
+
+void mm_sim_preferred_network_free (MMSimPreferredNetwork *self);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMSimPreferredNetwork, mm_sim_preferred_network_free)
+
+/*****************************************************************************/
+/* ModemManager/libmm-glib/mmcli specific methods */
+
+#if defined (_LIBMM_INSIDE_MM) || \
+ defined (_LIBMM_INSIDE_MMCLI) || \
+ defined (LIBMM_GLIB_COMPILATION)
+
+MMSimPreferredNetwork * mm_sim_preferred_network_new (void);
+MMSimPreferredNetwork * mm_sim_preferred_network_new_from_variant (GVariant *variant);
+
+void mm_sim_preferred_network_set_operator_code (MMSimPreferredNetwork *self,
+ const gchar *operator_code);
+void mm_sim_preferred_network_set_access_technology (MMSimPreferredNetwork *self,
+ MMModemAccessTechnology access_technology);
+
+GVariant *mm_sim_preferred_network_get_tuple (const MMSimPreferredNetwork *self);
+GVariant *mm_sim_preferred_network_list_get_variant (const GList *preferred_network_list);
+
+#endif
+
+G_END_DECLS
+
+#endif /* MM_SIM_PREFERRED_NETWORK_H */
diff --git a/libmm-glib/mm-sim.c b/libmm-glib/mm-sim.c
index 0a3b6071..ac509d3e 100644
--- a/libmm-glib/mm-sim.c
+++ b/libmm-glib/mm-sim.c
@@ -23,6 +23,7 @@
#include "mm-helpers.h"
#include "mm-sim.h"
+#include "mm-sim-preferred-network.h"
/**
* SECTION: mm-sim
@@ -860,6 +861,47 @@ mm_sim_change_pin_sync (MMSim *self,
/*****************************************************************************/
+/**
+ * mm_sim_get_preferred_networks:
+ * @self: A #MMSim.
+ *
+ * Gets the list of #MMSimPreferredNetwork objects exposed by this
+ * #MMSim.
+ *
+ * Returns: (transfer full) (element-type ModemManager.SimPreferredNetwork): a list of
+ * #MMSimPreferredNetwork objects, or #NULL. The returned value should
+ * be freed with g_list_free_full() using mm_sim_preferred_network_free() as #GDestroyNotify
+ * function.
+ *
+ * Since: 1.18
+ */
+GList *
+mm_sim_get_preferred_networks (MMSim *self)
+{
+ GList *network_list = NULL;
+ GVariant *container, *child;
+ GVariantIter iter;
+
+ g_return_val_if_fail (MM_IS_SIM (self), NULL);
+
+ container = mm_gdbus_sim_get_preferred_networks (MM_GDBUS_SIM (self));
+ g_return_val_if_fail (g_variant_is_of_type (container, G_VARIANT_TYPE ("a(su)")), NULL);
+
+ g_variant_iter_init (&iter, container);
+ while ((child = g_variant_iter_next_value (&iter))) {
+ MMSimPreferredNetwork *preferred_net;
+
+ preferred_net = mm_sim_preferred_network_new_from_variant (child);
+ if (preferred_net)
+ network_list = g_list_append (network_list, preferred_net);
+ g_variant_unref (child);
+ }
+
+ return network_list;
+}
+
+/*****************************************************************************/
+
static void
mm_sim_init (MMSim *self)
{
diff --git a/libmm-glib/mm-sim.h b/libmm-glib/mm-sim.h
index 3449e289..8ebf069f 100644
--- a/libmm-glib/mm-sim.h
+++ b/libmm-glib/mm-sim.h
@@ -87,6 +87,8 @@ gchar *mm_sim_dup_operator_name (MMSim *self);
const gchar * const *mm_sim_get_emergency_numbers (MMSim *self);
gchar **mm_sim_dup_emergency_numbers (MMSim *self);
+GList* mm_sim_get_preferred_networks (MMSim *self);
+
void mm_sim_send_pin (MMSim *self,
const gchar *pin,
GCancellable *cancellable,