From 33ed089d4b59bd79ae35f626ea6fc3da20c2edb9 Mon Sep 17 00:00:00 2001 From: Yevhen Mykhno Date: Thu, 9 Feb 2023 20:25:11 +0200 Subject: [GP-1597] mPower R.6.3.X: Cellular Provider Profiles - LTE Authentication --- src/MTS_IO_TelitRadio.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'src/MTS_IO_TelitRadio.cpp') diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 21af65d..00c1686 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -1178,6 +1178,109 @@ bool MTS::IO::TelitRadio::isContainsSignChar(const std::string& str) { return true; } +std::vector TelitRadio::getSupportedPdpContextAuthTypes() const { + return { + VALUE_PDP_CONTEXT_AUTH_TYPE_NONE, + VALUE_PDP_CONTEXT_AUTH_TYPE_PAP, + VALUE_PDP_CONTEXT_AUTH_TYPE_CHAP + }; +} + +ICellularRadio::CODE TelitRadio::isPdpContextAuthSupported(bool& isSupported) { + std::string sCmd("AT#PDPAUTH=?"); + return isCommandSupported(sCmd, isSupported); +} + +ICellularRadio::CODE TelitRadio::fillPdpContextAuthFields(Json::Value& jData) { + CODE rc; + std::string sCmd("AT#PDPAUTH?"); + std::string sResult; + + // #PDPAUTH: 1,0 + // #PDPAUTH: 2,0 + // #PDPAUTH: 3,0 + // #PDPAUTH: 4,1,"admin" + rc = sendBasicQuery(sCmd, "", sResult, 300); + + if (SUCCESS != rc) { + return rc; + } + + std::vector vContexts = MTS::Text::split(sResult, "#PDPAUTH:"); + std::string sContextId; + + for (std::string& sLine : vContexts) { + sLine = MTS::Text::trim(sLine); + + if (sLine.empty()) { + continue; + } + + // 4,1,"admin" + // [0][1] [2] + auto vAuthParams = MTS::Text::split(sLine, ","); + + // Contains 2 elements when the authentication type is NONE, contains 3 elements in other cases + if (vAuthParams.size() < 2) { + printError("%s| Failed to parse PDP context authentication string [%s]", getName().c_str(), sLine.c_str()); + return FAILURE; + } + + sContextId = vAuthParams[0]; + + uint8_t iValue; + if (! MTS::Text::parse(iValue, vAuthParams[1])) { + printError("%s| Failed to parse PDP context authentication type [%s]", getName().c_str(), vAuthParams[1].c_str()); + return FAILURE; + } + + rc = convertPdpContextAuthTypeToString(static_cast(iValue), sResult); + if (SUCCESS != rc) { + printError("%s| Failed to convert PDP context authentication type to string [%d]", getName().c_str(), iValue); + return rc; + } + + jData[sContextId][KEY_PDP_CONTEXT_AUTH_TYPE] = sResult; + + if (iValue == PDP_CONTEXT_AUTH_TYPE::NONE) { + continue; + } + + if (vAuthParams.size() < 3) { + printError("%s| Failed to parse PDP context authentication string [%s]", getName().c_str(), sLine.c_str()); + return FAILURE; + } + + jData[sContextId][KEY_PDP_CONTEXT_AUTH_USERNAME] = MTS::Text::trim(vAuthParams[2], '"'); + } + + return SUCCESS; +} + +ICellularRadio::CODE TelitRadio::setPdpContextAuth(const PdpContextInfo& pdpContext) { + printTrace("%s| Setting PDP context authentication to the radio", getName().c_str()); + + CODE rc; + std::string sCmd = "AT#PDPAUTH="; + PDP_CONTEXT_AUTH_TYPE eAuthType; + + sCmd += pdpContext.sId + ","; + + rc = convertStringToPdpContextAuthType(pdpContext.sAuthType, eAuthType); + + if (SUCCESS != rc) { + return rc; + } + + sCmd += std::to_string(eAuthType); + + if (PDP_CONTEXT_AUTH_TYPE::NONE != eAuthType) { + sCmd += "," + pdpContext.sUsername + "," + pdpContext.sPassword; + } + + return sendBasicCommand(sCmd); +} + const std::vector& TelitRadio::getDiagCommands(bool) { // Declare as static to initialize only when used, but cache the results. const static std::vector vCommands { -- cgit v1.2.3