Commit a34ffe8a409e353cf73faeaf83e6cc22c518a0ed

Authored by nickAS21
1 parent 68ba6892

LWM2M: merge with master

Showing 19 changed files with 408 additions and 384 deletions
@@ -29,12 +29,11 @@ import org.springframework.stereotype.Service; @@ -29,12 +29,11 @@ import org.springframework.stereotype.Service;
29 import org.thingsboard.common.util.JacksonUtil; 29 import org.thingsboard.common.util.JacksonUtil;
30 import org.thingsboard.server.common.data.device.data.lwm2m.BootstrapConfiguration; 30 import org.thingsboard.server.common.data.device.data.lwm2m.BootstrapConfiguration;
31 import org.thingsboard.server.gen.transport.TransportProtos; 31 import org.thingsboard.server.gen.transport.TransportProtos;
32 -import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo;  
33 import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator; 32 import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator;
  33 +import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo;
34 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener; 34 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener;
35 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext; 35 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext;
36 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; 36 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper;
37 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil;  
38 37
39 import java.io.IOException; 38 import java.io.IOException;
40 import java.security.GeneralSecurityException; 39 import java.security.GeneralSecurityException;
@@ -46,6 +45,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L @@ -46,6 +45,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L
46 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_INFO; 45 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_INFO;
47 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_TELEMETRY; 46 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_TELEMETRY;
48 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.getBootstrapParametersFromThingsboard; 47 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.getBootstrapParametersFromThingsboard;
  48 +import static org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer.BOOTSTRAP;
