udev: use USB vendor/product ID to determine behavior

When going into firmware upgrade mode, the modem comes back with
different IDs than in normal use. We should make sure we cancel the
reset sequence when that happens, and not start a new one.
This commit is contained in:
Arnaud Ferraris
2022-01-04 15:26:43 +01:00
committed by Arnaud Ferraris
parent df79247821
commit 9e6bccdf37
2 changed files with 30 additions and 9 deletions

View File

@@ -11,22 +11,42 @@
static void udev_event_cb(GUdevClient *client, gchar *action, GUdevDevice *device, gpointer data)
{
struct EG25Manager *manager = data;
const gchar *prop;
long vid = 0, pid = 0;
if (!manager->modem_usb_id)
return;
if (strcmp(g_udev_device_get_name(device), manager->modem_usb_id) == 0 &&
strcmp(action, "add") == 0 && manager->schedule_reset_timer != 0) {
g_message("Modem recovered before reset sequence was triggered, cancel reset.");
g_source_remove(manager->schedule_reset_timer);
manager->schedule_reset_timer = 0;
/*
* Act only if the device is the one identified as a modem by MM/ofono
*/
if (!manager->modem_usb_id ||
strcmp(g_udev_device_get_name(device), manager->modem_usb_id) != 0) {
return;
}
prop = g_udev_device_get_property(device, "ID_VENDOR_ID");
if (prop)
vid = strtol(prop, NULL, 16);
prop = g_udev_device_get_property(device, "ID_MODEL_ID");
if (prop)
pid = strtol(prop, NULL, 16);
if (strcmp(action, "bind") == 0 && vid != manager->usb_vid && pid != manager->usb_pid) {
/*
* Modem is probably executing a FW upgrade, make sure we don't interrupt it
*/
if (manager->schedule_reset_timer != 0) {
g_message("Modem re-appeared with different VID/PID, cancel reset.");
g_source_remove(manager->schedule_reset_timer);
manager->schedule_reset_timer = 0;
}
manager->modem_state = EG25_STATE_UPDATING;
}
if (strcmp(action, "unbind") != 0 ||
manager->modem_state == EG25_STATE_UPDATING ||
manager->modem_state == EG25_STATE_RESETTING ||
manager->complete_reset_timer != 0 ||
strcmp(g_udev_device_get_name(device), manager->modem_usb_id) != 0) {
manager->schedule_reset_timer != 0) {
return;
}