From a7673be0a434243c2011d809cc0a3a01441470fb Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 10:57:44 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Added a common implementation for the CellularRadio::getSimStatusSummary method --- include/mts/MTS_IO_CellularRadio.h | 1 + src/MTS_IO_CellularRadio.cpp | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index e23cbc9..5ca9f9a 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -61,6 +61,7 @@ namespace MTS { CODE getMeid(std::string& sMeid) override; CODE getImsi(std::string& sImsi) override; CODE getSimStatus(std::string& sSimStatus) override; + CODE getSimStatusSummary(Json::Value& jData) override; CODE getLac(std::string& sLac) override; CODE getMdn(std::string& sMdn) override; CODE getMsid(std::string& sMsid) override; diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index dbb64a5..8c4c75b 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -285,6 +285,50 @@ CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { return FAILURE; } +CellularRadio::CODE CellularRadio::getSimStatusSummary(Json::Value& jData) { + bool bIsSimInserted = false; + bool bIsSimLocked = true; + int iAttemptsPin = 0; + int iAttemptsPuk = 0; + std::string sSimLockStatus; + CODE retCode; + + do { + retCode = getIsSimInserted(bIsSimInserted); + if (retCode != SUCCESS) { + break; + } + + if (!bIsSimInserted) { + // There is no left much to do. Return one field only. + jData[KEY_IS_SIM_INSERTED] = bIsSimInserted; + break; + } + + // The following code assumes that the SIM card is inserted + retCode = getSimLockStatus(sSimLockStatus); + if (retCode != SUCCESS) { + break; + } + + bIsSimLocked = (sSimLockStatus != "READY"); // SIM PIN, SIM PUK or other values + + retCode = getSimLockAttempts(iAttemptsPin, iAttemptsPuk); + if (retCode != SUCCESS) { + break; + } + + // Everything fetched successfully. Populate the jData object + jData[KEY_IS_SIM_INSERTED] = bIsSimInserted; + jData[KEY_IS_SIM_LOCKED] = bIsSimLocked; + jData[KEY_SIM_LOCK_STATUS] = sSimLockStatus; + jData[KEY_ATTEMPTS_PIN] = iAttemptsPin; + jData[KEY_ATTEMPTS_PUK] = iAttemptsPuk; + } while (false); + + return retCode; +} + CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { Json::Value jData; -- cgit v1.2.3