summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-02-12 20:41:54 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-02-16 23:09:55 +0100
commit0c1b56ee2f9cffed0722fa1ad5a08e3db7ba34a7 (patch)
tree292537f85eb182156feefeffa0c90a68dd9fea8e /src
parent048cde053b2d2531599e8f34e70dcddcfde17c9a (diff)
libqmi-glib,device: new method to list available links
This generic method allows us to list all links that have been created from a base parent interface. The implementation is common for both rmnet and qmiwwan backends, based on the "upper" links in sysfs.
Diffstat (limited to 'src')
-rw-r--r--src/libqmi-glib/qmi-device.c18
-rw-r--r--src/libqmi-glib/qmi-device.h17
-rw-r--r--src/libqmi-glib/qmi-net-port-manager.c29
-rw-r--r--src/libqmi-glib/qmi-net-port-manager.h9
4 files changed, 73 insertions, 0 deletions
diff --git a/src/libqmi-glib/qmi-device.c b/src/libqmi-glib/qmi-device.c
index 3a6bd83..6b0154d 100644
--- a/src/libqmi-glib/qmi-device.c
+++ b/src/libqmi-glib/qmi-device.c
@@ -1933,6 +1933,24 @@ qmi_device_delete_link (QmiDevice *self,
/*****************************************************************************/
gboolean
+qmi_device_list_links (QmiDevice *self,
+ const gchar *base_ifname,
+ GPtrArray **out_links,
+ GError **error)
+{
+ if (!setup_net_port_manager (self, error))
+ return FALSE;
+
+ g_assert (self->priv->net_port_manager);
+ return qmi_net_port_manager_list_links (self->priv->net_port_manager,
+ base_ifname,
+ out_links,
+ error);
+}
+
+/*****************************************************************************/
+
+gboolean
qmi_device_check_link_supported (QmiDevice *self,
GError **error)
{
diff --git a/src/libqmi-glib/qmi-device.h b/src/libqmi-glib/qmi-device.h
index 602390c..2c3894f 100644
--- a/src/libqmi-glib/qmi-device.h
+++ b/src/libqmi-glib/qmi-device.h
@@ -999,6 +999,23 @@ gboolean qmi_device_delete_link_finish (QmiDevice *self,
GError **error);
/**
+ * qmi_device_list_links:
+ * @self: a #QmiDevice.
+ * @base_ifname: the base interface.
+ * @out_links: (out)(transfer full)(element-type utf8): a placeholder for the
+ * output #GPtrArray of link names.
+ * @error: Return location for error or %NULL.
+ *
+ * Returns: %TRUE if successful, %FALSE if @error is set.
+ *
+ * Since: 1.28
+ */
+gboolean qmi_device_list_links (QmiDevice *self,
+ const gchar *base_ifname,
+ GPtrArray **out_links,
+ GError **error);
+
+/**
* qmi_device_check_link_supported:
* @self: a #QmiDevice.
* @error: Return location for error or %NULL.
diff --git a/src/libqmi-glib/qmi-net-port-manager.c b/src/libqmi-glib/qmi-net-port-manager.c
index abfd56c..7e01879 100644
--- a/src/libqmi-glib/qmi-net-port-manager.c
+++ b/src/libqmi-glib/qmi-net-port-manager.c
@@ -21,6 +21,7 @@
*/
#include "qmi-net-port-manager.h"
+#include "qmi-helpers.h"
G_DEFINE_ABSTRACT_TYPE (QmiNetPortManager, qmi_net_port_manager, G_TYPE_OBJECT)
@@ -81,6 +82,33 @@ qmi_net_port_manager_del_link_finish (QmiNetPortManager *self,
return QMI_NET_PORT_MANAGER_GET_CLASS (self)->del_link_finish (self, res, error);
}
+gboolean
+qmi_net_port_manager_list_links (QmiNetPortManager *self,
+ const gchar *base_ifname,
+ GPtrArray **out_links,
+ GError **error)
+{
+ return QMI_NET_PORT_MANAGER_GET_CLASS (self)->list_links (self, base_ifname, out_links, error);
+}
+
+/*****************************************************************************/
+/* Default implementations */
+
+static gboolean
+net_port_manager_list_links (QmiNetPortManager *self,
+ const gchar *base_ifname,
+ GPtrArray **out_links,
+ GError **error)
+{
+ g_autoptr(GFile) sysfs_file = NULL;
+ g_autofree gchar *sysfs_path = NULL;
+
+ sysfs_path = g_strdup_printf ("/sys/class/net/%s", base_ifname);
+ sysfs_file = g_file_new_for_path (sysfs_path);
+
+ return qmi_helpers_list_links (sysfs_file, NULL, NULL, out_links, error);
+}
+
/*****************************************************************************/
static void
@@ -91,4 +119,5 @@ qmi_net_port_manager_init (QmiNetPortManager *self)
static void
qmi_net_port_manager_class_init (QmiNetPortManagerClass *klass)
{
+ klass->list_links = net_port_manager_list_links;
}
diff --git a/src/libqmi-glib/qmi-net-port-manager.h b/src/libqmi-glib/qmi-net-port-manager.h
index 100f2ee..3783745 100644
--- a/src/libqmi-glib/qmi-net-port-manager.h
+++ b/src/libqmi-glib/qmi-net-port-manager.h
@@ -45,6 +45,11 @@ struct _QmiNetPortManager {
struct _QmiNetPortManagerClass {
GObjectClass parent;
+ gboolean (* list_links) (QmiNetPortManager *self,
+ const gchar *base_ifname,
+ GPtrArray **out_links,
+ GError **error);
+
void (* add_link) (QmiNetPortManager *self,
guint mux_id,
const gchar *base_ifname,
@@ -73,6 +78,10 @@ struct _QmiNetPortManagerClass {
GType qmi_net_port_manager_get_type (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (QmiNetPortManager, g_object_unref)
+gboolean qmi_net_port_manager_list_links (QmiNetPortManager *self,
+ const gchar *base_ifname,
+ GPtrArray **out_links,
+ GError **error);
void qmi_net_port_manager_add_link (QmiNetPortManager *self,
guint mux_id,