Fix SIM2 PIN verification and replace Plymouth boot splash with rotating Bananarchy logo

This commit is contained in:
Luxferre
2026-10-25 13:10:37 +02:00
parent b7c57aab2f
commit fe8ba03941
18 changed files with 380 additions and 39 deletions
@@ -109,6 +109,8 @@ parse_uim_card_status() {
BEGIN {
prim_slot = 0
prim_app = 0
sec_slot = 0
sec_app = 0
cur_slot = 0
in_app = 0
for (s = 1; s <= 2; s++) {
@@ -141,6 +143,20 @@ parse_uim_card_status() {
prim_app = line + 0
}
}
/Secondary GW:/ {
if ($0 ~ /slot \x27[0-9]+\x27/) {
line = $0
sub(/.*slot \x27/, "", line)
sub(/\x27.*/, "", line)
sec_slot = line + 0
}
if ($0 ~ /application \x27[0-9]+\x27/) {
line = $0
sub(/.*application \x27/, "", line)
sub(/\x27.*/, "", line)
sec_app = line + 0
}
}
/^[[:space:]]*Slot \[[0-9]+\]:/ {
line = $0
sub(/.*Slot \[/, "", line)
@@ -239,7 +255,16 @@ parse_uim_card_status() {
printf "PREFERRED_SLOT=%d\n", (pref == 2 ? 2 : 1)
printf "PRIMARY_GW_SLOT=%d\n", prim_slot
printf "PRIMARY_GW_APP=%d\n", prim_app
printf "SECONDARY_GW_SLOT=%d\n", sec_slot
printf "SECONDARY_GW_APP=%d\n", sec_app
for (s = 1; s <= 2; s++) {
gsub(/[^A-Za-z0-9_.:-]/, "_", cstate[s])
gsub(/[^A-Za-z0-9_.:-]/, "_", rawstate[s])
gsub(/[^A-Za-z0-9_.:-]/, "_", app_type[s])
gsub(/[^A-Za-z0-9_.:-]/, "_", app_state[s])
gsub(/[^A-Za-z0-9_.:-]/, "", aid[s])
gsub(/[^A-Za-z0-9_.:-]/, "_", pin1_state[s])
gsub(/[^A-Za-z0-9_.:-]/, "_", upin_state[s])
printf "SLOT%d_STATE=%s\n", s, cstate[s]
printf "SLOT%d_RAW_STATE=%s\n", s, rawstate[s]
printf "SLOT%d_APP_TYPE=%s\n", s, app_type[s]
@@ -355,6 +380,7 @@ parse_nas_serving_system() {
printf "NAS_CS_STATE=%s\n", cs_state
printf "NAS_PS_STATE=%s\n", ps_state
printf "NAS_RAT=%s\n", rat
printf "NAS_RADIO=%s\n", rat
printf "NAS_MCC=%s\n", mcc
printf "NAS_MNC=%s\n", mnc
printf "NAS_OPERATOR=%s\n", op_desc
@@ -450,6 +476,10 @@ provision_slot() {
return 0
fi
if [ "${SECONDARY_GW_SLOT:-0}" = "$chosen_slot" ]; then
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=secondary-gw-provisioning' >/dev/null 2>&1 || true
fi
if [ "$PRIMARY_GW_SLOT" != "0" ]; then
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning' >/dev/null 2>&1 || true
fi
@@ -481,6 +511,9 @@ prepare_slot_for_pin_op() {
fi
eval "target_aid=\$SLOT${slot}_AID"
if [ "$PRIMARY_GW_SLOT" != "$slot" ]; then
if [ "${SECONDARY_GW_SLOT:-0}" = "$slot" ]; then
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=secondary-gw-provisioning' >/dev/null 2>&1 || true
fi
if [ "$PRIMARY_GW_SLOT" != "0" ]; then
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning' >/dev/null 2>&1 || true
fi
@@ -490,12 +523,26 @@ prepare_slot_for_pin_op() {
else
$QMICLI_MODEM --uim-change-provisioning-session="slot=$slot,activate=yes,session-type=primary-gw-provisioning" >/dev/null 2>&1 || true
fi
sleep 0.6
sleep 0.5
fi
fi
fi
}
restart_modemmanager_clean() {
if command -v rc-service >/dev/null 2>&1; then
timeout 4 rc-service polkit start >/dev/null 2>&1 || true
timeout 6 rc-service modemmanager restart >/dev/null 2>&1 || {
killall -q ModemManager 2>/dev/null || true
sleep 0.3
timeout 6 rc-service modemmanager zap >/dev/null 2>&1 || true
timeout 6 rc-service modemmanager start >/dev/null 2>&1 || true
}
elif command -v systemctl >/dev/null 2>&1; then
timeout 6 systemctl restart ModemManager >/dev/null 2>&1 || true
fi
}
enable_and_register_modem() {
target_slot="${1:-$PREFERRED_SIM_SLOT}"
force_unlock="${2:-0}"
@@ -506,7 +553,7 @@ enable_and_register_modem() {
i=0
mm_state=""
while [ "$i" -lt 10 ]; do
while [ "$i" -lt 8 ]; do
mm_state="$(timeout 3 mmcli -m any -K 2>/dev/null | awk -F': ' '/^modem\.generic\.state / {print $2; exit}' || true)"
if [ -n "$mm_state" ]; then
break
@@ -515,12 +562,8 @@ enable_and_register_modem() {
i=$((i + 1))
done
if [ "$mm_state" = "failed" ] || { [ "$force_unlock" = "1" ] && [ "$mm_state" = "locked" ]; }; then
if command -v rc-service >/dev/null 2>&1; then
timeout 6 rc-service modemmanager restart >/dev/null 2>&1 || true
elif command -v systemctl >/dev/null 2>&1; then
timeout 6 systemctl restart ModemManager >/dev/null 2>&1 || true
fi
if [ -z "$mm_state" ] || [ "$mm_state" = "failed" ] || { [ "$force_unlock" = "1" ] && [ "$mm_state" = "locked" ]; }; then
restart_modemmanager_clean
i=0
mm_state=""
while [ "$i" -lt 10 ]; do
@@ -604,6 +647,15 @@ case "$cmd" in
echo "PREFERRED_SLOT=$PREFERRED_SIM_SLOT"
exit 0
fi
eval "$(parse_uim_card_status "$QMI_CARDS" "$PREFERRED_SIM_SLOT")"
if [ "$PRIMARY_GW_SLOT" = "0" ] && { [ "$SLOT1_STATE" = "present" ] || [ "$SLOT2_STATE" = "present" ]; }; then
SIM_WAIT_TIME=1
provision_slot "$PREFERRED_SIM_SLOT" 2 >/dev/null 2>&1 || true
QMI_CARDS_NEW="$($QMICLI_MODEM --uim-get-card-status 2>/dev/null || true)"
if [ -n "$QMI_CARDS_NEW" ]; then
QMI_CARDS="$QMI_CARDS_NEW"
fi
fi
echo "MODEM_AVAILABLE=1"
parse_uim_card_status "$QMI_CARDS" "$PREFERRED_SIM_SLOT"
QMI_NAS="$($QMICLI_MODEM --nas-get-serving-system 2>/dev/null || true)"
@@ -622,11 +674,7 @@ case "$cmd" in
save_preferred_slot "$target"
SIM_WAIT_TIME=3
provision_slot "$target" 5
if command -v rc-service >/dev/null 2>&1; then
timeout 6 rc-service modemmanager restart >/dev/null 2>&1 || true
elif command -v systemctl >/dev/null 2>&1; then
timeout 6 systemctl restart ModemManager >/dev/null 2>&1 || true
fi
restart_modemmanager_clean
spawn_enable_and_register "$target" 0
exit 0
;;
@@ -639,30 +687,29 @@ case "$cmd" in
exit 1
fi
prepare_slot_for_pin_op "$slot"
eval "before_ret=\${SLOT${slot}_PIN1_RETRIES:-3}"
verified=0
wrong_pin=0
sim_id="$(timeout 3 mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
if [ -n "$sim_id" ] && timeout 4 mmcli -i "$sim_id" --pin="$pin" >/dev/null 2>&1; then
verified=1
if [ -n "$sim_id" ]; then
mm_pin_out="$(timeout 5 mmcli -i "$sim_id" --pin="$pin" 2>&1)" && verified=1 || {
if printf "%s\n" "$mm_pin_out" | grep -qiE "IncorrectPin|SimPin|SimPuk|PinBlocked|incorrect"; then
wrong_pin=1
fi
}
fi
if [ "$verified" = "0" ] && [ -n "$QMICLI_MODEM" ]; then
if $QMICLI_MODEM --uim-verify-pin="PIN1,$pin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
verified=1
elif $QMICLI_MODEM --uim-verify-pin="PIN1,$pin,session-type=card-slot-$slot" >/dev/null 2>&1; then
verified=1
elif $QMICLI_MODEM --uim-verify-pin="PIN1,$pin" >/dev/null 2>&1; then
verified=1
elif $QMICLI_MODEM --uim-verify-pin="UPIN,$pin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
verified=1
elif $QMICLI_MODEM --uim-verify-pin="UPIN,$pin,session-type=card-slot-$slot" >/dev/null 2>&1; then
verified=1
elif $QMICLI_MODEM --dms-uim-verify-pin="PIN,$pin" >/dev/null 2>&1; then
verified=1
fi
fi
if [ "$verified" = "0" ]; then
at_cpin="$("$0" at auto "AT+CPIN=\"$pin\"" 2>/dev/null || true)"
if printf "%s\n" "$at_cpin" | grep -qE "(^|[[:space:]])OK([[:space:]]|$)"; then
verified=1
if [ "$verified" = "0" ] && [ "$wrong_pin" = "0" ] && [ -n "$QMICLI_MODEM" ]; then
qmi_pin_out="$($QMICLI_MODEM --uim-verify-pin="PIN1,$pin,session-type=primary-gw-provisioning" 2>&1)" && verified=1 || {
if printf "%s\n" "$qmi_pin_out" | grep -qiE "IncorrectPin|PinBlocked|Blocked"; then
wrong_pin=1
fi
}
if [ "$verified" = "0" ] && [ "$wrong_pin" = "0" ]; then
qmi_pin_out="$($QMICLI_MODEM --uim-verify-pin="PIN1,$pin,session-type=card-slot-$slot" 2>&1)" && verified=1 || {
if printf "%s\n" "$qmi_pin_out" | grep -qiE "IncorrectPin|PinBlocked|Blocked"; then
wrong_pin=1
fi
}
fi
fi
if [ "$verified" = "0" ] && [ -n "$QMICLI_MODEM" ]; then
@@ -671,18 +718,24 @@ case "$cmd" in
eval "$(parse_uim_card_status "$QMI_CARDS_AFTER" "$slot")"
eval "after_pin1=\$SLOT${slot}_PIN1_STATE"
eval "after_app=\$SLOT${slot}_APP_STATE"
eval "after_ret=\$SLOT${slot}_PIN1_RETRIES"
if [ "$after_pin1" = "enabled-verified" ] || [ "$after_pin1" = "disabled" ] || [ "$after_app" = "ready" ]; then
verified=1
elif [ "$after_ret" -lt "$before_ret" ] 2>/dev/null; then
wrong_pin=1
fi
fi
fi
if [ "$verified" = "0" ] && [ "$wrong_pin" = "0" ]; then
at_cpin="$("$0" at auto "AT+CPIN=\"$pin\"" 2>/dev/null || true)"
if printf "%s\n" "$at_cpin" | grep -qE "(^|[[:space:]])OK([[:space:]]|$)"; then
verified=1
fi
fi
if [ "$verified" = "1" ]; then
save_preferred_slot "$slot"
SIM_WAIT_TIME=2
provision_slot "$slot" 3 >/dev/null 2>&1 || true
if [ -n "$sim_id" ]; then
timeout 4 mmcli -i "$sim_id" --pin="$pin" >/dev/null 2>&1 || true
fi
timeout 4 mmcli -m any -e >/dev/null 2>&1 || true
spawn_enable_and_register "$slot" 1
exit 0