kernel-device: Add get_wwandev_sysfs_path

The wwan subsystem is a new bus agnostic framework exposing wwan
device and its components (ports, netdev...). It can be useful to
get the wwan device a device belongs to

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
This commit is contained in:
Loic Poulain
2021-07-26 16:08:40 +02:00
committed by Aleksander Morgado
parent 97ab517348
commit 2f38ea0155
4 changed files with 68 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ struct _MMKernelDeviceGenericPrivate {
gchar **drivers;
gchar **subsystems;
gchar *sysfs_path;
gchar *wwandev_sysfs_path;
gchar *interface_sysfs_path;
guint8 interface_class;
guint8 interface_subclass;
@@ -460,6 +461,30 @@ preload_contents_usb (MMKernelDeviceGeneric *self)
self->priv->subsystems = (gchar **) g_ptr_array_free (subsystems, FALSE);
}
static void
preload_contents_wwan (MMKernelDeviceGeneric *self)
{
g_autofree gchar *iter = NULL;
/* Find the first parent device subsystem */
iter = g_path_get_dirname(self->priv->sysfs_path);
while (iter && (g_strcmp0 (iter, "/") != 0)) {
g_autofree gchar *current_subsystem = NULL;
gchar *parent;
current_subsystem = read_sysfs_attribute_link_basename (iter, "subsystem");
if (current_subsystem) {
if (g_strcmp0 (current_subsystem, "wwan") == 0)
self->priv->wwandev_sysfs_path = g_strdup (iter);
break;
}
parent = g_path_get_dirname (iter);
g_clear_pointer (&iter, g_free);
iter = parent;
}
}
static gchar *
find_device_bus_subsystem (MMKernelDeviceGeneric *self)
{
@@ -518,6 +543,8 @@ preload_contents (MMKernelDeviceGeneric *self)
else
preload_contents_other (self);
preload_contents_wwan (self); /* wwan is bus agnostic class */
if (!bus_subsys)
return;
@@ -580,6 +607,12 @@ kernel_device_get_sysfs_path (MMKernelDevice *self)
return MM_KERNEL_DEVICE_GENERIC (self)->priv->sysfs_path;
}
static const gchar *
kernel_device_get_wwandev_sysfs_path (MMKernelDevice *self)
{
return MM_KERNEL_DEVICE_GENERIC (self)->priv->wwandev_sysfs_path;
}
static gint
kernel_device_get_interface_number (MMKernelDevice *self)
{
@@ -1200,6 +1233,7 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass)
kernel_device_class->get_name = kernel_device_get_name;
kernel_device_class->get_driver = kernel_device_get_driver;
kernel_device_class->get_sysfs_path = kernel_device_get_sysfs_path;
kernel_device_class->get_wwandev_sysfs_path = kernel_device_get_wwandev_sysfs_path;
kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid;
kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid;
kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid;

View File

@@ -347,6 +347,27 @@ kernel_device_get_sysfs_path (MMKernelDevice *_self)
NULL);
}
static const gchar *
kernel_device_get_wwandev_sysfs_path (MMKernelDevice *_self)
{
g_autoptr(GUdevDevice) parent = NULL;
MMKernelDeviceUdev *self;
const gchar *subsys;
self = MM_KERNEL_DEVICE_UDEV (_self);
parent = g_udev_device_get_parent (self->priv->device);
if (!parent)
return NULL;
subsys = g_udev_device_get_subsystem (parent);
if (!subsys || g_strcmp0 (subsys, "wwan"))
return NULL;
return g_udev_device_get_sysfs_path (parent);
}
static const gchar *
kernel_device_get_physdev_uid (MMKernelDevice *_self)
{
@@ -780,6 +801,7 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass)
kernel_device_class->get_name = kernel_device_get_name;
kernel_device_class->get_driver = kernel_device_get_driver;
kernel_device_class->get_sysfs_path = kernel_device_get_sysfs_path;
kernel_device_class->get_wwandev_sysfs_path = kernel_device_get_wwandev_sysfs_path;
kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid;
kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid;
kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid;

View File

@@ -73,6 +73,14 @@ mm_kernel_device_get_sysfs_path (MMKernelDevice *self)
NULL);
}
const gchar *
mm_kernel_device_get_wwandev_sysfs_path (MMKernelDevice *self)
{
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_wwandev_sysfs_path ?
MM_KERNEL_DEVICE_GET_CLASS (self)->get_wwandev_sysfs_path (self) :
NULL);
}
const gchar *
mm_kernel_device_get_physdev_uid (MMKernelDevice *self)
{

View File

@@ -43,6 +43,8 @@ struct _MMKernelDeviceClass {
const gchar * (* get_driver) (MMKernelDevice *self);
const gchar * (* get_sysfs_path) (MMKernelDevice *self);
const gchar * (* get_wwandev_sysfs_path) (MMKernelDevice *self);
gint (* get_interface_number) (MMKernelDevice *self);
gint (* get_interface_class) (MMKernelDevice *self);
gint (* get_interface_subclass) (MMKernelDevice *self);
@@ -77,6 +79,8 @@ const gchar *mm_kernel_device_get_name (MMKernelDevice *self);
const gchar *mm_kernel_device_get_driver (MMKernelDevice *self);
const gchar *mm_kernel_device_get_sysfs_path (MMKernelDevice *self);
const gchar *mm_kernel_device_get_wwandev_sysfs_path (MMKernelDevice *self);
gint mm_kernel_device_get_interface_number (MMKernelDevice *self);
gint mm_kernel_device_get_interface_class (MMKernelDevice *self);
gint mm_kernel_device_get_interface_subclass (MMKernelDevice *self);