modem: bind QMI primary-gw-provisioning session before USIM PIN verification and fix SIM2 target slot resolution

This commit is contained in:
Luxferre
2026-10-25 11:50:57 +02:00
parent b56f310f21
commit 33d3d225c1
4 changed files with 142 additions and 54 deletions
+42 -31
View File
@@ -601,8 +601,28 @@ int runModemApp(int argc, char** argv) {
lastRefreshMs = nowMs();
};
auto defaultActiveOrPresentSlot = [&]() -> int {
if (status.slots[0].needsPin() || status.slots[0].needsPuk()) return 1;
if (status.slots[1].needsPin() || status.slots[1].needsPuk()) return 2;
if (status.primaryGwSlot >= 1 && status.primaryGwSlot <= 2 &&
status.slots[status.primaryGwSlot - 1].state == "present") {
return status.primaryGwSlot;
}
if (status.slots[1].state == "present" && status.slots[0].state != "present") {
return 2;
}
if (status.slots[0].state == "present" && status.slots[1].state != "present") {
return 1;
}
return std::clamp(status.preferredSlot, 1, 2);
};
auto openPinOrPukModalForSlot = [&](int slotNum) {
targetSlot = std::clamp(slotNum, 1, 2);
slotNum = std::clamp(slotNum, 1, 2);
if (status.slots[slotNum - 1].state != "present") {
slotNum = defaultActiveOrPresentSlot();
}
targetSlot = slotNum;
const auto& s = status.slots[targetSlot - 1];
wizardStep = 0;
revealDigits = false;
@@ -622,14 +642,7 @@ int runModemApp(int argc, char** argv) {
modal = ModalMode::None;
if (a == "unlock" || a == "pin" || a == "puk") {
activeTab = TabId::SimCards;
int lockSlot = (status.primaryGwSlot >= 1 && status.primaryGwSlot <= 2)
? status.primaryGwSlot
: status.preferredSlot;
if (status.slots[0].needsPin() || status.slots[0].needsPuk()) {
lockSlot = 1;
} else if (status.slots[1].needsPin() || status.slots[1].needsPuk()) {
lockSlot = 2;
}
int lockSlot = defaultActiveOrPresentSlot();
simRowSel = lockSlot - 1;
openPinOrPukModalForSlot(lockSlot);
} else if (a == "info" || a == "status" || a == "radio") {
@@ -647,12 +660,7 @@ int runModemApp(int argc, char** argv) {
ussdWaitingReply = false;
} else {
activeTab = TabId::SimCards;
// If active SIM is locked, auto-highlight it
if (status.slots[0].needsPin() || status.slots[0].needsPuk()) {
simRowSel = 0;
} else if (status.slots[1].needsPin() || status.slots[1].needsPuk()) {
simRowSel = 1;
}
simRowSel = defaultActiveOrPresentSlot() - 1;
}
};
@@ -1255,6 +1263,11 @@ int runModemApp(int argc, char** argv) {
std::to_string(slotNum) + " >/dev/null 2>&1", &rc);
runAsyncCmd("sxmo_hook_statusbar.sh modem >/dev/null 2>&1");
refreshData(false);
if (status.slots[slotNum - 1].needsPin() ||
status.slots[slotNum - 1].needsPuk()) {
openPinOrPukModalForSlot(slotNum);
return;
}
if (rc == 0) {
setBanner("Active SIM set to Slot " + std::to_string(slotNum));
} else {
@@ -1445,27 +1458,15 @@ int runModemApp(int argc, char** argv) {
}
switchSimSlotNow(otherSlot);
} else if (row == 3) {
int slot = (status.primaryGwSlot >= 1 && status.primaryGwSlot <= 2)
? status.primaryGwSlot
: status.preferredSlot;
if (status.slots[0].needsPin() || status.slots[0].needsPuk()) {
slot = 1;
} else if (status.slots[1].needsPin() || status.slots[1].needsPuk()) {
slot = 2;
}
openPinOrPukModalForSlot(slot);
openPinOrPukModalForSlot(defaultActiveOrPresentSlot());
} else if (row == 4) {
targetSlot = (status.primaryGwSlot >= 1 && status.primaryGwSlot <= 2)
? status.primaryGwSlot
: status.preferredSlot;
targetSlot = defaultActiveOrPresentSlot();
wizardStep = 0;
inputPin1.clear();
modalError.clear();
modal = ModalMode::TogglePinLock;
} else if (row == 5) {
targetSlot = (status.primaryGwSlot >= 1 && status.primaryGwSlot <= 2)
? status.primaryGwSlot
: status.preferredSlot;
targetSlot = defaultActiveOrPresentSlot();
wizardStep = 0;
inputPin1.clear();
inputPin2.clear();
@@ -1503,6 +1504,10 @@ int runModemApp(int argc, char** argv) {
if (modal == ModalMode::SimActions) {
int act = actionSel;
modal = ModalMode::None;
if (act >= 1 && act <= 4 &&
status.slots[targetSlot - 1].state != "present") {
targetSlot = defaultActiveOrPresentSlot();
}
if (act == 0) {
switchSimSlotNow(targetSlot);
} else if (act == 1) {
@@ -1537,7 +1542,13 @@ int runModemApp(int argc, char** argv) {
return;
}
if (activeTab == TabId::SimCards) {
targetSlot = (simRowSel == 1) ? 2 : 1;
if (simRowSel == 0) {
targetSlot = 1;
} else if (simRowSel == 1) {
targetSlot = 2;
} else {
targetSlot = defaultActiveOrPresentSlot();
}
actionSel = 0;
modal = ModalMode::SimActions;
} else if (activeTab == TabId::RadioInfo) {