diff options
author | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2019-06-22 11:24:51 +0300 |
---|---|---|
committer | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2019-06-22 13:53:16 +0300 |
commit | d9024556c684f2c157d472eee814e01ff2496ff9 (patch) | |
tree | 7b68c5e8365076f3f828cf5ac4fd28da85212f6d | |
parent | a7673be0a434243c2011d809cc0a3a01441470fb (diff) | |
download | libmts-io-d9024556c684f2c157d472eee814e01ff2496ff9.tar.gz libmts-io-d9024556c684f2c157d472eee814e01ff2496ff9.tar.bz2 libmts-io-d9024556c684f2c157d472eee814e01ff2496ff9.zip |
[MTS-MTQ] SIM status and PIN unlock procedures
Added common implementations for CellularRadio::unlockSimCard and
CellularRadio::getSimLockStatus
-rw-r--r-- | include/mts/MTS_IO_CellularRadio.h | 5 | ||||
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 44 |
2 files changed, 48 insertions, 1 deletions
diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 5ca9f9a..9866d73 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -76,6 +76,9 @@ namespace MTS { CODE getRegistration(REGISTRATION& eRegistration) override; CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) override; + + CODE unlockSimCard(const Json::Value& jArgs) override; + CODE getMipProfile(Json::Value& jMipProfile) override; CODE validateMsl(const Json::Value& jArgs) override; CODE setMsid(const Json::Value& jArgs) override; @@ -144,7 +147,7 @@ namespace MTS { * CODE::NOT_APPLICABLE when the modem doesn't support this feature, * CODE::ERROR otherwise (SIM card removed, modem is inaccessible, etc). */ - virtual CODE getSimLockStatus(std::string& sData) = 0; + virtual CODE getSimLockStatus(std::string& sData); /** * @brief getSimLockAttempts - get the number of SIM unlock attempts left. diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 8c4c75b..df1303c 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -760,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; @@ -821,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()); |