[PATCH v5 02/10] plugins/udevng: Add support for PCIe MBIM modems * Parses through the sysfs tree and detects MBIM control nodes, net and AT nodes

Muhammad Asif <[email protected]> Thu, 27 Nov 2025 22:49:36 +0500
Newsgroups dev.linux.lists.ofono
Message-ID <[email protected]>
---
 plugins/udevng.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 18954d44..bae0be76 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -1186,7 +1186,13 @@ static gboolean setup_mbim(struct modem_info *modem)
 {
 =09const char *ctl =3D NULL, *net =3D NULL, *atcmd =3D NULL;
 =09GSList *list;
+=09const char *sub_subsystem =3D NULL, *type =3D NULL;
+=09char path[512], wwan_path[1024], sub_path[2048];
 =09char descriptors[PATH_MAX];
+=09struct udev *new_udev;
+=09struct udev_device *wwan_device, *sub_device;
+=09struct dirent *dir =3D NULL, *subdir =3D NULL;
+=09DIR *d =3D NULL, *sd =3D NULL;
=20
 =09DBG("%s [%s:%s]", modem->syspath, modem->vendor, modem->model);
=20
@@ -1206,6 +1212,56 @@ static gboolean setup_mbim(struct modem_info *modem)
 =09=09else if (g_strcmp0(subsystem, "tty") =3D=3D 0) {
 =09=09=09if (g_strcmp0(info->number, "02") =3D=3D 0)
 =09=09=09=09atcmd =3D info->devnode;
+=09=09} else if (g_strcmp0(subsystem, "pci") =3D=3D 0) {
+=09=09=09sprintf(path, "%s/wwan", udev_device_get_syspath(info->udev_devic=
e));
+
+=09=09=09d =3D opendir(path);
+=09=09=09if (!d)
+=09=09=09=09return FALSE;
+
+=09=09=09new_udev =3D udev_new();
+
+=09=09=09while ((dir =3D readdir(d))) {
+=09=09=09=09if (g_strcmp0(dir->d_name, ".") =3D=3D 0 ||
+=09=09=09=09=09g_strcmp0(dir->d_name, "..") =3D=3D 0)
+=09=09=09=09=09continue;
+
+=09=09=09=09sprintf(wwan_path, "%s/%s", path, dir->d_name);
+
+=09=09=09=09wwan_device =3D udev_device_new_from_syspath(new_udev,
+=09=09=09=09=09=09=09=09=09wwan_path);
+=09=09=09=09net =3D udev_device_get_sysname(wwan_device);
+
+=09=09=09=09/* Parse all the subdirectories now */
+=09=09=09=09sd =3D opendir(wwan_path);
+=09=09=09=09while ((subdir =3D readdir(sd))) {
+=09=09=09=09=09if (subdir->d_type !=3D DT_DIR)
+=09=09=09=09=09=09continue;
+
+=09=09=09=09=09if (g_strcmp0(subdir->d_name, ".") =3D=3D 0 ||
+=09=09=09=09=09=09g_strcmp0(subdir->d_name, "..") =3D=3D 0)
+=09=09=09=09=09=09continue;
+
+=09=09=09=09=09sprintf(sub_path, "%s/%s", wwan_path, subdir->d_name);
+
+=09=09=09=09=09sub_device =3D udev_device_new_from_syspath(new_udev,
+=09=09=09=09=09=09=09=09=09=09sub_path);
+=09=09=09=09=09sub_subsystem =3D udev_device_get_subsystem(sub_device);
+
+=09=09=09=09=09if (g_strcmp0(sub_subsystem, "wwan") =3D=3D 0) {
+=09=09=09=09=09=09type =3D udev_device_get_sysattr_value(sub_device, "type=
");
+
+=09=09=09=09=09=09if (g_strcmp0(type, "MBIM") =3D=3D 0)
+=09=09=09=09=09=09=09ctl =3D udev_device_get_devnode(sub_device);
+=09=09=09=09=09=09else if (g_strcmp0(type, "AT") =3D=3D 0)
+=09=09=09=09=09=09=09atcmd =3D udev_device_get_devnode(sub_device);
+=09=09=09=09=09}
+=09=09=09=09}
+=09=09=09=09closedir(sd);
+=09=09=09=09break;
+=09=09=09}
+=09=09=09closedir(d);
+=09=09=09udev_unref(new_udev);
 =09=09}
 =09}
=20
--=20
2.52.0