49 49
50 @Slf4j 50 @Slf4j
51 @Service("LwM2MBootstrapSecurityStore") 51 @Service("LwM2MBootstrapSecurityStore")
@@ -68,7 +68,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { @@ -68,7 +68,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
68 68
69 @Override 69 @Override
70 public Iterator<SecurityInfo> getAllByEndpoint(String endPoint) { 70 public Iterator<SecurityInfo> getAllByEndpoint(String endPoint) {
71 - TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(endPoint, LwM2mTransportUtil.LwM2mTypeServer.BOOTSTRAP); 71 + TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(endPoint, BOOTSTRAP);
72 if (store.getBootstrapCredentialConfig() != null && store.getSecurityMode() != null) { 72 if (store.getBootstrapCredentialConfig() != null && store.getSecurityMode() != null) {
73 /* add value to store from BootstrapJson */ 73 /* add value to store from BootstrapJson */
74 this.setBootstrapConfigScurityInfo(store); 74 this.setBootstrapConfigScurityInfo(store);
@@ -92,7 +92,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { @@ -92,7 +92,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
92 92
93 @Override 93 @Override
94 public SecurityInfo getByIdentity(String identity) { 94 public SecurityInfo getByIdentity(String identity) {
95 - TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(identity, LwM2mTransportUtil.LwM2mTypeServer.BOOTSTRAP); 95 + TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(identity, BOOTSTRAP);
96 if (store.getBootstrapCredentialConfig() != null && store.getSecurityMode() != null) { 96 if (store.getBootstrapCredentialConfig() != null && store.getSecurityMode() != null) {
97 /* add value to store from BootstrapJson */ 97 /* add value to store from BootstrapJson */
98 this.setBootstrapConfigScurityInfo(store); 98 this.setBootstrapConfigScurityInfo(store);
@@ -33,7 +33,7 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; @@ -33,7 +33,7 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
33 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; 33 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
34 import org.thingsboard.server.transport.lwm2m.secure.credentials.LwM2MCredentials; 34 import org.thingsboard.server.transport.lwm2m.secure.credentials.LwM2MCredentials;
35 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext; 35 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext;
36 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil; 36 +import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer;
37 37
38 import java.io.IOException; 38 import java.io.IOException;
39 import java.security.GeneralSecurityException; 39 import java.security.GeneralSecurityException;
@@ -45,6 +45,7 @@ import static org.eclipse.leshan.core.SecurityMode.NO_SEC; @@ -45,6 +45,7 @@ import static org.eclipse.leshan.core.SecurityMode.NO_SEC;
45 import static org.eclipse.leshan.core.SecurityMode.PSK; 45 import static org.eclipse.leshan.core.SecurityMode.PSK;
46 import static org.eclipse.leshan.core.SecurityMode.RPK; 46 import static org.eclipse.leshan.core.SecurityMode.RPK;
47 import static org.eclipse.leshan.core.SecurityMode.X509; 47 import static org.eclipse.leshan.core.SecurityMode.X509;
  48 +import static org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer.BOOTSTRAP;
48 49
49 @Slf4j 50 @Slf4j
50 @Component 51 @Component
@@ -55,7 +56,7 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -55,7 +56,7 @@ public class LwM2mCredentialsSecurityInfoValidator {
55 private final LwM2mTransportContext context; 56 private final LwM2mTransportContext context;
56 private final LwM2MTransportServerConfig config; 57 private final LwM2MTransportServerConfig config;
57 58
58 - public TbLwM2MSecurityInfo getEndpointSecurityInfoByCredentialsId(String credentialsId, LwM2mTransportUtil.LwM2mTypeServer keyValue) { 59 + public TbLwM2MSecurityInfo getEndpointSecurityInfoByCredentialsId(String credentialsId, LwM2mTypeServer keyValue) {
59 CountDownLatch latch = new CountDownLatch(1); 60 CountDownLatch latch = new CountDownLatch(1);
60 final TbLwM2MSecurityInfo[] resultSecurityStore = new TbLwM2MSecurityInfo[1]; 61 final TbLwM2MSecurityInfo[] resultSecurityStore = new TbLwM2MSecurityInfo[1];
61 log.warn("001) [{}]", credentialsId); 62 log.warn("001) [{}]", credentialsId);
@@ -94,11 +95,11 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -94,11 +95,11 @@ public class LwM2mCredentialsSecurityInfoValidator {
94 * @param keyValue - 95 * @param keyValue -
95 * @return SecurityInfo 96 * @return SecurityInfo
96 */ 97 */
97 - private TbLwM2MSecurityInfo createSecurityInfo(String endpoint, String jsonStr, LwM2mTransportUtil.LwM2mTypeServer keyValue) { 98 + private TbLwM2MSecurityInfo createSecurityInfo(String endpoint, String jsonStr, LwM2mTypeServer keyValue) {
98 TbLwM2MSecurityInfo result = new TbLwM2MSecurityInfo(); 99 TbLwM2MSecurityInfo result = new TbLwM2MSecurityInfo();
99 LwM2MCredentials credentials = JacksonUtil.fromString(jsonStr, LwM2MCredentials.class); 100 LwM2MCredentials credentials = JacksonUtil.fromString(jsonStr, LwM2MCredentials.class);
100 if (credentials != null) { 101 if (credentials != null) {
101 - if (keyValue.equals(LwM2mTransportUtil.LwM2mTypeServer.BOOTSTRAP)) { 102 + if (keyValue.equals(BOOTSTRAP)) {
102 result.setBootstrapCredentialConfig(credentials.getBootstrap()); 103 result.setBootstrapCredentialConfig(credentials.getBootstrap());
103 if (LwM2MSecurityMode.PSK.equals(credentials.getClient().getSecurityConfigClientMode())) { 104 if (LwM2MSecurityMode.PSK.equals(credentials.getClient().getSecurityConfigClientMode())) {
104 PSKClientCredentials pskClientConfig = (PSKClientCredentials) credentials.getClient(); 105 PSKClientCredentials pskClientConfig = (PSKClientCredentials) credentials.getClient();
@@ -42,7 +42,6 @@ import org.thingsboard.server.common.transport.util.SslUtil; @@ -42,7 +42,6 @@ import org.thingsboard.server.common.transport.util.SslUtil;
42 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; 42 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
43 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; 43 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
44 import org.thingsboard.server.transport.lwm2m.secure.credentials.LwM2MCredentials; 44 import org.thingsboard.server.transport.lwm2m.secure.credentials.LwM2MCredentials;
45 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil;  
46 import org.thingsboard.server.transport.lwm2m.server.store.TbEditableSecurityStore; 45 import org.thingsboard.server.transport.lwm2m.server.store.TbEditableSecurityStore;
47 import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore; 46 import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore;
48 47
@@ -57,6 +56,8 @@ import java.security.cert.X509Certificate; @@ -57,6 +56,8 @@ import java.security.cert.X509Certificate;
57 import java.util.Arrays; 56 import java.util.Arrays;
58 import java.util.List; 57 import java.util.List;
59 58
  59 +import static org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer.CLIENT;
  60 +
60 @Slf4j 61 @Slf4j
61 @Component 62 @Component
62 @TbLwM2mTransportComponent 63 @TbLwM2mTransportComponent
@@ -117,7 +118,7 @@ public class TbLwM2MDtlsCertificateVerifier implements NewAdvancedCertificateVer @@ -117,7 +118,7 @@ public class TbLwM2MDtlsCertificateVerifier implements NewAdvancedCertificateVer
117 118
118 String strCert = SslUtil.getCertificateString(cert); 119 String strCert = SslUtil.getCertificateString(cert);
119 String sha3Hash = EncryptionUtil.getSha3Hash(strCert); 120 String sha3Hash = EncryptionUtil.getSha3Hash(strCert);
120 - TbLwM2MSecurityInfo securityInfo = securityInfoValidator.getEndpointSecurityInfoByCredentialsId(sha3Hash, LwM2mTransportUtil.LwM2mTypeServer.CLIENT); 121 + TbLwM2MSecurityInfo securityInfo = securityInfoValidator.getEndpointSecurityInfoByCredentialsId(sha3Hash, CLIENT);
121 ValidateDeviceCredentialsResponse msg = securityInfo != null ? securityInfo.getMsg() : null; 122 ValidateDeviceCredentialsResponse msg = securityInfo != null ? securityInfo.getMsg() : null;
122 if (msg != null && org.thingsboard.server.common.data.StringUtils.isNotEmpty(msg.getCredentials())) { 123 if (msg != null && org.thingsboard.server.common.data.StringUtils.isNotEmpty(msg.getCredentials())) {
123 LwM2MCredentials credentials = JacksonUtil.fromString(msg.getCredentials(), LwM2MCredentials.class); 124 LwM2MCredentials credentials = JacksonUtil.fromString(msg.getCredentials(), LwM2MCredentials.class);
@@ -65,7 +65,7 @@ import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_ECDHE @@ -65,7 +65,7 @@ import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_ECDHE
65 import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256; 65 import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256;
66 import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_PSK_WITH_AES_128_CCM_8; 66 import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_PSK_WITH_AES_128_CCM_8;
67 import static org.thingsboard.server.transport.lwm2m.server.LwM2mNetworkConfig.getCoapConfig; 67 import static org.thingsboard.server.transport.lwm2m.server.LwM2mNetworkConfig.getCoapConfig;
68 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FIRMWARE_UPDATE_COAP_RECOURSE; 68 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FIRMWARE_UPDATE_COAP_RECOURSE;
69 69
70 @Slf4j 70 @Slf4j
71 @Component 71 @Component
@@ -31,8 +31,8 @@ import java.util.concurrent.ConcurrentHashMap; @@ -31,8 +31,8 @@ import java.util.concurrent.ConcurrentHashMap;
31 import java.util.concurrent.ConcurrentMap; 31 import java.util.concurrent.ConcurrentMap;
32 import java.util.concurrent.atomic.AtomicInteger; 32 import java.util.concurrent.atomic.AtomicInteger;
33 33
34 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FIRMWARE_UPDATE_COAP_RECOURSE;  
35 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SOFTWARE_UPDATE_COAP_RECOURSE; 34 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FIRMWARE_UPDATE_COAP_RECOURSE;
  35 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SOFTWARE_UPDATE_COAP_RECOURSE;
36 36
37 @Slf4j 37 @Slf4j
38 public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource { 38 public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource {
@@ -43,13 +43,13 @@ import org.thingsboard.server.common.data.DeviceTransportType; @@ -43,13 +43,13 @@ import org.thingsboard.server.common.data.DeviceTransportType;
43 import org.thingsboard.server.common.data.device.data.lwm2m.BootstrapConfiguration; 43 import org.thingsboard.server.common.data.device.data.lwm2m.BootstrapConfiguration;
44 import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; 44 import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration;
45 import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration; 45 import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration;
46 -import org.thingsboard.server.common.data.ota.OtaPackageKey;  
47 -import org.thingsboard.server.common.data.ota.OtaPackageType;  
48 -import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus;  
49 -import org.thingsboard.server.common.data.ota.OtaPackageUtil;  
50 import org.thingsboard.server.common.transport.TransportServiceCallback; 46 import org.thingsboard.server.common.transport.TransportServiceCallback;
51 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; 47 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
52 import org.thingsboard.server.transport.lwm2m.server.client.ResourceValue; 48 import org.thingsboard.server.transport.lwm2m.server.client.ResourceValue;
  49 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.UpdateResultFw;
  50 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.UpdateStateFw;
  51 +import org.thingsboard.server.transport.lwm2m.server.ota.software.UpdateResultSw;
  52 +import org.thingsboard.server.transport.lwm2m.server.ota.software.UpdateStateSw;
53 import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2MUplinkMsgHandler; 53 import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2MUplinkMsgHandler;
54 54
55 import java.util.ArrayList; 55 import java.util.ArrayList;
@@ -77,277 +77,20 @@ import static org.eclipse.leshan.core.model.ResourceModel.Type.STRING; @@ -77,277 +77,20 @@ import static org.eclipse.leshan.core.model.ResourceModel.Type.STRING;
77 import static org.eclipse.leshan.core.model.ResourceModel.Type.TIME; 77 import static org.eclipse.leshan.core.model.ResourceModel.Type.TIME;
78 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY; 78 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY;
79 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; 79 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
80 -import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED;  
81 -import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING;  
82 -import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED;  
83 -import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATED;  
84 -import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING;  
85 -import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.VERIFIED; 80 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_RESULT_ID;
  81 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_STATE_ID;
  82 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_RESULT_ID;
  83 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_UPDATE_STATE_ID;
86 84
87 @Slf4j 85 @Slf4j
88 public class LwM2mTransportUtil { 86 public class LwM2mTransportUtil {
89 87
90 - public static final String EVENT_AWAKE = "AWAKE";  
91 - public static final String RESPONSE_REQUEST_CHANNEL = "RESP_REQ";  
92 - public static final String RESPONSE_CHANNEL = "RESP";  
93 - public static final String OBSERVE_CHANNEL = "OBSERVE";  
94 -  
95 - public static final String TRANSPORT_DEFAULT_LWM2M_VERSION = "1.0";  
96 - public static final String CLIENT_LWM2M_SETTINGS = "clientLwM2mSettings";  
97 - public static final String BOOTSTRAP = "bootstrap";  
98 - public static final String SERVERS = "servers";  
99 - public static final String LWM2M_SERVER = "lwm2mServer";  
100 - public static final String BOOTSTRAP_SERVER = "bootstrapServer";  
101 - public static final String OBSERVE_ATTRIBUTE_TELEMETRY = "observeAttr";  
102 - public static final String ATTRIBUTE = "attribute";  
103 - public static final String TELEMETRY = "telemetry";  
104 - public static final String KEY_NAME = "keyName";  
105 - public static final String OBSERVE_LWM2M = "observe";  
106 - public static final String ATTRIBUTE_LWM2M = "attributeLwm2m";  
107 -  
108 - private static final String REQUEST = "/request";  
109 - private static final String ATTRIBUTES = "/" + ATTRIBUTE;  
110 - public static final String TELEMETRIES = "/" + TELEMETRY;  
111 - public static final String ATTRIBUTES_REQUEST = ATTRIBUTES + REQUEST;  
112 - public static final String DEVICE_ATTRIBUTES_REQUEST = ATTRIBUTES_REQUEST + "/";  
113 -  
114 - public static final long DEFAULT_TIMEOUT = 2 * 60 * 1000L; // 2min in ms 88 + public static final String LWM2M_VERSION_DEFAULT = "1.0";
115 89
116 public static final String LOG_LWM2M_TELEMETRY = "logLwm2m"; 90 public static final String LOG_LWM2M_TELEMETRY = "logLwm2m";
117 public static final String LOG_LWM2M_INFO = "info"; 91 public static final String LOG_LWM2M_INFO = "info";
118 public static final String LOG_LWM2M_ERROR = "error"; 92 public static final String LOG_LWM2M_ERROR = "error";
119 public static final String LOG_LWM2M_WARN = "warn"; 93 public static final String LOG_LWM2M_WARN = "warn";
120 - public static final String LOG_LWM2M_VALUE = "value";  
121 -  
122 - public static final String CLIENT_NOT_AUTHORIZED = "Client not authorized";  
123 - public static final String LWM2M_VERSION_DEFAULT = "1.0";  
124 -  
125 - // Firmware  
126 - public static final String FIRMWARE_UPDATE_COAP_RECOURSE = "tbfw";  
127 - public static final String FW_UPDATE = "Firmware update";  
128 - public static final Integer FW_5_ID = 5;  
129 - public static final Integer FW_19_ID = 19;  
130 -  
131 - // Package W  
132 - public static final String FW_PACKAGE_5_ID = "/5/0/0";  
133 - public static final String FW_PACKAGE_19_ID = "/19/0/0";  
134 - // Package URI  
135 - public static final String FW_PACKAGE_URI_ID = "/5/0/1";  
136 - // State R  
137 - public static final String FW_STATE_ID = "/5/0/3";  
138 - // Update Result R  
139 - public static final String FW_RESULT_ID = "/5/0/5";  
140 -  
141 - public static final String FW_DELIVERY_METHOD = "/5/0/9";  
142 -  
143 - // PkgName R  
144 - public static final String FW_NAME_ID = "/5/0/6";  
145 - // PkgVersion R  
146 - public static final String FW_5_VER_ID = "/5/0/7";  
147 -  
148 - /**  
149 - * Quectel@Hi15RM1-HLB_V1.0@BC68JAR01A10,V150R100C20B300SP7,V150R100C20B300SP7@8  
150 - * BC68JAR01A10  
151 - * # Request prodct type number  
152 - * ATI  
153 - * Quectel  
154 - * BC68  
155 - * Revision:BC68JAR01A10  
156 - */  
157 - public static final String FW_3_VER_ID = "/3/0/3";  
158 - // Update E  
159 - public static final String FW_UPDATE_ID = "/5/0/2";  
160 -  
161 - // Software  
162 - public static final String SOFTWARE_UPDATE_COAP_RECOURSE = "softwareUpdateCoapRecourse";  
163 - public static final String SW_UPDATE = "Software update";  
164 - public static final Integer SW_ID = 9;  
165 - // Package W  
166 - public static final String SW_PACKAGE_ID = "/9/0/2";  
167 - // Package URI  
168 - public static final String SW_PACKAGE_URI_ID = "/9/0/3";  
169 - // Update State R  
170 - public static final String SW_UPDATE_STATE_ID = "/9/0/7";  
171 - // Update Result R  
172 - public static final String SW_RESULT_ID = "/9/0/9";  
173 - // PkgName R  
174 - public static final String SW_NAME_ID = "/9/0/0";  
175 - // PkgVersion R  
176 - public static final String SW_VER_ID = "/9/0/1";  
177 - // Install E  
178 - public static final String SW_INSTALL_ID = "/9/0/4";  
179 - // Uninstall E  
180 - public static final String SW_UN_INSTALL_ID = "/9/0/6";  
181 -  
182 - public enum LwM2mTypeServer {  
183 - BOOTSTRAP(0, "bootstrap"),  
184 - CLIENT(1, "client");  
185 -  
186 - public int code;  
187 - public String type;  
188 -  
189 - LwM2mTypeServer(int code, String type) {  
190 - this.code = code;  
191 - this.type = type;  
192 - }  
193 -  
194 - public static LwM2mTypeServer fromLwM2mTypeServer(String type) {  
195 - for (LwM2mTypeServer sm : LwM2mTypeServer.values()) {  
196 - if (sm.type.equals(type)) {  
197 - return sm;  
198 - }  
199 - }  
200 - throw new IllegalArgumentException(String.format("Unsupported typeServer type : %d", type));  
201 - }  
202 - }  
203 -  
204 - public static Optional<OtaPackageUpdateStatus> toOtaPackageUpdateStatus(UpdateResultFw updateResultFw) {  
205 - switch (updateResultFw) {  
206 - case INITIAL:  
207 - return Optional.empty();  
208 - case UPDATE_SUCCESSFULLY:  
209 - return Optional.of(UPDATED);  
210 - case NOT_ENOUGH:  
211 - case OUT_OFF_MEMORY:  
212 - case CONNECTION_LOST:  
213 - case INTEGRITY_CHECK_FAILURE:  
214 - case UNSUPPORTED_TYPE:  
215 - case INVALID_URI:  
216 - case UPDATE_FAILED:  
217 - case UNSUPPORTED_PROTOCOL:  
218 - return Optional.of(FAILED);  
219 - default:  
220 - throw new CodecException("Invalid value stateFw %s for FirmwareUpdateStatus.", updateResultFw.name());  
221 - }  
222 - }  
223 -  
224 - public static Optional<OtaPackageUpdateStatus> toOtaPackageUpdateStatus(UpdateStateFw updateStateFw) {  
225 - switch (updateStateFw) {  
226 - case IDLE:  
227 - return Optional.empty();  
228 - case DOWNLOADING:  
229 - return Optional.of(DOWNLOADING);  
230 - case DOWNLOADED:  
231 - return Optional.of(DOWNLOADED);  
232 - case UPDATING:  
233 - return Optional.of(UPDATING);  
234 - default:  
235 - throw new CodecException("Invalid value stateFw %d for FirmwareUpdateStatus.", updateStateFw);  
236 - }  
237 - }  
238 -  
239 - /**  
240 - * SW Update State R  
241 - * 0: INITIAL Before downloading. (see 5.1.2.1)  
242 - * 1: DOWNLOAD STARTED The downloading process has started and is on-going. (see 5.1.2.2)  
243 - * 2: DOWNLOADED The package has been completely downloaded (see 5.1.2.3)  
244 - * 3: DELIVERED In that state, the package has been correctly downloaded and is ready to be installed. (see 5.1.2.4)  
245 - * If executing the Install Resource failed, the state remains at DELIVERED.  
246 - * If executing the Install Resource was successful, the state changes from DELIVERED to INSTALLED.  
247 - * After executing the UnInstall Resource, the state changes to INITIAL.  
248 - * 4: INSTALLED  
249 - */  
250 - public enum UpdateStateSw {  
251 - INITIAL(0, "Initial"),  
252 - DOWNLOAD_STARTED(1, "DownloadStarted"),  
253 - DOWNLOADED(2, "Downloaded"),  
254 - DELIVERED(3, "Delivered"),  
255 - INSTALLED(4, "Installed");  
256 -  
257 - public int code;  
258 - public String type;  
259 -  
260 - UpdateStateSw(int code, String type) {  
261 - this.code = code;  
262 - this.type = type;  
263 - }  
264 -  
265 - public static UpdateStateSw fromUpdateStateSwByType(String type) {  
266 - for (UpdateStateSw to : UpdateStateSw.values()) {  
267 - if (to.type.equals(type)) {  
268 - return to;  
269 - }  
270 - }  
271 - throw new IllegalArgumentException(String.format("Unsupported SW State type : %s", type));  
272 - }  
273 -  
274 - public static UpdateStateSw fromUpdateStateSwByCode(int code) {  
275 - for (UpdateStateSw to : UpdateStateSw.values()) {  
276 - if (to.code == code) {  
277 - return to;  
278 - }  
279 - }  
280 - throw new IllegalArgumentException(String.format("Unsupported SW State type : %s", code));  
281 - }  
282 - }  
283 -  
284 - /**  
285 - * SW Update Result  
286 - * Contains the result of downloading or installing/uninstalling the software  
287 - * 0: Initial value.  
288 - * - Prior to download any new package in the Device, Update Result MUST be reset to this initial value.  
289 - * - One side effect of executing the Uninstall resource is to reset Update Result to this initial value "0".  
290 - * 1: Downloading.  
291 - * - The package downloading process is on-going.  
292 - * 2: Software successfully installed.  
293 - * 3: Successfully Downloaded and package integrity verified  
294 - * (( 4-49, for expansion, of other scenarios))  
295 - * ** Failed  
296 - * 50: Not enough storage for the new software package.  
297 - * 51: Out of memory during downloading process.  
298 - * 52: Connection lost during downloading process.  
299 - * 53: Package integrity check failure.  
300 - * 54: Unsupported package type.  
301 - * 56: Invalid URI  
302 - * 57: Device defined update error  
303 - * 58: Software installation failure  
304 - * 59: Uninstallation Failure during forUpdate(arg=0)  
305 - * 60-200 : (for expansion, selection to be in blocks depending on new introduction of features)  
306 - * This Resource MAY be reported by sending Observe operation.  
307 - */  
308 - public enum UpdateResultSw {  
309 - INITIAL(0, "Initial value", false),  
310 - DOWNLOADING(1, "Downloading", false),  
311 - SUCCESSFULLY_INSTALLED(2, "Software successfully installed", false),  
312 - SUCCESSFULLY_DOWNLOADED_VERIFIED(3, "Successfully Downloaded and package integrity verified", false),  
313 - NOT_ENOUGH_STORAGE(50, "Not enough storage for the new software package", true),  
314 - OUT_OFF_MEMORY(51, "Out of memory during downloading process", true),  
315 - CONNECTION_LOST(52, "Connection lost during downloading process", false),  
316 - PACKAGE_CHECK_FAILURE(53, "Package integrity check failure.", false),  
317 - UNSUPPORTED_PACKAGE_TYPE(54, "Unsupported package type", false),  
318 - INVALID_URI(56, "Invalid URI", true),  
319 - UPDATE_ERROR(57, "Device defined update error", true),  
320 - INSTALL_FAILURE(58, "Software installation failure", true),  
321 - UN_INSTALL_FAILURE(59, "Uninstallation Failure during forUpdate(arg=0)", true);  
322 -  
323 - public int code;  
324 - public String type;  
325 - public boolean isAgain;  
326 -  
327 - UpdateResultSw(int code, String type, boolean isAgain) {  
328 - this.code = code;  
329 - this.type = type;  
330 - this.isAgain = isAgain;  
331 - }  
332 -  
333 - public static UpdateResultSw fromUpdateResultSwByType(String type) {  
334 - for (UpdateResultSw to : UpdateResultSw.values()) {  
335 - if (to.type.equals(type)) {  
336 - return to;  
337 - }  
338 - }  
339 - throw new IllegalArgumentException(String.format("Unsupported SW Update Result type : %s", type));  
340 - }  
341 -  
342 - public static UpdateResultSw fromUpdateResultSwByCode(int code) {  
343 - for (UpdateResultSw to : UpdateResultSw.values()) {  
344 - if (to.code == code) {  
345 - return to;  
346 - }  
347 - }  
348 - throw new IllegalArgumentException(String.format("Unsupported SW Update Result code : %s", code));  
349 - }  
350 - }  
351 94
352 public enum LwM2MClientStrategy { 95 public enum LwM2MClientStrategy {
353 CLIENT_STRATEGY_1(1, "Read only resources marked as observation"), 96 CLIENT_STRATEGY_1(1, "Read only resources marked as observation"),
@@ -380,45 +123,7 @@ public class LwM2mTransportUtil { @@ -380,45 +123,7 @@ public class LwM2mTransportUtil {
380 } 123 }
381 } 124 }
382 125
383 - /**  
384 - * FirmwareUpdateStatus {  
385 - * DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED  
386 - */  
387 - public static OtaPackageUpdateStatus EqualsSwSateToFirmwareUpdateStatus(UpdateStateSw updateStateSw, UpdateResultSw updateResultSw) {  
388 - switch (updateResultSw) {  
389 - case INITIAL:  
390 - switch (updateStateSw) {  
391 - case INITIAL:  
392 - case DOWNLOAD_STARTED:  
393 - return DOWNLOADING;  
394 - case DOWNLOADED:  
395 - return DOWNLOADED;  
396 - case DELIVERED:  
397 - return VERIFIED;  
398 - }  
399 - case DOWNLOADING:  
400 - return DOWNLOADING;  
401 - case SUCCESSFULLY_INSTALLED:  
402 - return UPDATED;  
403 - case SUCCESSFULLY_DOWNLOADED_VERIFIED:  
404 - return VERIFIED;  
405 - case NOT_ENOUGH_STORAGE:  
406 - case OUT_OFF_MEMORY:  
407 - case CONNECTION_LOST:  
408 - case PACKAGE_CHECK_FAILURE:  
409 - case UNSUPPORTED_PACKAGE_TYPE:  
410 - case INVALID_URI:  
411 - case UPDATE_ERROR:  
412 - case INSTALL_FAILURE:  
413 - case UN_INSTALL_FAILURE:  
414 - return FAILED;  
415 - default:  
416 - throw new CodecException("Invalid value stateFw %s %s for FirmwareUpdateStatus.", updateStateSw.name(), updateResultSw.name());  
417 - }  
418 - }  
419 -  
420 -  
421 - public static boolean equalsResourceValue(Object valueOld, Object valueNew, ResourceModel.Type type, LwM2mPath 126 + public static boolean equalsResourceValue(Object valueOld, Object valueNew, ResourceModel.Type type, LwM2mPath
422 resourcePath) throws CodecException { 127 resourcePath) throws CodecException {
423 switch (type) { 128 switch (type) {
424 case BOOLEAN: 129 case BOOLEAN:
@@ -477,18 +182,6 @@ public class LwM2mTransportUtil { @@ -477,18 +182,6 @@ public class LwM2mTransportUtil {
477 return null; 182 return null;
478 } 183 }
479 184
480 -// public static LwM2mClientProfile getNewProfileParameters(JsonObject profilesConfigData, TenantId tenantId) {  
481 -// LwM2mClientProfile lwM2MClientProfile = new LwM2mClientProfile();  
482 -// lwM2MClientProfile.setTenantId(tenantId);  
483 -// lwM2MClientProfile.setPostClientLwM2mSettings(profilesConfigData.get(CLIENT_LWM2M_SETTINGS).getAsJsonObject());  
484 -// lwM2MClientProfile.setPostKeyNameProfile(profilesConfigData.get(OBSERVE_ATTRIBUTE_TELEMETRY).getAsJsonObject().get(KEY_NAME).getAsJsonObject());  
485 -// lwM2MClientProfile.setPostAttributeProfile(profilesConfigData.get(OBSERVE_ATTRIBUTE_TELEMETRY).getAsJsonObject().get(ATTRIBUTE).getAsJsonArray());  
486 -// lwM2MClientProfile.setPostTelemetryProfile(profilesConfigData.get(OBSERVE_ATTRIBUTE_TELEMETRY).getAsJsonObject().get(TELEMETRY).getAsJsonArray());  
487 -// lwM2MClientProfile.setPostObserveProfile(profilesConfigData.get(OBSERVE_ATTRIBUTE_TELEMETRY).getAsJsonObject().get(OBSERVE_LWM2M).getAsJsonArray());  
488 -// lwM2MClientProfile.setPostAttributeLwm2mProfile(profilesConfigData.get(OBSERVE_ATTRIBUTE_TELEMETRY).getAsJsonObject().get(ATTRIBUTE_LWM2M).getAsJsonObject());  
489 -// return lwM2MClientProfile;  
490 -// }  
491 -  
492 public static Lwm2mDeviceProfileTransportConfiguration toLwM2MClientProfile(DeviceProfile deviceProfile) { 185 public static Lwm2mDeviceProfileTransportConfiguration toLwM2MClientProfile(DeviceProfile deviceProfile) {
493 DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); 186 DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
494 if (transportConfiguration.getType().equals(DeviceTransportType.LWM2M)) { 187 if (transportConfiguration.getType().equals(DeviceTransportType.LWM2M)) {
@@ -603,7 +296,6 @@ public class LwM2mTransportUtil { @@ -603,7 +296,6 @@ public class LwM2mTransportUtil {
603 if (keyArray.length > 1 && keyArray[1].split(LWM2M_SEPARATOR_KEY).length == 2) { 296 if (keyArray.length > 1 && keyArray[1].split(LWM2M_SEPARATOR_KEY).length == 2) {
604 return pathIdVer; 297 return pathIdVer;
605 } else { 298 } else {
606 - LwM2mPath pathObjId = new LwM2mPath(pathIdVer);  
607 return convertObjectIdToVersionedId(pathIdVer, registration); 299 return convertObjectIdToVersionedId(pathIdVer, registration);
608 } 300 }
609 } 301 }
@@ -743,18 +435,18 @@ public class LwM2mTransportUtil { @@ -743,18 +435,18 @@ public class LwM2mTransportUtil {
743 } 435 }
744 } 436 }
745 437
746 - public static boolean isFwSwWords(String pathName) {  
747 - return OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION).equals(pathName)  
748 - || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE).equals(pathName)  
749 - || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.CHECKSUM).equals(pathName)  
750 - || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.CHECKSUM_ALGORITHM).equals(pathName)  
751 - || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.SIZE).equals(pathName)  
752 - || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION).equals(pathName)  
753 - || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE).equals(pathName)  
754 - || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.CHECKSUM).equals(pathName)  
755 - || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.CHECKSUM_ALGORITHM).equals(pathName)  
756 - || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.SIZE).equals(pathName);  
757 - } 438 +// public static boolean isFwSwWords(String pathName) {
  439 +// return OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION).equals(pathName)
  440 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE).equals(pathName)
  441 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.CHECKSUM).equals(pathName)
  442 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.CHECKSUM_ALGORITHM).equals(pathName)
  443 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.SIZE).equals(pathName)
  444 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION).equals(pathName)
  445 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE).equals(pathName)
  446 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.CHECKSUM).equals(pathName)
  447 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.CHECKSUM_ALGORITHM).equals(pathName)
  448 +// || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.SIZE).equals(pathName);
  449 +// }
758 450
759 /** 451 /**
760 * @param lwM2MClient - 452 * @param lwM2MClient -
@@ -33,12 +33,10 @@ import org.eclipse.leshan.server.security.SecurityInfo; @@ -33,12 +33,10 @@ import org.eclipse.leshan.server.security.SecurityInfo;
33 import org.thingsboard.server.common.data.Device; 33 import org.thingsboard.server.common.data.Device;
34 import org.thingsboard.server.common.data.DeviceProfile; 34 import org.thingsboard.server.common.data.DeviceProfile;
35 import org.thingsboard.server.common.data.id.TenantId; 35 import org.thingsboard.server.common.data.id.TenantId;
36 -import org.thingsboard.server.common.data.ota.OtaPackageType;  
37 import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; 36 import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse;
38 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; 37 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
39 import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto; 38 import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto;
40 import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest; 39 import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest;
41 -import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;  
42 40
43 import java.util.Collection; 41 import java.util.Collection;
44 import java.util.Map; 42 import java.util.Map;
@@ -53,7 +51,7 @@ import java.util.concurrent.locks.ReentrantLock; @@ -53,7 +51,7 @@ import java.util.concurrent.locks.ReentrantLock;
53 import java.util.stream.Collectors; 51 import java.util.stream.Collectors;
54 52
55 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; 53 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
56 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.TRANSPORT_DEFAULT_LWM2M_VERSION; 54 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_VERSION_DEFAULT;
57 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertObjectIdToVersionedId; 55 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertObjectIdToVersionedId;
58 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.equalsResourceTypeGetSimpleName; 56 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.equalsResourceTypeGetSimpleName;
59 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.fromVersionedIdToObjectId; 57 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.fromVersionedIdToObjectId;
@@ -307,7 +305,7 @@ public class LwM2mClient implements Cloneable { @@ -307,7 +305,7 @@ public class LwM2mClient implements Cloneable {
307 LwM2mPath pathIds = new LwM2mPath(fromVersionedIdToObjectId(path)); 305 LwM2mPath pathIds = new LwM2mPath(fromVersionedIdToObjectId(path));
308 String verSupportedObject = registration.getSupportedObject().get(pathIds.getObjectId()); 306 String verSupportedObject = registration.getSupportedObject().get(pathIds.getObjectId());
309 String verRez = getVerFromPathIdVerOrId(path); 307 String verRez = getVerFromPathIdVerOrId(path);
310 - return verRez == null ? TRANSPORT_DEFAULT_LWM2M_VERSION.equals(verSupportedObject) : verRez.equals(verSupportedObject); 308 + return verRez == null ? LWM2M_VERSION_DEFAULT.equals(verSupportedObject) : verRez.equals(verSupportedObject);
311 } 309 }
312 310
313 /** 311 /**
@@ -17,6 +17,7 @@ package org.thingsboard.server.transport.lwm2m.server.ota; @@ -17,6 +17,7 @@ package org.thingsboard.server.transport.lwm2m.server.ota;
17 17
18 import lombok.RequiredArgsConstructor; 18 import lombok.RequiredArgsConstructor;
19 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
  20 +import org.eclipse.leshan.core.node.codec.CodecException;
20 import org.eclipse.leshan.core.request.ContentFormat; 21 import org.eclipse.leshan.core.request.ContentFormat;
21 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.context.annotation.Lazy; 23 import org.springframework.context.annotation.Lazy;
@@ -32,12 +33,7 @@ import org.thingsboard.server.common.transport.TransportServiceCallback; @@ -32,12 +33,7 @@ import org.thingsboard.server.common.transport.TransportServiceCallback;
32 import org.thingsboard.server.gen.transport.TransportProtos; 33 import org.thingsboard.server.gen.transport.TransportProtos;
33 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; 34 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
34 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; 35 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
35 -import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy;  
36 -import org.thingsboard.server.transport.lwm2m.server.LwM2MSoftwareUpdateStrategy;  
37 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; 36 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper;
38 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil;  
39 -import org.thingsboard.server.transport.lwm2m.server.UpdateResultFw;  
40 -import org.thingsboard.server.transport.lwm2m.server.UpdateStateFw;  
41 import org.thingsboard.server.transport.lwm2m.server.attributes.LwM2MAttributesService; 37 import org.thingsboard.server.transport.lwm2m.server.attributes.LwM2MAttributesService;
42 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; 38 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
43 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; 39 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
@@ -48,6 +44,13 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MExecuteRequ @@ -48,6 +44,13 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MExecuteRequ
48 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteReplaceRequest; 44 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteReplaceRequest;
49 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteResponseCallback; 45 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteResponseCallback;
50 import org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService; 46 import org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService;
  47 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MFirmwareUpdateStrategy;
  48 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.UpdateDeliveryFw;
  49 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.UpdateResultFw;
  50 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.UpdateStateFw;
  51 +import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MSoftwareUpdateStrategy;
  52 +import org.thingsboard.server.transport.lwm2m.server.ota.software.UpdateResultSw;
  53 +import org.thingsboard.server.transport.lwm2m.server.ota.software.UpdateStateSw;
51 import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler; 54 import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
52 55
53 import javax.annotation.PostConstruct; 56 import javax.annotation.PostConstruct;
@@ -60,8 +63,13 @@ import java.util.UUID; @@ -60,8 +63,13 @@ import java.util.UUID;
60 import java.util.concurrent.ConcurrentHashMap; 63 import java.util.concurrent.ConcurrentHashMap;
61 64
62 import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE; 65 import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE;
  66 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED;
  67 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING;
  68 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED;
  69 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATED;
  70 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING;
  71 +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.VERIFIED;
63 import static org.thingsboard.server.common.data.ota.OtaPackageUtil.getAttributeKey; 72 import static org.thingsboard.server.common.data.ota.OtaPackageUtil.getAttributeKey;
64 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FIRMWARE_UPDATE_COAP_RECOURSE;  
65 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_TELEMETRY; 73 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_TELEMETRY;
66 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertObjectIdToVersionedId; 74 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertObjectIdToVersionedId;
67 75
@@ -78,13 +86,30 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -78,13 +86,30 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
78 public static final String SOFTWARE_TITLE = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE); 86 public static final String SOFTWARE_TITLE = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE);
79 public static final String SOFTWARE_URL = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.URL); 87 public static final String SOFTWARE_URL = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.URL);
80 88
  89 + public static final String FIRMWARE_UPDATE_COAP_RECOURSE = "tbfw";
  90 + public static final String SOFTWARE_UPDATE_COAP_RECOURSE = "tbsw";
81 private static final String FW_PACKAGE_5_ID = "/5/0/0"; 91 private static final String FW_PACKAGE_5_ID = "/5/0/0";
82 private static final String FW_URL_ID = "/5/0/1"; 92 private static final String FW_URL_ID = "/5/0/1";
83 private static final String FW_EXECUTE_ID = "/5/0/2"; 93 private static final String FW_EXECUTE_ID = "/5/0/2";
84 - private static final String FW_NAME_ID = "/5/0/6";  
85 - private static final String FW_VER_ID = "/5/0/7"; 94 + public static final String FW_STATE_ID = "/5/0/3";
  95 + public static final String FW_RESULT_ID = "/5/0/5";
  96 + public static final String FW_NAME_ID = "/5/0/6";
  97 + public static final String FW_5_VER_ID = "/5/0/7";
  98 + /**
  99 + * Quectel@Hi15RM1-HLB_V1.0@BC68JAR01A10,V150R100C20B300SP7,V150R100C20B300SP7@8
  100 + * Revision:BC68JAR01A10
  101 + */
  102 + public static final String FW_3_VER_ID = "/3/0/3";
  103 + public static final String FW_DELIVERY_METHOD = "/5/0/9";
  104 +
86 private static final String SW_NAME_ID = "/9/0/0"; 105 private static final String SW_NAME_ID = "/9/0/0";
87 private static final String SW_VER_ID = "/9/0/1"; 106 private static final String SW_VER_ID = "/9/0/1";
  107 + public static final String SW_PACKAGE_ID = "/9/0/2";
  108 + public static final String SW_PACKAGE_URI_ID = "/9/0/3";
  109 + public static final String SW_INSTALL_ID = "/9/0/4";
  110 + public static final String SW_UPDATE_STATE_ID = "/9/0/7";
  111 + public static final String SW_RESULT_ID = "/9/0/9";
  112 + public static final String SW_UN_INSTALL_ID = "/9/0/6";
88 113
89 private final Map<String, LwM2MClientOtaInfo> fwStates = new ConcurrentHashMap<>(); 114 private final Map<String, LwM2MClientOtaInfo> fwStates = new ConcurrentHashMap<>();
90 private final Map<String, LwM2MClientOtaInfo> swStates = new ConcurrentHashMap<>(); 115 private final Map<String, LwM2MClientOtaInfo> swStates = new ConcurrentHashMap<>();
@@ -216,7 +241,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -216,7 +241,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
216 executeFwUpdate(client); 241 executeFwUpdate(client);
217 } 242 }
218 fwInfo.setUpdateState(state); 243 fwInfo.setUpdateState(state);
219 - Optional<OtaPackageUpdateStatus> status = LwM2mTransportUtil.toOtaPackageUpdateStatus(state); 244 + Optional<OtaPackageUpdateStatus> status = this.toOtaPackageUpdateStatus(state);
220 status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, fwInfo, 245 status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, fwInfo,
221 otaStatus, "Firmware Update State: " + state.name())); 246 otaStatus, "Firmware Update State: " + state.name()));
222 } 247 }
@@ -226,7 +251,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -226,7 +251,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
226 log.debug("[{}] Current fw result: {}", client.getEndpoint(), code); 251 log.debug("[{}] Current fw result: {}", client.getEndpoint(), code);
227 LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client); 252 LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
228 UpdateResultFw result = UpdateResultFw.fromUpdateResultFwByCode(code.intValue()); 253 UpdateResultFw result = UpdateResultFw.fromUpdateResultFwByCode(code.intValue());
229 - Optional<OtaPackageUpdateStatus> status = LwM2mTransportUtil.toOtaPackageUpdateStatus(result); 254 + Optional<OtaPackageUpdateStatus> status = this.toOtaPackageUpdateStatus(result);
230 status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, fwInfo, 255 status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, fwInfo,
231 otaStatus, "Firmware Update Result: " + result.name())); 256 otaStatus, "Firmware Update Result: " + result.name()));
232 if (result.isAgain() && fwInfo.getRetryAttempts() <= 2) { 257 if (result.isAgain() && fwInfo.getRetryAttempts() <= 2) {
@@ -299,10 +324,10 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -299,10 +324,10 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
299 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())) { 324 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())) {
300 UUID otaPackageId = new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB()); 325 UUID otaPackageId = new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB());
301 LwM2MFirmwareUpdateStrategy strategy; 326 LwM2MFirmwareUpdateStrategy strategy;
302 - if (fwInfo.getDeliveryMethod() == null || fwInfo.getDeliveryMethod() == 2) { 327 + if (fwInfo.getDeliveryMethod() == null || fwInfo.getDeliveryMethod() == UpdateDeliveryFw.BOTH.code) {
303 strategy = fwInfo.getFwStrategy(); 328 strategy = fwInfo.getFwStrategy();
304 } else { 329 } else {
305 - strategy = fwInfo.getDeliveryMethod() == 0 ? LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL : LwM2MFirmwareUpdateStrategy.OBJ_5_BINARY; 330 + strategy = fwInfo.getDeliveryMethod() == UpdateDeliveryFw.PULL.code ? LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL : LwM2MFirmwareUpdateStrategy.OBJ_5_BINARY;
306 } 331 }
307 switch (strategy) { 332 switch (strategy) {
308 case OBJ_5_BINARY: 333 case OBJ_5_BINARY:
@@ -380,4 +405,78 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -380,4 +405,78 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
380 helper.sendParametersOnThingsboardTelemetry(result, client.getSession()); 405 helper.sendParametersOnThingsboardTelemetry(result, client.getSession());
381 } 406 }
382 407
  408 + private static Optional<OtaPackageUpdateStatus> toOtaPackageUpdateStatus(UpdateResultFw updateResultFw) {
  409 + switch (updateResultFw) {
  410 + case INITIAL:
  411 + return Optional.empty();
  412 + case UPDATE_SUCCESSFULLY:
  413 + return Optional.of(UPDATED);
  414 + case NOT_ENOUGH:
  415 + case OUT_OFF_MEMORY:
  416 + case CONNECTION_LOST:
  417 + case INTEGRITY_CHECK_FAILURE:
  418 + case UNSUPPORTED_TYPE:
  419 + case INVALID_URI:
  420 + case UPDATE_FAILED:
  421 + case UNSUPPORTED_PROTOCOL:
  422 + return Optional.of(FAILED);
  423 + default:
  424 + throw new CodecException("Invalid value stateFw %s for FirmwareUpdateStatus.", updateResultFw.name());
  425 + }
  426 + }
  427 +
  428 + private static Optional<OtaPackageUpdateStatus> toOtaPackageUpdateStatus(UpdateStateFw updateStateFw) {
  429 + switch (updateStateFw) {
  430 + case IDLE:
  431 + return Optional.empty();
  432 + case DOWNLOADING:
  433 + return Optional.of(DOWNLOADING);
  434 + case DOWNLOADED:
  435 + return Optional.of(DOWNLOADED);
  436 + case UPDATING:
  437 + return Optional.of(UPDATING);
  438 + default:
  439 + throw new CodecException("Invalid value stateFw %d for FirmwareUpdateStatus.", updateStateFw);
  440 + }
  441 + }
  442 +
  443 + /**
  444 + * FirmwareUpdateStatus {
  445 + * DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED
  446 + */
  447 + public static Optional<OtaPackageUpdateStatus> toSwSateResultUpdateStatus(UpdateStateSw updateStateSw, UpdateResultSw updateResultSw) {
  448 + switch (updateResultSw) {
  449 + case INITIAL:
  450 + switch (updateStateSw) {
  451 + case INITIAL:
  452 + case DOWNLOAD_STARTED:
  453 + return Optional.of(DOWNLOADING);
  454 + case DOWNLOADED:
  455 + return Optional.of(DOWNLOADED);
  456 + case DELIVERED:
  457 + return Optional.of(VERIFIED);
  458 + }
  459 + case DOWNLOADING:
  460 + return Optional.of(DOWNLOADING);
  461 + case SUCCESSFULLY_INSTALLED:
  462 + return Optional.of(UPDATED);
  463 + case SUCCESSFULLY_DOWNLOADED_VERIFIED:
  464 + return Optional.of(VERIFIED);
  465 + case NOT_ENOUGH_STORAGE:
  466 + case OUT_OFF_MEMORY:
  467 + case CONNECTION_LOST:
  468 + case PACKAGE_CHECK_FAILURE:
  469 + case UNSUPPORTED_PACKAGE_TYPE:
  470 + case INVALID_URI:
  471 + case UPDATE_ERROR:
  472 + case INSTALL_FAILURE:
  473 + case UN_INSTALL_FAILURE:
  474 + return Optional.of(FAILED);
  475 + default:
  476 + throw new CodecException("Invalid value stateFw %s %s for FirmwareUpdateStatus.", updateStateSw.name(), updateResultSw.name());
  477 + }
  478 + }
  479 +
  480 +
  481 +
