modemmanager: move plmn registration into own function
authorFlorian Eckert <fe@dev.tdt.de>
Fri, 18 Oct 2024 10:45:21 +0000 (12:45 +0200)
committerFlorian Eckert <Eckert.Florian@googlemail.com>
Fri, 15 Nov 2024 10:17:05 +0000 (11:17 +0100)
To improve the code, the setting of the 'plmn' is moved to separate function.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
net/modemmanager/files/lib/netifd/proto/modemmanager.sh

index 10ceba5759370f064ad05e92c4c6c1ef99a86628..295f7767443be80cd6efe077bde2bbb6d7d7010f 100644 (file)
@@ -527,6 +527,26 @@ modemmanager_init_epsbearer() {
        sleep 2
 }
 
+modemmanager_set_plmn() {
+       local device="$1"
+       local interface="$2"
+       local plmn="$3"
+       local force_connection="$4"
+
+       mmcli --modem="${device}" \
+               --timeout 120 \
+               --3gpp-register-in-operator="${plmn}" || {
+               if [ -n "${force_connection}" ] && [ "${force_connection}" -eq 1 ]; then
+                       echo "3GPP operator registration failed -> attempting restart"
+                               proto_notify_error "${interface}" MM_INTERFACE_RESTART
+                       else
+                               proto_notify_error "${interface}" MM_3GPP_OPERATOR_REGISTRATION_FAILED
+                               proto_block_restart "${interface}"
+               fi
+               return 1
+       }
+}
+
 proto_modemmanager_setup() {
        local interface="$1"
 
@@ -624,22 +644,10 @@ proto_modemmanager_setup() {
                [ "$?" -ne "0" ] && return 1
        }
 
-
        [ -z "${plmn}" ] || {
-               echo "starting network registraion with plmn '${plmn}'..."
-               mmcli --modem="${device}" \
-                       --timeout 120 \
-                       --3gpp-register-in-operator="${plmn}" || {
-
-                       if [ -n "${force_connection}" ] && [ "${force_connection}" -eq 1 ]; then
-                               echo "3GPP operator registration failed -> attempting restart"
-                               proto_notify_error "${interface}" MM_INTERFACE_RESTART
-                       else
-                               proto_notify_error "${interface}" MM_3GPP_OPERATOR_REGISTRATION_FAILED
-                               proto_block_restart "${interface}"
-                       fi
-                       return 1
-               }
+               echo "starting network registration with plmn '${plmn}'..."
+               modemmanager_set_plmn "$device" "$interface" "$plmn" "$force_connection"
+               [ "$?" -ne "0" ] && return 1
        }
 
        if [ -z "${allowedmode}" ]; then