modemmanager: add possibilty for setting initial EPS bearer

If no GSM but only 4G is available and a special APN must be used, it
is necessary to set an inital EPS bearer beforehand. If this is not set,
then modem cannot log in and register in the mobile network.

The new option 'init_epsbearer' could be set to the following options.
* none: No init EPS bearer is used and the old one is deleted (default)
* default: Use init EPS bearer with the following config options
  'iptype', 'allowedauth', 'password', 'user' and 'apn' as for the
  connection bearer.
* custom: Other parameters are used that do not match those of the
  default connection bearer. These have an 'init_' prefix and are named
  in the same way as the default connection bearer config options.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2023-11-08 13:18:35 +01:00
parent 7b4d82c58f
commit af12147f8c
3 changed files with 112 additions and 5 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=modemmanager
PKG_SOURCE_VERSION:=1.22.0
PKG_RELEASE:=6
PKG_RELEASE:=7
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://gitlab.freedesktop.org/mobile-broadband/ModemManager.git

View File

@ -26,6 +26,7 @@ Once installed, you can configure the 2G/3G/4G modem connections directly in
option lowpower '1'
option signalrate '30'
option allow_roaming '1'
option init_epsbearer '<none|default|custom>'
Only 'device' and 'proto' are mandatory options, the remaining ones are all
optional.
@ -42,3 +43,17 @@ The 'plmn' option allows to set the network operator MCCMNC.
The 'signalrate' option set's the signal refresh rate (in seconds) for the device.
You can call signal info with command: mmcli -m 0 --signal-get
If there is no Circuit switch network available, then an initial EPS
bearer must be set, so this could be used during the network registration
process in 4G and 5G network. For this resaon a new configuration option
'init_epsbearer' was added, which could have the following values.
* none: Do not set an initial EPS bearer (default)
* default: Use the configuration option 'apn', 'iptype', 'allowedauth',
'username' and 'password' for setting the initial EPS bearer.
These are the same options as when establishing a connection.
* custom: This could be used to use diffrent options when establishing a
connection. The options are prefixed with an 'init'. So we have
the following options 'init_apn', 'init_iptype',
'init_allowedauth', 'init_username' and 'init_password' for
setting the initial EPS bearer.

View File

@ -339,6 +339,12 @@ proto_modemmanager_init_config() {
proto_config_add_int signalrate
proto_config_add_boolean lowpower
proto_config_add_boolean allow_roaming
proto_config_add_string init_epsbearer
proto_config_add_string init_iptype
proto_config_add_string 'init_allowedauth:list(string)'
proto_config_add_string init_password
proto_config_add_string init_user
proto_config_add_string init_apn
proto_config_add_defaults
}
@ -438,6 +444,38 @@ modemmanager_set_preferred_mode() {
}
}
modemmanager_init_epsbearer() {
local eps="$1"
local device="$2"
local connectargs="$3"
local apn="$4"
[ "$eps" != 'none' ] && [ -z "${apn}" ] && {
echo "No '$eps' init eps bearer apn configured"
proto_notify_error "${interface}" MM_INIT_EPS_BEARER_APN_NOT_CONFIGURED
proto_block_restart "${interface}"
return 1
}
if [ "$eps" = "none" ]; then
echo "Deleting inital EPS bearer..."
else
echo "Setting '$eps' inital EPS bearer apn to '$apn'..."
fi
mmcli --modem="${device}" \
--timeout 120 \
--3gpp-set-initial-eps-bearer-settings="${connectargs}" || {
proto_notify_error "${interface}" MM_INIT_EPS_BEARER_SET_FAILED
proto_block_restart "${interface}"
return 1
}
# Wait here so that the modem can set the init EPS bearer
# for registration
sleep 2
}
proto_modemmanager_setup() {
local interface="$1"
@ -449,12 +487,20 @@ proto_modemmanager_setup() {
local device apn allowedauth username password pincode
local iptype plmn metric signalrate allow_roaming
local init_epsbearer
local init_iptype init_allowedauth
local init_password init_user init_apn
local address prefix gateway mtu dns1 dns2
json_get_vars device apn allowedauth username password
json_get_vars pincode iptype plmn metric signalrate allow_roaming
json_get_vars allowedmode preferredmode
json_get_vars init_epsbearer
json_get_vars init_iptype init_allowedauth
json_get_vars init_password init_user init_apn
# validate sysfs path given in config
[ -n "${device}" ] || {
echo "No device specified"
@ -507,10 +553,51 @@ proto_modemmanager_setup() {
# always cleanup before attempting a new connection, just in case
modemmanager_cleanup_connection "${modemstatus}"
# if allowedauth list given, build option string
for auth in $allowedauth; do
cliauth="${cliauth}${cliauth:+|}$auth"
done
mmcli --modem="${device}" --timeout 120 --enable || {
proto_notify_error "${interface}" MM_MODEM_DISABLED
return 1
}
# set initial eps bearer settings
[ -z "${init_epsbearer}" ] || {
case "$init_epsbearer" in
"none")
connectargs=""
modemmanager_init_epsbearer "none" \
"$device" "${connectargs}" "$apn"
;;
"default")
cliauth=""
for auth in $allowedauth; do
cliauth="${cliauth}${cliauth:+|}$auth"
done
connectargs=""
append_param "apn=${apn}"
append_param "${iptype:+ip-type=${iptype}}"
append_param "${cliauth:+allowed-auth=${cliauth}}"
append_param "${username:+user=${username}}"
append_param "${password:+password=${password}}"
modemmanager_init_epsbearer "default" \
"$device" "${connectargs}" "$apn"
;;
"custom")
cliauth=""
for auth in $init_allowedauth; do
cliauth="${cliauth}${cliauth:+|}$auth"
done
connectargs=""
append_param "apn=${init_apn}"
append_param "${init_iptype:+ip-type=${init_iptype}}"
append_param "${cliauth:+allowed-auth=${cliauth}}"
append_param "${init_username:+user=${init_username}}"
append_param "${init_password:+password=${init_password}}"
modemmanager_init_epsbearer "custom" \
"$device" "${connectargs}" "$init_apn"
;;
esac
# check error for init_epsbearer function call
[ "$?" -ne "0" ] && return 1
}
# setup connect args; APN mandatory (even if it may be empty)
echo "starting connection with apn '${apn}'..."
@ -524,7 +611,12 @@ proto_modemmanager_setup() {
allow_roaming="yes"
fi
cliauth=""
for auth in $allowedauth; do
cliauth="${cliauth}${cliauth:+|}$auth"
done
# Append options to 'connectargs' variable
connectargs=""
append_param "apn=${apn}"
append_param "allow-roaming=${allow_roaming}"
append_param "${iptype:+ip-type=${iptype}}"