summaryrefslogtreecommitdiff
path: root/src/MTS_IO_TelitRadio.cpp
diff options
context:
space:
mode:
authorSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2019-06-22 12:03:17 +0300
committerSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2019-06-22 13:53:16 +0300
commit25bbcb7482dbbb93c9edfc3e1de415cfa4c260d0 (patch)
tree2799b227dd8d50b6f4bce79927347c5b588d0fe5 /src/MTS_IO_TelitRadio.cpp
parentd9024556c684f2c157d472eee814e01ff2496ff9 (diff)
downloadlibmts-io-25bbcb7482dbbb93c9edfc3e1de415cfa4c260d0.tar.gz
libmts-io-25bbcb7482dbbb93c9edfc3e1de415cfa4c260d0.tar.bz2
libmts-io-25bbcb7482dbbb93c9edfc3e1de415cfa4c260d0.zip
[MTS-MTQ] SIM status and PIN unlock procedures
Added Telit-specific implementation of the CellularRadio::getIsSimInserted and CellularRadio::getSimLockAttempts utility methods
Diffstat (limited to 'src/MTS_IO_TelitRadio.cpp')
-rw-r--r--src/MTS_IO_TelitRadio.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp
index 4fcf836..8a21b46 100644
--- a/src/MTS_IO_TelitRadio.cpp
+++ b/src/MTS_IO_TelitRadio.cpp
@@ -537,3 +537,94 @@ bool TelitRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, st
return bResult;
}
+
+CellularRadio::CODE TelitRadio::getIsSimInserted(bool& bData) {
+ printTrace("%s| Get SIM insertion status", getName().c_str());
+ std::string sCmd("AT#SIMDET?");
+ std::string sResult = sendCommand(sCmd);
+
+ const std::string sPrefix = "#SIMDET: ";
+ size_t start = sResult.find(sPrefix);
+ size_t end = sResult.rfind(ICellularRadio::RSP_OK);
+
+ if (end == std::string::npos) {
+ printWarning("%s| Unable to get SIM insertion status from radio using command [%s]", getName().c_str(), sCmd.c_str());
+ return FAILURE;
+ }
+
+ if (start == std::string::npos) {
+ printDebug("%s| AT#SIMDET? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str());
+ return FAILURE;
+ }
+
+ // #SIMDET: <mode>,<simin>
+ start += sPrefix.size();
+ std::vector<std::string> vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start, end-start)), ',');
+
+ if(vParts.size() != 2) {
+ printWarning("%s| Unable to parse SIM insertion status from response [%s]", getName().c_str(), sResult.c_str());
+ return FAILURE;
+ }
+
+ if (vParts[1] == "1") { // <simin>
+ bData = true;
+ } else {
+ bData = false;
+ }
+
+ return SUCCESS;
+}
+
+CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) {
+ std::string sLockStatus;
+ CODE retCode;
+
+ retCode = getSimLockStatus(sLockStatus);
+ if (retCode != SUCCESS) {
+ printWarning("%s| Unable determine the number of SIM unlock attempts: SIM lock status is unavailable [%s]", getName().c_str(), sLockStatus.c_str());
+ return retCode;
+ }
+
+ return getSimLockAttempts(iAttemptsPin, iAttemptsPuk, sLockStatus);
+}
+
+CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus) {
+ printTrace("%s| Get SIM unlock attempts left", getName().c_str());
+ std::string sCmd("AT#PCT?");
+ std::string sResult = sendCommand(sCmd);
+ std::string sValue;
+ int iValue;
+
+ const std::string sPrefix = "#PCT: ";
+ size_t start = sResult.find(sPrefix);
+ size_t end = sResult.rfind(ICellularRadio::RSP_OK);
+
+ if (end == std::string::npos) {
+ printWarning("%s| Unable to get SIM unlock attempts from radio using command [%s]", getName().c_str(), sCmd.c_str());
+ return FAILURE;
+ }
+
+ if (start == std::string::npos) {
+ printDebug("%s| AT#PCT? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str());
+ return FAILURE;
+ }
+
+ // #PCT: <n>
+ start += sPrefix.size();
+ sValue = MTS::Text::trim(sResult.substr(start, end-start));
+
+ if (!MTS::Text::parse(iValue, sValue)) {
+ printWarning("%s| Unable to parse SIM unlock attempts from response [%s]", getName().c_str(), sResult.c_str());
+ return FAILURE;
+ }
+
+ if (sLockStatus == "READY" || sLockStatus == "SIM PIN") {
+ iAttemptsPin = iValue; // Some PIN attempts left, maximum PUK attempts left
+ iAttemptsPuk = 10;
+ } else {
+ iAttemptsPin = 0; // No PIN attempts left
+ iAttemptsPuk = iValue;
+ }
+
+ return SUCCESS;
+}