├── leshan-bs-server └── src │ └── main │ └── resources │ └── webapp │ └── index.html ├── eclipse └── settings │ ├── org.eclipse.core.runtime.prefs │ └── org.eclipse.core.resources.prefs ├── leshan-standalone └── src │ └── main │ ├── resources │ ├── webapp │ │ ├── img │ │ │ └── logo.png │ │ ├── vendor │ │ │ └── fonts │ │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ │ └── glyphicons-halflings-regular.woff │ │ ├── partials │ │ │ ├── resource-form.html │ │ │ ├── modal-instance.html │ │ │ ├── client-list.html │ │ │ ├── object.html │ │ │ └── instance.html │ │ └── js │ │ │ ├── ui-dialog-services.js │ │ │ ├── resource-form-directives.js │ │ │ ├── app.js │ │ │ └── modal-instance-controllers.js │ └── log4j2.xml │ └── java │ └── org │ └── eclipse │ └── leshan │ └── standalone │ └── servlet │ ├── log │ └── CoapMessageListener.java │ └── json │ ├── ResponseSerializer.java │ ├── ClientSerializer.java │ └── LwM2mNodeSerializer.java ├── .gitignore ├── docker └── Dockerfile ├── leshan-integration-tests └── src │ └── test │ ├── resources │ ├── logging.properties │ └── log4j2-test.xml │ └── java │ └── org │ └── eclipse │ └── leshan │ └── integration │ └── tests │ └── BootstrapTest.java ├── leshan-server-core └── src │ ├── main │ └── java │ │ └── org │ │ └── eclipse │ │ └── leshan │ │ └── server │ │ ├── Startable.java │ │ ├── Stoppable.java │ │ ├── Destroyable.java │ │ ├── request │ │ ├── RejectionException.java │ │ ├── RequestTimeoutException.java │ │ └── LwM2mRequestSender.java │ │ ├── observation │ │ ├── ObservationRegistryListener.java │ │ ├── ObservationListener.java │ │ └── Observation.java │ │ ├── bootstrap │ │ ├── BootstrapStore.java │ │ ├── SecurityMode.java │ │ ├── SmsSecurityMode.java │ │ └── LwM2mBootstrapServer.java │ │ ├── Version.java │ │ ├── security │ │ ├── SecurityStore.java │ │ ├── NonUniqueSecurityInfoException.java │ │ └── SecurityRegistry.java │ │ └── client │ │ └── ClientRegistryListener.java │ └── test │ └── java │ └── org │ └── eclipse │ └── leshan │ └── server │ ├── impl │ └── BasicTestSupport.java │ └── client │ └── ClientSortObjectTest.java ├── leshan-client └── src │ ├── main │ └── java │ │ └── org │ │ └── eclipse │ │ └── leshan │ │ └── client │ │ ├── resource │ │ ├── LinkFormattable.java │ │ ├── ClientObservable.java │ │ ├── LwM2mClientResourceDefinition.java │ │ ├── time │ │ │ ├── TimeLwM2mResource.java │ │ │ └── TimeLwM2mExchange.java │ │ ├── decimal │ │ │ ├── FloatLwM2mResource.java │ │ │ └── FloatLwM2mExchange.java │ │ ├── bool │ │ │ ├── BooleanLwM2mResource.java │ │ │ └── BooleanLwM2mExchange.java │ │ ├── opaque │ │ │ ├── OpaqueLwM2mResource.java │ │ │ └── OpaqueLwM2mExchange.java │ │ ├── string │ │ │ ├── StringLwM2mResource.java │ │ │ └── StringLwM2mExchange.java │ │ ├── integer │ │ │ ├── IntegerLwM2mResource.java │ │ │ └── IntegerLwM2mExchange.java │ │ ├── multiple │ │ │ └── MultipleLwM2mResource.java │ │ ├── LwM2mClientResource.java │ │ ├── ClientResourceBase.java │ │ ├── SingleResourceDefinition.java │ │ ├── MultipleResourceDefinition.java │ │ ├── LwM2mClientNode.java │ │ └── TypedLwM2mExchange.java │ │ ├── request │ │ ├── LwM2mIdentifierRequest.java │ │ ├── LwM2mContentRequest.java │ │ ├── identifier │ │ │ └── ClientIdentifier.java │ │ ├── LwM2mClientRequest.java │ │ ├── LwM2mClientRequestVisitor.java │ │ ├── LwM2mClientRequestSender.java │ │ ├── AbstractLwM2mClientRequest.java │ │ ├── BootstrapRequest.java │ │ ├── DeregisterRequest.java │ │ ├── AbstractRegisteredLwM2mClientRequest.java │ │ ├── RegisterRequest.java │ │ └── UpdateRequest.java │ │ ├── coap │ │ └── californium │ │ │ ├── Callback.java │ │ │ ├── CaliforniumBasedResource.java │ │ │ └── CaliforniumBasedLwM2mCallbackExchange.java │ │ ├── response │ │ ├── Callback.java │ │ ├── LwM2mResponse.java │ │ ├── ObserveResponse.java │ │ ├── DeleteResponse.java │ │ ├── ExecuteResponse.java │ │ ├── WriteResponse.java │ │ └── CreateResponse.java │ │ ├── californium │ │ └── impl │ │ │ └── CoapRequestVisitor.java │ │ ├── exchange │ │ ├── LwM2mCallbackExchange.java │ │ ├── LwM2mExchange.java │ │ ├── aggregate │ │ │ ├── LwM2mObjectInstanceReadResponseAggregator.java │ │ │ ├── LwM2mObjectReadResponseAggregator.java │ │ │ ├── LwM2mResponseAggregator.java │ │ │ ├── LwM2mObjectInstanceCreateResponseAggregator.java │ │ │ ├── AggregatedLwM2mExchange.java │ │ │ └── LwM2mReadResponseAggregator.java │ │ └── ForwardingLwM2mExchange.java │ │ ├── LwM2mClient.java │ │ └── util │ │ └── ResponseCallback.java │ └── test │ └── java │ ├── org │ └── eclipse │ │ └── leshan │ │ └── client │ │ ├── resource │ │ └── WriteResponseTest.java │ │ ├── response │ │ └── ResponseMatcher.java │ │ ├── util │ │ └── LinkFormatUtilsTest.java │ │ └── operation │ │ └── CreateResponseTest.java │ └── CaliforniumClientIdentifier │ └── CaliforniumClientIdentifierTest.java ├── leshan-core └── src │ ├── main │ └── java │ │ └── org │ │ └── eclipse │ │ └── leshan │ │ ├── core │ │ ├── request │ │ │ ├── LwM2mRequest.java │ │ │ ├── UplinkRequestVisitor.java │ │ │ ├── BindingMode.java │ │ │ ├── UplinkRequest.java │ │ │ ├── DownlinkRequestVisitor.java │ │ │ ├── DeregisterRequest.java │ │ │ ├── DownlinkRequest.java │ │ │ ├── AbstractDownlinkRequest.java │ │ │ ├── DeleteRequest.java │ │ │ ├── ContentFormat.java │ │ │ ├── ObserveRequest.java │ │ │ └── WriteAttributesRequest.java │ │ ├── response │ │ │ ├── ResponseConsumer.java │ │ │ ├── ExceptionConsumer.java │ │ │ ├── CreateResponse.java │ │ │ ├── LwM2mResponse.java │ │ │ ├── RegisterResponse.java │ │ │ ├── ValueResponse.java │ │ │ └── DiscoverResponse.java │ │ ├── node │ │ │ ├── LwM2mNodeVisitor.java │ │ │ ├── LwM2mNode.java │ │ │ └── codec │ │ │ │ └── InvalidValueException.java │ │ └── objectspec │ │ │ ├── json │ │ │ ├── ResourceSpecSerializer.java │ │ │ └── ObjectSpecSerializer.java │ │ │ ├── ObjectSpec.java │ │ │ └── ResourceSpec.java │ │ ├── tlv │ │ └── TlvException.java │ │ ├── ResponseCode.java │ │ └── util │ │ └── Charsets.java │ └── test │ └── java │ └── org │ └── eclipse │ └── leshan │ └── core │ └── node │ └── ValueTest.java ├── edl-v10 ├── leshan-server-cf └── src │ └── test │ └── java │ └── org │ └── eclipse │ └── leshan │ └── server │ └── californium │ └── impl │ └── CaliforniumTestSupport.java ├── about.html ├── CONTRIBUTING.md └── leshan-client-example └── pom.xml /leshan-bs-server/src/main/resources/webapp/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /eclipse/settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | line.separator=\n 3 | -------------------------------------------------------------------------------- /eclipse/settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b/leshan/master/leshan-standalone/src/main/resources/webapp/img/logo.png -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/vendor/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b/leshan/master/leshan-standalone/src/main/resources/webapp/vendor/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/vendor/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b/leshan/master/leshan-standalone/src/main/resources/webapp/vendor/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/vendor/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b/leshan/master/leshan-standalone/src/main/resources/webapp/vendor/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .classpath 3 | .project 4 | .settings 5 | target 6 | leshan-standalone/Californium.properties 7 | leshan-standalone/data 8 | leshan-bs-server/data 9 | Californium.properties 10 | bin/ 11 | # Package Files # 12 | *.jar 13 | *.war 14 | *.ear 15 | leshan-core/ddffiles 16 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:7.4 2 | MAINTAINER jvermillard@gmail.com 3 | 4 | RUN apt-get update 5 | RUN apt-get install -y openjdk-7-jre-headless wget 6 | 7 | RUN mkdir /opt/leshan 8 | RUN wget https://drone.io/github.com/jvermillard/leshan/files/leshan.jar -O /opt/leshan/leshan.jar 9 | ENTRYPOINT cd /opt/leshan && java -jar ./leshan.jar 10 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/partials/resource-form.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 |
8 |
-------------------------------------------------------------------------------- /leshan-integration-tests/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (c) 2013-2015 Sierra Wireless and others. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the Eclipse Public License v1.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.eclipse.org/legal/epl-v10.html 7 | # 8 | # Contributors: 9 | # Zebra Technologies - initial API and implementation 10 | ############################################################################### 11 | handlers = java.util.logging.ConsoleHandler 12 | .level = OFF -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/Startable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server; 17 | 18 | public interface Startable { 19 | 20 | void start(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/Stoppable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server; 17 | 18 | public interface Stoppable { 19 | 20 | void stop(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/LinkFormattable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | public interface LinkFormattable { 19 | 20 | String asLinkFormat(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/partials/modal-instance.html: -------------------------------------------------------------------------------- 1 | 4 | 16 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/java/org/eclipse/leshan/standalone/servlet/log/CoapMessageListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.standalone.servlet.log; 17 | 18 | public interface CoapMessageListener { 19 | 20 | void trace(CoapMessage message); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/LwM2mIdentifierRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | public interface LwM2mIdentifierRequest { 19 | 20 | public String getClientEndpointIdentifier(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/Destroyable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server; 17 | 18 | public interface Destroyable { 19 | 20 | /** Destroy the instances and frees all system resources. */ 21 | void destroy(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/coap/californium/Callback.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.coap.californium; 17 | 18 | public interface Callback { 19 | 20 | public void onSuccess(T t); 21 | 22 | public void onFailure(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/request/RejectionException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.request; 17 | 18 | public class RejectionException extends RuntimeException { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/LwM2mContentRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | import java.util.Map; 19 | 20 | public interface LwM2mContentRequest { 21 | 22 | public Map getClientParameters(); 23 | 24 | } -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/response/Callback.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | public interface Callback { 19 | public void onSuccess(OperationResponse response); 20 | 21 | public void onFailure(OperationResponse response); 22 | } 23 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/observation/ObservationRegistryListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.observation; 17 | 18 | public interface ObservationRegistryListener extends ObservationListener { 19 | void newObservation(Observation observation); 20 | } 21 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/partials/client-list.html: -------------------------------------------------------------------------------- 1 | 2 |

Connected clients: {{clients.length}}

