summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephan Gerhold <stephan@gerhold.net>2021-06-21 10:07:32 +0200
committerStephan Gerhold <stephan@gerhold.net>2021-06-21 10:12:54 +0200
commite3664bfdea485a94ee3e75114111e1c332cadc43 (patch)
tree5cc209eeac0790a428d1f5bd6fb7b1ae21c91673 /src
parent68c5489df8a3829341b8a2023438cb35cae5ad8e (diff)
libqmi-glib,helpers: Check WWAN "type" attribute for Linux 5.14+
Recent changes in the WWAN framework in the kernel changed the WWAN port names from e.g. "wwan0p1AT" and "wwan0p2QMI" to "wwan0at0" and "wwan0qmi0" [1, 2]. This means that qmi_helpers_get_transport_type() now fails to detect the port type since AT/QMI are now lower-case. However, recently additionally a "type" sysfs attribute was added for all WWAN ports [3], which makes it much more reliable to match the WWAN port names without relying on their exact device name. To handle Linux 5.14+, add some additional code that attempts to read the "type" attribute first. Note that we still need to keep the old device naming matching since Linux 5.13 does not have the "type" attribute yet. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=392c26f7f133b9f09e5f58db1ce6ef4b3b4df49f [2]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=f458709ff40b0d992fec496952f79c7820dd3fde [3]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=b3e22e10fdda8e7be3830289a4a63ae8b88d450c
Diffstat (limited to 'src')
-rw-r--r--src/libqmi-glib/qmi-helpers.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/libqmi-glib/qmi-helpers.c b/src/libqmi-glib/qmi-helpers.c
index 09fee3d..d8f1176 100644
--- a/src/libqmi-glib/qmi-helpers.c
+++ b/src/libqmi-glib/qmi-helpers.c
@@ -465,8 +465,10 @@ qmi_helpers_get_transport_type (const gchar *path,
g_autofree gchar *device_basename = NULL;
g_autofree gchar *usb_driver = NULL;
g_autofree gchar *wwan_sysfs_path = NULL;
+ g_autofree gchar *wwan_type_sysfs_path = NULL;
g_autofree gchar *smdpkt_sysfs_path = NULL;
g_autofree gchar *rpmsg_sysfs_path = NULL;
+ gchar wwan_type[16] = { 0 };
device_basename = qmi_helpers_get_devname (path, error);
if (!device_basename)
@@ -484,13 +486,24 @@ qmi_helpers_get_transport_type (const gchar *path,
return QMI_HELPERS_TRANSPORT_TYPE_UNKNOWN;
}
- /* WWAN devices have protocol in their name */
+ /* WWAN devices have a type attribute or protocol in their name */
wwan_sysfs_path = g_strdup_printf ("/sys/class/wwan/%s", device_basename);
if (g_file_test (wwan_sysfs_path, G_FILE_TEST_EXISTS)) {
- if (g_strrstr (device_basename, "QMI"))
- return QMI_HELPERS_TRANSPORT_TYPE_QMUX;
- if (g_strrstr (device_basename, "MBIM"))
- return QMI_HELPERS_TRANSPORT_TYPE_MBIM;
+ wwan_type_sysfs_path = g_strdup_printf ("/sys/class/wwan/%s/type", device_basename);
+ if (qmi_helpers_read_sysfs_file (wwan_type_sysfs_path, wwan_type,
+ sizeof (wwan_type) - 1, NULL)) {
+ g_strstrip (wwan_type);
+ if (!g_strcmp0 (wwan_type, "QMI"))
+ return QMI_HELPERS_TRANSPORT_TYPE_QMUX;
+ if (!g_strcmp0 (wwan_type, "MBIM"))
+ return QMI_HELPERS_TRANSPORT_TYPE_MBIM;
+ } else {
+ /* "type" attribute exists only on Linux 5.14+, fall back to device name */
+ if (g_strrstr (device_basename, "QMI"))
+ return QMI_HELPERS_TRANSPORT_TYPE_QMUX;
+ if (g_strrstr (device_basename, "MBIM"))
+ return QMI_HELPERS_TRANSPORT_TYPE_MBIM;
+ }
g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED,
"unsupported wwan port");
return QMI_HELPERS_TRANSPORT_TYPE_UNKNOWN;