Commit aa569ceec170bf43b6a098ae7c78f4f3ebcb0561

Authored by YevhenBondarenko
Committed by Andrew Shvayka
1 parent bbe7dc0e

added fw/sw update tests

... ... @@ -20,7 +20,6 @@ import org.apache.commons.io.IOUtils;
20 20 import org.eclipse.californium.core.network.config.NetworkConfig;
21 21 import org.eclipse.leshan.client.object.Security;
22 22 import org.eclipse.leshan.core.util.Hex;
23   -import org.jetbrains.annotations.NotNull;
24 23 import org.junit.After;
25 24 import org.junit.Assert;
26 25 import org.junit.Before;
... ... @@ -85,6 +84,7 @@ import java.util.concurrent.ScheduledExecutorService;
85 84 import static org.eclipse.leshan.client.object.Security.noSec;
86 85 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
87 86 import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
  87 +import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
88 88
89 89 @DaoSqlTest
90 90 public class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
... ... @@ -264,7 +264,7 @@ public class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
264 264 executor = Executors.newScheduledThreadPool(10);
265 265 loginTenantAdmin();
266 266
267   - String[] resources = new String[]{"1.xml", "2.xml", "3.xml"};
  267 + String[] resources = new String[]{"1.xml", "2.xml", "3.xml", "5.xml", "9.xml"};
268 268 for (String resourceName : resources) {
269 269 TbResource lwModel = new TbResource();
270 270 lwModel.setResourceType(ResourceType.LWM2M_MODEL);
... ... @@ -300,7 +300,6 @@ public class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
300 300 Assert.assertNotNull(deviceProfile);
301 301 }
302 302
303   - @NotNull
304 303 protected Device createDevice(LwM2MClientCredentials clientCredentials) throws Exception {
305 304 Device device = new Device();
306 305 device.setName("Device A");
... ... @@ -340,6 +339,22 @@ public class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
340 339 return savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, "SHA256");
341 340 }
342 341
  342 + protected OtaPackageInfo createSoftware() throws Exception {
  343 + String CHECKSUM = "4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a";
  344 +
  345 + OtaPackageInfo swInfo = new OtaPackageInfo();
  346 + swInfo.setDeviceProfileId(deviceProfile.getId());
  347 + swInfo.setType(SOFTWARE);
  348 + swInfo.setTitle("My sw");
  349 + swInfo.setVersion("v1.0");
  350 +
  351 + OtaPackageInfo savedFirmwareInfo = doPost("/api/otaPackage", swInfo, OtaPackageInfo.class);
  352 +
  353 + MockMultipartFile testData = new MockMultipartFile("file", "filename.txt", "text/plain", new byte[]{1});
  354 +
  355 + return savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, "SHA256");
  356 + }
  357 +
343 358 protected OtaPackageInfo savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception {
344 359 MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params);
345 360 postRequest.file(content);
... ...
... ... @@ -15,11 +15,15 @@
15 15 */
16 16 package org.thingsboard.server.transport.lwm2m;
17 17
  18 +import com.fasterxml.jackson.core.type.TypeReference;
18 19 import org.junit.Assert;
19 20 import org.junit.Test;
20 21 import org.thingsboard.server.common.data.Device;
21 22 import org.thingsboard.server.common.data.OtaPackageInfo;
22 23 import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredentials;
  24 +import org.thingsboard.server.common.data.kv.KvEntry;
  25 +import org.thingsboard.server.common.data.kv.TsKvEntry;
  26 +import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus;
23 27 import org.thingsboard.server.common.data.query.EntityData;
24 28 import org.thingsboard.server.common.data.query.EntityDataPageLink;
25 29 import org.thingsboard.server.common.data.query.EntityDataQuery;
... ... @@ -32,11 +36,99 @@ import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate;
32 36 import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
33 37 import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
34 38
  39 +import java.util.Arrays;
35 40 import java.util.Collections;
36 41 import java.util.List;
  42 +import java.util.stream.Collectors;
  43 +
  44 +import static org.thingsboard.rest.client.utils.RestJsonConverter.toTimeseries;
  45 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED;
  46 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING;
  47 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.INITIATED;
  48 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.QUEUED;
  49 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATED;
  50 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING;
  51 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.VERIFIED;
37 52
38 53 public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
39 54
  55 + private final String OTA_TRANSPORT_CONFIGURATION = "{\n" +
  56 + " \"observeAttr\": {\n" +
  57 + " \"keyName\": {\n" +
  58 + " \"/5_1.0/0/3\": \"state\",\n" +
  59 + " \"/5_1.0/0/5\": \"updateResult\",\n" +
  60 + " \"/5_1.0/0/6\": \"pkgname\",\n" +
  61 + " \"/5_1.0/0/7\": \"pkgversion\",\n" +
  62 + " \"/5_1.0/0/9\": \"firmwareUpdateDeliveryMethod\",\n" +
  63 + " \"/9_1.0/0/0\": \"pkgname\",\n" +
  64 + " \"/9_1.0/0/1\": \"pkgversion\",\n" +
  65 + " \"/9_1.0/0/7\": \"updateState\",\n" +
  66 + " \"/9_1.0/0/9\": \"updateResult\"\n" +
  67 + " },\n" +
  68 + " \"observe\": [\n" +
  69 + " \"/5_1.0/0/3\",\n" +
  70 + " \"/5_1.0/0/5\",\n" +
  71 + " \"/5_1.0/0/6\",\n" +
  72 + " \"/5_1.0/0/7\",\n" +
  73 + " \"/5_1.0/0/9\",\n" +
  74 + " \"/9_1.0/0/0\",\n" +
  75 + " \"/9_1.0/0/1\",\n" +
  76 + " \"/9_1.0/0/7\",\n" +
  77 + " \"/9_1.0/0/9\"\n" +
  78 + " ],\n" +
  79 + " \"attribute\": [],\n" +
  80 + " \"telemetry\": [\n" +
  81 + " \"/5_1.0/0/3\",\n" +
  82 + " \"/5_1.0/0/5\",\n" +
  83 + " \"/5_1.0/0/6\",\n" +
  84 + " \"/5_1.0/0/7\",\n" +
  85 + " \"/5_1.0/0/9\",\n" +
  86 + " \"/9_1.0/0/0\",\n" +
  87 + " \"/9_1.0/0/1\",\n" +
  88 + " \"/9_1.0/0/7\",\n" +
  89 + " \"/9_1.0/0/9\"\n" +
  90 + " ],\n" +
  91 + " \"attributeLwm2m\": {}\n" +
  92 + " },\n" +
  93 + " \"bootstrap\": {\n" +
  94 + " \"servers\": {\n" +
  95 + " \"binding\": \"UQ\",\n" +
  96 + " \"shortId\": 123,\n" +
  97 + " \"lifetime\": 300,\n" +
  98 + " \"notifIfDisabled\": true,\n" +
  99 + " \"defaultMinPeriod\": 1\n" +
  100 + " },\n" +
  101 + " \"lwm2mServer\": {\n" +
  102 + " \"host\": \"localhost\",\n" +
  103 + " \"port\": 5685,\n" +
  104 + " \"serverId\": 123,\n" +
  105 + " \"securityMode\": \"NO_SEC\",\n" +
  106 + " \"serverPublicKey\": \"\",\n" +
  107 + " \"clientHoldOffTime\": 1,\n" +
  108 + " \"bootstrapServerAccountTimeout\": 0\n" +
  109 + " },\n" +
  110 + " \"bootstrapServer\": {\n" +
  111 + " \"host\": \"localhost\",\n" +
  112 + " \"port\": 5687,\n" +
  113 + " \"serverId\": 111,\n" +
  114 + " \"securityMode\": \"NO_SEC\",\n" +
  115 + " \"serverPublicKey\": \"\",\n" +
  116 + " \"clientHoldOffTime\": 1,\n" +
  117 + " \"bootstrapServerAccountTimeout\": 0\n" +
  118 + " }\n" +
  119 + " },\n" +
  120 + " \"clientLwM2mSettings\": {\n" +
  121 + " \"fwUpdateStrategy\": 1,\n" +
  122 + " \"swUpdateStrategy\": 1,\n" +
  123 + " \"clientOnlyObserveAfterConnect\": 1,\n" +
  124 + " \"powerMode\": \"PSM\",\n" +
  125 + " \"fwUpdateResource\": \"\",\n" +
  126 + " \"swUpdateResource\": \"\",\n" +
  127 + " \"compositeOperationsSupport\": false\n" +
  128 + " },\n" +
  129 + " \"type\": \"LWM2M\"\n" +
  130 + "}";
  131 +
