Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/update-client-hub/modules/lwm2m-mbed/source/FirmwareUpdateResource.cpp@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 2 | // Copyright 2016-2017 ARM Ltd. |
leothedragon | 0:8f0bb79ddd48 | 3 | // |
leothedragon | 0:8f0bb79ddd48 | 4 | // SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 5 | // |
leothedragon | 0:8f0bb79ddd48 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
leothedragon | 0:8f0bb79ddd48 | 7 | // you may not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 8 | // You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 9 | // |
leothedragon | 0:8f0bb79ddd48 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 11 | // |
leothedragon | 0:8f0bb79ddd48 | 12 | // Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
leothedragon | 0:8f0bb79ddd48 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 15 | // See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 16 | // limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 17 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 18 | |
leothedragon | 0:8f0bb79ddd48 | 19 | // Note: this macro is needed on armcc to get the the PRI*32 macros |
leothedragon | 0:8f0bb79ddd48 | 20 | // from inttypes.h in a C++ code. |
leothedragon | 0:8f0bb79ddd48 | 21 | #ifndef __STDC_FORMAT_MACROS |
leothedragon | 0:8f0bb79ddd48 | 22 | #define __STDC_FORMAT_MACROS |
leothedragon | 0:8f0bb79ddd48 | 23 | #endif |
leothedragon | 0:8f0bb79ddd48 | 24 | |
leothedragon | 0:8f0bb79ddd48 | 25 | #include "update-client-lwm2m/FirmwareUpdateResource.h" |
leothedragon | 0:8f0bb79ddd48 | 26 | #include "update-client-common/arm_uc_config.h" |
leothedragon | 0:8f0bb79ddd48 | 27 | |
leothedragon | 0:8f0bb79ddd48 | 28 | #include "update-client-common/arm_uc_common.h" |
leothedragon | 0:8f0bb79ddd48 | 29 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 30 | #include "mbed-client/source/include/m2mcallbackstorage.h" |
leothedragon | 0:8f0bb79ddd48 | 31 | #include "mbed-client/m2mexecuteparams.h" |
leothedragon | 0:8f0bb79ddd48 | 32 | #include "mbed-client/m2mbase.h" |
leothedragon | 0:8f0bb79ddd48 | 33 | #endif |
leothedragon | 0:8f0bb79ddd48 | 34 | #include "source/update_client_hub_state_machine.h" |
leothedragon | 0:8f0bb79ddd48 | 35 | #include "source/update_client_hub_error_handler.h" |
leothedragon | 0:8f0bb79ddd48 | 36 | |
leothedragon | 0:8f0bb79ddd48 | 37 | #include <stdio.h> |
leothedragon | 0:8f0bb79ddd48 | 38 | #include <inttypes.h> |
leothedragon | 0:8f0bb79ddd48 | 39 | |
leothedragon | 0:8f0bb79ddd48 | 40 | #define ARM_UCS_LWM2M_INTERNAL_ERROR (-1) |
leothedragon | 0:8f0bb79ddd48 | 41 | #define ARM_UCS_LWM2M_INTERNAL_SUCCESS (0) |
leothedragon | 0:8f0bb79ddd48 | 42 | |
leothedragon | 0:8f0bb79ddd48 | 43 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 44 | #define RESOURCE_VALUE(arg) arg |
leothedragon | 0:8f0bb79ddd48 | 45 | #else |
leothedragon | 0:8f0bb79ddd48 | 46 | #define RESOURCE_VALUE(arg) #arg |
leothedragon | 0:8f0bb79ddd48 | 47 | #endif |
leothedragon | 0:8f0bb79ddd48 | 48 | |
leothedragon | 0:8f0bb79ddd48 | 49 | namespace FirmwareUpdateResource { |
leothedragon | 0:8f0bb79ddd48 | 50 | |
leothedragon | 0:8f0bb79ddd48 | 51 | /* send delayed response */ |
leothedragon | 0:8f0bb79ddd48 | 52 | enum { |
leothedragon | 0:8f0bb79ddd48 | 53 | ResourcePackage, |
leothedragon | 0:8f0bb79ddd48 | 54 | ResourcePackageURI, |
leothedragon | 0:8f0bb79ddd48 | 55 | ResourceUpdate |
leothedragon | 0:8f0bb79ddd48 | 56 | }; |
leothedragon | 0:8f0bb79ddd48 | 57 | |
leothedragon | 0:8f0bb79ddd48 | 58 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 59 | static void packageCallback(void *_parameters, const M2MExecuteParameter ¶ms); |
leothedragon | 0:8f0bb79ddd48 | 60 | static void packageURICallback(void *_parameters, const M2MExecuteParameter ¶ms); |
leothedragon | 0:8f0bb79ddd48 | 61 | static void updateCallback(void *, const M2MExecuteParameter ¶ms); |
leothedragon | 0:8f0bb79ddd48 | 62 | static void notificationCallback(void *client_args, const M2MBase &object, NotificationDeliveryStatus delivery_status); |
leothedragon | 0:8f0bb79ddd48 | 63 | /* Default values are non-standard, but the standard has no |
leothedragon | 0:8f0bb79ddd48 | 64 | values for indicating that the device is initializing. |
leothedragon | 0:8f0bb79ddd48 | 65 | To address this, Service ignores -1 and/or 255 values coming through, |
leothedragon | 0:8f0bb79ddd48 | 66 | so for our purposes this is the correct form of initialization. |
leothedragon | 0:8f0bb79ddd48 | 67 | */ |
leothedragon | 0:8f0bb79ddd48 | 68 | const uint8_t defaultValue = -1; |
leothedragon | 0:8f0bb79ddd48 | 69 | #else |
leothedragon | 0:8f0bb79ddd48 | 70 | static void packageCallback(void *_parameters); |
leothedragon | 0:8f0bb79ddd48 | 71 | static void updateCallback(void *); |
leothedragon | 0:8f0bb79ddd48 | 72 | static void notificationCallback(const M2MBase &object, NotificationDeliveryStatus delivery_status, void *client_args); |
leothedragon | 0:8f0bb79ddd48 | 73 | uint8_t defaultValue[] = {"-1"}; |
leothedragon | 0:8f0bb79ddd48 | 74 | #endif |
leothedragon | 0:8f0bb79ddd48 | 75 | static void sendDelayedResponseTask(uintptr_t parameter); |
leothedragon | 0:8f0bb79ddd48 | 76 | |
leothedragon | 0:8f0bb79ddd48 | 77 | /* LWM2M Firmware Update Object */ |
leothedragon | 0:8f0bb79ddd48 | 78 | static M2MObject *updateObject; |
leothedragon | 0:8f0bb79ddd48 | 79 | |
leothedragon | 0:8f0bb79ddd48 | 80 | /* LWM2M Firmware Update Object resources */ |
leothedragon | 0:8f0bb79ddd48 | 81 | static M2MResource *resourcePackage = NULL; |
leothedragon | 0:8f0bb79ddd48 | 82 | static M2MResource *resourcePackageURI = NULL; |
leothedragon | 0:8f0bb79ddd48 | 83 | static M2MResource *resourceUpdate = NULL; |
leothedragon | 0:8f0bb79ddd48 | 84 | static M2MResource *resourceState = NULL; |
leothedragon | 0:8f0bb79ddd48 | 85 | static M2MResource *resourceResult = NULL; |
leothedragon | 0:8f0bb79ddd48 | 86 | static M2MResource *resourceName = NULL; |
leothedragon | 0:8f0bb79ddd48 | 87 | static M2MResource *resourceVersion = NULL; |
leothedragon | 0:8f0bb79ddd48 | 88 | |
leothedragon | 0:8f0bb79ddd48 | 89 | /* function pointers to callback functions */ |
leothedragon | 0:8f0bb79ddd48 | 90 | static void (*externalPackageCallback)(const uint8_t *buffer, uint16_t length) = NULL; |
leothedragon | 0:8f0bb79ddd48 | 91 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 92 | static void (*externalPackageURICallback)(const uint8_t *buffer, uint16_t length) = NULL; |
leothedragon | 0:8f0bb79ddd48 | 93 | #endif |
leothedragon | 0:8f0bb79ddd48 | 94 | static void (*externalUpdateCallback)(void) = NULL; |
leothedragon | 0:8f0bb79ddd48 | 95 | static void (*externalNotificationCallback)(void) = NULL; |
leothedragon | 0:8f0bb79ddd48 | 96 | |
leothedragon | 0:8f0bb79ddd48 | 97 | /* Callback structs for delayed response. |
leothedragon | 0:8f0bb79ddd48 | 98 | * |
leothedragon | 0:8f0bb79ddd48 | 99 | * There needs to be one per callback type to avoid collisions between different operations. |
leothedragon | 0:8f0bb79ddd48 | 100 | */ |
leothedragon | 0:8f0bb79ddd48 | 101 | static arm_uc_callback_t callbackNodePackage = { NULL, 0, NULL, 0 }; |
leothedragon | 0:8f0bb79ddd48 | 102 | static arm_uc_callback_t callbackNodePackageURI = { NULL, 0, NULL, 0 }; |
leothedragon | 0:8f0bb79ddd48 | 103 | static arm_uc_callback_t callbackNodeResourceUpdate = { NULL, 0, NULL, 0 }; |
leothedragon | 0:8f0bb79ddd48 | 104 | |
leothedragon | 0:8f0bb79ddd48 | 105 | #if defined(ARM_UC_FEATURE_FW_SOURCE_COAP) && (ARM_UC_FEATURE_FW_SOURCE_COAP == 1) |
leothedragon | 0:8f0bb79ddd48 | 106 | /* M2MInterface */ |
leothedragon | 0:8f0bb79ddd48 | 107 | static M2MInterface *_m2m_interface; |
leothedragon | 0:8f0bb79ddd48 | 108 | #endif |
leothedragon | 0:8f0bb79ddd48 | 109 | } |
leothedragon | 0:8f0bb79ddd48 | 110 | |
leothedragon | 0:8f0bb79ddd48 | 111 | /** |
leothedragon | 0:8f0bb79ddd48 | 112 | * @brief Initialize LWM2M Firmware Update Object |
leothedragon | 0:8f0bb79ddd48 | 113 | * @details Sets up LWM2M object with accompanying resources. |
leothedragon | 0:8f0bb79ddd48 | 114 | */ |
leothedragon | 0:8f0bb79ddd48 | 115 | void FirmwareUpdateResource::Initialize(void) |
leothedragon | 0:8f0bb79ddd48 | 116 | { |
leothedragon | 0:8f0bb79ddd48 | 117 | static bool initialized = false; |
leothedragon | 0:8f0bb79ddd48 | 118 | |
leothedragon | 0:8f0bb79ddd48 | 119 | if (!initialized) { |
leothedragon | 0:8f0bb79ddd48 | 120 | /* The LWM2M Firmware Update Object for LITE client is at /10252 (Manifest) */ |
leothedragon | 0:8f0bb79ddd48 | 121 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 122 | updateObject = M2MInterfaceFactory::create_object(10252, _m2m_interface); |
leothedragon | 0:8f0bb79ddd48 | 123 | #else |
leothedragon | 0:8f0bb79ddd48 | 124 | updateObject = M2MInterfaceFactory::create_object("10252"); |
leothedragon | 0:8f0bb79ddd48 | 125 | #endif |
leothedragon | 0:8f0bb79ddd48 | 126 | |
leothedragon | 0:8f0bb79ddd48 | 127 | if (updateObject) { |
leothedragon | 0:8f0bb79ddd48 | 128 | initialized = true; |
leothedragon | 0:8f0bb79ddd48 | 129 | |
leothedragon | 0:8f0bb79ddd48 | 130 | #if defined(ARM_UC_PROFILE_MBED_CLOUD_CLIENT) && (ARM_UC_PROFILE_MBED_CLOUD_CLIENT == 1) |
leothedragon | 0:8f0bb79ddd48 | 131 | updateObject->set_register_uri(false); |
leothedragon | 0:8f0bb79ddd48 | 132 | |
leothedragon | 0:8f0bb79ddd48 | 133 | #endif |
leothedragon | 0:8f0bb79ddd48 | 134 | |
leothedragon | 0:8f0bb79ddd48 | 135 | /* Create first (and only) instance /10252/0 */ |
leothedragon | 0:8f0bb79ddd48 | 136 | M2MObjectInstance *updateInstance = updateObject->create_object_instance(); |
leothedragon | 0:8f0bb79ddd48 | 137 | |
leothedragon | 0:8f0bb79ddd48 | 138 | if (updateInstance) { |
leothedragon | 0:8f0bb79ddd48 | 139 | |
leothedragon | 0:8f0bb79ddd48 | 140 | #if defined(ARM_UC_PROFILE_MBED_CLOUD_CLIENT) && (ARM_UC_PROFILE_MBED_CLOUD_CLIENT == 1) |
leothedragon | 0:8f0bb79ddd48 | 141 | /* Set observable so the Portal can read it */ |
leothedragon | 0:8f0bb79ddd48 | 142 | updateInstance->set_register_uri(false); |
leothedragon | 0:8f0bb79ddd48 | 143 | #endif |
leothedragon | 0:8f0bb79ddd48 | 144 | uint8_t defaultVersion[] = {"-1"}; |
leothedragon | 0:8f0bb79ddd48 | 145 | |
leothedragon | 0:8f0bb79ddd48 | 146 | /* Create Package resource /10252/0/1 */ |
leothedragon | 0:8f0bb79ddd48 | 147 | resourcePackage = updateInstance->create_dynamic_resource( |
leothedragon | 0:8f0bb79ddd48 | 148 | RESOURCE_VALUE(1), "Package", M2MResourceInstance::OPAQUE, false); |
leothedragon | 0:8f0bb79ddd48 | 149 | if (resourcePackage) { |
leothedragon | 0:8f0bb79ddd48 | 150 | /* This should be PUT according to the standard but |
leothedragon | 0:8f0bb79ddd48 | 151 | Connector client doesn't support callbacks for PUT. |
leothedragon | 0:8f0bb79ddd48 | 152 | */ |
leothedragon | 0:8f0bb79ddd48 | 153 | resourcePackage->set_operation(M2MBase::POST_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 154 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 155 | resourcePackage->set_execute_function((M2MResourceBase::execute_callback)packageCallback, NULL); |
leothedragon | 0:8f0bb79ddd48 | 156 | #else |
leothedragon | 0:8f0bb79ddd48 | 157 | resourcePackage->set_execute_function(packageCallback); |
leothedragon | 0:8f0bb79ddd48 | 158 | |
leothedragon | 0:8f0bb79ddd48 | 159 | /* The delayed response if for processing heavier loads */ |
leothedragon | 0:8f0bb79ddd48 | 160 | resourcePackage->set_delayed_response(true); |
leothedragon | 0:8f0bb79ddd48 | 161 | #endif |
leothedragon | 0:8f0bb79ddd48 | 162 | |
leothedragon | 0:8f0bb79ddd48 | 163 | } |
leothedragon | 0:8f0bb79ddd48 | 164 | |
leothedragon | 0:8f0bb79ddd48 | 165 | /* Create State resource /10252/0/2 */ |
leothedragon | 0:8f0bb79ddd48 | 166 | resourceState = updateInstance->create_dynamic_resource( |
leothedragon | 0:8f0bb79ddd48 | 167 | RESOURCE_VALUE(2), "State", M2MResourceInstance::INTEGER, true); |
leothedragon | 0:8f0bb79ddd48 | 168 | if (resourceState) { |
leothedragon | 0:8f0bb79ddd48 | 169 | resourceState->set_operation(M2MBase::GET_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 170 | resourceState->set_notification_delivery_status_cb(notificationCallback, NULL); |
leothedragon | 0:8f0bb79ddd48 | 171 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 172 | resourceState->set_value(defaultValue); |
leothedragon | 0:8f0bb79ddd48 | 173 | #else |
leothedragon | 0:8f0bb79ddd48 | 174 | resourceState->set_value(defaultValue, sizeof(defaultValue) - 1); |
leothedragon | 0:8f0bb79ddd48 | 175 | #endif |
leothedragon | 0:8f0bb79ddd48 | 176 | resourceState->publish_value_in_registration_msg(true); |
leothedragon | 0:8f0bb79ddd48 | 177 | resourceState->set_auto_observable(true); |
leothedragon | 0:8f0bb79ddd48 | 178 | } |
leothedragon | 0:8f0bb79ddd48 | 179 | |
leothedragon | 0:8f0bb79ddd48 | 180 | /* Create Update Result resource /10252/0/3 */ |
leothedragon | 0:8f0bb79ddd48 | 181 | resourceResult = updateInstance->create_dynamic_resource( |
leothedragon | 0:8f0bb79ddd48 | 182 | RESOURCE_VALUE(3), "UpdateResult", M2MResourceInstance::INTEGER, true); |
leothedragon | 0:8f0bb79ddd48 | 183 | if (resourceResult) { |
leothedragon | 0:8f0bb79ddd48 | 184 | resourceResult->set_operation(M2MBase::GET_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 185 | resourceResult->set_notification_delivery_status_cb(notificationCallback, NULL); |
leothedragon | 0:8f0bb79ddd48 | 186 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 187 | resourceResult->set_value(defaultValue); |
leothedragon | 0:8f0bb79ddd48 | 188 | #else |
leothedragon | 0:8f0bb79ddd48 | 189 | resourceResult->set_value(defaultValue, sizeof(defaultValue) - 1); |
leothedragon | 0:8f0bb79ddd48 | 190 | #endif |
leothedragon | 0:8f0bb79ddd48 | 191 | resourceResult->publish_value_in_registration_msg(true); |
leothedragon | 0:8f0bb79ddd48 | 192 | resourceResult->set_auto_observable(true); |
leothedragon | 0:8f0bb79ddd48 | 193 | } |
leothedragon | 0:8f0bb79ddd48 | 194 | |
leothedragon | 0:8f0bb79ddd48 | 195 | /* Create PkgName resource /10252/0/5 */ |
leothedragon | 0:8f0bb79ddd48 | 196 | resourceName = updateInstance->create_dynamic_resource( |
leothedragon | 0:8f0bb79ddd48 | 197 | RESOURCE_VALUE(5), "PkgName", M2MResourceInstance::STRING, true); |
leothedragon | 0:8f0bb79ddd48 | 198 | if (resourceName) { |
leothedragon | 0:8f0bb79ddd48 | 199 | resourceName->set_operation(M2MBase::GET_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 200 | resourceName->set_value(defaultVersion, sizeof(defaultVersion) - 1); |
leothedragon | 0:8f0bb79ddd48 | 201 | resourceName->publish_value_in_registration_msg(true); |
leothedragon | 0:8f0bb79ddd48 | 202 | resourceName->set_auto_observable(true); |
leothedragon | 0:8f0bb79ddd48 | 203 | } |
leothedragon | 0:8f0bb79ddd48 | 204 | |
leothedragon | 0:8f0bb79ddd48 | 205 | /* Create PkgVersion resource /10252/0/6 */ |
leothedragon | 0:8f0bb79ddd48 | 206 | resourceVersion = updateInstance->create_dynamic_resource( |
leothedragon | 0:8f0bb79ddd48 | 207 | RESOURCE_VALUE(6), "PkgVersion", M2MResourceInstance::STRING, true); |
leothedragon | 0:8f0bb79ddd48 | 208 | if (resourceVersion) { |
leothedragon | 0:8f0bb79ddd48 | 209 | resourceVersion->set_operation(M2MBase::GET_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 210 | resourceVersion->set_value(defaultVersion, sizeof(defaultVersion) - 1); |
leothedragon | 0:8f0bb79ddd48 | 211 | resourceVersion->publish_value_in_registration_msg(true); |
leothedragon | 0:8f0bb79ddd48 | 212 | resourceVersion->set_auto_observable(true); |
leothedragon | 0:8f0bb79ddd48 | 213 | } |
leothedragon | 0:8f0bb79ddd48 | 214 | |
leothedragon | 0:8f0bb79ddd48 | 215 | #if !defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) || (ARM_UC_PROFILE_MBED_CLIENT_LITE == 0) |
leothedragon | 0:8f0bb79ddd48 | 216 | /* Create Update resource /10252/0/9 */ |
leothedragon | 0:8f0bb79ddd48 | 217 | resourceUpdate = updateInstance->create_dynamic_resource( |
leothedragon | 0:8f0bb79ddd48 | 218 | "9", "Update", M2MResourceInstance::STRING, false); |
leothedragon | 0:8f0bb79ddd48 | 219 | if (resourceUpdate) { |
leothedragon | 0:8f0bb79ddd48 | 220 | resourceUpdate->set_operation(M2MBase::POST_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 221 | resourceUpdate->set_execute_function(updateCallback); |
leothedragon | 0:8f0bb79ddd48 | 222 | resourceUpdate->set_delayed_response(true); |
leothedragon | 0:8f0bb79ddd48 | 223 | } |
leothedragon | 0:8f0bb79ddd48 | 224 | #endif |
leothedragon | 0:8f0bb79ddd48 | 225 | } |
leothedragon | 0:8f0bb79ddd48 | 226 | } |
leothedragon | 0:8f0bb79ddd48 | 227 | } |
leothedragon | 0:8f0bb79ddd48 | 228 | } |
leothedragon | 0:8f0bb79ddd48 | 229 | |
leothedragon | 0:8f0bb79ddd48 | 230 | M2MObject *FirmwareUpdateResource::getObject() |
leothedragon | 0:8f0bb79ddd48 | 231 | { |
leothedragon | 0:8f0bb79ddd48 | 232 | Initialize(); |
leothedragon | 0:8f0bb79ddd48 | 233 | |
leothedragon | 0:8f0bb79ddd48 | 234 | return updateObject; |
leothedragon | 0:8f0bb79ddd48 | 235 | } |
leothedragon | 0:8f0bb79ddd48 | 236 | |
leothedragon | 0:8f0bb79ddd48 | 237 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 238 | void FirmwareUpdateResource::packageCallback(void *_parameters, const M2MExecuteParameter ¶ms) |
leothedragon | 0:8f0bb79ddd48 | 239 | { |
leothedragon | 0:8f0bb79ddd48 | 240 | UC_SRCE_TRACE("FirmwareUpdateResource::packageCallback"); |
leothedragon | 0:8f0bb79ddd48 | 241 | |
leothedragon | 0:8f0bb79ddd48 | 242 | // Reset the resource values for every new Campaign |
leothedragon | 0:8f0bb79ddd48 | 243 | // to make sure values of new Campaign get sent to service |
leothedragon | 0:8f0bb79ddd48 | 244 | resourceState->set_value(defaultValue); |
leothedragon | 0:8f0bb79ddd48 | 245 | resourceResult->set_value(defaultValue); |
leothedragon | 0:8f0bb79ddd48 | 246 | |
leothedragon | 0:8f0bb79ddd48 | 247 | if (externalPackageCallback) { |
leothedragon | 0:8f0bb79ddd48 | 248 | /* read payload */ |
leothedragon | 0:8f0bb79ddd48 | 249 | const uint8_t *buffer = params.get_argument_value(); |
leothedragon | 0:8f0bb79ddd48 | 250 | uint16_t length = params.get_argument_value_length(); |
leothedragon | 0:8f0bb79ddd48 | 251 | |
leothedragon | 0:8f0bb79ddd48 | 252 | /* invoke external callback function */ |
leothedragon | 0:8f0bb79ddd48 | 253 | externalPackageCallback(buffer, length); |
leothedragon | 0:8f0bb79ddd48 | 254 | |
leothedragon | 0:8f0bb79ddd48 | 255 | params.get_resource().send_post_response(params.get_token(), params.get_token_length()); |
leothedragon | 0:8f0bb79ddd48 | 256 | |
leothedragon | 0:8f0bb79ddd48 | 257 | // TODO: Do we need to pass the token param to delayed callback |
leothedragon | 0:8f0bb79ddd48 | 258 | // Or is above send_post_response enough? |
leothedragon | 0:8f0bb79ddd48 | 259 | // Below callback is needed because otherwise UC Hub is not notified |
leothedragon | 0:8f0bb79ddd48 | 260 | #else |
leothedragon | 0:8f0bb79ddd48 | 261 | void FirmwareUpdateResource::packageCallback(void *_parameters) |
leothedragon | 0:8f0bb79ddd48 | 262 | { |
leothedragon | 0:8f0bb79ddd48 | 263 | UC_SRCE_TRACE("FirmwareUpdateResource::packageCallback"); |
leothedragon | 0:8f0bb79ddd48 | 264 | |
leothedragon | 0:8f0bb79ddd48 | 265 | // Reset the resource values for every new Campaign |
leothedragon | 0:8f0bb79ddd48 | 266 | // to make sure values of new Campaign get sent to service |
leothedragon | 0:8f0bb79ddd48 | 267 | resourceState->set_value(defaultValue, sizeof(defaultValue) - 1); |
leothedragon | 0:8f0bb79ddd48 | 268 | resourceResult->set_value(defaultValue, sizeof(defaultValue) - 1); |
leothedragon | 0:8f0bb79ddd48 | 269 | |
leothedragon | 0:8f0bb79ddd48 | 270 | if (_parameters && externalPackageCallback) { |
leothedragon | 0:8f0bb79ddd48 | 271 | /* recast parameter */ |
leothedragon | 0:8f0bb79ddd48 | 272 | M2MResource::M2MExecuteParameter *parameters = |
leothedragon | 0:8f0bb79ddd48 | 273 | static_cast<M2MResource::M2MExecuteParameter *>(_parameters); |
leothedragon | 0:8f0bb79ddd48 | 274 | |
leothedragon | 0:8f0bb79ddd48 | 275 | /* read payload */ |
leothedragon | 0:8f0bb79ddd48 | 276 | const uint8_t *buffer = parameters->get_argument_value(); |
leothedragon | 0:8f0bb79ddd48 | 277 | uint16_t length = parameters->get_argument_value_length(); |
leothedragon | 0:8f0bb79ddd48 | 278 | |
leothedragon | 0:8f0bb79ddd48 | 279 | /* invoke external callback function */ |
leothedragon | 0:8f0bb79ddd48 | 280 | externalPackageCallback(buffer, length); |
leothedragon | 0:8f0bb79ddd48 | 281 | #endif |
leothedragon | 0:8f0bb79ddd48 | 282 | /* schedule delayed response */ |
leothedragon | 0:8f0bb79ddd48 | 283 | ARM_UC_PostCallback(&callbackNodePackage, |
leothedragon | 0:8f0bb79ddd48 | 284 | FirmwareUpdateResource::sendDelayedResponseTask, |
leothedragon | 0:8f0bb79ddd48 | 285 | FirmwareUpdateResource::ResourcePackage); |
leothedragon | 0:8f0bb79ddd48 | 286 | } |
leothedragon | 0:8f0bb79ddd48 | 287 | } |
leothedragon | 0:8f0bb79ddd48 | 288 | |
leothedragon | 0:8f0bb79ddd48 | 289 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 290 | void FirmwareUpdateResource::packageURICallback(void *_parameters, const M2MExecuteParameter ¶ms) |
leothedragon | 0:8f0bb79ddd48 | 291 | { |
leothedragon | 0:8f0bb79ddd48 | 292 | UC_SRCE_TRACE("FirmwareUpdateResource::packageURICallback"); |
leothedragon | 0:8f0bb79ddd48 | 293 | |
leothedragon | 0:8f0bb79ddd48 | 294 | if (_parameters && externalPackageURICallback) { |
leothedragon | 0:8f0bb79ddd48 | 295 | /* read payload */ |
leothedragon | 0:8f0bb79ddd48 | 296 | const uint8_t *buffer = params.get_argument_value(); |
leothedragon | 0:8f0bb79ddd48 | 297 | uint16_t length = params.get_argument_value_length(); |
leothedragon | 0:8f0bb79ddd48 | 298 | |
leothedragon | 0:8f0bb79ddd48 | 299 | /* invoke external callback function */ |
leothedragon | 0:8f0bb79ddd48 | 300 | externalPackageURICallback(buffer, length); |
leothedragon | 0:8f0bb79ddd48 | 301 | |
leothedragon | 0:8f0bb79ddd48 | 302 | params.get_resource().send_post_response(params.get_token(), params.get_token_length()); |
leothedragon | 0:8f0bb79ddd48 | 303 | |
leothedragon | 0:8f0bb79ddd48 | 304 | // TODO: Do we need to pass the token param to delayed callback |
leothedragon | 0:8f0bb79ddd48 | 305 | // Or is above send_post_response enough? |
leothedragon | 0:8f0bb79ddd48 | 306 | // Below callback is needed because otherwise UC Hub is not notified |
leothedragon | 0:8f0bb79ddd48 | 307 | /* schedule delayed response */ |
leothedragon | 0:8f0bb79ddd48 | 308 | ARM_UC_PostCallback(&callbackNodePackageURI, |
leothedragon | 0:8f0bb79ddd48 | 309 | FirmwareUpdateResource::sendDelayedResponseTask, |
leothedragon | 0:8f0bb79ddd48 | 310 | FirmwareUpdateResource::ResourcePackageURI); |
leothedragon | 0:8f0bb79ddd48 | 311 | } |
leothedragon | 0:8f0bb79ddd48 | 312 | } |
leothedragon | 0:8f0bb79ddd48 | 313 | #endif |
leothedragon | 0:8f0bb79ddd48 | 314 | |
leothedragon | 0:8f0bb79ddd48 | 315 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 316 | void FirmwareUpdateResource::updateCallback(void *_parameters, const M2MExecuteParameter ¶ms) |
leothedragon | 0:8f0bb79ddd48 | 317 | { |
leothedragon | 0:8f0bb79ddd48 | 318 | UC_SRCE_TRACE("FirmwareUpdateResource::updateCallback"); |
leothedragon | 0:8f0bb79ddd48 | 319 | |
leothedragon | 0:8f0bb79ddd48 | 320 | (void) _parameters; |
leothedragon | 0:8f0bb79ddd48 | 321 | |
leothedragon | 0:8f0bb79ddd48 | 322 | if (externalUpdateCallback) { |
leothedragon | 0:8f0bb79ddd48 | 323 | /* invoke external callback function */ |
leothedragon | 0:8f0bb79ddd48 | 324 | externalUpdateCallback(); |
leothedragon | 0:8f0bb79ddd48 | 325 | |
leothedragon | 0:8f0bb79ddd48 | 326 | params.get_resource().send_post_response(params.get_token(), params.get_token_length()); |
leothedragon | 0:8f0bb79ddd48 | 327 | |
leothedragon | 0:8f0bb79ddd48 | 328 | // TODO: Do we need to pass the token param to delayed callback |
leothedragon | 0:8f0bb79ddd48 | 329 | // Or is above send_post_response enough? |
leothedragon | 0:8f0bb79ddd48 | 330 | #else |
leothedragon | 0:8f0bb79ddd48 | 331 | void FirmwareUpdateResource::updateCallback(void *_parameters) |
leothedragon | 0:8f0bb79ddd48 | 332 | { |
leothedragon | 0:8f0bb79ddd48 | 333 | UC_SRCE_TRACE("FirmwareUpdateResource::updateCallback"); |
leothedragon | 0:8f0bb79ddd48 | 334 | |
leothedragon | 0:8f0bb79ddd48 | 335 | (void) _parameters; |
leothedragon | 0:8f0bb79ddd48 | 336 | |
leothedragon | 0:8f0bb79ddd48 | 337 | if (externalUpdateCallback) { |
leothedragon | 0:8f0bb79ddd48 | 338 | /* invoke external callback function */ |
leothedragon | 0:8f0bb79ddd48 | 339 | externalUpdateCallback(); |
leothedragon | 0:8f0bb79ddd48 | 340 | |
leothedragon | 0:8f0bb79ddd48 | 341 | #endif |
leothedragon | 0:8f0bb79ddd48 | 342 | // Below callback is needed because otherwise UC Hub is not notified |
leothedragon | 0:8f0bb79ddd48 | 343 | /* schedule delayed response */ |
leothedragon | 0:8f0bb79ddd48 | 344 | ARM_UC_PostCallback(&callbackNodeResourceUpdate, |
leothedragon | 0:8f0bb79ddd48 | 345 | FirmwareUpdateResource::sendDelayedResponseTask, |
leothedragon | 0:8f0bb79ddd48 | 346 | FirmwareUpdateResource::ResourceUpdate); |
leothedragon | 0:8f0bb79ddd48 | 347 | } |
leothedragon | 0:8f0bb79ddd48 | 348 | } |
leothedragon | 0:8f0bb79ddd48 | 349 | |
leothedragon | 0:8f0bb79ddd48 | 350 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 351 | void FirmwareUpdateResource::notificationCallback(void *client_args, |
leothedragon | 0:8f0bb79ddd48 | 352 | const M2MBase &object, |
leothedragon | 0:8f0bb79ddd48 | 353 | const NotificationDeliveryStatus delivery_status) |
leothedragon | 0:8f0bb79ddd48 | 354 | |
leothedragon | 0:8f0bb79ddd48 | 355 | #else |
leothedragon | 0:8f0bb79ddd48 | 356 | void FirmwareUpdateResource::notificationCallback(const M2MBase &base, |
leothedragon | 0:8f0bb79ddd48 | 357 | const NotificationDeliveryStatus delivery_status, |
leothedragon | 0:8f0bb79ddd48 | 358 | void *client_args) |
leothedragon | 0:8f0bb79ddd48 | 359 | #endif |
leothedragon | 0:8f0bb79ddd48 | 360 | { |
leothedragon | 0:8f0bb79ddd48 | 361 | UC_SRCE_TRACE("FirmwareUpdateResource::notificationCallback status: %d", delivery_status); |
leothedragon | 0:8f0bb79ddd48 | 362 | #if defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) && (ARM_UC_PROFILE_MBED_CLIENT_LITE == 1) |
leothedragon | 0:8f0bb79ddd48 | 363 | path_buffer buffer; |
leothedragon | 0:8f0bb79ddd48 | 364 | object.uri_path(buffer); |
leothedragon | 0:8f0bb79ddd48 | 365 | UC_SRCE_TRACE("Callback for resource: %s", buffer.c_str()); |
leothedragon | 0:8f0bb79ddd48 | 366 | #endif |
leothedragon | 0:8f0bb79ddd48 | 367 | |
leothedragon | 0:8f0bb79ddd48 | 368 | if (delivery_status == NOTIFICATION_STATUS_DELIVERED) { |
leothedragon | 0:8f0bb79ddd48 | 369 | // Notification has been ACKed by server, complete to callback |
leothedragon | 0:8f0bb79ddd48 | 370 | UC_SRCE_TRACE("FirmwareUpdateResource::notificationCallback DELIVERED"); |
leothedragon | 0:8f0bb79ddd48 | 371 | |
leothedragon | 0:8f0bb79ddd48 | 372 | if (externalNotificationCallback) { |
leothedragon | 0:8f0bb79ddd48 | 373 | externalNotificationCallback(); |
leothedragon | 0:8f0bb79ddd48 | 374 | } |
leothedragon | 0:8f0bb79ddd48 | 375 | } else if (delivery_status == NOTIFICATION_STATUS_BUILD_ERROR || |
leothedragon | 0:8f0bb79ddd48 | 376 | delivery_status == NOTIFICATION_STATUS_RESEND_QUEUE_FULL || |
leothedragon | 0:8f0bb79ddd48 | 377 | delivery_status == NOTIFICATION_STATUS_SEND_FAILED || |
leothedragon | 0:8f0bb79ddd48 | 378 | delivery_status == NOTIFICATION_STATUS_UNSUBSCRIBED) { |
leothedragon | 0:8f0bb79ddd48 | 379 | // Error case, notification not reaching service |
leothedragon | 0:8f0bb79ddd48 | 380 | // We are sending out error because we cannot rely connection is |
leothedragon | 0:8f0bb79ddd48 | 381 | // anymore up and the service and client are not in sync anymore. |
leothedragon | 0:8f0bb79ddd48 | 382 | // Also sending new notifications after this might lock event |
leothedragon | 0:8f0bb79ddd48 | 383 | // machine because comms cannot service us anymore. |
leothedragon | 0:8f0bb79ddd48 | 384 | UC_SRCE_ERR_MSG("Received Notification delivery status: %d - ERROR!", delivery_status); |
leothedragon | 0:8f0bb79ddd48 | 385 | ARM_UC_HUB_ErrorHandler(HUB_ERR_CONNECTION, ARM_UC_HUB_getState()); |
leothedragon | 0:8f0bb79ddd48 | 386 | } else { |
leothedragon | 0:8f0bb79ddd48 | 387 | // NOTIFICATION_STATUS_INIT |
leothedragon | 0:8f0bb79ddd48 | 388 | // NOTIFICATION_STATUS_SENT |
leothedragon | 0:8f0bb79ddd48 | 389 | // NOTIFICATION_STATUS_SUBSCRIBED |
leothedragon | 0:8f0bb79ddd48 | 390 | UC_SRCE_TRACE("FirmwareUpdateResource::notificationCallback Status ignored, waiting delivery..."); |
leothedragon | 0:8f0bb79ddd48 | 391 | } |
leothedragon | 0:8f0bb79ddd48 | 392 | } |
leothedragon | 0:8f0bb79ddd48 | 393 | |
leothedragon | 0:8f0bb79ddd48 | 394 | void FirmwareUpdateResource::sendDelayedResponseTask(uintptr_t parameter) |
leothedragon | 0:8f0bb79ddd48 | 395 | { |
leothedragon | 0:8f0bb79ddd48 | 396 | UC_SRCE_TRACE("FirmwareUpdateResource::sendDelayedResponseTask"); |
leothedragon | 0:8f0bb79ddd48 | 397 | |
leothedragon | 0:8f0bb79ddd48 | 398 | switch (parameter) { |
leothedragon | 0:8f0bb79ddd48 | 399 | case FirmwareUpdateResource::ResourcePackage: |
leothedragon | 0:8f0bb79ddd48 | 400 | UC_SRCE_TRACE("resourcePackage->send_delayed_post_response"); |
leothedragon | 0:8f0bb79ddd48 | 401 | #if !defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) || (ARM_UC_PROFILE_MBED_CLIENT_LITE == 0) |
leothedragon | 0:8f0bb79ddd48 | 402 | resourcePackage->send_delayed_post_response(); |
leothedragon | 0:8f0bb79ddd48 | 403 | #else |
leothedragon | 0:8f0bb79ddd48 | 404 | //called already in callback: resourcePackage->send_delayed_post_response(); |
leothedragon | 0:8f0bb79ddd48 | 405 | #endif |
leothedragon | 0:8f0bb79ddd48 | 406 | break; |
leothedragon | 0:8f0bb79ddd48 | 407 | case FirmwareUpdateResource::ResourcePackageURI: |
leothedragon | 0:8f0bb79ddd48 | 408 | UC_SRCE_TRACE("resourcePackageURI->send_delayed_post_response"); |
leothedragon | 0:8f0bb79ddd48 | 409 | #if !defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) || (ARM_UC_PROFILE_MBED_CLIENT_LITE == 0) |
leothedragon | 0:8f0bb79ddd48 | 410 | resourcePackageURI->send_delayed_post_response(); |
leothedragon | 0:8f0bb79ddd48 | 411 | #else |
leothedragon | 0:8f0bb79ddd48 | 412 | //called already in callback: resourcePackageURI->send_delayed_post_response(); |
leothedragon | 0:8f0bb79ddd48 | 413 | #endif |
leothedragon | 0:8f0bb79ddd48 | 414 | break; |
leothedragon | 0:8f0bb79ddd48 | 415 | case FirmwareUpdateResource::ResourceUpdate: |
leothedragon | 0:8f0bb79ddd48 | 416 | UC_SRCE_TRACE("resourceUpdate->send_delayed_post_response"); |
leothedragon | 0:8f0bb79ddd48 | 417 | #if !defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) || (ARM_UC_PROFILE_MBED_CLIENT_LITE == 0) |
leothedragon | 0:8f0bb79ddd48 | 418 | resourceUpdate->send_delayed_post_response(); |
leothedragon | 0:8f0bb79ddd48 | 419 | #else |
leothedragon | 0:8f0bb79ddd48 | 420 | //called already in callback: resourceUpdate->send_delayed_post_response(); |
leothedragon | 0:8f0bb79ddd48 | 421 | #endif |
leothedragon | 0:8f0bb79ddd48 | 422 | break; |
leothedragon | 0:8f0bb79ddd48 | 423 | default: |
leothedragon | 0:8f0bb79ddd48 | 424 | UC_SRCE_ERR_MSG("unsupported resource"); |
leothedragon | 0:8f0bb79ddd48 | 425 | break; |
leothedragon | 0:8f0bb79ddd48 | 426 | } |
leothedragon | 0:8f0bb79ddd48 | 427 | } |
leothedragon | 0:8f0bb79ddd48 | 428 | |
leothedragon | 0:8f0bb79ddd48 | 429 | /*****************************************************************************/ |
leothedragon | 0:8f0bb79ddd48 | 430 | /* Update Client Source */ |
leothedragon | 0:8f0bb79ddd48 | 431 | /*****************************************************************************/ |
leothedragon | 0:8f0bb79ddd48 | 432 | |
leothedragon | 0:8f0bb79ddd48 | 433 | /* Add callback for resource /10252/0/1, Package */ |
leothedragon | 0:8f0bb79ddd48 | 434 | int32_t FirmwareUpdateResource::addPackageCallback(void (*cb)(const uint8_t *buffer, uint16_t length)) |
leothedragon | 0:8f0bb79ddd48 | 435 | { |
leothedragon | 0:8f0bb79ddd48 | 436 | UC_SRCE_TRACE("FirmwareUpdateResource::addPackageCallback: %p", cb); |
leothedragon | 0:8f0bb79ddd48 | 437 | |
leothedragon | 0:8f0bb79ddd48 | 438 | externalPackageCallback = cb; |
leothedragon | 0:8f0bb79ddd48 | 439 | |
leothedragon | 0:8f0bb79ddd48 | 440 | return ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 441 | } |
leothedragon | 0:8f0bb79ddd48 | 442 | |
leothedragon | 0:8f0bb79ddd48 | 443 | #if !defined(ARM_UC_PROFILE_MBED_CLIENT_LITE) || (ARM_UC_PROFILE_MBED_CLIENT_LITE == 0) |
leothedragon | 0:8f0bb79ddd48 | 444 | /* Add callback for resource /10252/0/9, Update */ |
leothedragon | 0:8f0bb79ddd48 | 445 | int32_t FirmwareUpdateResource::addUpdateCallback(void (*cb)(void)) |
leothedragon | 0:8f0bb79ddd48 | 446 | { |
leothedragon | 0:8f0bb79ddd48 | 447 | UC_SRCE_TRACE("FirmwareUpdateResource::addUpdateCallback: %p", cb); |
leothedragon | 0:8f0bb79ddd48 | 448 | |
leothedragon | 0:8f0bb79ddd48 | 449 | externalUpdateCallback = cb; |
leothedragon | 0:8f0bb79ddd48 | 450 | |
leothedragon | 0:8f0bb79ddd48 | 451 | return ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 452 | } |
leothedragon | 0:8f0bb79ddd48 | 453 | #endif |
leothedragon | 0:8f0bb79ddd48 | 454 | |
leothedragon | 0:8f0bb79ddd48 | 455 | /* Add callback for when send{State, UpdateResult} is done */ |
leothedragon | 0:8f0bb79ddd48 | 456 | int32_t FirmwareUpdateResource::addNotificationCallback(void (*cb)(void)) |
leothedragon | 0:8f0bb79ddd48 | 457 | { |
leothedragon | 0:8f0bb79ddd48 | 458 | UC_SRCE_TRACE("FirmwareUpdateResource::addNotificationCallback: %p", cb); |
leothedragon | 0:8f0bb79ddd48 | 459 | |
leothedragon | 0:8f0bb79ddd48 | 460 | externalNotificationCallback = cb; |
leothedragon | 0:8f0bb79ddd48 | 461 | |
leothedragon | 0:8f0bb79ddd48 | 462 | return ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 463 | } |
leothedragon | 0:8f0bb79ddd48 | 464 | |
leothedragon | 0:8f0bb79ddd48 | 465 | /*****************************************************************************/ |
leothedragon | 0:8f0bb79ddd48 | 466 | /* Update Client Status */ |
leothedragon | 0:8f0bb79ddd48 | 467 | /*****************************************************************************/ |
leothedragon | 0:8f0bb79ddd48 | 468 | |
leothedragon | 0:8f0bb79ddd48 | 469 | /* Send state for resource /10252/0/2, State */ |
leothedragon | 0:8f0bb79ddd48 | 470 | int32_t FirmwareUpdateResource::sendState(arm_ucs_lwm2m_state_t state) |
leothedragon | 0:8f0bb79ddd48 | 471 | { |
leothedragon | 0:8f0bb79ddd48 | 472 | UC_SRCE_TRACE("FirmwareUpdateResource::sendState"); |
leothedragon | 0:8f0bb79ddd48 | 473 | |
leothedragon | 0:8f0bb79ddd48 | 474 | int32_t result = ARM_UCS_LWM2M_INTERNAL_ERROR; |
leothedragon | 0:8f0bb79ddd48 | 475 | |
leothedragon | 0:8f0bb79ddd48 | 476 | if ((resourceState != NULL) |
leothedragon | 0:8f0bb79ddd48 | 477 | && ARM_UC_IsValidState(state) |
leothedragon | 0:8f0bb79ddd48 | 478 | && resourceState->set_value((int64_t)state)) { |
leothedragon | 0:8f0bb79ddd48 | 479 | result = ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 480 | } |
leothedragon | 0:8f0bb79ddd48 | 481 | return result; |
leothedragon | 0:8f0bb79ddd48 | 482 | } |
leothedragon | 0:8f0bb79ddd48 | 483 | |
leothedragon | 0:8f0bb79ddd48 | 484 | /* Send result for resource /10252/0/3, Update Result */ |
leothedragon | 0:8f0bb79ddd48 | 485 | int32_t FirmwareUpdateResource::sendUpdateResult(arm_ucs_lwm2m_result_t updateResult) |
leothedragon | 0:8f0bb79ddd48 | 486 | { |
leothedragon | 0:8f0bb79ddd48 | 487 | UC_SRCE_TRACE("FirmwareUpdateResource::sendUpdateResult"); |
leothedragon | 0:8f0bb79ddd48 | 488 | |
leothedragon | 0:8f0bb79ddd48 | 489 | int32_t result = ARM_UCS_LWM2M_INTERNAL_ERROR; |
leothedragon | 0:8f0bb79ddd48 | 490 | |
leothedragon | 0:8f0bb79ddd48 | 491 | if ((resourceResult != NULL) |
leothedragon | 0:8f0bb79ddd48 | 492 | && ARM_UC_IsValidResult(updateResult) |
leothedragon | 0:8f0bb79ddd48 | 493 | && resourceResult->set_value((int64_t)updateResult)) { |
leothedragon | 0:8f0bb79ddd48 | 494 | result = ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 495 | } |
leothedragon | 0:8f0bb79ddd48 | 496 | return result; |
leothedragon | 0:8f0bb79ddd48 | 497 | } |
leothedragon | 0:8f0bb79ddd48 | 498 | |
leothedragon | 0:8f0bb79ddd48 | 499 | /* Send name for resource /10252/0/5 PkgName */ |
leothedragon | 0:8f0bb79ddd48 | 500 | #define MAX_PACKAGE_NAME_CHARS 32 |
leothedragon | 0:8f0bb79ddd48 | 501 | int32_t FirmwareUpdateResource::sendPkgName(const uint8_t *name, uint16_t length) |
leothedragon | 0:8f0bb79ddd48 | 502 | { |
leothedragon | 0:8f0bb79ddd48 | 503 | UC_SRCE_TRACE("FirmwareUpdateResource::sendPkgName"); |
leothedragon | 0:8f0bb79ddd48 | 504 | |
leothedragon | 0:8f0bb79ddd48 | 505 | int32_t result = ARM_UCS_LWM2M_INTERNAL_ERROR; |
leothedragon | 0:8f0bb79ddd48 | 506 | |
leothedragon | 0:8f0bb79ddd48 | 507 | if ((resourceName == NULL) |
leothedragon | 0:8f0bb79ddd48 | 508 | || (name == NULL) |
leothedragon | 0:8f0bb79ddd48 | 509 | || (length > MAX_PACKAGE_NAME_CHARS)) { |
leothedragon | 0:8f0bb79ddd48 | 510 | UC_SRCE_ERR_MSG("bad arguments - resourceName, package name or length."); |
leothedragon | 0:8f0bb79ddd48 | 511 | } else { |
leothedragon | 0:8f0bb79ddd48 | 512 | /* the maximum length is defined in the OMA LWM2M standard. */ |
leothedragon | 0:8f0bb79ddd48 | 513 | uint8_t value[MAX_PACKAGE_NAME_CHARS * 2] = { 0 }; |
leothedragon | 0:8f0bb79ddd48 | 514 | uint8_t index = 0; |
leothedragon | 0:8f0bb79ddd48 | 515 | |
leothedragon | 0:8f0bb79ddd48 | 516 | /* convert to printable characters using lookup table */ |
leothedragon | 0:8f0bb79ddd48 | 517 | for (; (index < 32) && (index < length); index++) { |
leothedragon | 0:8f0bb79ddd48 | 518 | value[2 * index ] = arm_uc_hex_table[name[index] >> 4]; |
leothedragon | 0:8f0bb79ddd48 | 519 | value[2 * index + 1] = arm_uc_hex_table[name[index] & 0x0F]; |
leothedragon | 0:8f0bb79ddd48 | 520 | } |
leothedragon | 0:8f0bb79ddd48 | 521 | if (resourceName->set_value(value, 2 * index)) { |
leothedragon | 0:8f0bb79ddd48 | 522 | result = ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 523 | } |
leothedragon | 0:8f0bb79ddd48 | 524 | } |
leothedragon | 0:8f0bb79ddd48 | 525 | return result; |
leothedragon | 0:8f0bb79ddd48 | 526 | } |
leothedragon | 0:8f0bb79ddd48 | 527 | |
leothedragon | 0:8f0bb79ddd48 | 528 | /* Send version for resource /10252/0/6, PkgVersion */ |
leothedragon | 0:8f0bb79ddd48 | 529 | #define MAX_PACKAGE_VERSION_CHARS 21 |
leothedragon | 0:8f0bb79ddd48 | 530 | int32_t FirmwareUpdateResource::sendPkgVersion(uint64_t version) |
leothedragon | 0:8f0bb79ddd48 | 531 | { |
leothedragon | 0:8f0bb79ddd48 | 532 | UC_SRCE_TRACE("FirmwareUpdateResource::sendPkgVersion"); |
leothedragon | 0:8f0bb79ddd48 | 533 | |
leothedragon | 0:8f0bb79ddd48 | 534 | int32_t result = ARM_UCS_LWM2M_INTERNAL_ERROR; |
leothedragon | 0:8f0bb79ddd48 | 535 | if (resourceVersion != NULL) { |
leothedragon | 0:8f0bb79ddd48 | 536 | uint8_t value[MAX_PACKAGE_VERSION_CHARS + 1] = { 0 }; |
leothedragon | 0:8f0bb79ddd48 | 537 | uint8_t length = snprintf((char *)value, MAX_PACKAGE_VERSION_CHARS, "%" PRIu64, version); |
leothedragon | 0:8f0bb79ddd48 | 538 | if (resourceVersion->set_value(value, length)) { |
leothedragon | 0:8f0bb79ddd48 | 539 | result = ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 540 | } |
leothedragon | 0:8f0bb79ddd48 | 541 | } |
leothedragon | 0:8f0bb79ddd48 | 542 | return result; |
leothedragon | 0:8f0bb79ddd48 | 543 | } |
leothedragon | 0:8f0bb79ddd48 | 544 | |
leothedragon | 0:8f0bb79ddd48 | 545 | #if defined(ARM_UC_FEATURE_FW_SOURCE_COAP) && (ARM_UC_FEATURE_FW_SOURCE_COAP == 1) |
leothedragon | 0:8f0bb79ddd48 | 546 | int32_t FirmwareUpdateResource::setM2MInterface(M2MInterface *interface) |
leothedragon | 0:8f0bb79ddd48 | 547 | { |
leothedragon | 0:8f0bb79ddd48 | 548 | UC_SRCE_TRACE("FirmwareUpdateResource::setM2MInterface"); |
leothedragon | 0:8f0bb79ddd48 | 549 | |
leothedragon | 0:8f0bb79ddd48 | 550 | int32_t result = ARM_UCS_LWM2M_INTERNAL_ERROR; |
leothedragon | 0:8f0bb79ddd48 | 551 | |
leothedragon | 0:8f0bb79ddd48 | 552 | if (interface != NULL) { |
leothedragon | 0:8f0bb79ddd48 | 553 | _m2m_interface = interface; |
leothedragon | 0:8f0bb79ddd48 | 554 | result = ARM_UCS_LWM2M_INTERNAL_SUCCESS; |
leothedragon | 0:8f0bb79ddd48 | 555 | } |
leothedragon | 0:8f0bb79ddd48 | 556 | return result; |
leothedragon | 0:8f0bb79ddd48 | 557 | } |
leothedragon | 0:8f0bb79ddd48 | 558 | |
leothedragon | 0:8f0bb79ddd48 | 559 | M2MInterface *FirmwareUpdateResource::getM2MInterface(void) |
leothedragon | 0:8f0bb79ddd48 | 560 | { |
leothedragon | 0:8f0bb79ddd48 | 561 | return _m2m_interface; |
leothedragon | 0:8f0bb79ddd48 | 562 | } |
leothedragon | 0:8f0bb79ddd48 | 563 | #endif //ARM_UC_FEATURE_FW_SOURCE_COAP |
leothedragon | 0:8f0bb79ddd48 | 564 | |
leothedragon | 0:8f0bb79ddd48 | 565 | void FirmwareUpdateResource::Uninitialize(void) |
leothedragon | 0:8f0bb79ddd48 | 566 | { |
leothedragon | 0:8f0bb79ddd48 | 567 | UC_SRCE_TRACE("FirmwareUpdateResource::Uninitialize"); |
leothedragon | 0:8f0bb79ddd48 | 568 | delete updateObject; |
leothedragon | 0:8f0bb79ddd48 | 569 | updateObject = NULL; |
leothedragon | 0:8f0bb79ddd48 | 570 | resourcePackage = NULL; |
leothedragon | 0:8f0bb79ddd48 | 571 | resourcePackageURI = NULL; |
leothedragon | 0:8f0bb79ddd48 | 572 | resourceUpdate = NULL; |
leothedragon | 0:8f0bb79ddd48 | 573 | resourceState = NULL; |
leothedragon | 0:8f0bb79ddd48 | 574 | resourceResult = NULL; |
leothedragon | 0:8f0bb79ddd48 | 575 | resourceName = NULL; |
leothedragon | 0:8f0bb79ddd48 | 576 | resourceVersion = NULL; |
leothedragon | 0:8f0bb79ddd48 | 577 | |
leothedragon | 0:8f0bb79ddd48 | 578 | } |