summaryrefslogtreecommitdiff
path: root/src/MTS_IO_TelitRadio.cpp
diff options
context:
space:
mode:
authorjeff <jhatch@multitech.com>2023-03-30 14:58:30 -0500
committerjeff <jhatch@multitech.com>2023-03-30 14:58:30 -0500
commit2f94db705de8e44e3aae9bbbf36fae6b8a697f76 (patch)
treefaeeeb2198fc08d323d06ee259d27bf6831f67df /src/MTS_IO_TelitRadio.cpp
parent582634c91a778dba7047a69b5559f849d03be112 (diff)
parent7c868e58e1bc930f12a60f79d30ed40f57439657 (diff)
downloadlibmts-io-2f94db705de8e44e3aae9bbbf36fae6b8a697f76.tar.gz
libmts-io-2f94db705de8e44e3aae9bbbf36fae6b8a697f76.tar.bz2
libmts-io-2f94db705de8e44e3aae9bbbf36fae6b8a697f76.zip
Commit merge with master on libmts-io mirror
Diffstat (limited to 'src/MTS_IO_TelitRadio.cpp')
-rw-r--r--src/MTS_IO_TelitRadio.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp
index be307e6..a706069 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 {