40 132 @Test
41 133 public void testConnectAndObserveTelemetry() throws Exception {
42 134 NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
... ... @@ -94,4 +186,68 @@ public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
94 186 client.destroy();
95 187 }
96 188
  189 + @Test
  190 + public void testFirmwareUpdateByObject5() throws Exception {
  191 + createDeviceProfile(OTA_TRANSPORT_CONFIGURATION);
  192 + NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
  193 + clientCredentials.setEndpoint("OTA_" + ENDPOINT);
  194 + Device device = createDevice(clientCredentials);
  195 +
  196 + OtaPackageInfo firmware = createFirmware();
  197 +
  198 + LwM2MTestClient client = new LwM2MTestClient(executor, "OTA_" + ENDPOINT);
  199 + client.init(SECURITY, COAP_CONFIG);
  200 +
  201 + Thread.sleep(1000);
  202 +
  203 + device.setFirmwareId(firmware.getId());
  204 +
  205 + device = doPost("/api/device", device, Device.class);
  206 +
  207 + Thread.sleep(4000);
  208 +
  209 + List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
  210 + }));
  211 +
  212 + List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
  213 +
  214 + List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED);
  215 +
  216 + Assert.assertEquals(expectedStatuses, statuses);
  217 +
  218 + client.destroy();
  219 + }
  220 +
  221 + @Test
  222 + public void testSoftwareUpdateByObject9() throws Exception {
  223 + createDeviceProfile(OTA_TRANSPORT_CONFIGURATION);
  224 + NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
  225 + clientCredentials.setEndpoint("OTA_" + ENDPOINT);
  226 + Device device = createDevice(clientCredentials);
  227 +
  228 + OtaPackageInfo software = createSoftware();
  229 +
  230 + LwM2MTestClient client = new LwM2MTestClient(executor, "OTA_" + ENDPOINT);
  231 + client.init(SECURITY, COAP_CONFIG);
  232 +
  233 + Thread.sleep(1000);
  234 +
  235 + device.setSoftwareId(software.getId());
  236 +
  237 + device = doPost("/api/device", device, Device.class);
  238 +
  239 + Thread.sleep(4000);
  240 +
  241 + List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getId().getId() + "/values/timeseries?orderBy=ASC&keys=sw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
  242 + }));
  243 +
  244 + List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
  245 +
  246 + List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED);
  247 +
  248 + Assert.assertEquals(expectedStatuses, statuses);
  249 +
  250 + client.destroy();
  251 + }
  252 +
97 253 }
... ...
... ... @@ -23,6 +23,7 @@ import org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCred
23 23 import static org.eclipse.leshan.client.object.Security.rpk;
24 24
25 25 public class RpkLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
  26 +
