From 015106346ca1d6b71a83bb6c16be42112f1fc4ae Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 4 Aug 2023 15:00:41 +0200 Subject: [PATCH] modemmanager: add setting for allowed and preferred mode Signed-off-by: Florian Eckert --- net/modemmanager/Makefile | 2 +- net/modemmanager/files/modemmanager.proto | 80 ++++++++++++++++++++++- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/net/modemmanager/Makefile b/net/modemmanager/Makefile index fc372f96f3..6819e96b97 100644 --- a/net/modemmanager/Makefile +++ b/net/modemmanager/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=modemmanager PKG_SOURCE_VERSION:=1.20.6 -PKG_RELEASE:=10 +PKG_RELEASE:=11 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://gitlab.freedesktop.org/mobile-broadband/ModemManager.git diff --git a/net/modemmanager/files/modemmanager.proto b/net/modemmanager/files/modemmanager.proto index fbcf3c5402..e97b768d0b 100755 --- a/net/modemmanager/files/modemmanager.proto +++ b/net/modemmanager/files/modemmanager.proto @@ -340,6 +340,8 @@ proto_modemmanager_init_config() { proto_config_add_string 'allowedauth:list(string)' proto_config_add_string username proto_config_add_string password + proto_config_add_string allowedmode + proto_config_add_string preferredmode proto_config_add_string pincode proto_config_add_string iptype proto_config_add_string plmn @@ -358,18 +360,65 @@ append_param() { connectargs="${connectargs}${param}" } +modemmanager_set_allowed_mode() { + local device="$1" + local interface="$2" + local allowedmode="$3" + + echo "setting allowed mode to '${allowedmode}'" + mmcli --modem="${device}" --set-allowed-modes="${allowedmode}" || { + proto_notify_error "${interface}" MM_INVALID_ALLOWED_MODES_LIST + proto_block_restart "${interface}" + return 1 + } +} + +modemmanager_set_preferred_mode() { + local device="$1" + local interface="$2" + local allowedmode="$3" + local preferredmode="$4" + + [ -z "${preferredmode}" ] && { + echo "no preferred mode configured" + proto_notify_error "${interface}" MM_NO_PREFERRED_MODE_CONFIGURED + proto_block_restart "${interface}" + return 1 + } + + [ -z "${allowedmode}" ] && { + echo "no allowed mode configured" + proto_notify_error "${interface}" MM_NO_ALLOWED_MODE_CONFIGURED + proto_block_restart "${interface}" + return 1 + } + + echo "setting preferred mode to '${preferredmode}' (${allowedmode})" + mmcli --modem="${device}" \ + --set-preferred-mode="${preferredmode}" \ + --set-allowed-modes="${allowedmode}" || { + proto_notify_error "${interface}" MM_FAILED_SETTING_PREFERRED_MODE + proto_block_restart "${interface}" + return 1 + } +} + proto_modemmanager_setup() { local interface="$1" local modempath modemstatus bearercount bearerpath connectargs bearerstatus beareriface local bearermethod_ipv4 bearermethod_ipv6 auth cliauth local operatorname operatorid registration accesstech signalquality + local allowedmode preferredmode - local device apn allowedauth username password pincode iptype plmn metric signalrate allow_roaming + local device apn allowedauth username password pincode + local iptype plmn metric signalrate allow_roaming local address prefix gateway mtu dns1 dns2 - json_get_vars device apn allowedauth username password pincode iptype plmn metric signalrate allow_roaming + json_get_vars device apn allowedauth username password + json_get_vars pincode iptype plmn metric signalrate allow_roaming + json_get_vars allowedmode preferredmode # validate sysfs path given in config [ -n "${device}" ] || { @@ -390,6 +439,33 @@ proto_modemmanager_setup() { } echo "modem available at ${modempath}" + [ -z "${allowedmode}" ] || { + case "$allowedmode" in + "2g") + modemmanager_set_allowed_mode "$device" \ + "$interface" "2g" + ;; + "3g") + modemmanager_set_allowed_mode "$device" \ + "$interface" "3g" + ;; + "4g") + modemmanager_set_allowed_mode "$device" \ + "$interface" "4g" + ;; + "5g") + modemmanager_set_allowed_mode "$device" \ + "$interface" "5g" + ;; + *) + modemmanager_set_preferred_mode "$device" \ + "$interface" "${allowedmode}" "${preferredmode}" + ;; + esac + # check error for allowed_mode and preferred_mode function call + [ "$?" -ne "0" ] && return 1 + } + # always cleanup before attempting a new connection, just in case modemmanager_cleanup_connection "${modemstatus}" -- 2.30.2