Most of the modem issues follow a (incomplete) USB device reset. Instead
of relying solely on the existing timer, this patch adds a udev monitor
which resets the modem as soon as its associated USB device is reset,
which greatly improves recovery time.
This patch adds a 3s delay when resetting the modem during which we
avoid triggering a new reset. This makes sure we don't trigger a reset
twice in a row.
It also disables any related running timer to avoid being re-triggered
unnecessarily.
The response can include the command and an error number, so we want to
only check it contains ERROR, even if it's replying more than just the
'ERROR' string.
For some reason, during system the main loop exits before we call
g_main_loop_quit(), so don't rely on it and use a simple polling loop to
check for modem poweroff.
`Developer edition` phones have a different compatible string but should
be considered identical to BraveHeart edition here. Therefore BH is the
default phone, unless the compatible is that of a CE phone.
When powering off the modem, we must assert the RESET line only when the
modem has shut down (otherwise it'll cause a hard reset and won't allow
the modem to shut down properly).
This commit also polls the STATUS pin during poweroff and quits
immediately once this pin goes high.
RI won't be accessible due to it being used by the kernel as an
interrupt source, so we can check the STATUS pin (CE only) which will
allow us to know precisely when the modem is shut down.