From 26f6e69e9d5c7049d42559259933482b35559889 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Thu, 28 May 2020 14:51:31 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Declared base interface and added stub implementation for the Delta Radio Firmware Upgrade support in libmts-io. --- include/mts/MTS_IO_CellularRadio.h | 3 +++ include/mts/MTS_IO_ICellularRadio.h | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'include') diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 56506af..9fdb076 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -98,6 +98,9 @@ namespace MTS { CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE uploadDeltaFirmwareFile(int fd, UpdateCb& stepCb) override; + CODE removeDeltaFirmwareFile() override; + CODE applyDeltaFirmwareFile(UpdateCb& stepCb) override; CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE activate(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE setActiveFirmware(const Json::Value& jArgs) override; diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 58d5076..5123ba1 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -405,6 +405,56 @@ namespace MTS { */ virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) = 0; + /** + * @brief uploadDeltaFirmwareFile - upload delta file to the radio's internal memory. + * + * This command uploads (injects) the whole delta firmware image to some place that + * can be later used by the radio to perform the Delta Radio Firmware Upgrade. + * + * This delta firmware image is NOT validated on the firmware image upload step. + * + * @param fd - file sescriptor of a file that shall be uploaded to the radio. + * @param stepCb - the callback to receive status updates during the upload. + * @return CODE::SUCCESS when the file was successfully uploaded, + * CODE::INVALID_ARGS when the file can't be opened for reading, + * CODE::NOT_APPLICABLE when not supported by this radio, + * CODE::ERROR otherwise. + */ + virtual CODE uploadDeltaFirmwareFile(int fd, UpdateCb& stepCb) = 0; + + /** + * @brief removeDeltaFirmwareFile - remove the delta file from the radio's internal memory. + * + * This command allows to remove the old delta firmware image from the radio's internal + * memory for cases when it's no longer needed. + * + * @param fd - file sescriptor of a file that shall be uploaded to the radio. + * @return CODE::SUCCESS when the file was successfully deleted, + * CODE::FAILURE when the file can't be deleted (i.e. no such file), + * CODE::NOT_APPLICABLE when not supported by this radio, + * CODE::ERROR otherwise. + */ + virtual CODE removeDeltaFirmwareFile() = 0; + + /** + * @brief applyDeltaFirmwareFile - apply the delta file that was previously uploaded. + * + * This commands initializes and tracks the progress of the delta firmware upgrade + * procedure using the delta firmware image file that was previously uploaded + * into internal radio's memory. + * + * See ICellularRadio::removeDeltaFirmwareFile to upload the file and prepare + * for the upgrade. + * + * @param fd - file sescriptor of a file that shall be uploaded to the radio. + * @param stepCb - the callback to receive status updates during the upgrade. + * @return CODE::SUCCESS when the file was successfully deleted, + * CODE::FAILURE when the file can't be deleted (i.e. no such file), + * CODE::NOT_APPLICABLE when not supported by this radio, + * CODE::ERROR otherwise. + */ + virtual CODE applyDeltaFirmwareFile(UpdateCb& stepCb) = 0; + /* * jArgs = { * "msl" : "Master Subsidy Lock (Sprint): STRING" -- cgit v1.2.3 From 9f5a4f138b56a0a1b4e5764a69261aa4a4edaa71 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Thu, 28 May 2020 15:55:00 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Declared base interface and added started implementation for the QuectelRadio class. Implemented file listing (file status check) and file removal logic. --- include/mts/MTS_IO_QuectelRadio.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index df3b5b5..8aba437 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -42,6 +42,10 @@ namespace MTS { CODE setMdn(const Json::Value& jArgs) override; + CODE uploadDeltaFirmwareFile(int fd, UpdateCb& stepCb) override; + CODE removeDeltaFirmwareFile() override; + CODE applyDeltaFirmwareFile(UpdateCb& stepCb) override; + protected: QuectelRadio(const std::string& sName, const std::string& sRadioPort); @@ -51,7 +55,13 @@ namespace MTS { virtual CODE getServiceDomain(SERVICEDOMAIN& sd); virtual CODE convertToActiveBand(const std::string& sQuectelBand, ACTIVEBAND& band); + virtual CODE uploadFile(int fd, const std::string& sTargetFilename, UpdateCb& stepCb); + virtual CODE removeFile(const std::string& sTargetFilename); + virtual CODE checkFile(bool& bFilePresent, const std::string& sTargetFilename); + private: + static const std::string VALUE_MTS_DELTA_NAME; + static const std::string VALUE_MTS_DELTA_PATH; }; } -- cgit v1.2.3 From 6e9ce61addd97809d5ea7b912332dd11a4bf7cee Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 29 May 2020 21:02:15 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Initial implementation of the delta firmware image upload for Quectel radios. --- include/mts/MTS_IO_CellularRadio.h | 2 ++ include/mts/MTS_IO_ICellularRadio.h | 1 + include/mts/MTS_IO_QuectelRadio.h | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) (limited to 'include') diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 9fdb076..92df561 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -177,6 +177,8 @@ namespace MTS { REGISTRATION parseRegResponse(std::string sResult); CODE getRegistration(REGISTRATION& eRegistration, const std::string& sType); + virtual CODE sendData(const char* pData, size_t nBytes); + class RadioBandMap : public MTS::NonCopyable { public: RadioBandMap() diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 5123ba1..7ad69c7 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -103,6 +103,7 @@ namespace MTS { static const char *RSP_OK; static const char *RSP_ERROR; + static const char *RSP_CONNECT; static const char *VALUE_NOT_REGISTERED; static const char *VALUE_REGISTERED; diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index 8aba437..9ccf50a 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -60,11 +60,31 @@ namespace MTS { virtual CODE checkFile(bool& bFilePresent, const std::string& sTargetFilename); private: + static const size_t FILE_CHUNK_SIZE; + static const std::string CMD_ABORT_UPLOAD; static const std::string VALUE_MTS_DELTA_NAME; static const std::string VALUE_MTS_DELTA_PATH; + CODE startFileUpload(const std::string& sTargetFilename, size_t nBytes); + CODE abortFileUpload(); + + static uint16_t getQuectelChecksum(const void* data, size_t nBytes); + static inline void updateQuectelChecksum(uint16_t& iChecksum, uint16_t iNewFragment); + static inline uint16_t bytesToUint16(uint8_t high, uint8_t low); + static CODE getFileSize(int fd, size_t& nBytes, size_t& nFileChunks); + static CODE readChunk(int fd, char* pChunk, size_t dChunkSize, size_t& nReadBytes); }; } } +void MTS::IO::QuectelRadio::updateQuectelChecksum(uint16_t& iChecksum, uint16_t iNewFragment) { + iChecksum = iChecksum ^ iNewFragment; +} + +uint16_t MTS::IO::QuectelRadio::bytesToUint16(uint8_t high, uint8_t low) { + uint16_t comboHigh = static_cast(high << 8); // explicit cast to prevent warnings + uint16_t comboLow = low; + return (comboHigh | comboLow); +} + #endif /* MTS_IO_QUECTELRADIO_H_ */ -- cgit v1.2.3 From d1798ea6a82c46b43e4caf27148189f34cc44ca5 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 1 Jul 2020 11:25:34 +0300 Subject: WIP: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Initial implementation of the "Apply delta firmware" step. Requires cleanup. --- include/mts/MTS_IO_QuectelRadio.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index 506b21b..cb455d8 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -76,6 +76,9 @@ namespace MTS { static inline uint16_t bytesToUint16(uint8_t high, uint8_t low); static CODE getFileSize(int fd, size_t& nBytes, size_t& nFileChunks); static CODE readChunk(int fd, char* pChunk, size_t dChunkSize, size_t& nReadBytes); + CODE waitApplyDeltaFirmware(UpdateCb& stepCb); + CODE waitFotaFinish(UpdateCb& stepCb); + CODE waitNewFirmware(UpdateCb& stepCb); }; } } -- cgit v1.2.3 From 2c3296b5239b5d27f5df4d61a9609ace6d70904f Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 3 Jul 2020 17:59:47 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Started code cleanup before finishing the procedure. Renamed functions related to the delta radio firmware upgrade to follow established patterns: - uploadDeltaFirmwareFile -> fumoLocalInject - applyDeltaFirmwareFile -> fumoLocalApply - removeDeltaFirmwareFile -> fumoLocalCleanup - new function: updateFumoLocal - encapsulates all the magic for radios that may not support separate stages for the delta upload and delta apply --- include/mts/MTS_IO_CellularRadio.h | 7 +++-- include/mts/MTS_IO_ICellularRadio.h | 55 +++++++++++++++++++++++-------------- include/mts/MTS_IO_QuectelRadio.h | 12 ++++---- 3 files changed, 45 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index e65e7cd..e3941c3 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -99,9 +99,10 @@ namespace MTS { CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) override; - CODE uploadDeltaFirmwareFile(int fd, UpdateCb& stepCb) override; - CODE removeDeltaFirmwareFile() override; - CODE applyDeltaFirmwareFile(UpdateCb& stepCb) override; + CODE updateFumoLocal(int fd, UpdateCb& stepCb) override; + CODE fumoLocalInject(int fd, UpdateCb& stepCb) override; + CODE fumoLocalApply(UpdateCb& stepCb) override; + CODE fumoLocalCleanup() override; CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE activate(const Json::Value& jArgs, UpdateCb& stepCb) override; CODE startOmaDm(UpdateCb& stepCb) override; diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 3259041..e1edbcd 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -429,54 +429,69 @@ namespace MTS { virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) = 0; /** - * @brief uploadDeltaFirmwareFile - upload delta file to the radio's internal memory. + * @brief updateFumoLocal - Performs the radio firmware upgrade using local firmware image. * - * This command uploads (injects) the whole delta firmware image to some place that - * can be later used by the radio to perform the Delta Radio Firmware Upgrade. - * - * This delta firmware image is NOT validated on the firmware image upload step. + * This command uploads (injects) the whole delta firmware image to the radio, performs the + * upgrade and waits for it to complete. * - * @param fd - file sescriptor of a file that shall be uploaded to the radio. - * @param stepCb - the callback to receive status updates during the upload. - * @return CODE::SUCCESS when the file was successfully uploaded, + * @param fd - file descriptor of a file that shall be injected to the radio. + * @param stepCb - callback to receive status updates during the firmware upgrade. + * @return CODE::SUCCESS when the firmware upgrade was successful, * CODE::INVALID_ARGS when the file can't be opened for reading, + * CODE::FAILURE when upgrade failed on the radio side, * CODE::NOT_APPLICABLE when not supported by this radio, * CODE::ERROR otherwise. */ - virtual CODE uploadDeltaFirmwareFile(int fd, UpdateCb& stepCb) = 0; + virtual CODE updateFumoLocal(int fd, UpdateCb& stepCb) = 0; /** - * @brief removeDeltaFirmwareFile - remove the delta file from the radio's internal memory. + * @brief fumoLocalInject - upload delta file to the radio's internal memory. * - * This command allows to remove the old delta firmware image from the radio's internal - * memory for cases when it's no longer needed. + * This command uploads (injects) the whole delta firmware image to some place that + * can be later used by the radio to perform the Delta Radio Firmware Upgrade. + * + * This delta firmware image is NOT validated on the firmware image upload step. * * @param fd - file sescriptor of a file that shall be uploaded to the radio. - * @return CODE::SUCCESS when the file was successfully deleted, - * CODE::FAILURE when the file can't be deleted (i.e. no such file), + * @param stepCb - callback to receive status updates during the upload. + * @return CODE::SUCCESS when the file was successfully uploaded, + * CODE::INVALID_ARGS when the file can't be opened for reading, * CODE::NOT_APPLICABLE when not supported by this radio, * CODE::ERROR otherwise. */ - virtual CODE removeDeltaFirmwareFile() = 0; + virtual CODE fumoLocalInject(int fd, UpdateCb& stepCb) = 0; /** - * @brief applyDeltaFirmwareFile - apply the delta file that was previously uploaded. + * @brief fumoLocalApply - apply the delta file that was previously uploaded. * * This commands initializes and tracks the progress of the delta firmware upgrade * procedure using the delta firmware image file that was previously uploaded - * into internal radio's memory. + * into internal memory of the radio. * - * See ICellularRadio::removeDeltaFirmwareFile to upload the file and prepare + * See ICellularRadio::fumoLocalInject to upload the file and prepare * for the upgrade. * - * @param fd - file sescriptor of a file that shall be uploaded to the radio. + * @param fd - file descriptor of a file that shall be uploaded to the radio. * @param stepCb - the callback to receive status updates during the upgrade. + * @return CODE::SUCCESS when the firmware upgrade was successful, + * CODE::FAILURE when upgrade failed on the radio side, + * CODE::NOT_APPLICABLE when not supported by this radio, + * CODE::ERROR otherwise. + */ + virtual CODE fumoLocalApply(UpdateCb& stepCb) = 0; + + /** + * @brief fumoLocalCleanup - remove the delta file from the radio's internal memory. + * + * This command allows to remove the old delta firmware image from the radio's internal + * memory for cases when it's no longer needed. + * * @return CODE::SUCCESS when the file was successfully deleted, * CODE::FAILURE when the file can't be deleted (i.e. no such file), * CODE::NOT_APPLICABLE when not supported by this radio, * CODE::ERROR otherwise. */ - virtual CODE applyDeltaFirmwareFile(UpdateCb& stepCb) = 0; + virtual CODE fumoLocalCleanup() = 0; /* * jArgs = { diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index cb455d8..b805ed8 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -45,9 +45,10 @@ namespace MTS { CODE setCellularMode(CELLULAR_MODES networks) override; - CODE uploadDeltaFirmwareFile(int fd, UpdateCb& stepCb) override; - CODE removeDeltaFirmwareFile() override; - CODE applyDeltaFirmwareFile(UpdateCb& stepCb) override; + CODE updateFumoLocal(int fd, UpdateCb& stepCb) override; + CODE fumoLocalInject(int fd, UpdateCb& stepCb) override; + CODE fumoLocalCleanup() override; + CODE fumoLocalApply(UpdateCb& stepCb) override; protected: QuectelRadio(const std::string& sName, const std::string& sRadioPort); @@ -76,9 +77,8 @@ namespace MTS { static inline uint16_t bytesToUint16(uint8_t high, uint8_t low); static CODE getFileSize(int fd, size_t& nBytes, size_t& nFileChunks); static CODE readChunk(int fd, char* pChunk, size_t dChunkSize, size_t& nReadBytes); - CODE waitApplyDeltaFirmware(UpdateCb& stepCb); - CODE waitFotaFinish(UpdateCb& stepCb); - CODE waitNewFirmware(UpdateCb& stepCb); + CODE fumoWaitUpgradeFinished(UpdateCb& stepCb); + CODE fumoWaitNewFirmware(UpdateCb& stepCb); }; } } -- cgit v1.2.3 From d19829b7e9cdd3c7e3d209628044ab62cd46b907 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 3 Jul 2020 18:53:57 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Simplified usage of step callbacks in the QuectelRadio class. Refactored existing function to use a wrapper and preven repetitive checks. --- include/mts/MTS_IO_QuectelRadio.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index b805ed8..3751b5a 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -72,6 +72,9 @@ namespace MTS { CODE startFileUpload(const std::string& sTargetFilename, size_t nBytes); CODE abortFileUpload(); + static inline void callNextStep(UpdateCb& stepCb, const char* csMessage); + static inline void callNextStep(UpdateCb& stepCb, const std::string& sMessage); + static uint16_t getQuectelChecksum(const void* data, size_t nBytes); static inline void updateQuectelChecksum(uint16_t& iChecksum, uint16_t iNewFragment); static inline uint16_t bytesToUint16(uint8_t high, uint8_t low); @@ -83,6 +86,18 @@ namespace MTS { } } +void MTS::IO::QuectelRadio::callNextStep(ICellularRadio::UpdateCb& stepCb, const char* csMessage) { + if (stepCb) { + stepCb(Json::Value(csMessage)); + } +} + +void MTS::IO::QuectelRadio::callNextStep(ICellularRadio::UpdateCb& stepCb, const std::string& sMessage) { + if (stepCb) { + stepCb(Json::Value(sMessage)); + } +} + void MTS::IO::QuectelRadio::updateQuectelChecksum(uint16_t& iChecksum, uint16_t iNewFragment) { iChecksum = iChecksum ^ iNewFragment; } -- cgit v1.2.3 From 0d5806073d2e9bbd7259c474b4079991e0c5ef13 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 3 Jul 2020 22:59:02 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Implemented firmware version check detection. --- include/mts/MTS_IO_QuectelRadio.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index 3751b5a..d8228cb 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -64,11 +64,18 @@ namespace MTS { virtual CODE checkFile(bool& bFilePresent, const std::string& sTargetFilename); private: + // private variable to save old firmware versions during FOTA + std::string m_sQuectelFirmware; + static const size_t FILE_CHUNK_SIZE; static const std::string CMD_ABORT_UPLOAD; static const std::string VALUE_MTS_DELTA_NAME; static const std::string VALUE_MTS_DELTA_PATH; + // TODO: Consider asbtracting to the ICellularRadio::getFirmwareBuild + //!< Get Quectel-specific firmware version (firmware build?) + CODE getQuectelFirmware(std::string& sFirmware); + CODE startFileUpload(const std::string& sTargetFilename, size_t nBytes); CODE abortFileUpload(); -- cgit v1.2.3