diff options
Diffstat (limited to 'src/MTS_IO_TelitRadio.cpp')
| -rw-r--r-- | src/MTS_IO_TelitRadio.cpp | 103 | 
1 files changed, 103 insertions, 0 deletions
| 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<std::string> 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<std::string> 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<PDP_CONTEXT_AUTH_TYPE>(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<std::string>& TelitRadio::getDiagCommands(bool) {      // Declare as static to initialize only when used, but cache the results.      const static std::vector<std::string> vCommands { | 
