aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-01-20 12:50:07 +0100
committerAleksander Morgado <aleksander@aleksander.es>2017-01-20 12:50:07 +0100
commit3e7cda53b1ce24e23f8355b75ff13b924dd72f6d (patch)
treee32be04c6cc39257f891ca8249a2c69e0cabe766
parent95f8b1d20f51be943bad3ec060bf92af2469ba93 (diff)
downloadexternal_libqmi-3e7cda53b1ce24e23f8355b75ff13b924dd72f6d.zip
external_libqmi-3e7cda53b1ce24e23f8355b75ff13b924dd72f6d.tar.gz
external_libqmi-3e7cda53b1ce24e23f8355b75ff13b924dd72f6d.tar.bz2
qmi-firmware-update: new generic monitor to debug all udev events
As soon as we know the sysfs path of the device to use, we'll setup a generic udev monitor for all tty, net and usb devices so that we get notified of all their additions or removals. E.g. when going from normal mode to QDL download mode: [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove ttyUSB0 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove ttyUSB1 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove 4-1.4:1.0 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove wwan0 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove 4-1.4:1.2 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove ttyUSB2 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove 4-1.4:1.3 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove cdc-wdm2 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove 4-1.4:1.8 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove wwan1 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove cdc-wdm3 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove 4-1.4:1.10 [20 ene 2017, 12:49:26] [Debug] [qfu-udev] event: remove 4-1.4 [20 ene 2017, 12:49:27] [Debug] [qfu-udev] event: add 4-1.4 [20 ene 2017, 12:49:27] [Debug] [qfu-udev] event: add 4-1.4:1.0 [20 ene 2017, 12:49:27] [Debug] [qfu-udev] event: add ttyUSB0 [20 ene 2017, 12:49:27] [Debug] [qfu-udev] waiting device (tty) matched: ttyUSB0 [20 ene 2017, 12:49:27] [Debug] [qfu-updater] TTY device found: /dev/ttyUSB0
-rw-r--r--src/qmi-firmware-update/qfu-device-selection.c8
-rw-r--r--src/qmi-firmware-update/qfu-udev-helpers.c47
-rw-r--r--src/qmi-firmware-update/qfu-udev-helpers.h4
3 files changed, 56 insertions, 3 deletions
diff --git a/src/qmi-firmware-update/qfu-device-selection.c b/src/qmi-firmware-update/qfu-device-selection.c
index bc2d920..136840b 100644
--- a/src/qmi-firmware-update/qfu-device-selection.c
+++ b/src/qmi-firmware-update/qfu-device-selection.c
@@ -41,6 +41,8 @@ struct _QfuDeviceSelectionPrivate {
guint preferred_devnum;
/* sysfs path */
gchar *sysfs_path;
+ /* generic udev monitor */
+ QfuUdevHelperGenericMonitor *monitor;
};
/******************************************************************************/
@@ -270,6 +272,9 @@ qfu_device_selection_new (const gchar *preferred_cdc_wdm,
return NULL;
}
+ /* Initialize right away the generic udev monitor for this sysfs path */
+ self->priv->monitor = qfu_udev_helper_generic_monitor_new (self->priv->sysfs_path);
+
return self;
}
@@ -285,6 +290,9 @@ finalize (GObject *object)
QfuDeviceSelection *self = QFU_DEVICE_SELECTION (object);
guint i;
+ if (self->priv->monitor)
+ qfu_udev_helper_generic_monitor_free (self->priv->monitor);
+
for (i = 0; i < QFU_UDEV_HELPER_DEVICE_TYPE_LAST; i++)
g_free (self->priv->preferred_devices[i]);
g_free (self->priv->sysfs_path);
diff --git a/src/qmi-firmware-update/qfu-udev-helpers.c b/src/qmi-firmware-update/qfu-udev-helpers.c
index 33c4b15..c789703 100644
--- a/src/qmi-firmware-update/qfu-udev-helpers.c
+++ b/src/qmi-firmware-update/qfu-udev-helpers.c
@@ -495,8 +495,6 @@ handle_uevent (GUdevClient *client,
ctx = (WaitForDeviceContext *) g_task_get_task_data (task);
- g_debug ("[qfu-udev] event: %s %s", action, g_udev_device_get_name (device));
-
if (!g_str_equal (action, "add") && !g_str_equal (action, "move") && !g_str_equal (action, "change"))
return;
@@ -504,7 +502,9 @@ handle_uevent (GUdevClient *client,
if (!file)
return;
- g_debug ("[qfu-udev] waiting device matched");
+ g_debug ("[qfu-udev] waiting device (%s) matched: %s",
+ qfu_udev_helper_device_type_to_string (ctx->device_type),
+ g_udev_device_get_name (device));
/* Disconnect this handler */
g_signal_handler_disconnect (ctx->udev, ctx->uevent_id);
@@ -609,3 +609,44 @@ qfu_udev_helper_wait_for_device (QfuUdevHelperDeviceType device_type,
/* Note: task ownership is shared between the signals and the timeout */
}
+
+/******************************************************************************/
+
+struct _QfuUdevHelperGenericMonitor {
+ GUdevClient *udev;
+};
+
+void
+qfu_udev_helper_generic_monitor_free (QfuUdevHelperGenericMonitor *self)
+{
+ g_object_unref (self->udev);
+ g_slice_free (QfuUdevHelperGenericMonitor, self);
+}
+
+static void
+handle_uevent_generic (GUdevClient *client,
+ const char *action,
+ GUdevDevice *device,
+ GTask *task)
+{
+ g_debug ("[qfu-udev] event: %s %s", action, g_udev_device_get_name (device));
+}
+
+QfuUdevHelperGenericMonitor *
+qfu_udev_helper_generic_monitor_new (const gchar *sysfs_path)
+{
+ static const gchar *all_list[] = {
+ "usbmisc", "usb",
+ "tty",
+ "net",
+ NULL };
+
+ QfuUdevHelperGenericMonitor *self;
+
+ self = g_slice_new0 (QfuUdevHelperGenericMonitor);
+ self->udev = g_udev_client_new (all_list);
+
+ /* Monitor for device events. */
+ g_signal_connect (self->udev, "uevent", G_CALLBACK (handle_uevent_generic), NULL);
+ return self;
+}
diff --git a/src/qmi-firmware-update/qfu-udev-helpers.h b/src/qmi-firmware-update/qfu-udev-helpers.h
index 1d3672e..dad818e 100644
--- a/src/qmi-firmware-update/qfu-udev-helpers.h
+++ b/src/qmi-firmware-update/qfu-udev-helpers.h
@@ -56,6 +56,10 @@ void qfu_udev_helper_wait_for_device (QfuUdevHelperDeviceType device_
GFile *qfu_udev_helper_wait_for_device_finish (GAsyncResult *res,
GError **error);
+typedef struct _QfuUdevHelperGenericMonitor QfuUdevHelperGenericMonitor;
+QfuUdevHelperGenericMonitor *qfu_udev_helper_generic_monitor_new (const gchar *sysfs_path);
+void qfu_udev_helper_generic_monitor_free (QfuUdevHelperGenericMonitor *self);
+
G_END_DECLS
#endif /* QFU_UDEV_HELPERS_H */