Hotplug event for SIM insert in Modem

Hi. I'm facing issues while inserting SIM into mPCIe based modem. It is not automatically connected to the Internet. I either need to restart the router or to apply AT command to reset the modem.

Is there any hotplug.d event or any other way I can apply the AT+CFUN=0 and AT+CFUN=1 command when SIM is inserted to reset the modem so it will automatically connect without any user interference.

I'm using version 17.04.

Thanks.

Hey, you can create a script in /etc/hotplug.d/ to do this.
If you are compiling your own image you can add this to target/linux/(arch) /base-files/etc/hotplug.d/

See this page for reference on how to write a script:
https://openwrt.org/docs/guide-user/base-system/hotplug_lede

Thanks for the reply.

I've already tried once in hotplug.d/usb but didn't received event on usb. Also tried to put script directly for debugging purpose but no luck.

You said the modem was mPCIe?
Does it expose a USB interface or is it listed as a PCI device? - check /proc for this.

What is the output of dmesg when you plug in the sim?

It is showing as ttyUSBx, 4 ports for each modem.There is no output of dmesg on removal or insertion. What file should be in /proc?

In /proc/bus there will be usb and pci subfolders.

What modem are you using?
Have you checked the At command reference to see if it supports swapping natively?

In desktop Linux hotswapping is handled by mmcli qmcli etc so it is possible that you may have to extend a driver to support this.

A 'hacky' way to solve this would be map the reset command to a physical button on the unit. Not automatic but saves an SSH in.

Below is the output of folder

ls /proc/bus/pci
devices

cat /proc/bus/pci/devices
empty

I'm testing with Forge SLM750 and ZTE ZM8620 modems.

I didn't find AT command to check swapping functionality.

For "hacky" way, I've already provided a button on Luci interface to reset the modem but this needs user interference.

Are you sure your modem supports SIM hotplug with a dedicated pin in slot connected to the modem (inserting SIM when device is powered)? Usually, when modem is powered, SIM detection is performed only once. If SIM doesn't answer (see: https://en.wikipedia.org/wiki/Answer_to_reset), modem disables power supply in slot.

No.

Of course, you can write a small app which would listen on AT port (or MBIM/QMI) for SIM events sent by modem but still, if your modem doesn't support SIM hotplug it just won't work or you would need to (somehow) re-initialize SIM slot manually.

1 Like

Thanks for the reply.

I didn't find AT command to check for SIM hotplug support.

And you won't, you should look into modem and your host (where modem is plugged in) datasheets. And, as I can see now that you are using miniPCIe modems, you should be aware that they usually don't support SIM hotplug as the Mini Card interface doesn't define pin for SIM detection (SIM in slot).

Thanks. So final result is I've to go with manual option which I already implemented in Luci Interface.

And probably stop swapping SIM cards when device is running... if your platform lacks protection on SIM signal lines (yep, I have seen cheap solutions like that), you might break something with ESD.

This device is used to give remote site connectivity and have multiple SIM slots so if one stop working for whatever reason we cannot restart the device. So the hot swap functionality is very important there.

How do you switch between different SIM slots, GPIO? You might look at AT+CFUN command and use it between switching SIMs. For example, Quectel modems support SIM power down/up using QMI commands - you can switch SIM card quickly, without need for resetting whole modem.

I'm using AT+CFUN to reset the modem. In Luci interface, I've provided reset button so when someone insert the SIM, they will have to click the button. That's what I tried to automate if I able to found SIM hotplug.

@asifvazir is this a device you are developing yourself? If not, what hardware are you using?