Passing Operator to NetworkManager
Dan Williams
dcbw at redhat.com
Mon May 8 15:49:06 UTC 2017
On Mon, 2017-05-08 at 10:17 +0100, colin.helliwell at ln-systems.com
wrote:
> I'm hooking together ModemManager and NetworkManager (without
> systemd) and
> would like to grab the Operator determined by MM when it enables the
> modem
> and use it to set the apn setting in the NM connection. Basically -
> the NM
> setting needs to get configured automatically based on the SIM that's
> present.
> Is it possible to get a point in the interractions between the two
> where
> this can be done, or has, e.g. NM already parsed the connection
> settings by
> the time the modem registers?
> (To cater for the case of the registration failing, I guess I could
> pull the
> info from the SIM instead).
> And is there some sort of pre/post 'hook' which could be used to fire
> off a
> script?
This is easily possible with a little scripting, as long as you don't
use autoconnect by default (since that would start connecting before
you knew the operator). Something like:
1) pre-create an NM connection file in /etc/NetworkManager/system-
connections with a well-known connection ID and set it autoconnect=no
so it doesn't get autoconnected before its ready. Say that ID is
"cellular".
2) write a small script and run it at bootup or something:
# turn off autoconnect for this connection profile and make
# sure it's deactivated
nmcli con mod cellular connection.autoconnect=false
nmcli con down cellular
# enable the modem
MODEM_PATH=`mmcli -L | grep "ModemManager1" | cut -d' ' -f1`
mmcli -m ${MODEM_PATH} -e
# Wait 60 seconds for registration and then pull the MCC/MNC
# and figure out what APN to use
for i in `seq 60`; do
STATE=`mmcli -m ${MODEM_PATH} | grep " state:" | cut -d"'" -f 2`
if [[ "${STATE}" == "registered" ]]; then
OPERATOR=`mmcli -m ${MODEM_PATH} | grep "operator id:" | cut -d"'" -f 2`
APN=<use ${OPERATOR} to determine APN>
# modify the connection and let NM autoconnect it from now on
nmcli con mod cellular gsm.apn=${APN}
nmcli con mod cellular connection.autoconnect=true
exit 0
fi
done
exit 1
or something along those lines using whatever scripting language you
want. This can all be done through D-Bus too, but it would be somewhat
more involved (though more flexible and less error prone).
Dan
More information about the ModemManager-devel
mailing list