383 } 482 }
@@ -18,10 +18,10 @@ package org.thingsboard.server.transport.lwm2m.server.ota; @@ -18,10 +18,10 @@ package org.thingsboard.server.transport.lwm2m.server.ota;
18 import lombok.Data; 18 import lombok.Data;
19 import org.thingsboard.server.common.data.StringUtils; 19 import org.thingsboard.server.common.data.StringUtils;
20 import org.thingsboard.server.common.data.ota.OtaPackageType; 20 import org.thingsboard.server.common.data.ota.OtaPackageType;
21 -import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy;  
22 -import org.thingsboard.server.transport.lwm2m.server.LwM2MSoftwareUpdateStrategy;  
23 -import org.thingsboard.server.transport.lwm2m.server.UpdateResultFw;  
24 -import org.thingsboard.server.transport.lwm2m.server.UpdateStateFw; 21 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MFirmwareUpdateStrategy;
  22 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.UpdateResultFw;
  23 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.UpdateStateFw;
  24 +import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MSoftwareUpdateStrategy;
25 25
26 import java.util.Optional; 26 import java.util.Optional;
27 27
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/firmware/LwM2MFirmwareUpdateStrategy.java renamed from common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MFirmwareUpdateStrategy.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.transport.lwm2m.server; 16 +package org.thingsboard.server.transport.lwm2m.server.ota.firmware;
17 17
18 public enum LwM2MFirmwareUpdateStrategy { 18 public enum LwM2MFirmwareUpdateStrategy {
19 OBJ_5_BINARY(1, "ObjectId 5, Binary"), 19 OBJ_5_BINARY(1, "ObjectId 5, Binary"),
  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.server.ota.firmware;
  17 +
  18 +/**
  19 + * /** Delivery Method R
  20 + * 0: Pull only
  21 + * 1: Push only
  22 + * 2: Both:
  23 + * - In this case the LwM2M Server MAY choose the preferred mechanism for conveying the firmware image to the LwM2M Client.
  24 + */
  25 +public enum UpdateDeliveryFw {
  26 + PULL(0, "Pull only"),
  27 + PUSH(1, "Push only"),
  28 + BOTH(2, "Push or Push");
  29 +
  30 + public int code;
  31 + public String type;
  32 +
  33 + UpdateDeliveryFw(int code, String type) {
  34 + this.code = code;
  35 + this.type = type;
  36 + }
  37 +
  38 + public static UpdateDeliveryFw fromStateFwByType(String type) {
  39 + for (UpdateDeliveryFw to : UpdateDeliveryFw.values()) {
  40 + if (to.type.equals(type)) {
  41 + return to;
  42 + }
  43 + }
  44 + throw new IllegalArgumentException(String.format("Unsupported FW delivery type : %s", type));
  45 + }
  46 +
  47 + public static UpdateDeliveryFw fromStateFwByCode(int code) {
  48 + for (UpdateDeliveryFw to : UpdateDeliveryFw.values()) {
  49 + if (to.code == code) {
  50 + return to;
  51 + }
  52 + }
  53 + throw new IllegalArgumentException(String.format("Unsupported FW delivery code : %s", code));
  54 + }
  55 +}
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/firmware/UpdateResultFw.java renamed from common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/UpdateResultFw.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.transport.lwm2m.server; 16 +package org.thingsboard.server.transport.lwm2m.server.ota.firmware;
17 17
18 import lombok.Getter; 18 import lombok.Getter;
19 19
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/firmware/UpdateStateFw.java renamed from common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/UpdateStateFw.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.transport.lwm2m.server; 16 +package org.thingsboard.server.transport.lwm2m.server.ota.firmware;
17 17
18 /** 18 /**
19 * /** State R 19 * /** State R
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/software/LwM2MSoftwareUpdateStrategy.java renamed from common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MSoftwareUpdateStrategy.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.transport.lwm2m.server; 16 +package org.thingsboard.server.transport.lwm2m.server.ota.software;
17 17
18 public enum LwM2MSoftwareUpdateStrategy { 18 public enum LwM2MSoftwareUpdateStrategy {
19 BINARY(1, "ObjectId 9, Binary"), 19 BINARY(1, "ObjectId 9, Binary"),
  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.server.ota.software;
  17 +
  18 +/**
  19 + * SW Update Result
  20 + * Contains the result of downloading or installing/uninstalling the software
  21 + * 0: Initial value.
  22 + * - Prior to download any new package in the Device, Update Result MUST be reset to this initial value.
  23 + * - One side effect of executing the Uninstall resource is to reset Update Result to this initial value "0".
  24 + * 1: Downloading.
  25 + * - The package downloading process is on-going.
  26 + * 2: Software successfully installed.
  27 + * 3: Successfully Downloaded and package integrity verified
  28 + * (( 4-49, for expansion, of other scenarios))
  29 + * ** Failed
  30 + * 50: Not enough storage for the new software package.
  31 + * 51: Out of memory during downloading process.
  32 + * 52: Connection lost during downloading process.
  33 + * 53: Package integrity check failure.
  34 + * 54: Unsupported package type.
  35 + * 56: Invalid URI
  36 + * 57: Device defined update error
  37 + * 58: Software installation failure
  38 + * 59: Uninstallation Failure during forUpdate(arg=0)
  39 + * 60-200 : (for expansion, selection to be in blocks depending on new introduction of features)
  40 + * This Resource MAY be reported by sending Observe operation.
  41 + */
  42 +public enum UpdateResultSw {
  43 + INITIAL(0, "Initial value", false),
  44 + DOWNLOADING(1, "Downloading", false),
  45 + SUCCESSFULLY_INSTALLED(2, "Software successfully installed", false),
  46 + SUCCESSFULLY_DOWNLOADED_VERIFIED(3, "Successfully Downloaded and package integrity verified", false),
  47 + NOT_ENOUGH_STORAGE(50, "Not enough storage for the new software package", true),
  48 + OUT_OFF_MEMORY(51, "Out of memory during downloading process", true),
  49 + CONNECTION_LOST(52, "Connection lost during downloading process", false),
  50 + PACKAGE_CHECK_FAILURE(53, "Package integrity check failure.", false),
  51 + UNSUPPORTED_PACKAGE_TYPE(54, "Unsupported package type", false),
  52 + INVALID_URI(56, "Invalid URI", true),
  53 + UPDATE_ERROR(57, "Device defined update error", true),
  54 + INSTALL_FAILURE(58, "Software installation failure", true),
  55 + UN_INSTALL_FAILURE(59, "Uninstallation Failure during forUpdate(arg=0)", true);
  56 +
  57 + public int code;
  58 + public String type;
  59 + public boolean isAgain;
  60 +
  61 + UpdateResultSw(int code, String type, boolean isAgain) {
  62 + this.code = code;
  63 + this.type = type;
  64 + this.isAgain = isAgain;
  65 + }
  66 +
  67 + public static UpdateResultSw fromUpdateResultSwByType(String type) {
  68 + for (UpdateResultSw to : UpdateResultSw.values()) {
  69 + if (to.type.equals(type)) {
  70 + return to;
  71 + }
  72 + }
  73 + throw new IllegalArgumentException(String.format("Unsupported SW Update Result type : %s", type));
  74 + }
  75 +
  76 + public static UpdateResultSw fromUpdateResultSwByCode(int code) {
  77 + for (UpdateResultSw to : UpdateResultSw.values()) {
  78 + if (to.code == code) {
  79 + return to;
  80 + }
  81 + }
  82 + throw new IllegalArgumentException(String.format("Unsupported SW Update Result code : %s", code));
  83 + }
  84 +}
  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.server.ota.software;
  17 +
  18 +/**
  19 + * SW Update State R
  20 + * 0: INITIAL Before downloading. (see 5.1.2.1)
  21 + * 1: DOWNLOAD STARTED The downloading process has started and is on-going. (see 5.1.2.2)
  22 + * 2: DOWNLOADED The package has been completely downloaded (see 5.1.2.3)
  23 + * 3: DELIVERED In that state, the package has been correctly downloaded and is ready to be installed. (see 5.1.2.4)
  24 + * If executing the Install Resource failed, the state remains at DELIVERED.
  25 + * If executing the Install Resource was successful, the state changes from DELIVERED to INSTALLED.
  26 + * After executing the UnInstall Resource, the state changes to INITIAL.
  27 + * 4: INSTALLED
  28 + */
  29 +public enum UpdateStateSw {
  30 + INITIAL(0, "Initial"),
  31 + DOWNLOAD_STARTED(1, "DownloadStarted"),
  32 + DOWNLOADED(2, "Downloaded"),
  33 + DELIVERED(3, "Delivered"),
  34 + INSTALLED(4, "Installed");
  35 +
  36 + public int code;
  37 + public String type;
  38 +
  39 + UpdateStateSw(int code, String type) {
  40 + this.code = code;
  41 + this.type = type;
  42 + }
  43 +
  44 + public static UpdateStateSw fromUpdateStateSwByType(String type) {
  45 + for (UpdateStateSw to : UpdateStateSw.values()) {
  46 + if (to.type.equals(type)) {
  47 + return to;
  48 + }
  49 + }
  50 + throw new IllegalArgumentException(String.format("Unsupported SW State type : %s", type));
  51 + }
  52 +
  53 + public static UpdateStateSw fromUpdateStateSwByCode(int code) {
  54 + for (UpdateStateSw to : UpdateStateSw.values()) {
  55 + if (to.code == code) {
  56 + return to;
  57 + }
  58 + }
  59 + throw new IllegalArgumentException(String.format("Unsupported SW State type : %s", code));
  60 + }
  61 +}
  62 +
@@ -16,20 +16,13 @@ @@ -16,20 +16,13 @@
16 package org.thingsboard.server.transport.lwm2m.server.store; 16 package org.thingsboard.server.transport.lwm2m.server.store;
17 17
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 -import org.eclipse.leshan.server.security.EditableSecurityStore;  
20 import org.eclipse.leshan.server.security.NonUniqueSecurityInfoException; 19 import org.eclipse.leshan.server.security.NonUniqueSecurityInfoException;
21 import org.eclipse.leshan.server.security.SecurityInfo; 20 import org.eclipse.leshan.server.security.SecurityInfo;
22 -import org.eclipse.leshan.server.security.SecurityStore;  
23 -import org.eclipse.leshan.server.security.SecurityStoreListener;  
24 import org.jetbrains.annotations.Nullable; 21 import org.jetbrains.annotations.Nullable;
25 -import org.springframework.stereotype.Component;  
26 -import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;  
27 import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator; 22 import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator;
28 import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo; 23 import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo;
29 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil;  
30 -import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;  
31 24
32 -import java.util.Collection; 25 +import static org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer.CLIENT;
33 26
34 @Slf4j 27 @Slf4j
35 public class TbLwM2mSecurityStore implements TbEditableSecurityStore { 28 public class TbLwM2mSecurityStore implements TbEditableSecurityStore {
@@ -67,7 +60,7 @@ public class TbLwM2mSecurityStore implements TbEditableSecurityStore { @@ -67,7 +60,7 @@ public class TbLwM2mSecurityStore implements TbEditableSecurityStore {
67 60
68 @Nullable 61 @Nullable
69 public SecurityInfo fetchAndPutSecurityInfo(String credentialsId) { 62 public SecurityInfo fetchAndPutSecurityInfo(String credentialsId) {
70 - TbLwM2MSecurityInfo securityInfo = validator.getEndpointSecurityInfoByCredentialsId(credentialsId, LwM2mTransportUtil.LwM2mTypeServer.CLIENT); 63 + TbLwM2MSecurityInfo securityInfo = validator.getEndpointSecurityInfoByCredentialsId(credentialsId, CLIENT);
71 try { 64 try {
72 if (securityInfo != null) { 65 if (securityInfo != null) {
73 securityStore.put(securityInfo); 66 securityStore.put(securityInfo);
@@ -52,8 +52,6 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; @@ -52,8 +52,6 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent;
52 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; 52 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
53 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; 53 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
54 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; 54 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
55 -import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy;  
56 -import org.thingsboard.server.transport.lwm2m.server.LwM2MSoftwareUpdateStrategy;  
57 import org.thingsboard.server.transport.lwm2m.server.LwM2mOtaConvert; 55 import org.thingsboard.server.transport.lwm2m.server.LwM2mOtaConvert;
58 import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest; 56 import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest;
59 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener; 57 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener;
@@ -83,6 +81,8 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttrib @@ -83,6 +81,8 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttrib
83 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest; 81 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest;
84 import org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService; 82 import org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService;
85 import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService; 83 import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService;
  84 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MFirmwareUpdateStrategy;
  85 +import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MSoftwareUpdateStrategy;
86 import org.thingsboard.server.transport.lwm2m.server.rpc.LwM2MRpcRequestHandler; 86 import org.thingsboard.server.transport.lwm2m.server.rpc.LwM2MRpcRequestHandler;
87 import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore; 87 import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore;
88 import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; 88 import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
@@ -105,18 +105,18 @@ import java.util.concurrent.TimeUnit; @@ -105,18 +105,18 @@ import java.util.concurrent.TimeUnit;
105 import java.util.stream.Collectors; 105 import java.util.stream.Collectors;
106 106
107 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; 107 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
108 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_3_VER_ID;  
109 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_5_VER_ID;  
110 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_DELIVERY_METHOD;  
111 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_NAME_ID;  
112 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_RESULT_ID;  
113 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_STATE_ID;  
114 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_ERROR; 108 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_ERROR;
115 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_INFO; 109 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_INFO;
116 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_WARN; 110 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_WARN;
117 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertObjectIdToVersionedId; 111 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertObjectIdToVersionedId;
118 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertOtaUpdateValueToString; 112 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertOtaUpdateValueToString;
119 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.fromVersionedIdToObjectId; 113 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.fromVersionedIdToObjectId;
  114 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_3_VER_ID;
  115 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_5_VER_ID;
  116 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_DELIVERY_METHOD;
  117 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_NAME_ID;
  118 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_RESULT_ID;
  119 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_STATE_ID;
120 120
121 121
122 @Slf4j 122 @Slf4j
  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.server.uplink;
  17 +
  18 +public enum LwM2mTypeServer {
  19 + BOOTSTRAP(0, "bootstrap"),
  20 + CLIENT(1, "client");
  21 +
  22 + public int code;
  23 + public String type;
  24 +
  25 + LwM2mTypeServer(int code, String type) {
  26 + this.code = code;
  27 + this.type = type;
  28 + }
  29 +
  30 + public static LwM2mTypeServer fromLwM2mTypeServer(String type) {
  31 + for (LwM2mTypeServer sm : LwM2mTypeServer.values()) {
  32 + if (sm.type.equals(type)) {
  33 + return sm;
  34 + }
  35 + }
  36 + throw new IllegalArgumentException(String.format("Unsupported typeServer type : %d", type));
  37 + }
  38 +}
  39 +