19 #define SCHEME_DIVIDER "://"
20 #define COAP_SCHEME "coap"
21 #define COAPS_SCHEME "coaps"
22 #define HTTP_SCHEME "http"
23 #define HTTPS_SCHEME "https"
24 #define COAP_TCP_SCHEME "coap+tcp"
25 #define COAP_TLS_SCHEME "coaps+tcp"
28 #define TAG "FirmwareUpdate"
36 _internalDownloader = NULL;
38 _externalDownloader = NULL;
68 if (!inst)
return NULL;
74 if (!inst)
return NULL;
87 if (resLink.
resId ==
PACKAGE_0 && _internalDownloader) internalDownloaderHandler();
89 if (resLink.
resId ==
PACKAGE_URI_1 && _externalDownloader) externalDownloaderHandler(securityInst);
111 void FirmwareUpdate::resourcesCreate() {
144 void FirmwareUpdate::resourcesInit() {
148 if (value.empty() || isDeliveryTypeSupported(
PUSH))
return true;
181 if (!fw)
return false;
183 fw->resetStateMachine();
184 fw->clearArtifacts();
186 fw->_pkgUpdater = &updater;
220 if (!fw)
return false;
222 fw->resetStateMachine();
223 fw->clearArtifacts();
225 fw->_externalDownloader = &downloader;
227 std::vector<FwUpdProtocol> dlSupportedProtocols = fw->_externalDownloader->supportedProtocols();
228 if (dlSupportedProtocols.empty()) {
229 fw->_externalDownloader = NULL;
241 for (
auto prot : dlSupportedProtocols) {
253 if (!fw)
return false;
258 fw->resetStateMachine();
259 fw->clearArtifacts();
261 fw->_internalDownloader = &downloader;
275 bool FirmwareUpdate::pkgUpdaterHandler() {
283 if (!_pkgUpdater->
isUpdated())
return false;
310 void FirmwareUpdate::externalDownloaderHandler(Instance *securityInst) {
312 WPP_LOGE(
TAG,
"Security object instance is not set");
318 if (pkgUri.empty()) {
320 WPP_LOGD(
TAG,
"Server reset state machine through PACKAGE_URI_1");
324 _externalDownloader->startDownloading(pkgUri, *
static_cast<Lwm2mSecurity*
>(securityInst));
328 if (!_externalDownloader->isDownloaded())
return false;
330 FwUpdRes res = _externalDownloader->downloadResult();
341 void FirmwareUpdate::internalDownloaderHandler() {
349 WPP_LOGD(
TAG,
"Server reset state machine through PACKAGE_0");
370 void FirmwareUpdate::changeUpdRes(
FwUpdRes res) {
375 void FirmwareUpdate::changeState(
FwUpdState state) {
380 void FirmwareUpdate::resetStateMachine() {
390 if (_internalDownloader) _internalDownloader->
reset();
392 if (_externalDownloader) _externalDownloader->reset();
394 if (_pkgUpdater) _pkgUpdater->
reset();
400 void FirmwareUpdate::clearArtifacts() {
407 bool FirmwareUpdate::isUriValid(
STRING_T uri) {
408 if (uri.empty())
return true;
409 if (!isDeliveryTypeSupported(
PULL))
return false;
411 STRING_T scheme = extractSchemeFromUri(uri);
412 if (!isSchemeValid(scheme)) {
418 if (!isSchemeSupported(scheme)) {
429 if (startsAt == std::string::npos)
return STRING_T(
"");
430 return uri.substr(0, startsAt);
433 bool FirmwareUpdate::isSchemeValid(
STRING_T scheme) {
434 if (scheme.empty())
return false;
437 for (
auto s : validSchemes) {
438 if (!std::strcmp(scheme.c_str(), s))
return true;
444 bool FirmwareUpdate::isSchemeSupported(
STRING_T scheme) {
448 if (requiredProt == suppProt)
return true;
464 bool FirmwareUpdate::isDeliveryTypeSupported(
FwUpdDelivery type) {
466 if (deliveryType == type || deliveryType ==
BOTH)
return true;
#define WPP_LOGE(TAG, FMT,...)
#define WPP_LOGD(TAG, FMT,...)
#define WPP_TASK_MIN_DELAY_S
static Device * instance(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Gets an instance of the object.
void serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
static bool setFwExternalDownloader(WppClient &ctx, FwExternalDl &downloader)
Set the FwExternalDl object for downloading the firmware package from the specified URI.
void userOperationNotifier(ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
static bool setFwInternalDownloader(WppClient &ctx, FwInternalDl &downloader)
Set the FwInternalDl object for auto downloading firmware.
static std::vector< FwUpdProtocol > supportedProtocols(WppClient &ctx)
Return the list of supported protocols for downloading the firmware through uri.
static bool setFwUpdater(WppClient &ctx, FwUpdater &updater)
Set the FwUpdater object for updating the firmware package.
FirmwareUpdate(lwm2m_context_t &context, const OBJ_LINK_T &id)
static FirmwareUpdate * instance(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Gets an instance of the object.
static bool removeInst(WppClient &ctx, ID_T instId)
Removes an instance of the object.
static Object & object(WppClient &ctx)
Gets the Object reference.
static FirmwareUpdate * createInst(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Creates an instance of the object.
@ FIRMWARE_UPDATE_DELIVERY_METHOD_9
@ FIRMWARE_UPDATE_PROTOCOL_SUPPORT_8
virtual bool saveDownloadedBlock(const OPAQUE_T &dataBlock)=0
Request to save downloaded block of the firmware package.
virtual void reset()=0
Reset the download process. When this method is called, the download process is reset and the downloa...
virtual void downloadIsCompleted()=0
Notify about dwnloading process completion. Regardless of the reason for the termination,...
virtual FwUpdRes downloadResult()=0
Contains the result of the download process. Possible results when download is successful: R_INITIAL ...
virtual void downloadIsStarted()=0
Notify about dwnloading process start.
virtual void startUpdating()=0
Request to start updating the firmware. For notify that the update is completed, isUpdated() method s...
virtual FwUpdRes lastUpdateResult()=0
Contains the result of the last update process. This method is called whenever the FwExternalDl is re...
virtual void reset()=0
Returns the name and version of the last installed firmware package. These methods return the value o...
virtual bool isUpdated()=0
Returns true if the update process is completed. For notify update result, lastUpdateResult() method ...
void operationNotify(Instance &inst, const ResLink &resLink, ItemOp::TYPE type)
Notifies the observers about an operation on an instance resource.
Instance is interface class that implements manipulation with derived class resources....
void notifyResChanged(ID_T resId, ID_T resInstId=ID_T_MAX_VAL)
Notify server about resource value change.
Instance(lwm2m_context_t &context, const OBJ_LINK_T &id)
The Object class implements manipulation with Instance interface class and its inheritors.
Instance * instance(ID_T instanceID=ID_T_MAX_VAL)
Gets an instance of the object.
virtual Instance * createInstance(ID_T instanceID=ID_T_MAX_VAL)=0
Creates an instance of the object.
bool remove(ID_T instanceID)
Removes an instance of the object.
void setupResources(const std::vector< Resource > &resources)
This methods setup resources list.
Resource * resource(ID_T resId)
This method return resource ptr if it exists. If resources does not exist then return NULL.
std::vector< ID_T > instIds(ID_T resId)
Returns vector with available ids of resource instances.
std::vector< Resource > & resources()
This method return list with all resources that has been defined.
bool set(ID_T resId, const T &value)
Set data value by copy for the resource.
bool set(const T &value, ID_T resInstId=SINGLE_INSTANCE_ID)
Set data value by copy for the resource (instance)
std::vector< ID_T > instIds() const
Returns vector with available ids of resource instances.
bool setDataVerifier(const DATA_VERIFIER_T &verifier)
Set data verifier for the resource.
const T & get(ID_T resInstId=SINGLE_INSTANCE_ID)
Represents a client interface for Wpp library.
WppRegistry & registry()
Gets the WppRegistry associated with the WppClient.
Object & firmwareUpdate()
static task_id_t addTask(time_t delaySec, task_t task)
Add task to queue, ctx that passed to task equals to NULL.
static void requestToRemoveTask(task_id_t id)
This function does not immediately delete the task, it only marks it as one that should be deleted at...
The WppConnection class represents a connection interface for the Wpp library.
std::function< bool(Instance &, ID_T, const OPAQUE_T &)> EXECUTE_T
std::function< bool(const STRING_T &)> VERIFY_STRING_T
std::function< bool(const INT_T &)> VERIFY_INT_T
Data validation function types.
std::vector< uint8_t > OPAQUE_T
Opaque - represent buffer or string as lwm2m_data_t.value.asBuffer.
std::function< bool(const OPAQUE_T &)> VERIFY_OPAQUE_T
The ItemOp struct represents the operations that can be performed on a instance/resource.
TYPE
Enum representing the different types of operations.
ObjLink - (object ID):(instance ID), example: 1:3. Represent as two integers in lwm2m_data_t....