3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
Client EndpointRegistration IDRegistration Date
{{client.endpoint}}{{client.registrationId}}{{client.registrationDate | date:'medium'}}
23 |
24 |
25 | 26 | 27 |
{{error}}
28 |
29 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/LwM2mRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.core.response.LwM2mResponse; 19 | 20 | /** 21 | * A Lightweight M2M request. 22 | */ 23 | public interface LwM2mRequest { 24 | } 25 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/identifier/ClientIdentifier.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request.identifier; 17 | 18 | import org.eclipse.leshan.client.californium.impl.CoapRequestVisitor; 19 | 20 | public interface ClientIdentifier extends CoapRequestVisitor { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/californium/impl/CoapRequestVisitor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.californium.impl; 17 | 18 | import org.eclipse.californium.core.coap.Request; 19 | 20 | public interface CoapRequestVisitor { 21 | 22 | public void accept(Request coapRequest); 23 | } 24 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/LwM2mClientRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | public interface LwM2mClientRequest { 19 | /** 20 | * Accept a visitor for this request. 21 | */ 22 | void accept(LwM2mClientRequestVisitor visitor); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/response/ResponseConsumer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.response; 17 | 18 | 19 | /** 20 | * Functional interface consuming a response to a LWM2M request 21 | */ 22 | public interface ResponseConsumer { 23 | 24 | void accept(T response); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/BootstrapStore.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.bootstrap; 17 | 18 | /** 19 | * A store containing the bootstrap information to be sent to the devices. 20 | */ 21 | public interface BootstrapStore { 22 | 23 | BootstrapConfig getBootstrap(String endpoint); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/LwM2mCallbackExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange; 17 | 18 | import org.eclipse.leshan.client.resource.LwM2mClientNode; 19 | 20 | public interface LwM2mCallbackExchange extends LwM2mExchange { 21 | 22 | void setNode(T node); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/ClientObservable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | import org.eclipse.californium.core.server.resources.CoapExchange; 19 | 20 | public interface ClientObservable { 21 | 22 | void createObservation(ClientObservable observable, CoapExchange exchange); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/LwM2mClientResourceDefinition.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | public interface LwM2mClientResourceDefinition { 19 | 20 | public int getId(); 21 | 22 | public boolean isRequired(); 23 | 24 | public LwM2mClientResource createResource(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/observation/ObservationListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.observation; 17 | 18 | import org.eclipse.leshan.core.node.LwM2mNode; 19 | 20 | public interface ObservationListener { 21 | 22 | void cancelled(Observation observation); 23 | 24 | void newValue(Observation observation, LwM2mNode value); 25 | } 26 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/SecurityMode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.bootstrap; 17 | 18 | /** 19 | * The different DTLS security modes 20 | */ 21 | public enum SecurityMode { 22 | PSK(0), RPK(1), X509(2), NO_SEC(3); 23 | 24 | public final int code; 25 | 26 | private SecurityMode(int code) { 27 | this.code = code; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/js/ui-dialog-services.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | 17 | var myModule = angular.module('uiDialogServices', []); 18 | 19 | myModule.factory('dialog', function() { 20 | var serviceInstance = {}; 21 | 22 | serviceInstance.open = function (message) { 23 | $('#messageModalLabel').text(message); 24 | $('#messageModal').modal('show'); 25 | } 26 | return serviceInstance; 27 | }); -------------------------------------------------------------------------------- /leshan-integration-tests/src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/node/LwM2mNodeVisitor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.node; 17 | 18 | /** 19 | * A visitor to visit an object, an object instance, or a resource. 20 | */ 21 | public interface LwM2mNodeVisitor { 22 | 23 | void visit(LwM2mObject object); 24 | 25 | void visit(LwM2mObjectInstance instance); 26 | 27 | void visit(LwM2mResource resource); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/LwM2mClientRequestVisitor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | public interface LwM2mClientRequestVisitor { 19 | void visit(RegisterRequest request); 20 | 21 | void visit(DeregisterRequest request); 22 | 23 | void visit(UpdateRequest updateRequest); 24 | 25 | void visit(BootstrapRequest bootstrapRequest); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/response/ExceptionConsumer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.response; 17 | 18 | /** 19 | * Functional interface receiving errors produced by a LWM2M request 20 | */ 21 | public interface ExceptionConsumer { 22 | 23 | /** 24 | * Called when a exception occurs during a request 25 | * @param e the produced exception 26 | */ 27 | void accept(Exception e); 28 | } 29 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/tlv/TlvException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.tlv; 17 | 18 | public class TlvException extends Exception { 19 | 20 | public TlvException(String message) { 21 | super(message); 22 | } 23 | 24 | public TlvException(String message, Exception cause) { 25 | super(message, cause); 26 | } 27 | 28 | private static final long serialVersionUID = 9017593873541376092L; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/SmsSecurityMode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.bootstrap; 17 | 18 | /** 19 | * The different SMS security modes 20 | */ 21 | public enum SmsSecurityMode { 22 | RESERVED(0), SPS_DEVICE(1), SPS_SMARTCARD(2), NO_SEC(3), PROPRIETARY(255); 23 | 24 | public final int code; 25 | 26 | private SmsSecurityMode(int code) { 27 | this.code = code; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/response/LwM2mResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | import org.eclipse.leshan.tlv.Tlv; 20 | 21 | public interface LwM2mResponse { 22 | 23 | public ResponseCode getCode(); 24 | 25 | public byte[] getResponsePayload(); 26 | 27 | public boolean isSuccess(); 28 | 29 | Tlv getResponsePayloadAsTlv(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/UplinkRequestVisitor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | /** 19 | * A visitor to visit an Uplink Lightweight M2M request. 20 | */ 21 | public interface UplinkRequestVisitor { 22 | void visit(RegisterRequest request); 23 | 24 | void visit(UpdateRequest request); 25 | 26 | void visit(DeregisterRequest request); 27 | 28 | // void visit(BootstrapRequest request); 29 | } 30 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/node/LwM2mNode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.node; 17 | 18 | /** 19 | * A node in the LWM2M resource tree: Objects, Object instances and Resources. 20 | */ 21 | public interface LwM2mNode { 22 | 23 | /** 24 | * @return the node identifier 25 | */ 26 | int getId(); 27 | 28 | /** 29 | * Accept a visitor for this node. 30 | */ 31 | void accept(LwM2mNodeVisitor visitor); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/LwM2mClientRequestSender.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | import org.eclipse.leshan.client.response.OperationResponse; 19 | import org.eclipse.leshan.client.util.ResponseCallback; 20 | 21 | public interface LwM2mClientRequestSender { 22 | OperationResponse send(LwM2mClientRequest request); 23 | 24 | void send(LwM2mClientRequest request, ResponseCallback responseCallback); 25 | } 26 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/BindingMode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | /** 19 | * Transport binding and Queue Mode 20 | */ 21 | public enum BindingMode { 22 | 23 | /** UDP */ 24 | U, 25 | 26 | /** UDP with Queue Mode */ 27 | UQ, 28 | 29 | /** SMS */ 30 | S, 31 | 32 | /** SMS with Queue Mode */ 33 | SQ, 34 | 35 | /** UDP and SMS */ 36 | US, 37 | 38 | /** UDP with Queue Mode and SMS */ 39 | UQS 40 | } 41 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/UplinkRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.core.response.LwM2mResponse; 19 | 20 | /** 21 | * A Uplink Lightweight M2M request.
22 | * This is a request sent from client to server. 23 | */ 24 | public interface UplinkRequest extends LwM2mRequest { 25 | 26 | /** 27 | * Accept a visitor for this request. 28 | */ 29 | void accept(UplinkRequestVisitor visitor); 30 | } 31 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/time/TimeLwM2mResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.time; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.BaseTypedLwM2mResource; 20 | 21 | public class TimeLwM2mResource extends BaseTypedLwM2mResource { 22 | 23 | @Override 24 | protected TimeLwM2mExchange createSpecificExchange(final LwM2mExchange exchange) { 25 | return new TimeLwM2mExchange(exchange); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/response/ObserveResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | 20 | public class ObserveResponse extends BaseLwM2mResponse { 21 | 22 | private ObserveResponse(final ResponseCode code, final byte[] payload) { 23 | super(code, payload); 24 | } 25 | 26 | public static ObserveResponse notifyWithContent(final byte[] payload) { 27 | return new ObserveResponse(ResponseCode.CHANGED, payload); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/decimal/FloatLwM2mResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.decimal; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.BaseTypedLwM2mResource; 20 | 21 | public class FloatLwM2mResource extends BaseTypedLwM2mResource { 22 | 23 | @Override 24 | protected FloatLwM2mExchange createSpecificExchange(final LwM2mExchange exchange) { 25 | return new FloatLwM2mExchange(exchange); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/bool/BooleanLwM2mResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.bool; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.BaseTypedLwM2mResource; 20 | 21 | public class BooleanLwM2mResource extends BaseTypedLwM2mResource { 22 | 23 | @Override 24 | protected BooleanLwM2mExchange createSpecificExchange(final LwM2mExchange exchange) { 25 | return new BooleanLwM2mExchange(exchange); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/opaque/OpaqueLwM2mResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.opaque; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.BaseTypedLwM2mResource; 20 | 21 | public class OpaqueLwM2mResource extends BaseTypedLwM2mResource { 22 | 23 | @Override 24 | protected OpaqueLwM2mExchange createSpecificExchange(final LwM2mExchange exchange) { 25 | return new OpaqueLwM2mExchange(exchange); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/string/StringLwM2mResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.string; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.BaseTypedLwM2mResource; 20 | 21 | public class StringLwM2mResource extends BaseTypedLwM2mResource { 22 | 23 | @Override 24 | protected StringLwM2mExchange createSpecificExchange(final LwM2mExchange exchange) { 25 | return new StringLwM2mExchange(exchange); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/integer/IntegerLwM2mResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.integer; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.BaseTypedLwM2mResource; 20 | 21 | public class IntegerLwM2mResource extends BaseTypedLwM2mResource { 22 | 23 | @Override 24 | protected IntegerLwM2mExchange createSpecificExchange(final LwM2mExchange exchange) { 25 | return new IntegerLwM2mExchange(exchange); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/multiple/MultipleLwM2mResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.multiple; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.BaseTypedLwM2mResource; 20 | 21 | public class MultipleLwM2mResource extends BaseTypedLwM2mResource { 22 | 23 | @Override 24 | protected MultipleLwM2mExchange createSpecificExchange(final LwM2mExchange exchange) { 25 | return new MultipleLwM2mExchange(exchange); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/LwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange; 17 | 18 | import org.eclipse.leshan.ObserveSpec; 19 | import org.eclipse.leshan.client.response.LwM2mResponse; 20 | 21 | public interface LwM2mExchange { 22 | 23 | public void respond(LwM2mResponse response); 24 | 25 | public byte[] getRequestPayload(); 26 | 27 | public boolean hasObjectInstanceId(); 28 | 29 | public int getObjectInstanceId(); 30 | 31 | public boolean isObserve(); 32 | 33 | public ObserveSpec getObserveSpec(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/Version.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server; 17 | 18 | public class Version { 19 | public static String value; 20 | 21 | public final static String getValue(){ 22 | if (value == null) 23 | { 24 | Package p = Version.class.getPackage(); 25 | String version = p.getImplementationVersion(); 26 | if (version != null) 27 | value = version; 28 | else 29 | value = "unknown"; 30 | } 31 | return value; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/partials/object.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 |
{{object.name}}
6 |
{{object.path}} 7 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | 24 |
25 |
26 |
27 | 28 |
29 |
-------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/LwM2mClientResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | 20 | public abstract class LwM2mClientResource extends LwM2mClientNode { 21 | 22 | @Override 23 | public abstract void read(LwM2mExchange exchange); 24 | 25 | public abstract void write(LwM2mExchange exchange); 26 | 27 | public abstract void execute(LwM2mExchange exchange); 28 | 29 | public abstract boolean isReadable(); 30 | 31 | public abstract void notifyResourceUpdated(); 32 | } 33 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/AbstractLwM2mClientRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | public abstract class AbstractLwM2mClientRequest implements LwM2mClientRequest { 19 | protected static final long DEFAULT_TIMEOUT_MS = 500; 20 | 21 | private final long timeout; 22 | 23 | public AbstractLwM2mClientRequest() { 24 | this(DEFAULT_TIMEOUT_MS); 25 | } 26 | 27 | public AbstractLwM2mClientRequest(final long timeout) { 28 | this.timeout = timeout; 29 | } 30 | 31 | public final long getTimeout() { 32 | return timeout; 33 | } 34 | } -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/response/DeleteResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | 20 | public class DeleteResponse extends BaseLwM2mResponse { 21 | 22 | private DeleteResponse(final ResponseCode code) { 23 | super(code, new byte[0]); 24 | } 25 | 26 | public static DeleteResponse success() { 27 | return new DeleteResponse(ResponseCode.DELETED); 28 | } 29 | 30 | public static DeleteResponse notAllowed() { 31 | return new DeleteResponse(ResponseCode.METHOD_NOT_ALLOWED); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/ClientResourceBase.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | import org.eclipse.californium.core.CoapResource; 19 | 20 | public abstract class ClientResourceBase extends CoapResource implements LinkFormattable, ClientObservable { 21 | protected static final int IS_OBSERVE = 0; 22 | 23 | public ClientResourceBase(final Integer id) { 24 | super(Integer.toString(id)); 25 | setObservable(true); 26 | } 27 | 28 | @Override 29 | public void notifyObserverRelations() { 30 | super.notifyObserverRelations(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/request/RequestTimeoutException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.request; 17 | 18 | public class RequestTimeoutException extends ResourceAccessException { 19 | 20 | private static final long serialVersionUID = -6372006578730743741L; 21 | 22 | /** 23 | * @param uri the resource URI accessed 24 | * @param timeout the number of milliseconds after which the request has timed out 25 | */ 26 | public RequestTimeoutException(String uri, long timeout) { 27 | super(null, uri, String.format("Request timed out after %d milliseconds", timeout)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/DownlinkRequestVisitor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | /** 19 | * A visitor to visit a Downlink Lightweight M2M request. 20 | */ 21 | public interface DownlinkRequestVisitor { 22 | void visit(ReadRequest request); 23 | 24 | void visit(DiscoverRequest request); 25 | 26 | void visit(WriteRequest request); 27 | 28 | void visit(WriteAttributesRequest request); 29 | 30 | void visit(ExecuteRequest request); 31 | 32 | void visit(CreateRequest request); 33 | 34 | void visit(DeleteRequest request); 35 | 36 | void visit(ObserveRequest request); 37 | } 38 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/DeregisterRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.core.response.LwM2mResponse; 19 | 20 | public class DeregisterRequest implements UplinkRequest { 21 | 22 | private String registrationID = null; 23 | 24 | public DeregisterRequest(String registrationID) { 25 | this.registrationID = registrationID; 26 | } 27 | 28 | public String getRegistrationID() { 29 | return registrationID; 30 | } 31 | 32 | @Override 33 | public void accept(UplinkRequestVisitor visitor) { 34 | visitor.visit(this); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/LwM2mClient.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client; 17 | 18 | import org.eclipse.leshan.LinkObject; 19 | import org.eclipse.leshan.client.request.LwM2mClientRequest; 20 | import org.eclipse.leshan.client.response.OperationResponse; 21 | import org.eclipse.leshan.client.util.ResponseCallback; 22 | 23 | public interface LwM2mClient { 24 | 25 | public void start(); 26 | 27 | public void stop(); 28 | 29 | public OperationResponse send(LwM2mClientRequest request); 30 | 31 | public void send(LwM2mClientRequest request, ResponseCallback callback); 32 | 33 | public LinkObject[] getObjectModel(Integer... ids); 34 | 35 | } -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/BootstrapRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | public class BootstrapRequest extends AbstractLwM2mClientRequest implements LwM2mIdentifierRequest { 19 | private final String clientEndpointIdentifier; 20 | 21 | public BootstrapRequest(final String clientEndpointIdentifier) { 22 | this.clientEndpointIdentifier = clientEndpointIdentifier; 23 | } 24 | 25 | @Override 26 | public void accept(final LwM2mClientRequestVisitor visitor) { 27 | visitor.visit(this); 28 | } 29 | 30 | @Override 31 | public String getClientEndpointIdentifier() { 32 | return clientEndpointIdentifier; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/DeregisterRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | import org.eclipse.leshan.client.request.identifier.ClientIdentifier; 19 | 20 | public class DeregisterRequest extends AbstractRegisteredLwM2mClientRequest { 21 | 22 | public DeregisterRequest(final ClientIdentifier clientIdentifier) { 23 | super(clientIdentifier); 24 | } 25 | 26 | public DeregisterRequest(final ClientIdentifier clientIdentifier, final long timeout) { 27 | super(clientIdentifier, timeout); 28 | } 29 | 30 | @Override 31 | public void accept(final LwM2mClientRequestVisitor visitor) { 32 | visitor.visit(this); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/opaque/OpaqueLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.opaque; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.TypedLwM2mExchange; 20 | 21 | public class OpaqueLwM2mExchange extends TypedLwM2mExchange { 22 | 23 | public OpaqueLwM2mExchange(final LwM2mExchange exchange) { 24 | super(exchange); 25 | } 26 | 27 | @Override 28 | protected byte[] convertFromBytes(final byte[] value) { 29 | return value; 30 | } 31 | 32 | @Override 33 | protected byte[] convertToBytes(final byte[] value) { 34 | return value; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/string/StringLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.string; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.TypedLwM2mExchange; 20 | 21 | public class StringLwM2mExchange extends TypedLwM2mExchange { 22 | 23 | public StringLwM2mExchange(final LwM2mExchange exchange) { 24 | super(exchange); 25 | } 26 | 27 | @Override 28 | protected String convertFromBytes(final byte[] value) { 29 | return new String(value); 30 | } 31 | 32 | @Override 33 | protected byte[] convertToBytes(final String value) { 34 | return value.getBytes(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/response/CreateResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | 20 | public class CreateResponse extends LwM2mResponse { 21 | 22 | private String location; 23 | 24 | public CreateResponse(ResponseCode code) { 25 | super(code); 26 | } 27 | 28 | public CreateResponse(ResponseCode code, String location) { 29 | super(code); 30 | this.location = location; 31 | } 32 | 33 | public String getLocation() { 34 | return location; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return String.format("CreateResponse [location=%s, code=%s]", location, code); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/decimal/FloatLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.decimal; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.TypedLwM2mExchange; 20 | 21 | public class FloatLwM2mExchange extends TypedLwM2mExchange { 22 | 23 | public FloatLwM2mExchange(final LwM2mExchange exchange) { 24 | super(exchange); 25 | } 26 | 27 | @Override 28 | protected Float convertFromBytes(final byte[] value) { 29 | return Float.parseFloat(new String(value)); 30 | } 31 | 32 | @Override 33 | protected byte[] convertToBytes(final Float value) { 34 | return Float.toString(value).getBytes(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/DownlinkRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.core.node.LwM2mPath; 19 | import org.eclipse.leshan.core.response.LwM2mResponse; 20 | 21 | /** 22 | * A Downlink Lightweight M2M request.
23 | * This is a request sent from server to client to interact with the client resource tree. 24 | */ 25 | public interface DownlinkRequest extends LwM2mRequest { 26 | 27 | /** 28 | * Gets the requested resource path. 29 | * 30 | * @return the request path 31 | */ 32 | LwM2mPath getPath(); 33 | 34 | /** 35 | * Accept a visitor for this request. 36 | */ 37 | void accept(DownlinkRequestVisitor visitor); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/integer/IntegerLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.integer; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.TypedLwM2mExchange; 20 | 21 | public class IntegerLwM2mExchange extends TypedLwM2mExchange { 22 | 23 | public IntegerLwM2mExchange(final LwM2mExchange exchange) { 24 | super(exchange); 25 | } 26 | 27 | @Override 28 | protected Integer convertFromBytes(final byte[] value) { 29 | return Integer.parseInt(new String(value)); 30 | } 31 | 32 | @Override 33 | protected byte[] convertToBytes(final Integer value) { 34 | return Integer.toString(value).getBytes(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | 17 | package org.eclipse.leshan.integration.tests; 18 | 19 | import static org.junit.Assert.assertTrue; 20 | 21 | import org.eclipse.leshan.client.response.OperationResponse; 22 | import org.junit.After; 23 | import org.junit.Ignore; 24 | import org.junit.Test; 25 | 26 | public class BootstrapTest { 27 | 28 | private final IntegrationTestHelper helper = new IntegrationTestHelper(true); 29 | 30 | @After 31 | public void stop() { 32 | helper.stop(); 33 | } 34 | 35 | @Ignore 36 | @Test 37 | public void boostrap_device_exists() { 38 | final OperationResponse bootstrap = helper.bootstrap(); 39 | 40 | assertTrue(bootstrap.isSuccess()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/security/SecurityStore.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.security; 17 | 18 | /** 19 | * A store for {@link SecurityInfo}. 20 | */ 21 | public interface SecurityStore { 22 | 23 | /** 24 | * Returns the security information for a given end-point. 25 | * 26 | * @param endpoint the client end-point 27 | * @return the security information of null if not found. 28 | */ 29 | SecurityInfo getByEndpoint(String endpoint); 30 | 31 | /** 32 | * Returns the security information for a identity. 33 | * 34 | * @param identity of the client 35 | * @return the security information of null if not found. 36 | */ 37 | SecurityInfo getByIdentity(String Identity); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /leshan-client/src/test/java/org/eclipse/leshan/client/resource/WriteResponseTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import org.eclipse.leshan.ResponseCode; 21 | import org.eclipse.leshan.client.response.WriteResponse; 22 | import org.junit.Test; 23 | 24 | public class WriteResponseTest { 25 | 26 | @Test 27 | public void canCreateSuccessfulResponse() { 28 | final WriteResponse response = WriteResponse.success(); 29 | assertEquals(ResponseCode.CHANGED, response.getCode()); 30 | } 31 | 32 | @Test 33 | public void canCreateFailureResponse() { 34 | final WriteResponse response = WriteResponse.failure(); 35 | assertEquals(ResponseCode.BAD_REQUEST, response.getCode()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/LwM2mBootstrapServer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.bootstrap; 17 | 18 | import org.eclipse.leshan.server.security.SecurityStore; 19 | 20 | /** 21 | * 22 | * A Lightweight M2M server in charge of handling device bootstrap on the /bs resource. 23 | * 24 | */ 25 | public interface LwM2mBootstrapServer { 26 | 27 | /** 28 | * Access to the bootstrap configuration store. It's used for sending configuration to the devices initiating a 29 | * bootstrap. 30 | */ 31 | BootstrapStore getBoostrapStore(); 32 | 33 | /** 34 | * security store used for DTLS authentication on the bootstrap ressource. 35 | */ 36 | SecurityStore getSecurityStore(); 37 | 38 | void start(); 39 | 40 | void stop(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /edl-v10: -------------------------------------------------------------------------------- 1 | Eclipse Distribution License - v 1.0 2 | 3 | Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 8 | 9 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/client/ClientRegistryListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.client; 17 | 18 | /** 19 | * Listen for client registration events. 20 | */ 21 | public interface ClientRegistryListener { 22 | 23 | /** 24 | * Invoked when a new client has been registered on the server. 25 | * 26 | * @param client 27 | */ 28 | void registered(Client client); 29 | 30 | /** 31 | * Invoked when a client has been updated. 32 | * 33 | * @param clientUpdated the client after the update 34 | */ 35 | void updated(Client clientUpdated); 36 | 37 | /** 38 | * Invoked when a new client has been unregistered from the server. 39 | * 40 | * @param client 41 | */ 42 | void unregistered(Client client); 43 | } 44 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/response/ExecuteResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | 20 | public class ExecuteResponse extends BaseLwM2mResponse { 21 | 22 | private ExecuteResponse(final ResponseCode code) { 23 | super(code, new byte[0]); 24 | } 25 | 26 | public static ExecuteResponse success() { 27 | return new ExecuteResponse(ResponseCode.CHANGED); 28 | } 29 | 30 | // TODO Evaluate whether this needs to be used 31 | public static ExecuteResponse failure() { 32 | return new ExecuteResponse(ResponseCode.METHOD_NOT_ALLOWED); 33 | } 34 | 35 | public static ExecuteResponse notAllowed() { 36 | return new ExecuteResponse(ResponseCode.METHOD_NOT_ALLOWED); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/response/LwM2mResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | import org.eclipse.leshan.util.Validate; 20 | 21 | /** 22 | * A response to a server request. 23 | */ 24 | public class LwM2mResponse { 25 | 26 | protected final ResponseCode code; 27 | 28 | public LwM2mResponse(final ResponseCode code) { 29 | Validate.notNull(code); 30 | this.code = code; 31 | } 32 | 33 | /** 34 | * Gets the response code. 35 | * 36 | * @return the code 37 | */ 38 | public final ResponseCode getCode() { 39 | return this.code; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return String.format("LwM2mResponse [code=%s]", code); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/InvalidValueException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.node.codec; 17 | 18 | import org.eclipse.leshan.core.node.LwM2mPath; 19 | 20 | public class InvalidValueException extends Exception { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | private final LwM2mPath path; 25 | 26 | public InvalidValueException(String message, LwM2mPath path) { 27 | super(message); 28 | this.path = path; 29 | } 30 | 31 | public InvalidValueException(String message, LwM2mPath path, Exception e) { 32 | super(message, e); 33 | this.path = path; 34 | } 35 | 36 | /** 37 | * @return the path of the resource with an invalid value 38 | */ 39 | public LwM2mPath getPath() { 40 | return path; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /leshan-client/src/test/java/CaliforniumClientIdentifier/CaliforniumClientIdentifierTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package CaliforniumClientIdentifier; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import org.eclipse.leshan.client.californium.impl.CaliforniumClientIdentifier; 21 | import org.junit.Test; 22 | 23 | public class CaliforniumClientIdentifierTest { 24 | 25 | @Test 26 | public void two_instances_are_equal() { 27 | String oneLocation = "/rd/something"; 28 | String oneEndpoint = "dfasdfs"; 29 | CaliforniumClientIdentifier idOne = new CaliforniumClientIdentifier(oneLocation, oneEndpoint); 30 | CaliforniumClientIdentifier idTwo = new CaliforniumClientIdentifier(oneLocation, oneEndpoint); 31 | 32 | assertEquals(idOne, idTwo); 33 | assertEquals(idOne.hashCode(), idTwo.hashCode()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/ResponseCode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan; 17 | 18 | /** 19 | * Response codes defined for LWM2M enabler 20 | */ 21 | public enum ResponseCode { 22 | /** Resource correctly created */ 23 | CREATED, 24 | /** Resource correctly deleted */ 25 | DELETED, 26 | /** Resource correctly changed */ 27 | CHANGED, 28 | /** Content correctly delivered */ 29 | CONTENT, 30 | /** Operation not authorized */ 31 | UNAUTHORIZED, 32 | /** Cannot fulfill the request, it's incorrect */ 33 | BAD_REQUEST, 34 | /** This method (GET/PUT/POST/DELETE) is not allowed on this resource */ 35 | METHOD_NOT_ALLOWED, 36 | /** The End-point Client Name results in a duplicate entry on the LWM2M Server */ 37 | FORBIDDEN, 38 | /** Resource not found */ 39 | NOT_FOUND; 40 | } 41 | -------------------------------------------------------------------------------- /leshan-server-core/src/test/java/org/eclipse/leshan/server/impl/BasicTestSupport.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.impl; 17 | 18 | import java.net.InetAddress; 19 | import java.net.InetSocketAddress; 20 | import java.net.UnknownHostException; 21 | 22 | import org.eclipse.leshan.server.client.Client; 23 | 24 | public class BasicTestSupport { 25 | 26 | public Client client; 27 | public InetAddress destination; 28 | public int destinationPort = 5000; 29 | public InetSocketAddress registrationAddress; 30 | 31 | public void givenASimpleClient() throws UnknownHostException { 32 | registrationAddress = InetSocketAddress.createUnresolved("localhost", 5683); 33 | client = new Client("ID", "urn:client", InetAddress.getLocalHost(), 10000, "1.0", 10000L, null, null, null, 34 | registrationAddress); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/aggregate/LwM2mObjectInstanceReadResponseAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange.aggregate; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.response.LwM2mResponse; 20 | import org.eclipse.leshan.tlv.Tlv; 21 | 22 | public class LwM2mObjectInstanceReadResponseAggregator extends LwM2mReadResponseAggregator { 23 | 24 | public LwM2mObjectInstanceReadResponseAggregator(final LwM2mExchange exchange, final int numExpectedResults) { 25 | super(exchange, numExpectedResults); 26 | } 27 | 28 | @Override 29 | protected Tlv createTlv(final int id, final LwM2mResponse response) { 30 | Tlv result = response.getResponsePayloadAsTlv(); 31 | result.setIdentifier(id); 32 | return result; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/response/WriteResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | 20 | public class WriteResponse extends BaseLwM2mResponse { 21 | 22 | private WriteResponse(final ResponseCode code) { 23 | super(code, new byte[0]); 24 | } 25 | 26 | public static WriteResponse success() { 27 | return new WriteResponse(ResponseCode.CHANGED); 28 | } 29 | 30 | public static WriteResponse failure() { 31 | return new WriteResponse(ResponseCode.BAD_REQUEST); 32 | } 33 | 34 | public static WriteResponse notAllowed() { 35 | return new WriteResponse(ResponseCode.METHOD_NOT_ALLOWED); 36 | } 37 | 38 | public static WriteResponse badRequest() { 39 | return new WriteResponse(ResponseCode.BAD_REQUEST); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/AbstractRegisteredLwM2mClientRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | import org.eclipse.leshan.client.request.identifier.ClientIdentifier; 19 | 20 | public abstract class AbstractRegisteredLwM2mClientRequest extends AbstractLwM2mClientRequest { 21 | 22 | protected final ClientIdentifier clientIdentifier; 23 | 24 | public AbstractRegisteredLwM2mClientRequest(final ClientIdentifier clientIdentifier, final long timeout) { 25 | super(timeout); 26 | this.clientIdentifier = clientIdentifier; 27 | } 28 | 29 | public AbstractRegisteredLwM2mClientRequest(final ClientIdentifier clientIdentifier) { 30 | this(clientIdentifier, DEFAULT_TIMEOUT_MS); 31 | } 32 | 33 | public ClientIdentifier getClientIdentifier() { 34 | return clientIdentifier; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CaliforniumTestSupport.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.californium.impl; 17 | 18 | import java.net.InetAddress; 19 | import java.net.InetSocketAddress; 20 | import java.net.UnknownHostException; 21 | 22 | import org.eclipse.leshan.server.client.Client; 23 | 24 | public class CaliforniumTestSupport { 25 | 26 | public Client client; 27 | public InetAddress destination; 28 | public int destinationPort = 5000; 29 | public InetSocketAddress registrationAddress; 30 | 31 | public void givenASimpleClient() throws UnknownHostException { 32 | registrationAddress = InetSocketAddress.createUnresolved("localhost", 5683); 33 | client = new Client("ID", "urn:client", InetAddress.getLocalHost(), 10000, "1.0", 10000L, null, null, null, 34 | registrationAddress); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/js/resource-form-directives.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | 17 | angular.module('resourceFormDirectives', []) 18 | 19 | .directive('resourceform', function ($compile, $routeParams, $http, dialog,$filter) { 20 | return { 21 | restrict: "E", 22 | replace: true, 23 | scope: { 24 | resource: '=', 25 | parent: '=' 26 | }, 27 | templateUrl: "partials/resource-form.html", 28 | link: function (scope, element, attrs) { 29 | scope.writable = function() { 30 | if(scope.resource.def.instancetype != "multiple") { 31 | if(scope.resource.def.hasOwnProperty("operations")) { 32 | return scope.resource.def.operations.indexOf("W") != -1; 33 | } 34 | } 35 | return false; 36 | } 37 | } 38 | } 39 | }); -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/SingleResourceDefinition.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | public class SingleResourceDefinition implements LwM2mClientResourceDefinition { 19 | 20 | private final int id; 21 | private final LwM2mClientResource resource; 22 | private final boolean required; 23 | 24 | public SingleResourceDefinition(final int id, final LwM2mClientResource resource, final boolean required) { 25 | this.id = id; 26 | this.resource = resource; 27 | this.required = required; 28 | } 29 | 30 | @Override 31 | public int getId() { 32 | return id; 33 | } 34 | 35 | @Override 36 | public LwM2mClientResource createResource() { 37 | return resource; 38 | } 39 | 40 | @Override 41 | public boolean isRequired() { 42 | return required; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/security/NonUniqueSecurityInfoException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.security; 17 | 18 | public class NonUniqueSecurityInfoException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * Constructs a {@code NonUniqueSecurityInfoException} with the specified message and root cause. 24 | * 25 | * @param msg the detail message 26 | * @param t the root cause 27 | */ 28 | public NonUniqueSecurityInfoException(String msg, Throwable t) { 29 | super(msg, t); 30 | } 31 | 32 | /** 33 | * Constructs a {@code NonUniqueSecurityInfoException} with the specified message and no root cause. 34 | * 35 | * @param msg the detail message 36 | */ 37 | public NonUniqueSecurityInfoException(String msg) { 38 | super(msg); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/AbstractDownlinkRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.core.node.LwM2mPath; 19 | import org.eclipse.leshan.core.response.LwM2mResponse; 20 | import org.eclipse.leshan.util.Validate; 21 | 22 | /** 23 | * A base class for concrete LWM2M Downlink request types. 24 | * 25 | * Provides generic support for specifying the target client and the resource path. 26 | */ 27 | public abstract class AbstractDownlinkRequest implements DownlinkRequest { 28 | 29 | private final LwM2mPath path; 30 | 31 | protected AbstractDownlinkRequest(final LwM2mPath path) { 32 | Validate.notNull(path); 33 | this.path = path; 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public LwM2mPath getPath() { 41 | return this.path; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/response/RegisterResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | 20 | /** 21 | * Response to a client registration request 22 | */ 23 | public class RegisterResponse extends LwM2mResponse { 24 | 25 | private final String registrationID; 26 | 27 | public RegisterResponse(ResponseCode code) { 28 | super(code); 29 | this.registrationID = null; 30 | } 31 | 32 | public RegisterResponse(ResponseCode code, String registrationID) { 33 | super(code); 34 | this.registrationID = registrationID; 35 | } 36 | 37 | public String getRegistrationID() { 38 | return registrationID; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return String.format("RegisterResponse [registrationID=%s, code=%s]", registrationID, code); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | About 5 | 6 | 7 |

About This Content

8 | 9 |

December 9, 2013

10 |

License

11 | 12 |

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise 13 | indicated below, the Content is provided to you under the terms and conditions of the 14 | Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL"). 15 | A copy of the EPL is available at 16 | http://www.eclipse.org/legal/epl-v10.html 17 | and a copy of the EDL is available at 18 | http://www.eclipse.org/org/documents/edl-v10.php. 19 | For purposes of the EPL, "Program" will mean the Content.

20 | 21 |

If you did not receive this Content directly from the Eclipse Foundation, the Content is 22 | being redistributed by another party ("Redistributor") and different terms and conditions may 23 | apply to your use of any object code in the Content. Check the Redistributor's license that was 24 | provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise 25 | indicated below, the terms and conditions of the EPL still apply to any source code in the Content 26 | and such source code may be obtained at http://www.eclipse.org.

27 | 28 | 29 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/request/LwM2mRequestSender.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.request; 17 | 18 | import org.eclipse.leshan.core.request.DownlinkRequest; 19 | import org.eclipse.leshan.core.response.ExceptionConsumer; 20 | import org.eclipse.leshan.core.response.LwM2mResponse; 21 | import org.eclipse.leshan.core.response.ResponseConsumer; 22 | import org.eclipse.leshan.server.client.Client; 23 | 24 | public interface LwM2mRequestSender { 25 | /** 26 | * Send a Lightweight M2M request synchronously. Will block until a response is received from the remote client. 27 | */ 28 | T send(Client destination, DownlinkRequest request); 29 | 30 | /** 31 | * Send a Lightweight M2M request asynchronously. 32 | */ 33 | void send(Client destination, DownlinkRequest request, 34 | ResponseConsumer responseCallback, ExceptionConsumer errorCallback); 35 | } 36 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/time/TimeLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.time; 17 | 18 | import java.util.Date; 19 | 20 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 21 | import org.eclipse.leshan.client.resource.TypedLwM2mExchange; 22 | 23 | public class TimeLwM2mExchange extends TypedLwM2mExchange { 24 | 25 | public TimeLwM2mExchange(final LwM2mExchange exchange) { 26 | super(exchange); 27 | } 28 | 29 | @Override 30 | protected Date convertFromBytes(final byte[] value) { 31 | final int secondsSinceEpoch = Integer.parseInt(new String(value)); 32 | final long millisSinceEpoch = secondsSinceEpoch * 1000L; 33 | return new Date(millisSinceEpoch); 34 | } 35 | 36 | @Override 37 | protected byte[] convertToBytes(final Date value) { 38 | final long secondsSinceEpoch = value.getTime() / 1000; 39 | return Long.toString(secondsSinceEpoch).getBytes(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/observation/Observation.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.observation; 17 | 18 | import org.eclipse.leshan.core.node.LwM2mPath; 19 | import org.eclipse.leshan.server.client.Client; 20 | 21 | /** 22 | * An observation of a resource provided by a LWM2M Client. 23 | * 24 | * Instances are managed by an {@link ObservationRegistry}. 25 | */ 26 | public interface Observation { 27 | 28 | /** 29 | * Gets the observed client. 30 | * 31 | * @return the client 32 | */ 33 | Client getClient(); 34 | 35 | /** 36 | * Gets the observed resource path. 37 | * 38 | * @return the resource path 39 | */ 40 | LwM2mPath getPath(); 41 | 42 | /** 43 | * Cancels the observation. 44 | * 45 | * As a result the observer will no longer get notified about changes to the resource. 46 | */ 47 | void cancel(); 48 | 49 | void addListener(ObservationListener listener); 50 | 51 | void removeListener(ObservationListener listener); 52 | } 53 | -------------------------------------------------------------------------------- /leshan-client/src/test/java/org/eclipse/leshan/client/response/ResponseMatcher.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | import java.util.Arrays; 19 | 20 | import org.eclipse.californium.core.coap.CoAP.ResponseCode; 21 | import org.eclipse.californium.core.coap.Response; 22 | import org.hamcrest.BaseMatcher; 23 | import org.hamcrest.Description; 24 | 25 | public class ResponseMatcher extends BaseMatcher { 26 | 27 | private final ResponseCode code; 28 | private final byte[] payload; 29 | 30 | public ResponseMatcher(final ResponseCode code, final byte[] payload) { 31 | this.code = code; 32 | this.payload = payload; 33 | } 34 | 35 | @Override 36 | public boolean matches(final Object arg0) { 37 | final ResponseCode responseCode = ResponseCode.valueOf(((Response) arg0).getCode().value); 38 | return responseCode == code && Arrays.equals(payload, ((Response) arg0).getPayload()); 39 | } 40 | 41 | @Override 42 | public void describeTo(final Description arg0) { 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/RegisterRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | import java.util.Map; 19 | 20 | public class RegisterRequest extends AbstractLwM2mClientRequest implements LwM2mContentRequest, LwM2mIdentifierRequest { 21 | private final Map clientParameters; 22 | private final String clientEndpointIdentifier; 23 | 24 | public RegisterRequest(final String clientEndpointIdentifier, final Map clientParameters) { 25 | this.clientEndpointIdentifier = clientEndpointIdentifier; 26 | this.clientParameters = clientParameters; 27 | } 28 | 29 | @Override 30 | public void accept(final LwM2mClientRequestVisitor visitor) { 31 | visitor.visit(this); 32 | } 33 | 34 | @Override 35 | public Map getClientParameters() { 36 | return clientParameters; 37 | } 38 | 39 | @Override 40 | public String getClientEndpointIdentifier() { 41 | return clientEndpointIdentifier; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/java/org/eclipse/leshan/standalone/servlet/json/ResponseSerializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.standalone.servlet.json; 17 | 18 | import java.lang.reflect.Type; 19 | 20 | import org.eclipse.leshan.core.response.LwM2mResponse; 21 | import org.eclipse.leshan.core.response.ValueResponse; 22 | 23 | import com.google.gson.JsonElement; 24 | import com.google.gson.JsonObject; 25 | import com.google.gson.JsonSerializationContext; 26 | import com.google.gson.JsonSerializer; 27 | 28 | public class ResponseSerializer implements JsonSerializer { 29 | 30 | @Override 31 | public JsonElement serialize(final LwM2mResponse src, final Type typeOfSrc, final JsonSerializationContext context) { 32 | final JsonObject element = new JsonObject(); 33 | 34 | element.addProperty("status", src.getCode().toString()); 35 | 36 | if (typeOfSrc == ValueResponse.class) { 37 | element.add("content", context.serialize(((ValueResponse) src).getContent())); 38 | } 39 | 40 | return element; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/MultipleResourceDefinition.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | import org.eclipse.leshan.client.resource.multiple.MultipleLwM2mResource; 19 | 20 | public class MultipleResourceDefinition implements LwM2mClientResourceDefinition 21 | { 22 | private final int id; 23 | private final MultipleLwM2mResource multipleResource; 24 | private final boolean required; 25 | 26 | public MultipleResourceDefinition(final int id, final MultipleLwM2mResource multipleResource, 27 | final boolean required) 28 | { 29 | this.id = id; 30 | this.multipleResource = multipleResource; 31 | this.required = required; 32 | } 33 | 34 | @Override 35 | public int getId() 36 | { 37 | return id; 38 | } 39 | 40 | @Override 41 | public boolean isRequired() 42 | { 43 | return required; 44 | } 45 | 46 | @Override 47 | public LwM2mClientResource createResource() 48 | { 49 | return multipleResource; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/js/app.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | 17 | 'use strict'; 18 | 19 | /* App Module */ 20 | 21 | var leshanApp = angular.module('leshanApp',[ 22 | 'ngRoute', 23 | 'clientControllers', 24 | 'objectDirectives', 25 | 'instanceDirectives', 26 | 'resourceDirectives', 27 | 'resourceFormDirectives', 28 | 'lwResourcesServices', 29 | 'securityControllers', 30 | 'uiDialogServices', 31 | 'modalInstanceControllers', 32 | 'ui.bootstrap', 33 | ]); 34 | 35 | leshanApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { 36 | $routeProvider. 37 | when('/clients', { templateUrl : 'partials/client-list.html', controller : 'ClientListCtrl' }). 38 | when('/clients/:clientId', { templateUrl : 'partials/client-detail.html', controller : 'ClientDetailCtrl' }). 39 | when('/security', { templateUrl : 'partials/security-list.html', controller : 'SecurityCtrl' }). 40 | otherwise({ redirectTo : '/clients' }); 41 | }]); 42 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/bool/BooleanLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource.bool; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.resource.TypedLwM2mExchange; 20 | 21 | public class BooleanLwM2mExchange extends TypedLwM2mExchange { 22 | 23 | private static String ZERO = Integer.toString(0); 24 | private static String ONE = Integer.toString(1); 25 | 26 | public BooleanLwM2mExchange(final LwM2mExchange exchange) { 27 | super(exchange); 28 | } 29 | 30 | @Override 31 | protected Boolean convertFromBytes(final byte[] value) { 32 | final String parsedValue = new String(value); 33 | if (!parsedValue.equals(ZERO) && !parsedValue.equals(ONE)) { 34 | throw new IllegalArgumentException(); 35 | } 36 | 37 | return parsedValue.equals(ONE); 38 | } 39 | 40 | @Override 41 | protected byte[] convertToBytes(final Boolean value) { 42 | final int numericalValue = value ? 1 : 0; 43 | return Integer.toString(numericalValue).getBytes(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/response/ValueResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.response; 17 | 18 | import org.eclipse.leshan.ResponseCode; 19 | import org.eclipse.leshan.core.node.LwM2mNode; 20 | import org.eclipse.leshan.util.Validate; 21 | 22 | public class ValueResponse extends LwM2mResponse { 23 | 24 | private final LwM2mNode content; 25 | 26 | public ValueResponse(ResponseCode code) { 27 | this(code, null); 28 | } 29 | 30 | public ValueResponse(ResponseCode code, LwM2mNode content) { 31 | super(code); 32 | 33 | if (ResponseCode.CONTENT.equals(code)) { 34 | Validate.notNull(content); 35 | } 36 | this.content = content; 37 | } 38 | 39 | /** 40 | * Get the {@link LwM2mNode} value returned as response payload. 41 | * 42 | * @return the value or null if the client returned an error response. 43 | */ 44 | public LwM2mNode getContent() { 45 | return content; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return String.format("ValueResponse [content=%s, code=%s]", content, code); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/aggregate/LwM2mObjectReadResponseAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange.aggregate; 17 | 18 | import java.nio.ByteBuffer; 19 | 20 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 21 | import org.eclipse.leshan.client.response.LwM2mResponse; 22 | import org.eclipse.leshan.tlv.Tlv; 23 | import org.eclipse.leshan.tlv.TlvDecoder; 24 | import org.eclipse.leshan.tlv.TlvException; 25 | import org.eclipse.leshan.tlv.Tlv.TlvType; 26 | 27 | public class LwM2mObjectReadResponseAggregator extends LwM2mReadResponseAggregator { 28 | 29 | public LwM2mObjectReadResponseAggregator(final LwM2mExchange exchange, final int numExpectedResults) { 30 | super(exchange, numExpectedResults); 31 | } 32 | 33 | @Override 34 | protected Tlv createTlv(final int id, final LwM2mResponse response) { 35 | try { 36 | return new Tlv(TlvType.OBJECT_INSTANCE, TlvDecoder.decode(ByteBuffer.wrap(response.getResponsePayload())), 37 | null, id); 38 | } catch (TlvException e) { 39 | throw new IllegalStateException(e); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/request/UpdateRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.request; 17 | 18 | import java.util.Map; 19 | 20 | import org.eclipse.leshan.client.request.identifier.ClientIdentifier; 21 | 22 | public class UpdateRequest extends AbstractRegisteredLwM2mClientRequest implements LwM2mContentRequest { 23 | 24 | private final Map updatedParameters; 25 | 26 | public UpdateRequest(final ClientIdentifier clientIdentifier, final Map updatedParameters) { 27 | super(clientIdentifier); 28 | this.updatedParameters = updatedParameters; 29 | } 30 | 31 | public UpdateRequest(final ClientIdentifier clientIdentifier, final long timeout, 32 | final Map updatedParameters) { 33 | super(clientIdentifier, timeout); 34 | this.updatedParameters = updatedParameters; 35 | } 36 | 37 | @Override 38 | public Map getClientParameters() { 39 | return updatedParameters; 40 | } 41 | 42 | @Override 43 | public void accept(final LwM2mClientRequestVisitor visitor) { 44 | visitor.visit(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/DeleteRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.core.node.LwM2mPath; 19 | import org.eclipse.leshan.core.response.LwM2mResponse; 20 | 21 | public class DeleteRequest extends AbstractDownlinkRequest { 22 | 23 | /** 24 | * Creates a request for deleting a particular object instance implemented by a client. 25 | * 26 | * @param objectId the object type 27 | * @param objectInstanceId the object instance 28 | */ 29 | public DeleteRequest(final int objectId, final int objectInstanceId) { 30 | this(new LwM2mPath(objectId, objectInstanceId)); 31 | } 32 | 33 | public DeleteRequest(final String target) { 34 | super(new LwM2mPath(target)); 35 | } 36 | 37 | private DeleteRequest(final LwM2mPath target) { 38 | super(target); 39 | } 40 | 41 | @Override 42 | public void accept(final DownlinkRequestVisitor visitor) { 43 | visitor.visit(this); 44 | } 45 | 46 | @Override 47 | public final String toString() { 48 | return String.format("DeleteRequest [%s]", getPath()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /leshan-server-core/src/test/java/org/eclipse/leshan/server/client/ClientSortObjectTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | 17 | package org.eclipse.leshan.server.client; 18 | 19 | import java.net.Inet4Address; 20 | import java.net.InetSocketAddress; 21 | import java.net.UnknownHostException; 22 | 23 | import org.eclipse.leshan.LinkObject; 24 | import org.eclipse.leshan.server.client.Client; 25 | import org.junit.Assert; 26 | import org.junit.Test; 27 | 28 | public class ClientSortObjectTest { 29 | 30 | @Test 31 | public void sort_link_object_on_get() throws UnknownHostException { 32 | LinkObject[] objs = new LinkObject[3]; 33 | objs[0] = new LinkObject("/0/1024/2"); 34 | objs[1] = new LinkObject("/0/2"); 35 | objs[2] = null; 36 | Client c = new Client("registrationId", "endpoint", Inet4Address.getByName("127.0.0.1"), 1, "1.0", null, null, 37 | null, objs, new InetSocketAddress(212)); 38 | 39 | LinkObject[] res = c.getSortedObjectLinks(); 40 | Assert.assertEquals(3, res.length); 41 | Assert.assertNull(res[0]); 42 | Assert.assertEquals("/0/2", res[1].getPath()); 43 | Assert.assertEquals("/0/1024/2", res[2].getPath()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/coap/californium/CaliforniumBasedResource.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.coap.californium; 17 | 18 | import org.eclipse.californium.core.coap.LinkFormat; 19 | import org.eclipse.californium.core.server.resources.CoapExchange; 20 | import org.eclipse.leshan.client.resource.LinkFormattable; 21 | import org.eclipse.leshan.client.resource.LwM2mClientResource; 22 | 23 | class CaliforniumBasedResource extends CaliforniumBasedLwM2mNode implements LinkFormattable { 24 | 25 | public CaliforniumBasedResource(final int id, final LwM2mClientResource lwM2mResource) { 26 | super(id, lwM2mResource); 27 | } 28 | 29 | @Override 30 | public void handlePOST(final CoapExchange exchange) { 31 | node.execute(new CaliforniumBasedLwM2mExchange(exchange)); 32 | } 33 | 34 | @Override 35 | public String asLinkFormat() { 36 | final StringBuilder linkFormat = LinkFormat.serializeResource(this).append( 37 | LinkFormat.serializeAttributes(getAttributes())); 38 | 39 | linkFormat.deleteCharAt(linkFormat.length() - 1); 40 | 41 | return linkFormat.toString(); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/ForwardingLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange; 17 | 18 | import org.eclipse.leshan.ObserveSpec; 19 | import org.eclipse.leshan.client.response.LwM2mResponse; 20 | 21 | public class ForwardingLwM2mExchange implements LwM2mExchange { 22 | 23 | protected final LwM2mExchange exchange; 24 | 25 | public ForwardingLwM2mExchange(final LwM2mExchange exchange) { 26 | this.exchange = exchange; 27 | } 28 | 29 | @Override 30 | public void respond(final LwM2mResponse response) { 31 | exchange.respond(response); 32 | } 33 | 34 | @Override 35 | public byte[] getRequestPayload() { 36 | return exchange.getRequestPayload(); 37 | } 38 | 39 | @Override 40 | public boolean hasObjectInstanceId() { 41 | return exchange.hasObjectInstanceId(); 42 | } 43 | 44 | @Override 45 | public int getObjectInstanceId() { 46 | return exchange.getObjectInstanceId(); 47 | } 48 | 49 | @Override 50 | public boolean isObserve() { 51 | return exchange.isObserve(); 52 | } 53 | 54 | @Override 55 | public ObserveSpec getObserveSpec() { 56 | return exchange.getObserveSpec(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/coap/californium/CaliforniumBasedLwM2mCallbackExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.coap.californium; 17 | 18 | import org.eclipse.californium.core.server.resources.CoapExchange; 19 | import org.eclipse.leshan.client.exchange.LwM2mCallbackExchange; 20 | import org.eclipse.leshan.client.resource.LwM2mClientNode; 21 | import org.eclipse.leshan.client.response.LwM2mResponse; 22 | 23 | public class CaliforniumBasedLwM2mCallbackExchange extends CaliforniumBasedLwM2mExchange 24 | implements LwM2mCallbackExchange { 25 | 26 | private final Callback callback; 27 | private T node; 28 | 29 | public CaliforniumBasedLwM2mCallbackExchange(final CoapExchange exchange, final Callback callback) { 30 | super(exchange); 31 | this.callback = callback; 32 | } 33 | 34 | @Override 35 | public void respond(final LwM2mResponse response) { 36 | if (response.isSuccess()) { 37 | callback.onSuccess(node); 38 | } else { 39 | callback.onFailure(); 40 | } 41 | super.respond(response); 42 | } 43 | 44 | @Override 45 | public void setNode(final T node) { 46 | this.node = node; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/LwM2mClientNode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | import java.util.concurrent.ScheduledExecutorService; 19 | 20 | import org.eclipse.leshan.ObserveSpec; 21 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 22 | import org.eclipse.leshan.client.exchange.ObserveNotifyExchange; 23 | import org.eclipse.leshan.client.response.WriteResponse; 24 | 25 | public abstract class LwM2mClientNode { 26 | 27 | protected ObserveSpec observeSpec; 28 | protected ObserveNotifyExchange observer; 29 | 30 | public LwM2mClientNode() { 31 | this.observeSpec = new ObserveSpec.Builder().build(); 32 | } 33 | 34 | public abstract void read(LwM2mExchange exchange); 35 | 36 | public void observe(final LwM2mExchange exchange, final ScheduledExecutorService service) { 37 | observer = new ObserveNotifyExchange(exchange, this, observeSpec, service); 38 | } 39 | 40 | public void write(LwM2mExchange exchange) { 41 | exchange.respond(WriteResponse.notAllowed()); 42 | } 43 | 44 | public void writeAttributes(LwM2mExchange exchange, ObserveSpec spec) { 45 | this.observeSpec = spec; 46 | exchange.respond(WriteResponse.success()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /leshan-core/src/test/java/org/eclipse/leshan/core/node/ValueTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.node; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertNotEquals; 20 | 21 | import org.eclipse.leshan.core.node.Value; 22 | import org.junit.Test; 23 | 24 | public class ValueTest { 25 | 26 | @Test 27 | public void two_identical_strings_are_equal() { 28 | assertEquals(Value.newStringValue("hello"), Value.newStringValue("hello")); 29 | } 30 | 31 | @Test 32 | public void two_non_identical_strings_are_not_equal() { 33 | assertNotEquals(Value.newStringValue("hello"), Value.newStringValue("world")); 34 | } 35 | 36 | @Test 37 | public void two_identical_opaques_are_equal() { 38 | assertEquals(Value.newBinaryValue("hello".getBytes()), Value.newBinaryValue("hello".getBytes())); 39 | } 40 | 41 | @Test 42 | public void two_non_identical_opaques_are_not_equal() { 43 | assertNotEquals(Value.newBinaryValue("hello".getBytes()), Value.newBinaryValue("world".getBytes())); 44 | } 45 | 46 | @Test 47 | public void two_string_and_binary_are_not_equal() { 48 | assertNotEquals(Value.newStringValue("hello"), Value.newBinaryValue("hello".getBytes())); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/resource/TypedLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.resource; 17 | 18 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 19 | import org.eclipse.leshan.client.response.ReadResponse; 20 | import org.eclipse.leshan.client.response.WriteResponse; 21 | 22 | public abstract class TypedLwM2mExchange { 23 | 24 | private final LwM2mExchange exchange; 25 | 26 | public TypedLwM2mExchange(final LwM2mExchange exchange) { 27 | this.exchange = exchange; 28 | } 29 | 30 | public final LwM2mExchange advanced() { 31 | return exchange; 32 | } 33 | 34 | public final void respondSuccess() { 35 | exchange.respond(WriteResponse.success()); 36 | } 37 | 38 | public final void respondFailure() { 39 | exchange.respond(WriteResponse.failure()); 40 | } 41 | 42 | public final T getRequestPayload() { 43 | final byte[] requestPayload = exchange.getRequestPayload(); 44 | return convertFromBytes(requestPayload); 45 | } 46 | 47 | public void respondContent(final T value) { 48 | exchange.respond(ReadResponse.success(convertToBytes(value))); 49 | } 50 | 51 | protected abstract T convertFromBytes(final byte[] value); 52 | 53 | protected abstract byte[] convertToBytes(final T value); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/response/DiscoverResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.response; 17 | 18 | import java.util.Arrays; 19 | 20 | import org.eclipse.leshan.LinkObject; 21 | import org.eclipse.leshan.ResponseCode; 22 | import org.eclipse.leshan.util.Validate; 23 | 24 | public class DiscoverResponse extends LwM2mResponse { 25 | 26 | private final LinkObject[] links; 27 | 28 | public DiscoverResponse(ResponseCode code) { 29 | this(code, null); 30 | } 31 | 32 | public DiscoverResponse(ResponseCode code, LinkObject[] links) { 33 | super(code); 34 | if (ResponseCode.CONTENT.equals(code)) { 35 | Validate.notNull(links); 36 | this.links = Arrays.copyOf(links, links.length); 37 | } else { 38 | this.links = null; 39 | } 40 | } 41 | 42 | /** 43 | * Get the list of {@link LinkObject} returned as response payload. 44 | * 45 | * @return the object links or null if the client returned an error response. 46 | */ 47 | public LinkObject[] getObjectLinks() { 48 | return links != null ? links.clone() : null; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return String.format("DiscoverResponse [links=%s, code=%s]", Arrays.toString(links), code); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/objectspec/json/ResourceSpecSerializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.objectspec.json; 17 | 18 | import java.lang.reflect.Type; 19 | 20 | import org.eclipse.leshan.core.objectspec.ResourceSpec; 21 | 22 | import com.google.gson.JsonElement; 23 | import com.google.gson.JsonObject; 24 | import com.google.gson.JsonSerializationContext; 25 | import com.google.gson.JsonSerializer; 26 | 27 | public class ResourceSpecSerializer implements JsonSerializer { 28 | 29 | @Override 30 | public JsonElement serialize(ResourceSpec resource, Type typeOfSrc, JsonSerializationContext context) { 31 | JsonObject element = new JsonObject(); 32 | 33 | element.addProperty("id", resource.id); 34 | element.addProperty("name", resource.name); 35 | element.addProperty("operations", resource.operations.toString()); 36 | element.addProperty("instancetype", resource.multiple ? "multiple" : "single"); 37 | element.addProperty("mandatory", resource.mandatory); 38 | element.addProperty("type", resource.type.toString().toLowerCase()); 39 | element.addProperty("range", resource.rangeEnumeration); 40 | element.addProperty("units", resource.units); 41 | element.addProperty("description", resource.description); 42 | 43 | return element; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/partials/instance.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
{{instance.name}}
4 |
{{instance.path}}
5 |
6 | 38 |
39 |
40 | 41 |
42 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Guide to contributing 2 | 3 | Please read this if you intend to contribute to the project. 4 | 5 | ## Legal stuff 6 | 7 | Apologies in advance for the extra work required here - this is necessary to comply with the Eclipse Foundation's 8 | strict IP policy. 9 | 10 | Please also read [this](http://wiki.eclipse.org/Development_Resources/Contributing_via_Git) 11 | 12 | In order for any contributions to be accepted you MUST do the following things. 13 | 14 | * Sign the [Eclipse Foundation Contributor License Agreement](http://www.eclipse.org/legal/CLA.php). 15 | To sign the Eclipse CLA you need to: 16 | 17 | * Obtain an Eclipse Foundation userid. Anyone who currently uses Eclipse Bugzilla or Gerrit systems already has one of those. 18 | If you don’t, you need to [register](https://dev.eclipse.org/site_login/createaccount.php). 19 | 20 | * Login into the [projects portal](https://projects.eclipse.org/), select “My Account”, and then the “Contributor License Agreement” tab. 21 | 22 | * Add your github username in your Eclipse Foundation account settings. Log in it to Eclipse and go to account settings. 23 | 24 | * "Sign-off" your commits 25 | 26 | Every commit you make in your patch or pull request MUST be "signed off". 27 | 28 | You do this by adding the `-s` flag when you make the commit(s), e.g. 29 | 30 | git commit -s -m "Shave the yak some more" 31 | 32 | ## Making your changes 33 | 34 | * Fork the repository on GitHub 35 | * Create a new branch for your changes 36 | * Make your changes 37 | * Make sure you include tests 38 | * Make sure the test suite passes after your changes 39 | * Commit your changes into that branch 40 | * Use descriptive and meaningful commit messages 41 | * If you have a lot of commits squash them into a single commit 42 | * Make sure you use the `-s` flag when committing as explained above. 43 | * Push your changes to your branch in your forked repository 44 | 45 | ## Submitting the changes 46 | 47 | Submit a pull request via the normal GitHub UI. 48 | 49 | ## After submitting 50 | 51 | * Do not use your branch for any other development, otherwise further changes that you make will be visible in the PR. 52 | 53 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/objectspec/ObjectSpec.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.objectspec; 17 | 18 | import java.util.Collections; 19 | import java.util.Map; 20 | 21 | /** 22 | * An object description 23 | */ 24 | public class ObjectSpec { 25 | 26 | public final int id; 27 | public final String name; 28 | public final String description; 29 | public final boolean multiple; 30 | public final boolean mandatory; 31 | 32 | public final Map resources; // resources by ID 33 | 34 | public ObjectSpec(int id, String name, String description, boolean multiple, boolean mandatory, 35 | Map resources) { 36 | this.id = id; 37 | this.name = name; 38 | this.description = description; 39 | this.multiple = multiple; 40 | this.mandatory = mandatory; 41 | this.resources = Collections.unmodifiableMap(resources); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | StringBuilder builder = new StringBuilder(); 47 | builder.append("ObjectDesc [id=").append(id).append(", name=").append(name).append(", description=") 48 | .append(description).append(", multiple=").append(multiple).append(", mandatory=").append(mandatory) 49 | .append(", resources=").append(resources).append("]"); 50 | return builder.toString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/aggregate/LwM2mResponseAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange.aggregate; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.ConcurrentHashMap; 20 | 21 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 22 | import org.eclipse.leshan.client.response.LwM2mResponse; 23 | 24 | public abstract class LwM2mResponseAggregator { 25 | 26 | private final LwM2mExchange exchange; 27 | private final Map responses; 28 | private final int numExpectedResults; 29 | 30 | public LwM2mResponseAggregator(final LwM2mExchange exchange, final int numExpectedResults) { 31 | this.exchange = exchange; 32 | this.responses = new ConcurrentHashMap<>(); 33 | this.numExpectedResults = numExpectedResults; 34 | respondIfReady(); 35 | } 36 | 37 | public void respond(final int id, final LwM2mResponse response) { 38 | responses.put(id, response); 39 | respondIfReady(); 40 | } 41 | 42 | private void respondIfReady() { 43 | if (responses.size() == numExpectedResults) { 44 | respondToExchange(responses, exchange); 45 | } 46 | } 47 | 48 | protected abstract void respondToExchange(Map responses, LwM2mExchange exchange); 49 | 50 | public LwM2mExchange getUnderlyingExchange() { 51 | return exchange; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/util/ResponseCallback.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.util; 17 | 18 | import java.util.concurrent.atomic.AtomicBoolean; 19 | 20 | import org.eclipse.californium.core.coap.CoAP.ResponseCode; 21 | import org.eclipse.leshan.client.response.Callback; 22 | import org.eclipse.leshan.client.response.OperationResponse; 23 | 24 | public class ResponseCallback implements Callback { 25 | 26 | private final AtomicBoolean called; 27 | private OperationResponse response; 28 | 29 | public ResponseCallback() { 30 | called = new AtomicBoolean(false); 31 | } 32 | 33 | @Override 34 | public void onSuccess(final OperationResponse t) { 35 | called.set(true); 36 | response = t; 37 | } 38 | 39 | @Override 40 | public void onFailure(final OperationResponse t) { 41 | called.set(true); 42 | response = t; 43 | } 44 | 45 | public AtomicBoolean isCalled() { 46 | return called; 47 | } 48 | 49 | public byte[] getResponsePayload() { 50 | return response.getPayload(); 51 | } 52 | 53 | public ResponseCode getResponseCode() { 54 | return response.getResponseCode(); 55 | } 56 | 57 | public boolean isSuccess() { 58 | return response.isSuccess(); 59 | } 60 | 61 | public void reset() { 62 | called.set(false); 63 | } 64 | 65 | public OperationResponse getResponse() { 66 | return response; 67 | } 68 | } -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/aggregate/LwM2mObjectInstanceCreateResponseAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange.aggregate; 17 | 18 | import java.util.Collection; 19 | import java.util.Map; 20 | 21 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 22 | import org.eclipse.leshan.client.response.CreateResponse; 23 | import org.eclipse.leshan.client.response.LwM2mResponse; 24 | 25 | public class LwM2mObjectInstanceCreateResponseAggregator extends LwM2mResponseAggregator { 26 | 27 | private final int instanceId; 28 | 29 | public LwM2mObjectInstanceCreateResponseAggregator(final LwM2mExchange exchange, final int numExpectedResults, 30 | final int instanceId) { 31 | super(exchange, numExpectedResults); 32 | this.instanceId = instanceId; 33 | } 34 | 35 | @Override 36 | protected void respondToExchange(final Map responses, final LwM2mExchange exchange) { 37 | if (isSuccess(responses.values())) { 38 | exchange.respond(CreateResponse.success(instanceId)); 39 | } else { 40 | exchange.respond(CreateResponse.methodNotAllowed()); 41 | } 42 | } 43 | 44 | private boolean isSuccess(final Collection values) { 45 | for (final LwM2mResponse response : values) { 46 | if (!response.isSuccess()) { 47 | return false; 48 | } 49 | } 50 | return true; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/aggregate/AggregatedLwM2mExchange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange.aggregate; 17 | 18 | import org.eclipse.leshan.ObserveSpec; 19 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 20 | import org.eclipse.leshan.client.response.LwM2mResponse; 21 | 22 | public class AggregatedLwM2mExchange implements LwM2mExchange { 23 | 24 | private final LwM2mResponseAggregator aggr; 25 | private final int id; 26 | private byte[] payload; 27 | 28 | public AggregatedLwM2mExchange(final LwM2mResponseAggregator aggr, final int id) { 29 | this.aggr = aggr; 30 | this.id = id; 31 | } 32 | 33 | @Override 34 | public void respond(final LwM2mResponse response) { 35 | aggr.respond(id, response); 36 | } 37 | 38 | @Override 39 | public byte[] getRequestPayload() { 40 | return payload; 41 | } 42 | 43 | public void setRequestPayload(final byte[] newPayload) { 44 | payload = newPayload; 45 | } 46 | 47 | @Override 48 | public boolean hasObjectInstanceId() { 49 | return false; 50 | } 51 | 52 | @Override 53 | public int getObjectInstanceId() { 54 | throw new UnsupportedOperationException(); 55 | } 56 | 57 | @Override 58 | public boolean isObserve() { 59 | return aggr.getUnderlyingExchange().isObserve(); 60 | } 61 | 62 | @Override 63 | public ObserveSpec getObserveSpec() { 64 | return aggr.getUnderlyingExchange().getObserveSpec(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/response/CreateResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.response; 17 | 18 | import java.util.Objects; 19 | 20 | import org.eclipse.leshan.ResponseCode; 21 | 22 | public class CreateResponse extends BaseLwM2mResponse { 23 | 24 | private final String location; 25 | 26 | private CreateResponse(final ResponseCode code, final String location) { 27 | super(code, new byte[0]); 28 | this.location = location; 29 | } 30 | 31 | private CreateResponse(final ResponseCode code) { 32 | this(code, null); 33 | } 34 | 35 | public static CreateResponse success(final int instanceId) { 36 | return new CreateResponse(ResponseCode.CREATED, Integer.toString(instanceId)); 37 | } 38 | 39 | public static CreateResponse methodNotAllowed() { 40 | return new CreateResponse(ResponseCode.METHOD_NOT_ALLOWED); 41 | } 42 | 43 | public static CreateResponse invalidResource() { 44 | return new CreateResponse(ResponseCode.BAD_REQUEST); 45 | } 46 | 47 | public String getLocation() { 48 | return location; 49 | } 50 | 51 | @Override 52 | public boolean equals(final Object o) { 53 | if (!(o instanceof CreateResponse) || !super.equals(o)) { 54 | return false; 55 | } 56 | final CreateResponse other = (CreateResponse) o; 57 | return Objects.equals(location, other.location); 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return Objects.hash(super.hashCode(), location); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/util/Charsets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache license, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the license for the specific language governing permissions and 15 | * limitations under the license. 16 | */ 17 | package org.eclipse.leshan.util; 18 | 19 | import java.nio.charset.Charset; 20 | 21 | /** 22 | * Charset utilities. Contains the standard character sets guaranteed to be available on all implementations of the Java 23 | * platform. Parts adapted from JDK 1.7 (in particular, the {@code java.nio.charset.StandardCharsets} class). 24 | * 25 | * @see java.nio.charset.Charset 26 | */ 27 | public final class Charsets { 28 | 29 | /** 30 | * Seven-bit ASCII. ISO646-US. The Basic Latin block of the Unicode character set. 31 | */ 32 | public static final Charset US_ASCII = Charset.forName("US-ASCII"); 33 | 34 | /** 35 | * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1. 36 | */ 37 | public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); 38 | 39 | /** 40 | * Eight-bit UCS Transformation Format. 41 | */ 42 | public static final Charset UTF_8 = Charset.forName("UTF-8"); 43 | 44 | /** 45 | * Sixteen-bit UCS Transformation Format, big-endian byte order. 46 | */ 47 | public static final Charset UTF_16BE = Charset.forName("UTF-16BE"); 48 | 49 | /** 50 | * Sixteen-bit UCS Transformation Format, little-endian byte order. 51 | */ 52 | public static final Charset UTF_16LE = Charset.forName("UTF-16LE"); 53 | 54 | /** 55 | * Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark. 56 | */ 57 | public static final Charset UTF_16 = Charset.forName("UTF-16"); 58 | } 59 | -------------------------------------------------------------------------------- /leshan-server-core/src/main/java/org/eclipse/leshan/server/security/SecurityRegistry.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.server.security; 17 | 18 | import java.security.PrivateKey; 19 | import java.security.PublicKey; 20 | import java.util.Collection; 21 | 22 | public interface SecurityRegistry extends SecurityStore { 23 | 24 | /** 25 | * Returns the {@link SecurityInfo} for all end-points. 26 | * 27 | * @return an unmodifiable collection of {@link SecurityInfo} 28 | */ 29 | Collection getAll(); 30 | 31 | /** 32 | * Registers new security information for a client end-point. 33 | * 34 | * @param info the new security information 35 | * @return the {@link SecurityInfo} previously stored for the end-point or null if there was no 36 | * security information for the end-point. 37 | * @throws NonUniqueSecurityInfoException if some identifiers (PSK identity, RPK public key...) are not unique among 38 | * all end-points. 39 | */ 40 | SecurityInfo add(SecurityInfo info) throws NonUniqueSecurityInfoException; 41 | 42 | /** 43 | * Removes the security information for a given end-point. 44 | * 45 | * @param endpoint the client end-point 46 | * @return the removed {@link SecurityInfo} or null if no info for the end-point. 47 | */ 48 | SecurityInfo remove(String endpoint); 49 | 50 | /** 51 | * Returns the Server Public Key 52 | */ 53 | PublicKey getServerPublicKey(); 54 | 55 | /** 56 | * Returns the Server Private Key 57 | */ 58 | PrivateKey getServerPrivateKey(); 59 | } 60 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/java/org/eclipse/leshan/standalone/servlet/json/ClientSerializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.standalone.servlet.json; 17 | 18 | import java.lang.reflect.Type; 19 | 20 | import org.eclipse.leshan.server.californium.LeshanServerBuilder; 21 | import org.eclipse.leshan.server.client.Client; 22 | 23 | import com.google.gson.JsonElement; 24 | import com.google.gson.JsonObject; 25 | import com.google.gson.JsonSerializationContext; 26 | import com.google.gson.JsonSerializer; 27 | 28 | public class ClientSerializer implements JsonSerializer { 29 | 30 | @Override 31 | public JsonElement serialize(Client src, Type typeOfSrc, JsonSerializationContext context) { 32 | JsonObject element = new JsonObject(); 33 | 34 | element.addProperty("endpoint", src.getEndpoint()); 35 | element.addProperty("registrationId", src.getRegistrationId()); 36 | element.add("registrationDate", context.serialize(src.getRegistrationDate())); 37 | element.addProperty("address", src.getAddress().toString() + ":" + src.getPort()); 38 | element.addProperty("smsNumber", src.getSmsNumber()); 39 | element.addProperty("lwM2MmVersion", src.getLwM2mVersion()); 40 | element.addProperty("lifetime", src.getLifeTimeInSec()); 41 | element.addProperty("bindingMode", src.getBindingMode().toString()); 42 | element.add("rootPath", context.serialize(src.getRootPath())); 43 | element.add("objectLinks", context.serialize(src.getSortedObjectLinks())); 44 | element.add("secure", 45 | context.serialize(src.getRegistrationEndpointAddress().getPort() == LeshanServerBuilder.PORT_DTLS)); 46 | 47 | return element; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /leshan-client/src/main/java/org/eclipse/leshan/client/exchange/aggregate/LwM2mReadResponseAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.exchange.aggregate; 17 | 18 | import java.util.LinkedList; 19 | import java.util.Map; 20 | import java.util.Map.Entry; 21 | import java.util.Queue; 22 | import java.util.TreeMap; 23 | 24 | import org.eclipse.leshan.client.exchange.LwM2mExchange; 25 | import org.eclipse.leshan.client.response.LwM2mResponse; 26 | import org.eclipse.leshan.client.response.ReadResponse; 27 | import org.eclipse.leshan.tlv.Tlv; 28 | import org.eclipse.leshan.tlv.TlvEncoder; 29 | 30 | public abstract class LwM2mReadResponseAggregator extends LwM2mResponseAggregator { 31 | 32 | public LwM2mReadResponseAggregator(final LwM2mExchange exchange, final int numExpectedResults) { 33 | super(exchange, numExpectedResults); 34 | } 35 | 36 | @Override 37 | protected void respondToExchange(final Map responses, final LwM2mExchange exchange) { 38 | final TreeMap sortedResponses = new TreeMap<>(responses); 39 | final Queue tlvs = new LinkedList(); 40 | for (final Entry entry : sortedResponses.entrySet()) { 41 | final int id = entry.getKey(); 42 | final LwM2mResponse response = entry.getValue(); 43 | if (response.isSuccess()) { 44 | tlvs.add(createTlv(id, response)); 45 | } 46 | } 47 | final byte[] payload = TlvEncoder.encode(tlvs.toArray(new Tlv[0])).array(); 48 | exchange.respond(ReadResponse.success(payload)); 49 | } 50 | 51 | protected abstract Tlv createTlv(final int id, final LwM2mResponse response); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/objectspec/json/ObjectSpecSerializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.objectspec.json; 17 | 18 | import java.lang.reflect.Type; 19 | import java.util.ArrayList; 20 | import java.util.Collections; 21 | import java.util.Comparator; 22 | import java.util.List; 23 | 24 | import org.eclipse.leshan.core.objectspec.ObjectSpec; 25 | import org.eclipse.leshan.core.objectspec.ResourceSpec; 26 | 27 | import com.google.gson.JsonElement; 28 | import com.google.gson.JsonObject; 29 | import com.google.gson.JsonSerializationContext; 30 | import com.google.gson.JsonSerializer; 31 | 32 | public class ObjectSpecSerializer implements JsonSerializer { 33 | 34 | @Override 35 | public JsonElement serialize(ObjectSpec object, Type typeOfSrc, JsonSerializationContext context) { 36 | JsonObject element = new JsonObject(); 37 | 38 | // sort resources value 39 | List resourceSpecs = new ArrayList(object.resources.values()); 40 | Collections.sort(resourceSpecs, new Comparator() { 41 | @Override 42 | public int compare(ResourceSpec r1, ResourceSpec r2) { 43 | return r1.id - r2.id; 44 | } 45 | }); 46 | 47 | // serialize fields 48 | element.addProperty("name", object.name); 49 | element.addProperty("id", object.id); 50 | element.addProperty("instancetype", object.multiple ? "multiple" : "single"); 51 | element.addProperty("mandatory", object.mandatory); 52 | element.addProperty("description", object.description); 53 | element.add("resourcedefs", context.serialize(resourceSpecs)); 54 | 55 | return element; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /leshan-client/src/test/java/org/eclipse/leshan/client/util/LinkFormatUtilsTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.util; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import org.eclipse.leshan.LinkObject; 21 | import org.eclipse.leshan.client.util.LinkFormatUtils; 22 | import org.junit.Test; 23 | 24 | public class LinkFormatUtilsTest { 25 | private final String VALID_REQUEST_PAYLOAD = ";rt=\"oma.lwm2m\", , , , , , , , "; 26 | private final String VALID_REQUEST_SIMPLE_PAYLOAD = ", , , , , , , "; 27 | private final String INVALID_REQUEST_PAYLOAD = ""; 28 | 29 | @Test 30 | public void testValidOne() { 31 | validateExpectedPayload(VALID_REQUEST_PAYLOAD); 32 | } 33 | 34 | @Test 35 | public void testValidTwo() { 36 | validateExpectedPayload(VALID_REQUEST_SIMPLE_PAYLOAD); 37 | } 38 | 39 | @Test 40 | public void testInvalid() { 41 | final LinkObject[] links = generateLinksFromPayload(INVALID_REQUEST_PAYLOAD); 42 | final String actualPayload = LinkFormatUtils.payloadize(links); 43 | 44 | assertEquals(LinkFormatUtils.INVALID_LINK_PAYLOAD, actualPayload); 45 | } 46 | 47 | private void validateExpectedPayload(final String expectedPayload) { 48 | final LinkObject[] links = generateLinksFromPayload(expectedPayload); 49 | final String actualPayload = LinkFormatUtils.payloadize(links); 50 | 51 | assertEquals(expectedPayload, actualPayload); 52 | } 53 | 54 | private LinkObject[] generateLinksFromPayload(final String payload) { 55 | return LinkObject.parse(payload.getBytes()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/resources/webapp/js/modal-instance-controllers.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | 17 | angular.module('modalInstanceControllers', []) 18 | 19 | .controller('modalInstanceController',[ 20 | '$scope', 21 | '$modalInstance', 22 | 'object', 23 | 'instanceId', 24 | function($scope, $modalInstance, object, instanceId) { 25 | $scope.object = object; 26 | 27 | // Set dialog 28 | if (instanceId != undefined) { 29 | // Update mode 30 | $scope.title = "Update Instance " + instanceId + " of " + object.name; 31 | $scope.oklabel = "Update"; 32 | $scope.showinstanceid = false; 33 | } else { 34 | // Create mode 35 | $scope.title = "Create New Instance of " + object.name; 36 | $scope.oklabel = "Create"; 37 | $scope.showinstanceid = true; 38 | } 39 | 40 | // Create a working object 41 | var instance = { 42 | name : "Instance " + instanceId, 43 | id : instanceId, 44 | resources : [] 45 | }; 46 | for (j in object.resourcedefs) { 47 | var resourcedef = object.resourcedefs[j] 48 | instance.resources.push({ 49 | def : resourcedef, 50 | id : resourcedef.id 51 | }); 52 | } 53 | $scope.instance = instance 54 | 55 | 56 | // Define button function 57 | $scope.submit = function() { 58 | $scope.$broadcast('show-errors-check-validity'); 59 | if ($scope.form.$valid){ 60 | $modalInstance.close($scope.instance); 61 | } 62 | }; 63 | $scope.cancel = function() { 64 | $modalInstance.dismiss(); 65 | }; 66 | } 67 | ]); 68 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/ContentFormat.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | /** 19 | * Data format defined by the LWM2M specification 20 | */ 21 | public enum ContentFormat { 22 | 23 | // TODO: update media type codes once they have been assigned by IANA 24 | LINK("application/link-format", 40), TEXT("application/vnd.oma.lwm2m+text", 1541), TLV( 25 | "application/vnd.oma.lwm2m+tlv", 1542), JSON("application/vnd.oma.lwm2m+json", 1543), OPAQUE( 26 | "application/vnd.oma.lwm2m+opaque", 1544); 27 | 28 | private final String mediaType; 29 | private final int code; 30 | 31 | private ContentFormat(String mediaType, int code) { 32 | this.mediaType = mediaType; 33 | this.code = code; 34 | } 35 | 36 | public String getMediaType() { 37 | return this.mediaType; 38 | } 39 | 40 | public int getCode() { 41 | return this.code; 42 | } 43 | 44 | /** 45 | * Find the {@link ContentFormat} for the given media type (null if not found) 46 | */ 47 | public static ContentFormat fromMediaType(String mediaType) { 48 | for (ContentFormat t : ContentFormat.values()) { 49 | if (t.getMediaType().equals(mediaType)) { 50 | return t; 51 | } 52 | } 53 | return null; 54 | } 55 | 56 | /** 57 | * Finds the {@link ContentFormat} for a given media type code. 58 | * 59 | * @return the media type or null if the given code is unknown 60 | */ 61 | public static ContentFormat fromCode(int code) { 62 | for (ContentFormat t : ContentFormat.values()) { 63 | if (t.getCode() == code) { 64 | return t; 65 | } 66 | } 67 | return null; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/ObserveRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.core.node.LwM2mPath; 19 | import org.eclipse.leshan.core.response.ValueResponse; 20 | 21 | public class ObserveRequest extends AbstractDownlinkRequest { 22 | 23 | public ObserveRequest(String target) { 24 | super(new LwM2mPath(target)); 25 | } 26 | 27 | /** 28 | * Creates a request for observing future changes of all instances of a particular object of a client. 29 | * 30 | * @param objectId the object ID of the resource 31 | */ 32 | public ObserveRequest(int objectId) { 33 | super(new LwM2mPath(objectId)); 34 | } 35 | 36 | /** 37 | * Creates a request for observing future changes of a particular object instance of a client. 38 | * 39 | * @param objectId the object ID of the resource 40 | * @param objectInstanceId the object instance ID 41 | */ 42 | public ObserveRequest(int objectId, int objectInstanceId) { 43 | super(new LwM2mPath(objectId, objectInstanceId)); 44 | } 45 | 46 | /** 47 | * Creates a request for observing future changes of a specific resource of a client. 48 | * 49 | * @param objectId the object ID of the resource 50 | * @param objectInstanceId the object instance ID 51 | * @param resourceId the (individual) resource's ID 52 | */ 53 | public ObserveRequest(int objectId, int objectInstanceId, int resourceId) { 54 | super(new LwM2mPath(objectId, objectInstanceId, resourceId)); 55 | } 56 | 57 | @Override 58 | public void accept(DownlinkRequestVisitor visitor) { 59 | visitor.visit(this); 60 | } 61 | 62 | @Override 63 | public final String toString() { 64 | return String.format("ObserveRequest [%s]", getPath()); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/request/WriteAttributesRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.request; 17 | 18 | import org.eclipse.leshan.ObserveSpec; 19 | import org.eclipse.leshan.core.node.LwM2mPath; 20 | import org.eclipse.leshan.core.response.LwM2mResponse; 21 | import org.eclipse.leshan.util.Validate; 22 | 23 | public class WriteAttributesRequest extends AbstractDownlinkRequest { 24 | 25 | private final ObserveSpec observeSpec; 26 | 27 | public WriteAttributesRequest(final int objectId, final ObserveSpec observeSpec) { 28 | this(new LwM2mPath(objectId), observeSpec); 29 | } 30 | 31 | public WriteAttributesRequest(final int objectId, final int objectInstanceId, final ObserveSpec observeSpec) { 32 | this(new LwM2mPath(objectId, objectInstanceId), observeSpec); 33 | } 34 | 35 | public WriteAttributesRequest(final int objectId, final int objectInstanceId, final int resourceId, 36 | final ObserveSpec observeSpec) { 37 | this(new LwM2mPath(objectId, objectInstanceId, resourceId), observeSpec); 38 | } 39 | 40 | public WriteAttributesRequest(final String path, final ObserveSpec observeSpec) { 41 | this(new LwM2mPath(path), observeSpec); 42 | } 43 | 44 | private WriteAttributesRequest(final LwM2mPath path, final ObserveSpec observeSpec) { 45 | super(path); 46 | Validate.notNull(observeSpec); 47 | this.observeSpec = observeSpec; 48 | } 49 | 50 | @Override 51 | public void accept(final DownlinkRequestVisitor visitor) { 52 | visitor.visit(this); 53 | } 54 | 55 | public ObserveSpec getObserveSpec() { 56 | return this.observeSpec; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return String.format("WriteAttributesRequest [%s, attributes=%s]", getPath(), getObserveSpec()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /leshan-standalone/src/main/java/org/eclipse/leshan/standalone/servlet/json/LwM2mNodeSerializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.standalone.servlet.json; 17 | 18 | import java.lang.reflect.Type; 19 | 20 | import org.eclipse.leshan.core.node.LwM2mNode; 21 | import org.eclipse.leshan.core.node.LwM2mObject; 22 | import org.eclipse.leshan.core.node.LwM2mObjectInstance; 23 | import org.eclipse.leshan.core.node.LwM2mResource; 24 | 25 | import com.google.gson.JsonElement; 26 | import com.google.gson.JsonObject; 27 | import com.google.gson.JsonSerializationContext; 28 | import com.google.gson.JsonSerializer; 29 | 30 | public class LwM2mNodeSerializer implements JsonSerializer { 31 | 32 | @Override 33 | public JsonElement serialize(LwM2mNode src, Type typeOfSrc, JsonSerializationContext context) { 34 | JsonObject element = new JsonObject(); 35 | 36 | element.addProperty("id", src.getId()); 37 | 38 | if (typeOfSrc == LwM2mObject.class) { 39 | element.add("instances", context.serialize(((LwM2mObject) src).getInstances().values())); 40 | } else if (typeOfSrc == LwM2mObjectInstance.class) { 41 | element.add("resources", context.serialize(((LwM2mObjectInstance) src).getResources().values())); 42 | } else if (typeOfSrc == LwM2mResource.class) { 43 | LwM2mResource rsc = (LwM2mResource) src; 44 | if (rsc.isMultiInstances()) { 45 | Object[] values = new Object[rsc.getValues().length]; 46 | for (int i = 0; i < rsc.getValues().length; i++) { 47 | values[i] = rsc.getValues()[i].value; 48 | } 49 | element.add("values", context.serialize(values)); 50 | } else { 51 | element.add("value", context.serialize(rsc.getValue().value)); 52 | } 53 | } 54 | 55 | return element; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /leshan-core/src/main/java/org/eclipse/leshan/core/objectspec/ResourceSpec.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Sierra Wireless - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.core.objectspec; 17 | 18 | /** 19 | * A resource description 20 | */ 21 | public class ResourceSpec { 22 | 23 | public enum Operations { 24 | NONE, R, W, RW, E, RE, WE, RWE 25 | } 26 | 27 | public enum Type { 28 | STRING, INTEGER, FLOAT, BOOLEAN, OPAQUE, TIME 29 | } 30 | 31 | public final int id; 32 | public final String name; 33 | public final Operations operations; 34 | public final boolean multiple; 35 | public final boolean mandatory; 36 | public final Type type; 37 | public final String rangeEnumeration; 38 | public final String units; 39 | public final String description; 40 | 41 | public ResourceSpec(int id, String name, Operations operations, boolean multiple, boolean mandatory, Type type, 42 | String rangeEnumeration, String units, String description) { 43 | this.id = id; 44 | this.name = name; 45 | this.operations = operations; 46 | this.multiple = multiple; 47 | this.mandatory = mandatory; 48 | this.type = type; 49 | this.rangeEnumeration = rangeEnumeration; 50 | this.units = units; 51 | this.description = description; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | StringBuilder builder = new StringBuilder(); 57 | builder.append("ResourceDesc [id=").append(id).append(", name=").append(name).append(", operations=") 58 | .append(operations).append(", multiple=").append(multiple).append(", mandatory=").append(mandatory) 59 | .append(", type=").append(type).append(", rangeEnumeration=").append(rangeEnumeration) 60 | .append(", units=").append(units).append(", description=").append(description).append("]"); 61 | return builder.toString(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /leshan-client/src/test/java/org/eclipse/leshan/client/operation/CreateResponseTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013-2015 Sierra Wireless and others. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.html. 12 | * 13 | * Contributors: 14 | * Zebra Technologies - initial API and implementation 15 | *******************************************************************************/ 16 | package org.eclipse.leshan.client.operation; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertNotEquals; 20 | 21 | import org.eclipse.leshan.client.response.CreateResponse; 22 | import org.junit.Test; 23 | 24 | public class CreateResponseTest { 25 | 26 | @Test 27 | public void testEqualityRobustnessForSuccesses() { 28 | assertEquals(CreateResponse.success(1), CreateResponse.success(1)); 29 | assertNotEquals(CreateResponse.success(1), CreateResponse.success(2)); 30 | assertNotEquals(CreateResponse.success(2), CreateResponse.success(1)); 31 | assertNotEquals(CreateResponse.success(1), CreateResponse.invalidResource()); 32 | assertNotEquals(CreateResponse.success(1), null); 33 | } 34 | 35 | @Test 36 | public void testHashCodeRobustnessForSuccesses() { 37 | assertEquals(CreateResponse.success(1).hashCode(), CreateResponse.success(1).hashCode()); 38 | assertNotEquals(CreateResponse.success(1).hashCode(), CreateResponse.success(2).hashCode()); 39 | assertNotEquals(CreateResponse.success(1).hashCode(), CreateResponse.invalidResource().hashCode()); 40 | } 41 | 42 | @Test 43 | public void testEqualityRobustnessForFailures() { 44 | assertEquals(CreateResponse.invalidResource(), CreateResponse.invalidResource()); 45 | assertNotEquals(CreateResponse.invalidResource(), CreateResponse.success(2)); 46 | assertNotEquals(CreateResponse.invalidResource(), null); 47 | } 48 | 49 | @Test 50 | public void testHashCodeRobustnessForFailures() { 51 | assertEquals(CreateResponse.invalidResource().hashCode(), CreateResponse.invalidResource().hashCode()); 52 | assertNotEquals(CreateResponse.invalidResource(), CreateResponse.success(2).hashCode()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /leshan-client-example/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 4.0.0 20 | 21 | org.eclipse.leshan 22 | leshan 23 | 0.1.11-SNAPSHOT 24 | 25 | leshan-client-example 26 | leshan - client example 27 | A demonstration client built upon the Leshan client. 28 | 29 | 30 | 31 | org.eclipse.leshan 32 | leshan-client 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-assembly-plugin 41 | 2.4 42 | 43 | 44 | 45 | leshan.client.example.LeshanClientExample 46 | 47 | 48 | 49 | jar-with-dependencies 50 | 51 | 52 | 53 | 54 | make-assembly 55 | package 56 | 57 | single 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | --------------------------------------------------------------------------------