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.
mbed-cloud-client/update-client-hub/modules/lwm2m-mbed/source/lwm2m-source.cpp@0:276e7a263c35, 2018-07-02 (annotated)
- Committer:
- MACRUM
- Date:
- Mon Jul 02 06:30:39 2018 +0000
- Revision:
- 0:276e7a263c35
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:276e7a263c35 | 1 | // ---------------------------------------------------------------------------- |
MACRUM | 0:276e7a263c35 | 2 | // Copyright 2016-2017 ARM Ltd. |
MACRUM | 0:276e7a263c35 | 3 | // |
MACRUM | 0:276e7a263c35 | 4 | // SPDX-License-Identifier: Apache-2.0 |
MACRUM | 0:276e7a263c35 | 5 | // |
MACRUM | 0:276e7a263c35 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
MACRUM | 0:276e7a263c35 | 7 | // you may not use this file except in compliance with the License. |
MACRUM | 0:276e7a263c35 | 8 | // You may obtain a copy of the License at |
MACRUM | 0:276e7a263c35 | 9 | // |
MACRUM | 0:276e7a263c35 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
MACRUM | 0:276e7a263c35 | 11 | // |
MACRUM | 0:276e7a263c35 | 12 | // Unless required by applicable law or agreed to in writing, software |
MACRUM | 0:276e7a263c35 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
MACRUM | 0:276e7a263c35 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MACRUM | 0:276e7a263c35 | 15 | // See the License for the specific language governing permissions and |
MACRUM | 0:276e7a263c35 | 16 | // limitations under the License. |
MACRUM | 0:276e7a263c35 | 17 | // ---------------------------------------------------------------------------- |
MACRUM | 0:276e7a263c35 | 18 | |
MACRUM | 0:276e7a263c35 | 19 | #include "update-client-common/arm_uc_common.h" |
MACRUM | 0:276e7a263c35 | 20 | #include "update-client-lwm2m/lwm2m-source.h" |
MACRUM | 0:276e7a263c35 | 21 | #include "update-client-lwm2m/FirmwareUpdateResource.h" |
MACRUM | 0:276e7a263c35 | 22 | #include "update-client-lwm2m/DeviceMetadataResource.h" |
MACRUM | 0:276e7a263c35 | 23 | |
MACRUM | 0:276e7a263c35 | 24 | |
MACRUM | 0:276e7a263c35 | 25 | /* forward declaration */ |
MACRUM | 0:276e7a263c35 | 26 | static void ARM_UCS_PackageCallback(const uint8_t* buffer, uint16_t length); |
MACRUM | 0:276e7a263c35 | 27 | |
MACRUM | 0:276e7a263c35 | 28 | /* local copy of the received manifest */ |
MACRUM | 0:276e7a263c35 | 29 | static uint8_t* arm_ucs_manifest_buffer = NULL; |
MACRUM | 0:276e7a263c35 | 30 | static uint16_t arm_ucs_manifest_length = 0; |
MACRUM | 0:276e7a263c35 | 31 | |
MACRUM | 0:276e7a263c35 | 32 | /* callback function pointer and struct */ |
MACRUM | 0:276e7a263c35 | 33 | static void (*ARM_UCS_EventHandler)(uint32_t event) = 0; |
MACRUM | 0:276e7a263c35 | 34 | static arm_uc_callback_t callbackNodeManifest = { NULL, 0, NULL, 0 }; |
MACRUM | 0:276e7a263c35 | 35 | static arm_uc_callback_t callbackNodeNotification = { NULL, 0, NULL, 0 }; |
MACRUM | 0:276e7a263c35 | 36 | |
MACRUM | 0:276e7a263c35 | 37 | /** |
MACRUM | 0:276e7a263c35 | 38 | * @brief Get driver version. |
MACRUM | 0:276e7a263c35 | 39 | * @return Driver version. |
MACRUM | 0:276e7a263c35 | 40 | */ |
MACRUM | 0:276e7a263c35 | 41 | uint32_t ARM_UCS_LWM2M_SOURCE_GetVersion(void) |
MACRUM | 0:276e7a263c35 | 42 | { |
MACRUM | 0:276e7a263c35 | 43 | return 0; |
MACRUM | 0:276e7a263c35 | 44 | } |
MACRUM | 0:276e7a263c35 | 45 | |
MACRUM | 0:276e7a263c35 | 46 | /** |
MACRUM | 0:276e7a263c35 | 47 | * @brief Get Source capabilities. |
MACRUM | 0:276e7a263c35 | 48 | * @return Struct containing capabilites. See definition above. |
MACRUM | 0:276e7a263c35 | 49 | */ |
MACRUM | 0:276e7a263c35 | 50 | ARM_SOURCE_CAPABILITIES ARM_UCS_LWM2M_SOURCE_GetCapabilities(void) |
MACRUM | 0:276e7a263c35 | 51 | { |
MACRUM | 0:276e7a263c35 | 52 | ARM_SOURCE_CAPABILITIES result = { .notify = 0, |
MACRUM | 0:276e7a263c35 | 53 | .manifest_default = 0, |
MACRUM | 0:276e7a263c35 | 54 | .manifest_url = 0, |
MACRUM | 0:276e7a263c35 | 55 | .firmware = 0, |
MACRUM | 0:276e7a263c35 | 56 | .keytable = 0 }; |
MACRUM | 0:276e7a263c35 | 57 | |
MACRUM | 0:276e7a263c35 | 58 | /* the event handler must be set before module can be used */ |
MACRUM | 0:276e7a263c35 | 59 | if (ARM_UCS_EventHandler != 0) |
MACRUM | 0:276e7a263c35 | 60 | { |
MACRUM | 0:276e7a263c35 | 61 | result.notify = 1; |
MACRUM | 0:276e7a263c35 | 62 | result.manifest_default = 1; |
MACRUM | 0:276e7a263c35 | 63 | } |
MACRUM | 0:276e7a263c35 | 64 | |
MACRUM | 0:276e7a263c35 | 65 | return result; |
MACRUM | 0:276e7a263c35 | 66 | } |
MACRUM | 0:276e7a263c35 | 67 | |
MACRUM | 0:276e7a263c35 | 68 | /** |
MACRUM | 0:276e7a263c35 | 69 | * @brief Initialize Source. |
MACRUM | 0:276e7a263c35 | 70 | * @details Function pointer to event handler is passed as argument. |
MACRUM | 0:276e7a263c35 | 71 | * |
MACRUM | 0:276e7a263c35 | 72 | * @param cb_event Function pointer to event handler. See events above. |
MACRUM | 0:276e7a263c35 | 73 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 74 | */ |
MACRUM | 0:276e7a263c35 | 75 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_Initialize(ARM_SOURCE_SignalEvent_t cb_event) |
MACRUM | 0:276e7a263c35 | 76 | { |
MACRUM | 0:276e7a263c35 | 77 | UC_SRCE_TRACE("ARM_UCS_LWM2M_SOURCE_Initialize: %p", cb_event); |
MACRUM | 0:276e7a263c35 | 78 | |
MACRUM | 0:276e7a263c35 | 79 | arm_uc_error_t result = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 80 | |
MACRUM | 0:276e7a263c35 | 81 | if (cb_event != 0) |
MACRUM | 0:276e7a263c35 | 82 | { |
MACRUM | 0:276e7a263c35 | 83 | /* store callback handler */ |
MACRUM | 0:276e7a263c35 | 84 | ARM_UCS_EventHandler = cb_event; |
MACRUM | 0:276e7a263c35 | 85 | |
MACRUM | 0:276e7a263c35 | 86 | /* Initialize LWM2M Firmware Update Object */ |
MACRUM | 0:276e7a263c35 | 87 | FirmwareUpdateResource::Initialize(); |
MACRUM | 0:276e7a263c35 | 88 | |
MACRUM | 0:276e7a263c35 | 89 | /* Register callback handler */ |
MACRUM | 0:276e7a263c35 | 90 | FirmwareUpdateResource::addPackageCallback(ARM_UCS_PackageCallback); |
MACRUM | 0:276e7a263c35 | 91 | |
MACRUM | 0:276e7a263c35 | 92 | DeviceMetadataResource::Initialize(); |
MACRUM | 0:276e7a263c35 | 93 | |
MACRUM | 0:276e7a263c35 | 94 | result.code = SRCE_ERR_NONE; |
MACRUM | 0:276e7a263c35 | 95 | } |
MACRUM | 0:276e7a263c35 | 96 | |
MACRUM | 0:276e7a263c35 | 97 | return result; |
MACRUM | 0:276e7a263c35 | 98 | } |
MACRUM | 0:276e7a263c35 | 99 | |
MACRUM | 0:276e7a263c35 | 100 | /** |
MACRUM | 0:276e7a263c35 | 101 | * @brief Uninitialized Source. |
MACRUM | 0:276e7a263c35 | 102 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 103 | */ |
MACRUM | 0:276e7a263c35 | 104 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_Uninitialize(void) |
MACRUM | 0:276e7a263c35 | 105 | { |
MACRUM | 0:276e7a263c35 | 106 | arm_uc_error_t retval = { .code = SRCE_ERR_NONE }; |
MACRUM | 0:276e7a263c35 | 107 | DeviceMetadataResource::Uninitialize(); |
MACRUM | 0:276e7a263c35 | 108 | FirmwareUpdateResource::Uninitialize(); |
MACRUM | 0:276e7a263c35 | 109 | |
MACRUM | 0:276e7a263c35 | 110 | return retval; |
MACRUM | 0:276e7a263c35 | 111 | } |
MACRUM | 0:276e7a263c35 | 112 | |
MACRUM | 0:276e7a263c35 | 113 | /** |
MACRUM | 0:276e7a263c35 | 114 | * @brief Cost estimation for retrieving manifest from the default location. |
MACRUM | 0:276e7a263c35 | 115 | * @details The estimation can vary over time and should not be cached too long. |
MACRUM | 0:276e7a263c35 | 116 | * 0x00000000 - The manifest is already downloaded. |
MACRUM | 0:276e7a263c35 | 117 | * 0xFFFFFFFF - Cannot retrieve manifest from this Source. |
MACRUM | 0:276e7a263c35 | 118 | * |
MACRUM | 0:276e7a263c35 | 119 | * @param cost Pointer to variable for the return value. |
MACRUM | 0:276e7a263c35 | 120 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 121 | */ |
MACRUM | 0:276e7a263c35 | 122 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetManifestDefaultCost(uint32_t* cost) |
MACRUM | 0:276e7a263c35 | 123 | { |
MACRUM | 0:276e7a263c35 | 124 | arm_uc_error_t result = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 125 | |
MACRUM | 0:276e7a263c35 | 126 | if (cost != 0) |
MACRUM | 0:276e7a263c35 | 127 | { |
MACRUM | 0:276e7a263c35 | 128 | /* set cost to 0 when manifest is cached */ |
MACRUM | 0:276e7a263c35 | 129 | if (arm_ucs_manifest_buffer && arm_ucs_manifest_length) |
MACRUM | 0:276e7a263c35 | 130 | { |
MACRUM | 0:276e7a263c35 | 131 | *cost = 0; |
MACRUM | 0:276e7a263c35 | 132 | } |
MACRUM | 0:276e7a263c35 | 133 | /* set cost to 0xFFFFFFFF when manifest has been read */ |
MACRUM | 0:276e7a263c35 | 134 | else |
MACRUM | 0:276e7a263c35 | 135 | { |
MACRUM | 0:276e7a263c35 | 136 | *cost = 0xFFFFFFFF; |
MACRUM | 0:276e7a263c35 | 137 | } |
MACRUM | 0:276e7a263c35 | 138 | |
MACRUM | 0:276e7a263c35 | 139 | result.code = SRCE_ERR_NONE; |
MACRUM | 0:276e7a263c35 | 140 | } |
MACRUM | 0:276e7a263c35 | 141 | |
MACRUM | 0:276e7a263c35 | 142 | return result; |
MACRUM | 0:276e7a263c35 | 143 | } |
MACRUM | 0:276e7a263c35 | 144 | |
MACRUM | 0:276e7a263c35 | 145 | /** |
MACRUM | 0:276e7a263c35 | 146 | * @brief Retrieve manifest from the default location. |
MACRUM | 0:276e7a263c35 | 147 | * @details Manifest is stored in supplied buffer. |
MACRUM | 0:276e7a263c35 | 148 | * Event is generated once manifest is in buffer. |
MACRUM | 0:276e7a263c35 | 149 | * |
MACRUM | 0:276e7a263c35 | 150 | * @param buffer Struct containing byte array, maximum size, and actual size. |
MACRUM | 0:276e7a263c35 | 151 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 152 | */ |
MACRUM | 0:276e7a263c35 | 153 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetManifestDefault(arm_uc_buffer_t* buffer, |
MACRUM | 0:276e7a263c35 | 154 | uint32_t offset) |
MACRUM | 0:276e7a263c35 | 155 | { |
MACRUM | 0:276e7a263c35 | 156 | arm_uc_error_t result = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 157 | |
MACRUM | 0:276e7a263c35 | 158 | /* copy manifest from cache into buffer */ |
MACRUM | 0:276e7a263c35 | 159 | if ((buffer != NULL) && |
MACRUM | 0:276e7a263c35 | 160 | (buffer->ptr != NULL) && |
MACRUM | 0:276e7a263c35 | 161 | (arm_ucs_manifest_buffer != NULL) && |
MACRUM | 0:276e7a263c35 | 162 | (arm_ucs_manifest_length != 0) && |
MACRUM | 0:276e7a263c35 | 163 | (offset < arm_ucs_manifest_length)) |
MACRUM | 0:276e7a263c35 | 164 | { |
MACRUM | 0:276e7a263c35 | 165 | /* remaining length based on offset request */ |
MACRUM | 0:276e7a263c35 | 166 | uint16_t length = arm_ucs_manifest_length - offset; |
MACRUM | 0:276e7a263c35 | 167 | |
MACRUM | 0:276e7a263c35 | 168 | /* set actual length based on buffer size */ |
MACRUM | 0:276e7a263c35 | 169 | if (length > buffer->size_max) |
MACRUM | 0:276e7a263c35 | 170 | { |
MACRUM | 0:276e7a263c35 | 171 | length = buffer->size_max; |
MACRUM | 0:276e7a263c35 | 172 | } |
MACRUM | 0:276e7a263c35 | 173 | |
MACRUM | 0:276e7a263c35 | 174 | /* size check */ |
MACRUM | 0:276e7a263c35 | 175 | if (length > 0) |
MACRUM | 0:276e7a263c35 | 176 | { |
MACRUM | 0:276e7a263c35 | 177 | /* copy manifest from local buffer to external buffer */ |
MACRUM | 0:276e7a263c35 | 178 | memcpy(buffer->ptr, &arm_ucs_manifest_buffer[offset], length); |
MACRUM | 0:276e7a263c35 | 179 | buffer->size = length; |
MACRUM | 0:276e7a263c35 | 180 | |
MACRUM | 0:276e7a263c35 | 181 | /* delete local buffer once the entire manifest has been read */ |
MACRUM | 0:276e7a263c35 | 182 | if (offset + length >= arm_ucs_manifest_length) |
MACRUM | 0:276e7a263c35 | 183 | { |
MACRUM | 0:276e7a263c35 | 184 | delete[] arm_ucs_manifest_buffer; |
MACRUM | 0:276e7a263c35 | 185 | arm_ucs_manifest_buffer = NULL; |
MACRUM | 0:276e7a263c35 | 186 | arm_ucs_manifest_length = 0; |
MACRUM | 0:276e7a263c35 | 187 | } |
MACRUM | 0:276e7a263c35 | 188 | |
MACRUM | 0:276e7a263c35 | 189 | result.code = SRCE_ERR_NONE; |
MACRUM | 0:276e7a263c35 | 190 | |
MACRUM | 0:276e7a263c35 | 191 | /* signal event handler that manifest has been copied to buffer */ |
MACRUM | 0:276e7a263c35 | 192 | if (ARM_UCS_EventHandler) |
MACRUM | 0:276e7a263c35 | 193 | { |
MACRUM | 0:276e7a263c35 | 194 | ARM_UC_PostCallback(&callbackNodeManifest, |
MACRUM | 0:276e7a263c35 | 195 | ARM_UCS_EventHandler, |
MACRUM | 0:276e7a263c35 | 196 | EVENT_MANIFEST); |
MACRUM | 0:276e7a263c35 | 197 | } |
MACRUM | 0:276e7a263c35 | 198 | } |
MACRUM | 0:276e7a263c35 | 199 | } |
MACRUM | 0:276e7a263c35 | 200 | |
MACRUM | 0:276e7a263c35 | 201 | return result; |
MACRUM | 0:276e7a263c35 | 202 | } |
MACRUM | 0:276e7a263c35 | 203 | |
MACRUM | 0:276e7a263c35 | 204 | static void ARM_UCS_PackageCallback(const uint8_t* buffer, uint16_t length) |
MACRUM | 0:276e7a263c35 | 205 | { |
MACRUM | 0:276e7a263c35 | 206 | uint32_t event_code = EVENT_ERROR; |
MACRUM | 0:276e7a263c35 | 207 | |
MACRUM | 0:276e7a263c35 | 208 | if (arm_ucs_manifest_buffer) |
MACRUM | 0:276e7a263c35 | 209 | { |
MACRUM | 0:276e7a263c35 | 210 | UC_SRCE_ERR_MSG("received new manifest before reading the old one"); |
MACRUM | 0:276e7a263c35 | 211 | |
MACRUM | 0:276e7a263c35 | 212 | /* delete old buffer to make space for the new one */ |
MACRUM | 0:276e7a263c35 | 213 | delete[] arm_ucs_manifest_buffer; |
MACRUM | 0:276e7a263c35 | 214 | arm_ucs_manifest_length = 0; |
MACRUM | 0:276e7a263c35 | 215 | } |
MACRUM | 0:276e7a263c35 | 216 | |
MACRUM | 0:276e7a263c35 | 217 | /* allocate a local buffer of the same size as the manifest */ |
MACRUM | 0:276e7a263c35 | 218 | arm_ucs_manifest_buffer = new uint8_t[length]; |
MACRUM | 0:276e7a263c35 | 219 | |
MACRUM | 0:276e7a263c35 | 220 | if (arm_ucs_manifest_buffer) |
MACRUM | 0:276e7a263c35 | 221 | { |
MACRUM | 0:276e7a263c35 | 222 | /* copy manifest from payload to local buffer */ |
MACRUM | 0:276e7a263c35 | 223 | memcpy(arm_ucs_manifest_buffer, buffer, length); |
MACRUM | 0:276e7a263c35 | 224 | arm_ucs_manifest_length = length; |
MACRUM | 0:276e7a263c35 | 225 | |
MACRUM | 0:276e7a263c35 | 226 | event_code = EVENT_NOTIFICATION; |
MACRUM | 0:276e7a263c35 | 227 | } |
MACRUM | 0:276e7a263c35 | 228 | |
MACRUM | 0:276e7a263c35 | 229 | /* signal event handler with result */ |
MACRUM | 0:276e7a263c35 | 230 | if (ARM_UCS_EventHandler) |
MACRUM | 0:276e7a263c35 | 231 | { |
MACRUM | 0:276e7a263c35 | 232 | ARM_UC_PostCallback(&callbackNodeNotification, |
MACRUM | 0:276e7a263c35 | 233 | ARM_UCS_EventHandler, |
MACRUM | 0:276e7a263c35 | 234 | event_code); |
MACRUM | 0:276e7a263c35 | 235 | } |
MACRUM | 0:276e7a263c35 | 236 | } |
MACRUM | 0:276e7a263c35 | 237 | |
MACRUM | 0:276e7a263c35 | 238 | /*****************************************************************************/ |
MACRUM | 0:276e7a263c35 | 239 | /* Capabilities not supported by this source */ |
MACRUM | 0:276e7a263c35 | 240 | /*****************************************************************************/ |
MACRUM | 0:276e7a263c35 | 241 | |
MACRUM | 0:276e7a263c35 | 242 | /** |
MACRUM | 0:276e7a263c35 | 243 | * @brief Cost estimation for retrieving manifest from URL. |
MACRUM | 0:276e7a263c35 | 244 | * @details The estimation can vary over time and should not be cached too long. |
MACRUM | 0:276e7a263c35 | 245 | * 0x00000000 - The manifest is already downloaded. |
MACRUM | 0:276e7a263c35 | 246 | * 0xFFFFFFFF - Cannot retrieve manifest from this Source. |
MACRUM | 0:276e7a263c35 | 247 | * |
MACRUM | 0:276e7a263c35 | 248 | * @param uri URI struct with manifest location. |
MACRUM | 0:276e7a263c35 | 249 | * @param cost Pointer to variable for the return value. |
MACRUM | 0:276e7a263c35 | 250 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 251 | */ |
MACRUM | 0:276e7a263c35 | 252 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetManifestURLCost(arm_uc_uri_t* uri, |
MACRUM | 0:276e7a263c35 | 253 | uint32_t* cost) |
MACRUM | 0:276e7a263c35 | 254 | { |
MACRUM | 0:276e7a263c35 | 255 | (void) uri; |
MACRUM | 0:276e7a263c35 | 256 | (void) cost; |
MACRUM | 0:276e7a263c35 | 257 | |
MACRUM | 0:276e7a263c35 | 258 | arm_uc_error_t result = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 259 | |
MACRUM | 0:276e7a263c35 | 260 | /* not supported - return default cost regardless of actual uri location */ |
MACRUM | 0:276e7a263c35 | 261 | if (cost) |
MACRUM | 0:276e7a263c35 | 262 | { |
MACRUM | 0:276e7a263c35 | 263 | *cost = 0xFFFFFFFF; |
MACRUM | 0:276e7a263c35 | 264 | result.code = SRCE_ERR_NONE; |
MACRUM | 0:276e7a263c35 | 265 | } |
MACRUM | 0:276e7a263c35 | 266 | |
MACRUM | 0:276e7a263c35 | 267 | return result; |
MACRUM | 0:276e7a263c35 | 268 | } |
MACRUM | 0:276e7a263c35 | 269 | |
MACRUM | 0:276e7a263c35 | 270 | /** |
MACRUM | 0:276e7a263c35 | 271 | * @brief Cost estimation for retrieving firmware from URL. |
MACRUM | 0:276e7a263c35 | 272 | * @details The estimation can vary over time and should not be cached too long. |
MACRUM | 0:276e7a263c35 | 273 | * 0x00000000 - The firmware is already downloaded. |
MACRUM | 0:276e7a263c35 | 274 | * 0xFFFFFFFF - Cannot retrieve firmware from this Source. |
MACRUM | 0:276e7a263c35 | 275 | * |
MACRUM | 0:276e7a263c35 | 276 | * @param uri URI struct with firmware location. |
MACRUM | 0:276e7a263c35 | 277 | * @param cost Pointer to variable for the return value. |
MACRUM | 0:276e7a263c35 | 278 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 279 | */ |
MACRUM | 0:276e7a263c35 | 280 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetFirmwareURLCost(arm_uc_uri_t* uri, |
MACRUM | 0:276e7a263c35 | 281 | uint32_t* cost) |
MACRUM | 0:276e7a263c35 | 282 | { |
MACRUM | 0:276e7a263c35 | 283 | (void) uri; |
MACRUM | 0:276e7a263c35 | 284 | (void) cost; |
MACRUM | 0:276e7a263c35 | 285 | |
MACRUM | 0:276e7a263c35 | 286 | arm_uc_error_t result = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 287 | |
MACRUM | 0:276e7a263c35 | 288 | /* not supported - return default cost regardless of actual uri location */ |
MACRUM | 0:276e7a263c35 | 289 | if (cost != 0) |
MACRUM | 0:276e7a263c35 | 290 | { |
MACRUM | 0:276e7a263c35 | 291 | *cost = 0xFFFFFFFF; |
MACRUM | 0:276e7a263c35 | 292 | result.code = SRCE_ERR_NONE; |
MACRUM | 0:276e7a263c35 | 293 | } |
MACRUM | 0:276e7a263c35 | 294 | |
MACRUM | 0:276e7a263c35 | 295 | return result; |
MACRUM | 0:276e7a263c35 | 296 | } |
MACRUM | 0:276e7a263c35 | 297 | |
MACRUM | 0:276e7a263c35 | 298 | /** |
MACRUM | 0:276e7a263c35 | 299 | * @brief Cost estimation for retrieving key table from URL. |
MACRUM | 0:276e7a263c35 | 300 | * @details The estimation can vary over time and should not be cached too long. |
MACRUM | 0:276e7a263c35 | 301 | * 0x00000000 - The firmware is already downloaded. |
MACRUM | 0:276e7a263c35 | 302 | * 0xFFFFFFFF - Cannot retrieve firmware from this Source. |
MACRUM | 0:276e7a263c35 | 303 | * |
MACRUM | 0:276e7a263c35 | 304 | * @param uri URI struct with keytable location. |
MACRUM | 0:276e7a263c35 | 305 | * @param cost Pointer to variable for the return value. |
MACRUM | 0:276e7a263c35 | 306 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 307 | */ |
MACRUM | 0:276e7a263c35 | 308 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetKeytableURLCost(arm_uc_uri_t* uri, |
MACRUM | 0:276e7a263c35 | 309 | uint32_t* cost) |
MACRUM | 0:276e7a263c35 | 310 | { |
MACRUM | 0:276e7a263c35 | 311 | (void) uri; |
MACRUM | 0:276e7a263c35 | 312 | (void) cost; |
MACRUM | 0:276e7a263c35 | 313 | |
MACRUM | 0:276e7a263c35 | 314 | arm_uc_error_t result = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 315 | |
MACRUM | 0:276e7a263c35 | 316 | /* not supported - return default cost regardless of actual uri location */ |
MACRUM | 0:276e7a263c35 | 317 | if ((uri != 0) && (cost != 0)) |
MACRUM | 0:276e7a263c35 | 318 | { |
MACRUM | 0:276e7a263c35 | 319 | *cost = 0xFFFFFFFF; |
MACRUM | 0:276e7a263c35 | 320 | result.code = SRCE_ERR_NONE; |
MACRUM | 0:276e7a263c35 | 321 | } |
MACRUM | 0:276e7a263c35 | 322 | |
MACRUM | 0:276e7a263c35 | 323 | return result; |
MACRUM | 0:276e7a263c35 | 324 | } |
MACRUM | 0:276e7a263c35 | 325 | |
MACRUM | 0:276e7a263c35 | 326 | /** |
MACRUM | 0:276e7a263c35 | 327 | * @brief Retrieve manifest from URL. |
MACRUM | 0:276e7a263c35 | 328 | * @details Manifest is stored in supplied buffer. |
MACRUM | 0:276e7a263c35 | 329 | * Event is generated once manifest is in buffer. |
MACRUM | 0:276e7a263c35 | 330 | * |
MACRUM | 0:276e7a263c35 | 331 | * @param uri URI struct with manifest location. |
MACRUM | 0:276e7a263c35 | 332 | * @param buffer Struct containing byte array, maximum size, and actual size. |
MACRUM | 0:276e7a263c35 | 333 | * |
MACRUM | 0:276e7a263c35 | 334 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 335 | */ |
MACRUM | 0:276e7a263c35 | 336 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetManifestURL(arm_uc_uri_t* uri, |
MACRUM | 0:276e7a263c35 | 337 | arm_uc_buffer_t* buffer, |
MACRUM | 0:276e7a263c35 | 338 | uint32_t offset) |
MACRUM | 0:276e7a263c35 | 339 | { |
MACRUM | 0:276e7a263c35 | 340 | (void) uri; |
MACRUM | 0:276e7a263c35 | 341 | (void) buffer; |
MACRUM | 0:276e7a263c35 | 342 | (void) offset; |
MACRUM | 0:276e7a263c35 | 343 | |
MACRUM | 0:276e7a263c35 | 344 | arm_uc_error_t retval = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 345 | |
MACRUM | 0:276e7a263c35 | 346 | return retval; |
MACRUM | 0:276e7a263c35 | 347 | } |
MACRUM | 0:276e7a263c35 | 348 | |
MACRUM | 0:276e7a263c35 | 349 | /** |
MACRUM | 0:276e7a263c35 | 350 | * @brief Retrieve firmware fragment. |
MACRUM | 0:276e7a263c35 | 351 | * @details Firmware fragment is stored in supplied buffer. |
MACRUM | 0:276e7a263c35 | 352 | * Event is generated once fragment is in buffer. |
MACRUM | 0:276e7a263c35 | 353 | * |
MACRUM | 0:276e7a263c35 | 354 | * @param uri URI struct with firmware location. |
MACRUM | 0:276e7a263c35 | 355 | * @param buffer Struct containing byte array, maximum size, and actual size. |
MACRUM | 0:276e7a263c35 | 356 | * @param offset Firmware offset to retrieve fragment from. |
MACRUM | 0:276e7a263c35 | 357 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 358 | */ |
MACRUM | 0:276e7a263c35 | 359 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetFirmwareFragment(arm_uc_uri_t* uri, |
MACRUM | 0:276e7a263c35 | 360 | arm_uc_buffer_t* buffer, |
MACRUM | 0:276e7a263c35 | 361 | uint32_t offset) |
MACRUM | 0:276e7a263c35 | 362 | { |
MACRUM | 0:276e7a263c35 | 363 | (void) uri; |
MACRUM | 0:276e7a263c35 | 364 | (void) buffer; |
MACRUM | 0:276e7a263c35 | 365 | (void) offset; |
MACRUM | 0:276e7a263c35 | 366 | |
MACRUM | 0:276e7a263c35 | 367 | arm_uc_error_t retval = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 368 | |
MACRUM | 0:276e7a263c35 | 369 | return retval; |
MACRUM | 0:276e7a263c35 | 370 | } |
MACRUM | 0:276e7a263c35 | 371 | |
MACRUM | 0:276e7a263c35 | 372 | /** |
MACRUM | 0:276e7a263c35 | 373 | * @brief Retrieve a key table from a URL. |
MACRUM | 0:276e7a263c35 | 374 | * @details Key table is stored in supplied buffer. |
MACRUM | 0:276e7a263c35 | 375 | * Event is generated once fragment is in buffer. |
MACRUM | 0:276e7a263c35 | 376 | * |
MACRUM | 0:276e7a263c35 | 377 | * @param uri URI struct with keytable location. |
MACRUM | 0:276e7a263c35 | 378 | * @param buffer Struct containing byte array, maximum size, and actual size. |
MACRUM | 0:276e7a263c35 | 379 | * @return Error code. |
MACRUM | 0:276e7a263c35 | 380 | */ |
MACRUM | 0:276e7a263c35 | 381 | arm_uc_error_t ARM_UCS_LWM2M_SOURCE_GetKeytableURL(arm_uc_uri_t* uri, |
MACRUM | 0:276e7a263c35 | 382 | arm_uc_buffer_t* buffer) |
MACRUM | 0:276e7a263c35 | 383 | { |
MACRUM | 0:276e7a263c35 | 384 | (void) uri; |
MACRUM | 0:276e7a263c35 | 385 | (void) buffer; |
MACRUM | 0:276e7a263c35 | 386 | |
MACRUM | 0:276e7a263c35 | 387 | arm_uc_error_t retval = { .code = SRCE_ERR_INVALID_PARAMETER }; |
MACRUM | 0:276e7a263c35 | 388 | |
MACRUM | 0:276e7a263c35 | 389 | return retval; |
MACRUM | 0:276e7a263c35 | 390 | } |
MACRUM | 0:276e7a263c35 | 391 | |
MACRUM | 0:276e7a263c35 | 392 | ARM_UPDATE_SOURCE ARM_UCS_LWM2M_SOURCE = |
MACRUM | 0:276e7a263c35 | 393 | { |
MACRUM | 0:276e7a263c35 | 394 | .GetVersion = ARM_UCS_LWM2M_SOURCE_GetVersion, |
MACRUM | 0:276e7a263c35 | 395 | .GetCapabilities = ARM_UCS_LWM2M_SOURCE_GetCapabilities, |
MACRUM | 0:276e7a263c35 | 396 | .Initialize = ARM_UCS_LWM2M_SOURCE_Initialize, |
MACRUM | 0:276e7a263c35 | 397 | .Uninitialize = ARM_UCS_LWM2M_SOURCE_Uninitialize, |
MACRUM | 0:276e7a263c35 | 398 | .GetManifestDefaultCost = ARM_UCS_LWM2M_SOURCE_GetManifestDefaultCost, |
MACRUM | 0:276e7a263c35 | 399 | .GetManifestURLCost = ARM_UCS_LWM2M_SOURCE_GetManifestURLCost, |
MACRUM | 0:276e7a263c35 | 400 | .GetFirmwareURLCost = ARM_UCS_LWM2M_SOURCE_GetFirmwareURLCost, |
MACRUM | 0:276e7a263c35 | 401 | .GetKeytableURLCost = ARM_UCS_LWM2M_SOURCE_GetKeytableURLCost, |
MACRUM | 0:276e7a263c35 | 402 | .GetManifestDefault = ARM_UCS_LWM2M_SOURCE_GetManifestDefault, |
MACRUM | 0:276e7a263c35 | 403 | .GetManifestURL = ARM_UCS_LWM2M_SOURCE_GetManifestURL, |
MACRUM | 0:276e7a263c35 | 404 | .GetFirmwareFragment = ARM_UCS_LWM2M_SOURCE_GetFirmwareFragment, |
MACRUM | 0:276e7a263c35 | 405 | .GetKeytableURL = ARM_UCS_LWM2M_SOURCE_GetKeytableURL |
MACRUM | 0:276e7a263c35 | 406 | }; |