diff options
Diffstat (limited to 'src/MTS_IO_QuectelRadio.cpp')
-rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index c4b6ac4..b1ac6fa 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -1629,6 +1629,114 @@ ICellularRadio::CODE QuectelRadio::setRxDiversity(const Json::Value& jArgs) { return SUCCESS; } +ICellularRadio::CODE QuectelRadio::convertStringToPdpContextType(const std::string& sStringType, std::string& sIntType) { + CODE rc = FAILURE; + + if ("IP" == sStringType) { + sIntType = "1"; + rc = SUCCESS; + } else if ("IPV6" == sStringType) { + sIntType = "2"; + rc = SUCCESS; + } else if ("IPV4V6" == sStringType) { + sIntType = "3"; + rc = SUCCESS; + } + + return rc; +} + +std::vector<std::string> QuectelRadio::getSupportedPdpContextAuthTypes() const { + return { + VALUE_PDP_CONTEXT_AUTH_TYPE_NONE, + VALUE_PDP_CONTEXT_AUTH_TYPE_PAP, + VALUE_PDP_CONTEXT_AUTH_TYPE_CHAP, + VALUE_PDP_CONTEXT_AUTH_TYPE_PAP_CHAP + }; +} + +ICellularRadio::CODE QuectelRadio::isPdpContextAuthSupported(bool& isSupported) { + std::string sCmd("AT+QICSGP=?"); + return isCommandSupported(sCmd, isSupported); +} + +ICellularRadio::CODE QuectelRadio::fillPdpContextAuthFields(Json::Value& jData) { + CODE rc; + std::string sCmd("AT+QICSGP="); + std::string sResult; + uint8_t iValue; + + // iterate over PDP contex IDs to get context settings + for (std::string & sContextId : jData.getMemberNames()) { + // +QICSGP: <context_type>,<APN>,<username>,<password>,<authentication> + // +QICSGP: 0,"","","",0 -- if the context does not exist + + rc = sendBasicQuery(sCmd+sContextId, "+QICSGP:", sResult, 300); + + if (SUCCESS != rc) { + return rc; + } + + // 1,"test","login","password",1 + // [0] [1] [2] [3] [4] + auto vAuthParams = MTS::Text::split(sResult, ","); + + if (vAuthParams.size() < 5) { + printError("%s| Failed to parse PDP context authentication string [%s]", getName().c_str(), sResult.c_str()); + return FAILURE; + } + + if (! MTS::Text::parse(iValue, vAuthParams[4])) { + printError("%s| Failed to parse PDP context authentication type [%s]", getName().c_str(), vAuthParams[4].c_str()); + return FAILURE; + } + + rc = convertPdpContextAuthTypeToString(static_cast<PDP_CONTEXT_AUTH_TYPE>(iValue), sResult); + if (SUCCESS != rc) { + return rc; + } + + jData[sContextId][KEY_PDP_CONTEXT_AUTH_TYPE] = sResult; + + if (iValue != PDP_CONTEXT_AUTH_TYPE::NONE) { + jData[sContextId][KEY_PDP_CONTEXT_AUTH_USERNAME] = MTS::Text::trim(vAuthParams[2], '"'); + jData[sContextId][KEY_PDP_CONTEXT_AUTH_PASSWORD] = MTS::Text::trim(vAuthParams[3], '"'); + } + } + + return SUCCESS; +} + +// AT+QICSGP=<contextID>[,<context_type>,<APN>[,<username>,<password>)[,<authentication>[,<cdma_pwd>]]]] +ICellularRadio::CODE QuectelRadio::setPdpContextAuth(const PdpContextInfo& pdpContext) { + printTrace("%s| Setting PDP context authentication to the radio", getName().c_str()); + + CODE rc; + std::string sContextType; + std::string sCmd = "AT+QICSGP="; + PDP_CONTEXT_AUTH_TYPE eAuthType; + + rc = convertStringToPdpContextType(pdpContext.sIpMode, sContextType); + if (SUCCESS != rc) { + return rc; + } + + rc = convertStringToPdpContextAuthType(pdpContext.sAuthType, eAuthType); + if (SUCCESS != rc) { + return rc; + } + + sCmd += pdpContext.sId + "," + sContextType + ",\"" + pdpContext.sApn + "\""; + + if (PDP_CONTEXT_AUTH_TYPE::NONE == eAuthType) { + sCmd += ",\"\",\"\"," + std::to_string(eAuthType); + } else { + sCmd += ",\"" + pdpContext.sUsername + "\",\"" + pdpContext.sPassword +"\"," + std::to_string(eAuthType); + } + + return sendBasicCommand(sCmd); +} + const std::vector<std::string>& QuectelRadio::getDiagCommands(bool) { // Declare as static to initialize only when used, but cache the results. const static std::vector<std::string> vCommands { |