summaryrefslogtreecommitdiff
path: root/src/MTS_IO_CellularRadio.cpp
diff options
context:
space:
mode:
authorSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2019-06-24 11:30:51 +0300
committerSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2019-06-24 11:47:11 +0300
commit83c86fe26b69439f75c893618114d16be0d1d2e8 (patch)
tree4608bf8e5b881016fd74d2caa5a426ba9f9ad438 /src/MTS_IO_CellularRadio.cpp
parent143feb6a4587817d28c77e4df3a1b594b855f5e5 (diff)
parent28ce5eaaa648670a2c83d583ebff2dc517af002e (diff)
downloadlibmts-io-83c86fe26b69439f75c893618114d16be0d1d2e8.tar.gz
libmts-io-83c86fe26b69439f75c893618114d16be0d1d2e8.tar.bz2
libmts-io-83c86fe26b69439f75c893618114d16be0d1d2e8.zip
Merge branch 'mtr-mtq-sim-status' into quectel-radio
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r--src/MTS_IO_CellularRadio.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index dbb64a5..df1303c 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;
@@ -716,6 +760,31 @@ void CellularRadio::getCommonNetworkStats(Json::Value& jData) {
}
}
+CellularRadio::CODE CellularRadio::getSimLockStatus(std::string& sData)
+{
+ printTrace("%s| Get SIM lock status", m_sName.c_str());
+ std::string sCmd("AT+CPIN?");
+ std::string sResult = sendCommand(sCmd);
+
+ const std::string sPrefix = "+CPIN: ";
+ size_t start = sResult.find(sPrefix);
+ size_t end = sResult.rfind(ICellularRadio::RSP_OK);
+
+ if (start == std::string::npos || end == std::string::npos) {
+ printWarning("%s| Unable to get SIM lock status from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
+ return FAILURE;
+ }
+
+ start += sPrefix.size();
+ sData = MTS::Text::trim(sResult.substr(start, end-start));
+ if(sData.size() == 0) {
+ printWarning("%s| Unable to get SIM lock status from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
void CellularRadio::initMipProfile(Json::Value& jData) {
jData[ICellularRadio::KEY_MIP_ID] = 0;
jData[ICellularRadio::KEY_MIP_ENABLED] = false;
@@ -777,6 +846,25 @@ CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eReg
return eCode;
}
+CellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) {
+ printTrace("%s| Unlock the SIM card using PIN code", m_sName.c_str());
+
+ if(!jArgs["pin"].isString()) {
+ return INVALID_ARGS;
+ }
+
+ std::string sCmd = "AT+CPIN=" + jArgs["pin"].asString();
+ std::string sResult = sendCommand(sCmd);
+
+ size_t pos = sResult.find(ICellularRadio::RSP_OK);
+ if (pos == std::string::npos) {
+ printWarning("%s| Failed to unlock the SIM card using command [%s]", m_sName.c_str(), sCmd.c_str());
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
CellularRadio::CODE CellularRadio::validateMsl(const Json::Value&) {
printTrace("%s| Validate MSL", m_sName.c_str());