26 27 @Test
27 28 public void testConnectWithRPKAndObserveTelemetry() throws Exception {
28 29 RPKClientCredentials rpkClientCredentials = new RPKClientCredentials();
... ...
  1 +/**
  2 + * Copyright © 2016-2021 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.transport.lwm2m.client;
  17 +
  18 +import lombok.extern.slf4j.Slf4j;
  19 +import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
  20 +import org.eclipse.leshan.client.servers.ServerIdentity;
  21 +import org.eclipse.leshan.core.model.ObjectModel;
  22 +import org.eclipse.leshan.core.node.LwM2mResource;
  23 +import org.eclipse.leshan.core.response.ExecuteResponse;
  24 +import org.eclipse.leshan.core.response.ReadResponse;
  25 +import org.eclipse.leshan.core.response.WriteResponse;
  26 +
  27 +import javax.security.auth.Destroyable;
  28 +import java.util.Arrays;
  29 +import java.util.List;
  30 +import java.util.concurrent.Executors;
  31 +import java.util.concurrent.ScheduledExecutorService;
  32 +import java.util.concurrent.TimeUnit;
  33 +import java.util.concurrent.atomic.AtomicInteger;
  34 +
  35 +@Slf4j
  36 +public class FwLwM2MDevice extends BaseInstanceEnabler implements Destroyable {
  37 +
  38 + private static final List<Integer> supportedResources = Arrays.asList(0, 1, 2, 3, 5, 6, 7, 9);
  39 +
  40 + private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
  41 +
  42 + private final AtomicInteger state = new AtomicInteger(0);
  43 +
  44 + private final AtomicInteger updateResult = new AtomicInteger(0);
  45 +
  46 + @Override
  47 + public ReadResponse read(ServerIdentity identity, int resourceId) {
  48 + if (!identity.isSystem())
  49 + log.info("Read on Device resource /{}/{}/{}", getModel().id, getId(), resourceId);
  50 + switch (resourceId) {
  51 + case 3:
  52 + return ReadResponse.success(resourceId, getState());
  53 + case 5:
  54 + return ReadResponse.success(resourceId, getUpdateResult());
  55 + case 6:
  56 + return ReadResponse.success(resourceId, getPkgName());
  57 + case 7:
  58 + return ReadResponse.success(resourceId, getPkgVersion());
  59 + case 9:
  60 + return ReadResponse.success(resourceId, getFirmwareUpdateDeliveryMethod());
  61 + default:
  62 + return super.read(identity, resourceId);
  63 + }
  64 + }
  65 +
  66 + @Override
  67 + public ExecuteResponse execute(ServerIdentity identity, int resourceId, String params) {
  68 + String withParams = null;
  69 + if (params != null && params.length() != 0) {
  70 + withParams = " with params " + params;
  71 + }
  72 + log.info("Execute on Device resource /{}/{}/{} {}", getModel().id, getId(), resourceId, withParams != null ? withParams : "");
  73 +
  74 + switch (resourceId) {
  75 + case 2:
  76 + startUpdating();
  77 + return ExecuteResponse.success();
  78 + default:
  79 + return super.execute(identity, resourceId, params);
  80 + }
  81 + }
  82 +
  83 + @Override
  84 + public WriteResponse write(ServerIdentity identity, boolean replace, int resourceId, LwM2mResource value) {
  85 + log.info("Write on Device resource /{}/{}/{}", getModel().id, getId(), resourceId);
  86 +
  87 + switch (resourceId) {
  88 + case 0:
  89 + startDownloading();
  90 + return WriteResponse.success();
  91 + case 1:
  92 + startDownloading();
  93 + return WriteResponse.success();
  94 + default:
  95 + return super.write(identity, replace, resourceId, value);
  96 + }
  97 + }
  98 +
  99 + private int getState() {
  100 + return state.get();
  101 + }
  102 +
  103 + private int getUpdateResult() {
  104 + return updateResult.get();
  105 + }
  106 +
  107 + private String getPkgName() {
  108 + return "firmware";
  109 + }
  110 +
  111 + private String getPkgVersion() {
  112 + return "1.0.0";
  113 + }
  114 +
  115 + private int getFirmwareUpdateDeliveryMethod() {
  116 + return 1;
  117 + }
  118 +
  119 + @Override
  120 + public List<Integer> getAvailableResourceIds(ObjectModel model) {
  121 + return supportedResources;
  122 + }
  123 +
  124 + @Override
  125 + public void destroy() {
  126 + scheduler.shutdownNow();
  127 + }
  128 +
  129 + private void startDownloading() {
  130 + scheduler.schedule(() -> {
  131 + state.set(1);
  132 + fireResourcesChange(3);
  133 + state.set(2);
  134 + fireResourcesChange(3);
  135 + }, 100, TimeUnit.MILLISECONDS);
  136 + }
  137 +
  138 + private void startUpdating() {
  139 + scheduler.schedule(() -> {
  140 + try {
  141 + state.set(3);
  142 + fireResourcesChange(3);
  143 + Thread.sleep(100);
  144 + updateResult.set(1);
  145 + fireResourcesChange(5);
  146 + } catch (Exception e) {
  147 +
  148 + }
  149 + }, 100, TimeUnit.MILLISECONDS);
  150 + }
  151 +
  152 +}
... ...
... ... @@ -53,8 +53,10 @@ import java.util.List;
53 53 import java.util.concurrent.ScheduledExecutorService;
54 54
55 55 import static org.eclipse.leshan.core.LwM2mId.DEVICE;
  56 +import static org.eclipse.leshan.core.LwM2mId.FIRMWARE;
56 57 import static org.eclipse.leshan.core.LwM2mId.SECURITY;
57 58 import static org.eclipse.leshan.core.LwM2mId.SERVER;
  59 +import static org.eclipse.leshan.core.LwM2mId.SOFTWARE_MANAGEMENT;
58 60
59 61 @Slf4j
60 62 @Data
... ... @@ -65,7 +67,7 @@ public class LwM2MTestClient {
65 67 private LeshanClient client;
66 68
67 69 public void init(Security security, NetworkConfig coapConfig) throws InvalidDDFFileException, IOException {
68   - String[] resources = new String[]{"0.xml", "1.xml", "2.xml", "3.xml"};
  70 + String[] resources = new String[]{"0.xml", "1.xml", "2.xml", "3.xml", "5.xml", "9.xml"};
69 71 List<ObjectModel> models = new ArrayList<>();
70 72 for (String resourceName : resources) {
71 73 models.addAll(ObjectLoader.loadDdfFile(LwM2MTestClient.class.getClassLoader().getResourceAsStream("lwm2m/" + resourceName), resourceName));
... ... @@ -75,6 +77,8 @@ public class LwM2MTestClient {
75 77 initializer.setInstancesForObject(SECURITY, security);
76 78 initializer.setInstancesForObject(SERVER, new Server(123, 300));
77 79 initializer.setInstancesForObject(DEVICE, new SimpleLwM2MDevice());
  80 + initializer.setInstancesForObject(FIRMWARE, new FwLwM2MDevice());
  81 + initializer.setInstancesForObject(SOFTWARE_MANAGEMENT, new SwLwM2MDevice());
78 82 initializer.setClassForObject(LwM2mId.ACCESS_CONTROL, DummyInstanceEnabler.class);
79 83
80 84 DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder();
... ...
... ... @@ -45,74 +45,74 @@ public class SimpleLwM2MDevice extends BaseInstanceEnabler implements Destroyabl
45 45 );
46 46
47 47 @Override
48   - public ReadResponse read(ServerIdentity identity, int resourceid) {
  48 + public ReadResponse read(ServerIdentity identity, int resourceId) {
49 49 if (!identity.isSystem())
50   - log.info("Read on Device resource /{}/{}/{}", getModel().id, getId(), resourceid);
51   - switch (resourceid) {
  50 + log.info("Read on Device resource /{}/{}/{}", getModel().id, getId(), resourceId);
  51 + switch (resourceId) {
52 52 case 0:
53   - return ReadResponse.success(resourceid, getManufacturer());
  53 + return ReadResponse.success(resourceId, getManufacturer());
54 54 case 1:
55   - return ReadResponse.success(resourceid, getModelNumber());
  55 + return ReadResponse.success(resourceId, getModelNumber());
56 56 case 2:
57   - return ReadResponse.success(resourceid, getSerialNumber());
  57 + return ReadResponse.success(resourceId, getSerialNumber());
58 58 case 3:
59   - return ReadResponse.success(resourceid, getFirmwareVersion());
  59 + return ReadResponse.success(resourceId, getFirmwareVersion());
60 60 case 9:
61   - return ReadResponse.success(resourceid, getBatteryLevel());
  61 + return ReadResponse.success(resourceId, getBatteryLevel());
62 62 case 10:
63   - return ReadResponse.success(resourceid, getMemoryFree());
  63 + return ReadResponse.success(resourceId, getMemoryFree());
64 64 case 11:
65 65 Map<Integer, Long> errorCodes = new HashMap<>();
66 66 errorCodes.put(0, getErrorCode());
67   - return ReadResponse.success(resourceid, errorCodes, ResourceModel.Type.INTEGER);
  67 + return ReadResponse.success(resourceId, errorCodes, ResourceModel.Type.INTEGER);
68 68 case 14:
69   - return ReadResponse.success(resourceid, getUtcOffset());
  69 + return ReadResponse.success(resourceId, getUtcOffset());
70 70 case 15:
71   - return ReadResponse.success(resourceid, getTimezone());
  71 + return ReadResponse.success(resourceId, getTimezone());
72 72 case 16:
73   - return ReadResponse.success(resourceid, getSupportedBinding());
  73 + return ReadResponse.success(resourceId, getSupportedBinding());
74 74 case 17:
75   - return ReadResponse.success(resourceid, getDeviceType());
  75 + return ReadResponse.success(resourceId, getDeviceType());
76 76 case 18:
77   - return ReadResponse.success(resourceid, getHardwareVersion());
  77 + return ReadResponse.success(resourceId, getHardwareVersion());
78 78 case 19:
79   - return ReadResponse.success(resourceid, getSoftwareVersion());
  79 + return ReadResponse.success(resourceId, getSoftwareVersion());
80 80 case 20:
81   - return ReadResponse.success(resourceid, getBatteryStatus());
  81 + return ReadResponse.success(resourceId, getBatteryStatus());
82 82 case 21:
83   - return ReadResponse.success(resourceid, getMemoryTotal());
  83 + return ReadResponse.success(resourceId, getMemoryTotal());
84 84 default:
85   - return super.read(identity, resourceid);
  85 + return super.read(identity, resourceId);
86 86 }
87 87 }
88 88
89 89 @Override
90   - public ExecuteResponse execute(ServerIdentity identity, int resourceid, String params) {
  90 + public ExecuteResponse execute(ServerIdentity identity, int resourceId, String params) {
91 91 String withParams = null;
92 92 if (params != null && params.length() != 0) {
93 93 withParams = " with params " + params;
94 94 }
95   - log.info("Execute on Device resource /{}/{}/{} {}", getModel().id, getId(), resourceid, withParams != null ? withParams : "");
  95 + log.info("Execute on Device resource /{}/{}/{} {}", getModel().id, getId(), resourceId, withParams != null ? withParams : "");
96 96 return ExecuteResponse.success();
97 97 }
98 98
99 99 @Override
100   - public WriteResponse write(ServerIdentity identity, boolean replace, int resourceid, LwM2mResource value) {
101   - log.info("Write on Device resource /{}/{}/{}", getModel().id, getId(), resourceid);
  100 + public WriteResponse write(ServerIdentity identity, boolean replace, int resourceId, LwM2mResource value) {
  101 + log.info("Write on Device resource /{}/{}/{}", getModel().id, getId(), resourceId);
102 102
103   - switch (resourceid) {
  103 + switch (resourceId) {
104 104 case 13:
105 105 return WriteResponse.notFound();
106 106 case 14:
107 107 setUtcOffset((String) value.getValue());
108   - fireResourcesChange(resourceid);
  108 + fireResourcesChange(resourceId);
109 109 return WriteResponse.success();
110 110 case 15:
111 111 setTimezone((String) value.getValue());
112   - fireResourcesChange(resourceid);
  112 + fireResourcesChange(resourceId);
113 113 return WriteResponse.success();
114 114 default:
115   - return super.write(identity, replace, resourceid, value);
  115 + return super.write(identity, replace, resourceId, value);
116 116 }
117 117 }
118 118
... ...
  1 +/**
  2 + * Copyright © 2016-2021 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.transport.lwm2m.client;
  17 +
  18 +import lombok.SneakyThrows;
  19 +import lombok.extern.slf4j.Slf4j;
  20 +import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
  21 +import org.eclipse.leshan.client.servers.ServerIdentity;
  22 +import org.eclipse.leshan.core.model.ObjectModel;
  23 +import org.eclipse.leshan.core.node.LwM2mResource;
  24 +import org.eclipse.leshan.core.response.ExecuteResponse;
  25 +import org.eclipse.leshan.core.response.ReadResponse;
  26 +import org.eclipse.leshan.core.response.WriteResponse;
  27 +
  28 +import javax.security.auth.Destroyable;
  29 +import java.util.Arrays;
  30 +import java.util.List;
  31 +import java.util.concurrent.Executors;
  32 +import java.util.concurrent.ScheduledExecutorService;
  33 +import java.util.concurrent.TimeUnit;
  34 +import java.util.concurrent.atomic.AtomicInteger;
  35 +
  36 +@Slf4j
  37 +public class SwLwM2MDevice extends BaseInstanceEnabler implements Destroyable {
  38 +
  39 + private static final List<Integer> supportedResources = Arrays.asList(0, 1, 2, 3, 4, 6, 7, 9);
  40 +
  41 + private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
  42 +
  43 + private final AtomicInteger state = new AtomicInteger(0);
  44 +
  45 + private final AtomicInteger updateResult = new AtomicInteger(0);
  46 +
  47 + @Override
  48 + public ReadResponse read(ServerIdentity identity, int resourceId) {
  49 + if (!identity.isSystem())
  50 + log.info("Read on Device resource /{}/{}/{}", getModel().id, getId(), resourceId);
  51 + switch (resourceId) {
  52 + case 0:
  53 + return ReadResponse.success(resourceId, getPkgName());
  54 + case 1:
  55 + return ReadResponse.success(resourceId, getPkgVersion());
  56 + case 7:
  57 + return ReadResponse.success(resourceId, getUpdateState());
  58 + case 9:
  59 + return ReadResponse.success(resourceId, getUpdateResult());
  60 + default:
  61 + return super.read(identity, resourceId);
  62 + }
  63 + }
  64 +
  65 + @Override
  66 + public ExecuteResponse execute(ServerIdentity identity, int resourceId, String params) {
  67 + String withParams = null;
  68 + if (params != null && params.length() != 0) {
  69 + withParams = " with params " + params;
  70 + }
  71 + log.info("Execute on Device resource /{}/{}/{} {}", getModel().id, getId(), resourceId, withParams != null ? withParams : "");
  72 +
  73 + switch (resourceId) {
  74 + case 4:
  75 + startUpdating();
  76 + return ExecuteResponse.success();
  77 + case 6:
  78 + return ExecuteResponse.success();
  79 + default:
  80 + return super.execute(identity, resourceId, params);
  81 + }
  82 + }
  83 +
  84 + @Override
  85 + public WriteResponse write(ServerIdentity identity, boolean replace, int resourceId, LwM2mResource value) {
  86 + log.info("Write on Device resource /{}/{}/{}", getModel().id, getId(), resourceId);
  87 +
  88 + switch (resourceId) {
  89 + case 2:
  90 + startDownloading();
  91 + return WriteResponse.success();
  92 + case 3:
  93 + startDownloading();
  94 + return WriteResponse.success();
  95 + default:
  96 + return super.write(identity, replace, resourceId, value);
  97 + }
  98 + }
  99 +
  100 + private int getUpdateState() {
  101 + return state.get();
  102 + }
  103 +
  104 + private int getUpdateResult() {
  105 + return updateResult.get();
  106 + }
  107 +
  108 + private String getPkgName() {
  109 + return "software";
  110 + }
  111 +
  112 + private String getPkgVersion() {
  113 + return "1.0.0";
  114 + }
  115 +
  116 + @Override
  117 + public List<Integer> getAvailableResourceIds(ObjectModel model) {
  118 + return supportedResources;
  119 + }
  120 +
  121 + @Override
  122 + public void destroy() {
  123 + scheduler.shutdownNow();
  124 + }
  125 +
  126 + private void startDownloading() {
  127 + scheduler.schedule(() -> {
  128 + try {
  129 + state.set(1);
  130 + updateResult.set(1);
  131 + fireResourcesChange(7, 9);
  132 + Thread.sleep(100);
  133 + state.set(2);
  134 + fireResourcesChange(7);
  135 + Thread.sleep(100);
  136 + state.set(3);
  137 + fireResourcesChange(7);
  138 + Thread.sleep(100);
  139 + updateResult.set(3);
  140 + fireResourcesChange(9);
  141 + } catch (Exception e) {
  142 +
  143 + }
  144 + }, 100, TimeUnit.MILLISECONDS);
  145 + }
  146 +
  147 + private void startUpdating() {
  148 + scheduler.schedule(() -> {
  149 + state.set(4);
  150 + updateResult.set(2);
  151 + fireResourcesChange(7, 9);
  152 + }, 100, TimeUnit.MILLISECONDS);
  153 + }
  154 +
  155 +}
... ...
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +
  3 +<!--
  4 +FILE INFORMATION
  5 +
  6 +OMA Permanent Document
  7 + File: OMA-SUP-XML_LWM2M_Firmware_Update-V1_0_3-20190617-A
  8 + Type: xml
  9 + Date: 2019-Jun-17
  10 +
  11 +Public Reachable Information
  12 + Path: http://www.openmobilealliance.org/tech/profiles
  13 + Name: LWM2M_Firmware_Update-v1_0_3.xml
  14 +
  15 +NORMATIVE INFORMATION
  16 +
  17 + Information about this file can be found in the latest revision of
  18 +
  19 + OMA-TS-LightweightM2M-V1_0_2
  20 + OMA-TS-LightweightM2M_Core-V1_1_1
  21 +
  22 + This is available at http://www.openmobilealliance.org/
  23 +
  24 + Send comments to https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues
  25 +
  26 +LEGAL DISCLAIMER
  27 +
  28 + Copyright 2019 Open Mobile Alliance.
  29 +
  30 + Redistribution and use in source and binary forms, with or without
  31 + modification, are permitted provided that the following conditions
  32 + are met:
  33 +
  34 + 1. Redistributions of source code must retain the above copyright
  35 + notice, this list of conditions and the following disclaimer.
  36 + 2. Redistributions in binary form must reproduce the above copyright
  37 + notice, this list of conditions and the following disclaimer in the
  38 + documentation and/or other materials provided with the distribution.
  39 + 3. Neither the name of the copyright holder nor the names of its
  40 + contributors may be used to endorse or promote products derived
  41 + from this software without specific prior written permission.
  42 +
  43 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  46 + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  47 + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  48 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  49 + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  50 + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51 + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52 + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  53 + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54 + POSSIBILITY OF SUCH DAMAGE.
  55 +
  56 + The above license is used as a license under copyright only. Please
  57 + reference the OMA IPR Policy for patent licensing terms:
  58 + https://www.omaspecworks.org/about/intellectual-property-rights/
  59 +
  60 +-->
  61 +
  62 +<LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.openmobilealliance.org/tech/profiles/LWM2M.xsd">
  63 + <Object ObjectType="MODefinition">
  64 + <Name>Firmware Update V_1_0</Name>
  65 + <Description1><![CDATA[This LwM2M Object enables management of firmware which is to be updated. This Object includes installing a firmware package, updating firmware, and performing actions after updating firmware. The firmware update MAY require to reboot the device; it will depend on a number of factors, such as the operating system architecture and the extent of the updated software.
  66 +The envisioned functionality is to allow a LwM2M Client to connect to any LwM2M Server to obtain a firmware image using the object and resource structure defined in this section experiencing communication security protection using TLS/DTLS. There are, however, other design decisions that need to be taken into account to allow a manufacturer of a device to securely install firmware on a device. Examples for such design decisions are how to manage the firmware update repository at the server side (which may include user interface considerations), the techniques to provide additional application layer security protection of the firmware image, how many versions of firmware images to store on the device, and how to execute the firmware update process considering the hardware specific details of a given IoT hardware product. These aspects are considered to be outside the scope of this version of the specification.
  67 +A LwM2M Server may also instruct a LwM2M Client to fetch a firmware image from a dedicated server (instead of pushing firmware images to the LwM2M Client). The Package URI resource is contained in the Firmware object and can be used for this purpose.
  68 +A LwM2M Client MUST support block-wise transfer [CoAP_Blockwise] if it implements the Firmware Update object.
  69 +A LwM2M Server MUST support block-wise transfer. Other protocols, such as HTTP/HTTPs, MAY also be used for downloading firmware updates (via the Package URI resource). For constrained devices it is, however, RECOMMENDED to use CoAP for firmware downloads to avoid the need for additional protocol implementations.]]></Description1>
  70 + <ObjectID>5</ObjectID>
  71 + <ObjectURN>urn:oma:lwm2m:oma:5</ObjectURN>
  72 + <LWM2MVersion>1.0</LWM2MVersion>
  73 + <ObjectVersion>1.0</ObjectVersion>
  74 + <MultipleInstances>Single</MultipleInstances>
  75 + <Mandatory>Optional</Mandatory>
  76 + <Resources>
  77 + <Item ID="0">
  78 + <Name>Package</Name>
  79 + <Operations>W</Operations>
  80 + <MultipleInstances>Single</MultipleInstances>
  81 + <Mandatory>Mandatory</Mandatory>
  82 + <Type>Opaque</Type>
  83 + <RangeEnumeration></RangeEnumeration>
  84 + <Units></Units>
  85 + <Description><![CDATA[Firmware package]]></Description>
  86 + </Item>
  87 + <Item ID="1">
  88 + <Name>Package URI</Name>
  89 + <Operations>RW</Operations>
  90 + <MultipleInstances>Single</MultipleInstances>
  91 + <Mandatory>Mandatory</Mandatory>
  92 + <Type>String</Type>
  93 + <RangeEnumeration>0..255</RangeEnumeration>
  94 + <Units></Units>
  95 + <Description><![CDATA[URI from where the device can download the firmware package by an alternative mechanism. As soon the device has received the Package URI it performs the download at the next practical opportunity.
  96 +The URI format is defined in RFC 3986. For example, coaps://example.org/firmware is a syntactically valid URI. The URI scheme determines the protocol to be used. For CoAP this endpoint MAY be a LwM2M Server but does not necessarily need to be. A CoAP server implementing block-wise transfer is sufficient as a server hosting a firmware repository and the expectation is that this server merely serves as a separate file server making firmware images available to LwM2M Clients.]]></Description>
  97 + </Item>
  98 + <Item ID="2">
  99 + <Name>Update</Name>
  100 + <Operations>E</Operations>
  101 + <MultipleInstances>Single</MultipleInstances>
  102 + <Mandatory>Mandatory</Mandatory>
  103 + <Type></Type>
  104 + <RangeEnumeration></RangeEnumeration>
  105 + <Units></Units>
  106 + <Description><![CDATA[Updates firmware by using the firmware package stored in Package, or, by using the firmware downloaded from the Package URI.
  107 +This Resource is only executable when the value of the State Resource is Downloaded.]]></Description>
  108 + </Item>
  109 + <Item ID="3">
  110 + <Name>State</Name>
  111 + <Operations>R</Operations>
  112 + <MultipleInstances>Single</MultipleInstances>
  113 + <Mandatory>Mandatory</Mandatory>
  114 + <Type>Integer</Type>
  115 + <RangeEnumeration>0..3</RangeEnumeration>
  116 + <Units></Units>
  117 + <Description><![CDATA[Indicates current state with respect to this firmware update. This value is set by the LwM2M Client.
  118 +0: Idle (before downloading or after successful updating)
  119 +1: Downloading (The data sequence is on the way)
  120 +2: Downloaded
  121 +3: Updating
  122 +If writing the firmware package to Package Resource has completed, or, if the device has downloaded the firmware package from the Package URI the state changes to Downloaded.
  123 +Writing an empty string to Package URI Resource or setting the Package Resource to NULL (‘\0’), resets the Firmware Update State Machine: the State Resource value is set to Idle and the Update Result Resource value is set to 0.
  124 +When in Downloaded state, and the executable Resource Update is triggered, the state changes to Updating.
  125 +If the Update Resource failed, the state returns at Downloaded.
  126 +If performing the Update Resource was successful, the state changes from Updating to Idle.
  127 +The firmware update state machine is illustrated in Figure 29 of the LwM2M version 1.0 specification (and also in Figure E.6.1-1 of this specification).]]></Description>
  128 + </Item>
  129 + <Item ID="5">
  130 + <Name>Update Result</Name>
  131 + <Operations>R</Operations>
  132 + <MultipleInstances>Single</MultipleInstances>
  133 + <Mandatory>Mandatory</Mandatory>
  134 + <Type>Integer</Type>
  135 + <RangeEnumeration>0..9</RangeEnumeration>
  136 + <Units></Units>
  137 + <Description><![CDATA[Contains the result of downloading or updating the firmware
  138 +0: Initial value. Once the updating process is initiated (Download /Update), this Resource MUST be reset to Initial value.
  139 +1: Firmware updated successfully.
  140 +2: Not enough flash memory for the new firmware package.
  141 +3: Out of RAM during downloading process.
  142 +4: Connection lost during downloading process.
  143 +5: Integrity check failure for new downloaded package.
  144 +6: Unsupported package type.
  145 +7: Invalid URI.
  146 +8: Firmware update failed.
  147 +9: Unsupported protocol. A LwM2M client indicates the failure to retrieve the firmware image using the URI provided in the Package URI resource by writing the value 9 to the /5/0/5 (Update Result resource) when the URI contained a URI scheme unsupported by the client. Consequently, the LwM2M Client is unable to retrieve the firmware image using the URI provided by the LwM2M Server in the Package URI when it refers to an unsupported protocol.]]></Description>
  148 + </Item>
  149 + <Item ID="6">
  150 + <Name>PkgName</Name>
  151 + <Operations>R</Operations>
  152 + <MultipleInstances>Single</MultipleInstances>
  153 + <Mandatory>Optional</Mandatory>
  154 + <Type>String</Type>
  155 + <RangeEnumeration>0..255</RangeEnumeration>
  156 + <Units></Units>
  157 + <Description><![CDATA[Name of the Firmware Package]]></Description>
  158 + </Item>
  159 + <Item ID="7">
  160 + <Name>PkgVersion</Name>
  161 + <Operations>R</Operations>
  162 + <MultipleInstances>Single</MultipleInstances>
  163 + <Mandatory>Optional</Mandatory>
  164 + <Type>String</Type>
  165 + <RangeEnumeration>0..255</RangeEnumeration>
  166 + <Units></Units>
  167 + <Description><![CDATA[Version of the Firmware package]]></Description>
  168 + </Item>
  169 + <Item ID="8">
  170 + <Name>Firmware Update Protocol Support</Name>
  171 + <Operations>R</Operations>
  172 + <MultipleInstances>Multiple</MultipleInstances>
  173 + <Mandatory>Optional</Mandatory>
  174 + <Type>Integer</Type>
  175 + <RangeEnumeration>0..5</RangeEnumeration>
  176 + <Units></Units>
  177 + <Description><![CDATA[This resource indicates what protocols the LwM2M Client implements to retrieve firmware images. The LwM2M server uses this information to decide what URI to include in the Package URI. A LwM2M Server MUST NOT include a URI in the Package URI object that uses a protocol that is unsupported by the LwM2M client.
  178 +For example, if a LwM2M client indicates that it supports CoAP and CoAPS then a LwM2M Server must not provide an HTTP URI in the Packet URI.
  179 +The following values are defined by this version of the specification:
  180 +0: CoAP (as defined in RFC 7252) with the additional support for block-wise transfer. CoAP is the default setting.
  181 +1: CoAPS (as defined in RFC 7252) with the additional support for block-wise transfer
  182 +2: HTTP 1.1 (as defined in RFC 7230)
  183 +3: HTTPS 1.1 (as defined in RFC 7230)
  184 +4: CoAP over TCP (as defined in RFC 8323)
  185 +5: CoAP over TLS (as defined in RFC 8323)
  186 +Additional values MAY be defined in the future. Any value not understood by the LwM2M Server MUST be ignored.]]></Description>
  187 + </Item>
  188 + <Item ID="9">
  189 + <Name>Firmware Update Delivery Method</Name>
  190 + <Operations>R</Operations>
  191 + <MultipleInstances>Single</MultipleInstances>
  192 + <Mandatory>Mandatory</Mandatory>
  193 + <Type>Integer</Type>
  194 + <RangeEnumeration>0..2</RangeEnumeration>
  195 + <Units></Units>
  196 + <Description><![CDATA[The LwM2M Client uses this resource to indicate its support for transferring firmware images to the client either via the Package Resource (=push) or via the Package URI Resource (=pull) mechanism.
  197 +0: Pull only
  198 +1: Push only
  199 +2: Both. In this case the LwM2M Server MAY choose the preferred mechanism for conveying the firmware image to the LwM2M Client.]]></Description>
  200 + </Item>
  201 + </Resources>
  202 + <Description2><![CDATA[]]></Description2>
  203 + </Object>
  204 +</LWM2M>
... ...
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +
  3 +<!--
  4 +FILE INFORMATION
  5 +
  6 +OMA Permanent Document
  7 + File: OMA-SUP-XML_9-V1_0_2-20210119-A.xml
  8 + Path: http://www.openmobilealliance.org/release/LWM2M_SWMGMT
  9 +
  10 +OMNA LwM2M Registry
  11 + Path: https://github.com/OpenMobileAlliance/lwm2m-registry
  12 + Name: 9.xml
  13 +
  14 +NORMATIVE INFORMATION
  15 +
  16 + Information about this file can be found in the latest revision of
  17 +
  18 + OMA-TS-LightweightM2M-V1_0
  19 +
  20 + This is available at http://www.openmobilealliance.org/release/LightweightM2M/
  21 +
  22 + Send comments to https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues
  23 +
  24 +LEGAL DISCLAIMER
  25 +
  26 + Copyright 2021 Open Mobile Alliance.
  27 +
  28 + Redistribution and use in source and binary forms, with or without
  29 + modification, are permitted provided that the following conditions
  30 + are met:
  31 +
  32 + 1. Redistributions of source code must retain the above copyright
  33 + notice, this list of conditions and the following disclaimer.
  34 + 2. Redistributions in binary form must reproduce the above copyright
  35 + notice, this list of conditions and the following disclaimer in the
  36 + documentation and/or other materials provided with the distribution.
  37 + 3. Neither the name of the copyright holder nor the names of its
  38 + contributors may be used to endorse or promote products derived
  39 + from this software without specific prior written permission.
  40 +
  41 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  42 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44 + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  45 + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  46 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  47 + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  48 + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49 + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50 + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  51 + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  52 + POSSIBILITY OF SUCH DAMAGE.
  53 +
  54 + The above license is used as a license under copyright only. Please
  55 + reference the OMA IPR Policy for patent licensing terms:
  56 + https://www.omaspecworks.org/about/intellectual-property-rights/
  57 +
  58 +-->
  59 +
  60 +<LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://openmobilealliance.org/tech/profiles/LWM2M.xsd">
  61 + <Object ObjectType="MODefinition">
  62 + <Name>LWM2M Software Management</Name>
  63 + <Description1><![CDATA[This LwM2M objects provides the resources needed to perform software management on the device. Each software component is managed via a dedicated Software Management Object instance.]]></Description1>
  64 + <ObjectID>9</ObjectID>
  65 + <ObjectURN>urn:oma:lwm2m:oma:9</ObjectURN>
  66 + <LWM2MVersion>1.0</LWM2MVersion>
  67 + <ObjectVersion>1.0</ObjectVersion>
  68 + <MultipleInstances>Multiple</MultipleInstances>
  69 + <Mandatory>Optional</Mandatory>
  70 + <Resources>
  71 + <Item ID="0">
  72 + <Name>PkgName</Name>
  73 + <Operations>R</Operations>
  74 + <MultipleInstances>Single</MultipleInstances>
  75 + <Mandatory>Mandatory</Mandatory>
  76 + <Type>String</Type>
  77 + <RangeEnumeration>0..255 bytes</RangeEnumeration>
  78 + <Units></Units>
  79 + <Description><![CDATA[Name of the software package]]></Description>
  80 + </Item>
  81 + <Item ID="1">
  82 + <Name>PkgVersion</Name>
  83 + <Operations>R</Operations>
  84 + <MultipleInstances>Single</MultipleInstances>
  85 + <Mandatory>Mandatory</Mandatory>
  86 + <Type>String</Type>
  87 + <RangeEnumeration>0..255 bytes</RangeEnumeration>
  88 + <Units></Units>
  89 + <Description><![CDATA[Version of the software package]]></Description>
  90 + </Item>
  91 + <Item ID="2">
  92 + <Name>Package</Name>
  93 + <Operations>W</Operations>
  94 + <MultipleInstances>Single</MultipleInstances>
  95 + <Mandatory>Optional</Mandatory>
  96 + <Type>Opaque</Type>
  97 + <RangeEnumeration></RangeEnumeration>
  98 + <Units></Units>
  99 + <Description><![CDATA[Software package
  100 +The package can be in one single software component, or any delivery material used by the Device to determine the software component(s) and proceed to their installation.
  101 +Can be archive file, executable, manifest. This resource to be used when it is single block of delivery.
  102 +]]> </Description>
  103 + </Item>
  104 + <Item ID="3">
  105 + <Name>Package URI</Name>
  106 + <Operations>W</Operations>
  107 + <MultipleInstances>Single</MultipleInstances>
  108 + <Mandatory>Optional</Mandatory>
  109 + <Type>String</Type>
  110 + <RangeEnumeration>0..255 bytes</RangeEnumeration>
  111 + <Units></Units>
  112 + <Description><![CDATA[URI from where the device can download the software package by an alternative mechanism. As soon the device has received the Package URI it performs the download at the next practical opportunity.
  113 +Can be direct link to a single software component or link to archive file, executable, or manifest, used by the Device to determine, then access to the software component(s). This resource to be used when it is single block of delivery.
  114 +]]> </Description>
  115 + </Item>
  116 +
  117 + <Item ID="4">
  118 + <Name>Install</Name>
  119 + <Operations>E</Operations>
  120 + <MultipleInstances>Single</MultipleInstances>
  121 + <Mandatory>Mandatory</Mandatory>
  122 + <Type></Type>
  123 + <RangeEnumeration></RangeEnumeration>
  124 + <Units></Units>
  125 + <Description><![CDATA[Installs software from the package either stored in Package resource, or, downloaded from the Package URI. This Resource is only executable when the value of the State Resource is DELIVERED.]]></Description>
  126 + </Item>
  127 + <Item ID="5">
  128 + <Name>Checkpoint</Name>
  129 + <Operations>R</Operations>
  130 + <MultipleInstances>Single</MultipleInstances>
  131 + <Mandatory>Optional</Mandatory>
  132 + <Type>Objlnk</Type>
  133 + <RangeEnumeration></RangeEnumeration>
  134 + <Units></Units>
  135 + <Description><![CDATA[Link to a "Checkpoint" object which allows to specify conditions/dependencies for a software update. E.g. power connected, sufficient memory, target system.]]></Description>
  136 + </Item>
  137 + <Item ID="6">
  138 + <Name>Uninstall</Name>
  139 + <Operations>E</Operations>
  140 + <MultipleInstances>Single</MultipleInstances>
  141 + <Mandatory>Mandatory</Mandatory>
  142 + <Type></Type>
  143 + <RangeEnumeration></RangeEnumeration>
  144 + <Units></Units>
  145 + <Description><![CDATA[Uninstalls the software package.
  146 +This executable resource may have one argument.
  147 +If used with no argument or argument is 0, the Package is removed i from the Device. If the argument is 1 ("ForUpdate"), the Client MUST prepare itself for receiving a Package used to upgrade the Software already in place. Update State is set back to INITIAL state.
  148 +]]> </Description>
  149 + </Item>
  150 + <Item ID="7">
  151 + <Name>Update State</Name>
  152 + <Operations>R</Operations>
  153 + <MultipleInstances>Single</MultipleInstances>
  154 + <Mandatory>Mandatory</Mandatory>
  155 + <Type>Integer</Type>
  156 + <RangeEnumeration>0..4</RangeEnumeration>
  157 + <Units></Units>
  158 + <Description><![CDATA[Indicates current state with respect to this software update. This value is set by the LwM2M Client.
  159 +0: INITIAL
  160 +Before downloading.
  161 +(see 5.1.2.1)
  162 +1: DOWNLOAD STARTED
  163 +The downloading process has started and is on-going.
  164 +(see 5.1.2.2)
  165 +2: DOWNLOADED
  166 +The package has been completely downloaded
  167 +(see 5.1.2.3)
  168 +3: DELIVERED
  169 +In that state, the package has been correctly downloaded and is ready to be installed.
  170 +(see 5.1.2.4)
  171 +If executing the Install Resource failed, the state remains at DELIVERED.
  172 +If executing the Install Resource was successful, the state changes from DELIVERED to INSTALLED.
  173 +After executing the UnInstall Resource, the state changes to INITIAL.
  174 +4: INSTALLED
  175 +In that state the software is correctly installed and can be activated or deactivated according to the Activation State Machine.
  176 +(see 5.1.2.5)
  177 +]]> </Description>
  178 + </Item>
  179 + <Item ID="8">
  180 + <Name>Update Supported Objects</Name>
  181 + <Operations>RW</Operations>
  182 + <MultipleInstances>Single</MultipleInstances>
  183 + <Mandatory>Optional</Mandatory>
  184 + <Type>Boolean</Type>
  185 + <RangeEnumeration></RangeEnumeration>
  186 + <Units></Units>
  187 + <Description><![CDATA[If this value is true, the LwM2M Client MUST inform the registered LwM2M Servers of Objects and Object Instances parameter by sending an Update or Registration message after the software update operation at the next practical opportunity if supported Objects in the LwM2M Client have changed, in order for the LwM2M Servers to promptly manage newly installed Objects.
  188 +If false, Objects and Object Instances parameter MUST be reported at the next periodic Update message.
  189 +The default value is false.
  190 +]]> </Description>
  191 + </Item>
  192 + <Item ID="9">
  193 + <Name>Update Result</Name>
  194 + <Operations>R</Operations>
  195 + <MultipleInstances>Single</MultipleInstances>
  196 + <Mandatory>Mandatory</Mandatory>
  197 + <Type>Integer</Type>
  198 + <RangeEnumeration>0..200</RangeEnumeration>
  199 + <Units></Units>
  200 + <Description><![CDATA[Contains the result of downloading or installing/uninstalling the software
  201 +0: Initial value. Prior to download any new package in the Device, Update Result MUST be reset to this initial value. One side effect of executing the Uninstall resource is to reset Update Result to this initial value "0".
  202 +1: Downloading. The package downloading process is on-going.
  203 +2: Software successfully installed.
  204 +3: Successfully Downloaded and package integrity verified
  205 +(( 4-49, for expansion, of other scenarios))
  206 +50: Not enough storage for the new software package.
  207 +51: Out of memory during downloading process.
  208 +52: Connection lost during downloading process.
  209 +53: Package integrity check failure.
  210 +54: Unsupported package type.
  211 +56: Invalid URI
  212 +57: Device defined update error
  213 +58: Software installation failure
  214 +59: Uninstallation Failure during forUpdate(arg=0)
  215 +60-200 : (for expansion, selection to be in blocks depending on new introduction of features)
  216 +This Resource MAY be reported by sending Observe operation.
  217 +]]> </Description>
  218 + </Item>
  219 + <Item ID="10">
  220 + <Name>Activate</Name>
  221 + <Operations>E</Operations>
  222 + <MultipleInstances>Single</MultipleInstances>
  223 + <Mandatory>Mandatory</Mandatory>
  224 + <Type></Type>
  225 + <RangeEnumeration></RangeEnumeration>
  226 + <Units></Units>
  227 + <Description><![CDATA[This action activates the software previously successfully installed (the Package Installation State Machine is currently in the INSTALLED state)]]></Description>
  228 + </Item>
  229 + <Item ID="11">
  230 + <Name>Deactivate</Name>
  231 + <Operations>E</Operations>
  232 + <MultipleInstances>Single</MultipleInstances>
  233 + <Mandatory>Mandatory</Mandatory>
  234 + <Type></Type>
  235 + <RangeEnumeration></RangeEnumeration>
  236 + <Units></Units>
  237 + <Description><![CDATA[This action deactivates softwareif the Package Installation State Machine is currently in the INSTALLED state.]]></Description>
  238 + </Item>
  239 + <Item ID="12">
  240 + <Name>Activation State</Name>
  241 + <Operations>R</Operations>
  242 + <MultipleInstances>Single</MultipleInstances>
  243 + <Mandatory>Mandatory</Mandatory>
  244 + <Type>Boolean</Type>
  245 + <RangeEnumeration></RangeEnumeration>
  246 + <Units></Units>
  247 + <Description><![CDATA[Indicates the current activation state of this software:
  248 +0: DISABLED
  249 +Activation State is DISABLED if the Software Activation State Machine is in the INACTIVE state or not alive.
  250 +1: ENABLED
  251 +Activation State is ENABLED only if the Software Activation State Machine is in the ACTIVE state
  252 +]]> </Description>
  253 + </Item>
  254 + <Item ID="13">
  255 + <Name>Package Settings</Name>
  256 + <Operations>RW</Operations>
  257 + <MultipleInstances>Single</MultipleInstances>
  258 + <Mandatory>Optional</Mandatory>
  259 + <Type>Objlnk</Type>
  260 + <RangeEnumeration></RangeEnumeration>
  261 + <Units></Units>
  262 + <Description><![CDATA[Link to "Package Settings" object which allows to modify at any time software configuration settings. This is an application specific object.
  263 +Note: OMA might provide a template for a Package Settings object in a future release of this specification.
  264 +]]> </Description>
  265 + </Item>
  266 + <Item ID="14">
  267 + <Name>User Name</Name>
  268 + <Operations>W</Operations>
  269 + <MultipleInstances>Single</MultipleInstances>
  270 + <Mandatory>Optional</Mandatory>
  271 + <Type>String</Type>
  272 + <RangeEnumeration>0..255 bytes</RangeEnumeration>
  273 + <Units></Units>
  274 + <Description><![CDATA[User Name for access to SW Update Package in pull mode.
  275 +Key based mechanism can alternatively use for talking to the component server instead of user name and password combination.
  276 +]]> </Description>
  277 + </Item>
  278 + <Item ID="15">
  279 + <Name>Password</Name>
  280 + <Operations>W</Operations>
  281 + <MultipleInstances>Single</MultipleInstances>
  282 + <Mandatory>Optional</Mandatory>
  283 + <Type>String</Type>
  284 + <RangeEnumeration>0..255 bytes</RangeEnumeration>
  285 + <Units></Units>
  286 + <Description><![CDATA[Password for access to SW Update Package in pull mode.]]></Description>
  287 + </Item>
  288 + <Item ID="16">
  289 + <Name>Status Reason</Name>
  290 + <Operations>R</Operations>
  291 + <MultipleInstances>Single</MultipleInstances>
  292 + <Mandatory>Optional</Mandatory>
  293 + <Type>String</Type>
  294 + <RangeEnumeration></RangeEnumeration>
  295 + <Units></Units>
  296 + <Description><![CDATA[Contains the status of the actions done by the client on the SW Component(s) referred by the present SW Update Package. The status is defined in Appendix B.]]></Description>
  297 + </Item>
  298 + <Item ID="17">
  299 + <Name>Software Component Link</Name>
  300 + <Operations>R</Operations>
  301 + <MultipleInstances>Multiple</MultipleInstances>
  302 + <Mandatory>Optional</Mandatory>
  303 + <Type>Objlnk</Type>
  304 + <RangeEnumeration></RangeEnumeration>
  305 + <Units></Units>
  306 + <Description><![CDATA[Reference to SW Components downloaded and installed in scope of the present SW Update Package Note: When resource 17 objlink exist, resources 2, 3 and 12 in this table are ignored.]]></Description>
  307 + </Item>
  308 + <Item ID="18">
  309 + <Name>Software Component tree length</Name>
  310 + <Operations>R</Operations>
  311 + <MultipleInstances>Single</MultipleInstances>
  312 + <Mandatory>Optional</Mandatory>
  313 + <Type>Integer</Type>
  314 + <RangeEnumeration>0..255</RangeEnumeration>
  315 + <Units></Units>
  316 + <Description><![CDATA[Software Component tree length indicates the number of instances existing for this software package in the Software Component Object.]]></Description>
  317 + </Item>
  318 + </Resources>
  319 + <Description2><![CDATA[]]></Description2>
  320 + </Object>
  321 +</LWM2M>
... ...
... ... @@ -158,7 +158,6 @@ public class LwM2mClient implements Serializable {
158 158 this.session = builder.build();
159 159 }
160 160
161   -
162 161 private SessionInfoProto createSession(String nodeId, UUID sessionId, ValidateDeviceCredentialsResponse msg) {
163 162 return SessionInfoProto.newBuilder()
164 163 .setNodeId(nodeId)
... ...
... ... @@ -337,7 +337,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
337 337 SoftwareUpdateResult result = SoftwareUpdateResult.fromUpdateResultSwByCode(code.intValue());
338 338 Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(result);
339 339 status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, swInfo,
340   - otaStatus, "Firmware Update Result: " + result.name()));
  340 + otaStatus, "Software Update Result: " + result.name()));
341 341 if (result.isAgain() && swInfo.getRetryAttempts() <= 2) {
342 342 swInfo.setRetryAttempts(swInfo.getRetryAttempts() + 1);
343 343 startSoftwareUpdateIfNeeded(client, swInfo);
... ...
... ... @@ -15,8 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.transport.lwm2m.server.store;
17 17
18   -import org.thingsboard.server.common.data.ota.OtaPackageType;
19   -import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MClientOtaInfo;
20 18 import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo;
21 19 import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo;
22 20
... ...