UDEV in Android?

247 views
Skip to first unread message

Gianmaria Iaculo

unread,
Jun 4, 2020, 1:10:52 PM6/4/20
to android-platform
Hello,
we are developing on android 9, and we have a GSM modem that creates ttyACM0 to ttyACM5. Till now everything goes ok. We defined the ttyACM0 in our RIL and that's all. 
For some reason we still didnt identified, maybe a modem reset, the modem goes on other ports.. ttyACM1 to ttyACM6, and RIL stops working cause continue to seach the ttyACM0 that does not exist anymore. 
In linux it's quite easy to define udev rules, but this are missing in android. How can we assign always same tty to same device even in case of reboot or disconnection and reconnection?

Regards,
Gianmaria

Arne-Christian Blystad

unread,
Jun 5, 2020, 10:47:20 AM6/5/20
to android-platform
Hey Gianmaria.

I feel your pain, we've had the exact same issue previously on a device where we used a USB GSM modem....

This happens when the modem disappears (e.g. due to it crashing), and you keeping the inode open while the crash happens, and not releasing it before the modem comes back. (But it's of course difficult to know that you need to release it, since you don't know that it crashed until you get some error result from the kernel when reading or polling). Since ttyACM0 is still active, the Linux kernel will assign it to ttyACM1... and so on. Linux could maybe assign it to ttyACM0 if it kept trying, but it doesn't.

For us the fix when this happens was to just force a reset of the modem again, and then it would come back on ttyACM0. We did experiment a bit with just dynamically scanning through the various ttyACMs, but since pppd depended on ttyACM1 and we didn't want to make a change a bunch of different places, we selected for the force-reset approach.

Best regards,
Arne Christian

Gianmaria Iaculo

unread,
Jun 5, 2020, 3:57:38 PM6/5/20
to android-platform
Thank you so much Christian,
we will use same approach. The problem is.. when to reboot the modem? When I have no connection for 5 minutes for example? And if it is normal cause the modem is in a zone without coverage? .. Maybe we can watch the file system and intercept the missing ttyACM0 port and then react with a reboot. I have to do it in RIL maybe.. on port open failed.. Reboot. 

Thank you again.
Ciao
Gianmaria

Arne-Christian Blystad

unread,
Jun 8, 2020, 10:22:41 AM6/8/20
to android-platform
If the modem is in a zone without coverage then you should see that it's unable to find any networks (AT+CSQ will return 99, and AT+COPS? will just return no network). This should not cause a modem crash (which will make it disappear, and then show up again). In this state you should still be able to freely communicate with the modem. This is separate from the error handling which you need to do when the modem crashes and re-enumerates.

In our case we got an error from the read() call on /dev/ttyACM0 when the modem crashed, from the Linux kernel (since the modem disappeared). We then call close() on the old file descriptor. We after that entered a retry loop where we try to open /dev/ttyACM0 again 15 times, with 2000ms delay between each attempt. If the open fails then we check if /dev/ttyACM1 exists, and if it exists we make the modem reset (by asserting the modems RESET GPIO). We then reset the loop counter, and continue with the 15 retries. It should now show up as /dev/ttyACM0. We then sent all the initialisation commands, like it was a normal boot, and the modem would be up again.

Best regards,
Arne Christian
Reply all
Reply to author
Forward
0 new messages