mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 23:32:14 +02:00
manager: make modem_reset more reliable
`modem_reset()` could previously either fail silently, or fall back to using AT commands without indicating what happened. This commit adds informative messages and makes sure we fall back to resetting using AT commands whenever we encounter an error.
This commit is contained in:
@@ -149,16 +149,20 @@ void modem_reset(struct EG25Manager *manager)
|
|||||||
{
|
{
|
||||||
int fd, ret, len;
|
int fd, ret, len;
|
||||||
|
|
||||||
if (manager->reset_timer)
|
if (manager->reset_timer) {
|
||||||
|
g_message("modem_reset: timer already setup, skipping...");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we are managing the modem through lets say ofono, we should not
|
* If we are managing the modem through lets say ofono, we should not
|
||||||
* reset the modem based on the availability of USB ID
|
* reset the modem based on the availability of USB ID
|
||||||
* TODO: Improve ofono plugin and add support for fetching USB ID
|
* TODO: Improve ofono plugin and add support for fetching USB ID
|
||||||
*/
|
*/
|
||||||
if (manager->modem_iface != MODEM_IFACE_MODEMMANAGER)
|
if (manager->modem_iface != MODEM_IFACE_MODEMMANAGER) {
|
||||||
|
g_message("modem_reset: not using ModemManager, bail out!");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (manager->modem_recovery_timer) {
|
if (manager->modem_recovery_timer) {
|
||||||
g_source_remove(manager->modem_recovery_timer);
|
g_source_remove(manager->modem_recovery_timer);
|
||||||
@@ -166,30 +170,42 @@ void modem_reset(struct EG25Manager *manager)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!manager->modem_usb_id) {
|
if (!manager->modem_usb_id) {
|
||||||
g_warning("Unknown modem USB ID");
|
g_warning("Empty modem USB ID");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_message("Trying to reset modem with USB ID '%s'", manager->modem_usb_id);
|
||||||
|
|
||||||
len = strlen(manager->modem_usb_id);
|
len = strlen(manager->modem_usb_id);
|
||||||
|
|
||||||
manager->modem_state = EG25_STATE_RESETTING;
|
manager->modem_state = EG25_STATE_RESETTING;
|
||||||
|
|
||||||
fd = open("/sys/bus/usb/drivers/usb/unbind", O_WRONLY);
|
fd = open("/sys/bus/usb/drivers/usb/unbind", O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
|
g_warning("Unable to open /sys/bus/usb/drivers/usb/unbind");
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
ret = write(fd, manager->modem_usb_id, len);
|
ret = write(fd, manager->modem_usb_id, len);
|
||||||
if (ret < len)
|
if (ret < len) {
|
||||||
g_warning("Couldn't unbind modem: wrote %d/%d bytes", ret, len);
|
g_warning("Couldn't unbind modem: wrote %d/%d bytes", ret, len);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
fd = open("/sys/bus/usb/drivers/usb/bind", O_WRONLY);
|
fd = open("/sys/bus/usb/drivers/usb/bind", O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
|
g_warning("Unable to open /sys/bus/usb/drivers/usb/unbind");
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
ret = write(fd, manager->modem_usb_id, len);
|
ret = write(fd, manager->modem_usb_id, len);
|
||||||
if (ret < len)
|
if (ret < len) {
|
||||||
g_warning("Couldn't bind modem: wrote %d/%d bytes", ret, len);
|
g_warning("Couldn't bind modem: wrote %d/%d bytes", ret, len);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
g_message("Successfully reset modem's USB connection");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 3s is long enough to make sure the modem has been bound back and
|
* 3s is long enough to make sure the modem has been bound back and
|
||||||
* short enough to ensure it hasn't been acquired by ModemManager
|
* short enough to ensure it hasn't been acquired by ModemManager
|
||||||
@@ -206,8 +222,13 @@ error:
|
|||||||
g_source_remove(manager->modem_boot_timer);
|
g_source_remove(manager->modem_boot_timer);
|
||||||
manager->modem_boot_timer = 0;
|
manager->modem_boot_timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything else failed, reboot the modem
|
// Everything else failed, reboot the modem
|
||||||
|
g_message("USB reset failed, falling back to AT command");
|
||||||
at_sequence_reset(manager);
|
at_sequence_reset(manager);
|
||||||
|
|
||||||
|
// Setup timer for making sure we don't queue other reset commands
|
||||||
|
manager->reset_timer = g_timeout_add_seconds(30, G_SOURCE_FUNC(modem_reset_done), manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
void modem_suspend_pre(struct EG25Manager *manager)
|
void modem_suspend_pre(struct EG25Manager *manager)
|
||||||
|
Reference in New Issue
Block a user