diff options
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index b18478e..49a2b32 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -21,6 +21,7 @@ #include "mts/MTS_IO_CellularRadio.h" #include <unistd.h> +#include <sys/stat.h> #include <mts/MTS_IO_MccMncTable.h> #include <mts/MTS_Thread.h> @@ -200,6 +201,11 @@ ICellularRadio::CODE CellularRadio::getFirmwareBuild(std::string& sFirmwareBuild return FAILURE; } +ICellularRadio::CODE CellularRadio::getVendorFirmware(std::string& sVendorFirmware) { + sVendorFirmware = ICellularRadio::VALUE_NOT_SUPPORTED; + return FAILURE; +} + ICellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { printTrace("%s| Get Hardware", m_sName.c_str()); sHardware = ICellularRadio::VALUE_NOT_SUPPORTED; @@ -1051,6 +1057,30 @@ ICellularRadio::CODE CellularRadio::updateFumo(const Json::Value&, UpdateCb&) { return NOT_APPLICABLE; } +ICellularRadio::CODE CellularRadio::updateFumoLocal(int, ICellularRadio::UpdateCb&) { + printTrace("%s| Update Local Firmware Update Management Object", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +ICellularRadio::CODE CellularRadio::fumoLocalInject(int, ICellularRadio::UpdateCb&) { + printTrace("%s| Inject Delta Firmware Image File: not applicable", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +ICellularRadio::CODE CellularRadio::fumoLocalApply(ICellularRadio::UpdateCb&) { + printTrace("%s| Apply Delta Firmware Image File: not applicable", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +ICellularRadio::CODE CellularRadio::fumoLocalCleanup() { + printTrace("%s| Cleanup Delta Firmware Image File: not applicable", m_sName.c_str()); + + return NOT_APPLICABLE; +} + ICellularRadio::CODE CellularRadio::resetHfa(const Json::Value&, UpdateCb&) { printTrace("%s| HFA Reset", m_sName.c_str()); @@ -1103,6 +1133,34 @@ std::string CellularRadio::sendCommand(const std::string& sCmd, MTS::IO::Cellula return ICellularRadio::sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); } +ICellularRadio::CODE CellularRadio::sendData(const char* pData, size_t nBytes) { + if(m_apIo.isNull()) { + printError("RADIO| IO is not set in sendData"); + return ERROR; + } + + // This limit comes from the Connection::write implementation. Otherwise we can get overflows. + const size_t maxInt32 = INT32_MAX; // iSize parameter type in Connection::write + const size_t maxUInt32 = UINT32_MAX; // return value type in Connection::write + const size_t nSizeLimit = std::min(maxInt32, maxUInt32); + + if (nBytes > nSizeLimit) { + printError("RADIO| Chunks larger than %d bytes are not supported", nSizeLimit); + return INVALID_ARGS; + } + + // Now we can ignore conversion and overflow warnings emitted by compiler. + int32_t iResult; + iResult = m_apIo->write(pData, nBytes); + + if(iResult != static_cast<int32_t>(nBytes)) { + printError("RADIO| Failed to send data to radio"); + return ERROR; + } + + return SUCCESS; +} + bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType) { std::vector<std::string> vParts = MTS::Text::split(sLine, ":", 2); @@ -1221,3 +1279,78 @@ const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &cha return band; } + +ICellularRadio::CODE CellularRadio::getFileSize(int fd, size_t& nBytes) { + CODE rc = FAILURE; + + do { + struct stat fileStatus; + + // On success, zero is returned. On error, -1 is returned, and errno is set appropriately. + if (fstat(fd, &fileStatus) < 0) { + printError("Failed to determine file size: %d", errno); + break; + } + + if (fileStatus.st_size < 0) { + printError("Failed to determine file size, file size is negative: %d", fileStatus.st_size); + break; + } + + nBytes = static_cast<size_t>(fileStatus.st_size); + rc = SUCCESS; + + } while (false); + + lseek(fd, 0, SEEK_SET); + return rc; +} + +ICellularRadio::CODE CellularRadio::sizeToChunks(const size_t nBytes, const size_t chunkSize, size_t& nChunks) { + nChunks = (nBytes + chunkSize - 1) / chunkSize; + return SUCCESS; +} + +ICellularRadio::CODE CellularRadio::readChunk(int fd, char* pChunk, size_t dChunkSize, size_t& nReadBytes) { + size_t nUsedBuffer = 0; + CODE rc = FAILURE; + + while (true) { + + if (nUsedBuffer > dChunkSize) { + printError("Internal pointer error, abort upload: %d", nUsedBuffer); + rc = ERROR; + break; + } + + if (nUsedBuffer == dChunkSize) { + // full chunk received + rc = SUCCESS; + nReadBytes = dChunkSize; + break; + } + + char* pData = pChunk + nUsedBuffer; + size_t nFreeBuffer = dChunkSize - nUsedBuffer; + + ssize_t dReadCount = read(fd, pData, nFreeBuffer); + if (dReadCount < 0) { + printError("Failed to read from the source file: %d", errno); + rc = ERROR; + break; + } + + size_t duReadCount = static_cast<size_t>(dReadCount); + if (duReadCount == 0) { + // EOF. Return what was already read + nReadBytes = nUsedBuffer; + rc = SUCCESS; + break; + } + + nUsedBuffer += duReadCount; + + } + + return rc; +} |