Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions examples/wakaama/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# name of your application
APPLICATION = wakaama

# If no BOARD is found in the environment, use this default:
BOARD ?= native

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..

# TinyDTLS only has support for 32-bit architectures ATM
BOARD_BLACKLIST := arduino-duemilanove arduino-mega2560 arduino-uno chronos \
msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b wsn430-v1_4 \
z1

BOARD_INSUFFICIENT_MEMORY := airfy-beacon b-l072z-lrwan1 bluepill calliope-mini \
cc2650-launchpad cc2650stk maple-mini \
microbit nrf51dongle nrf6310 nucleo32-f031 \
nucleo32-f042 nucleo32-f303 nucleo32-l031 nucleo-f030 \
nucleo-f070 nucleo-f072 nucleo-f103 nucleo-f302 nucleo-f334 \
nucleo-l053 nucleo-l073 opencm904 \
spark-core stm32f0discovery yunjia-nrf51822


# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
# Specify the mandatory networking modules for IPv6 and sUDP
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_sock_udp
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo
# Add also the shell, some shell commands
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps

# NOTE: Required by object_float_sensor.c
USEMODULE += saul_reg
# NOTE: Uncomment to automatically add any supported devices to the lwm2m client
#USEMODULE += saul_default
# NOTE: Uncomment to automatically add all GPIO pins from the SAUL registry to the lwm2m client
#USEMODULE += saul_gpio

# NOTE: Load module for memory allocator
USEMODULE += memarray

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1

# Specific the server URI address (NOTE: Domain names not supported yet)
SERVER_URI ?= '"coap://[fd00:dead:beef::1]"'

ifneq (,$(SERVER_URI))
CFLAGS += -DLWM2M_SERVER_URI=$(SERVER_URI)
endif

ifneq (,$(findstring coaps,$(SERVER_URI)))
$(info Enabling tinyDTLS)
# NOTE: Add the package for TinyDTLS
USEPKG += tinydtls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the following lines:

#  (temporary fix) TinyDTLS <= 0.8.6 requires around 426 bytes in RAM.
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\)

This will mitigate problems with stack corruption. But, will restrict even more the available boards for the example 😭

# (temporary fix) TinyDTLS <= 0.8.6 requires around 426 bytes in RAM.
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\)

#TinyDTLs (crypto.c) made use of pthread
ifneq ($(BOARD),native)
USEMODULE += pthread
endif

# NOTE: Those are taken from TinyDTLS. As the original Makefiles are
# overwitten is a good idea to preserve them here.
CFLAGS += -DDTLSv12 -DWITH_SHA256

# NOTE: This adds support for TLS_PSK_WITH_AES_128_CCM_8
CFLAGS += -DDTLS_PSK

# NOTE: Without ECC, this defaults to 100 for RIOT which is not enough.
CFLAGS += -DDTLS_MAX_BUF=200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated line


# NOTE: The configuration for socket or non-socket communication in TinyDTLS.
# (This can be removed once PR #7615 is merged)
CFLAGS += -DWITH_RIOT_GNRC

# NOTE: This adds support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8; UNTESTED!!
#CFLAGS += -DDTLS_ECC

# NOTE: If enabled TinyDTLS' log are disabled (if memory is a issue).
# WARNING: Sometimes the log leads to Stack pointer corrupted.
# The reason is not identified yet.
# If said issue appears, enable this line.
#CFLAGS += -DNDEBUG

# NOTE: Set the TinyDTLS log level
# (see lwm2mconfig.h or log_t in dtls_debug.h in the TinyDTLS source
# tree for possible values.)
#CFLAGS += -DDTLS_LOG_LEVEL=DTLS_LOG_DEBUG
else
# Any special variable required to take TinyDTLS place.
endif

# NOTE: Add the package for wakaama
USEPKG += wakaama

# NOTE: Enabled Wakaama debug log
#CFLAGS += -DLWM2M_WITH_LOGS

# NOTE: Use wakaama in client mode with bootstrapping enabled
CFLAGS += -DLWM2M_CLIENT_MODE -DLWM2M_BOOTSTRAP

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

include $(RIOTBASE)/Makefile.include
204 changes: 204 additions & 0 deletions examples/wakaama/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
Eclipse Wakaama Example Client
==============================

This application is a port of the Eclipse Wakaama [example client
code](https://github.com/eclipse/wakaama/tree/master/examples/client)
to RIOT/GNRC.

Usage
=====

Edit the defines in `lwm2mconfig.h` according to your setup (see the
comments for what they do).

By setting `LWM2M_SERVER_PSK_ID` and `LWM2M_SERVER_PSK_KEY` to NULL in
`lwm2mconfig.h`, CoAP will be used for communication instead of CoAPS.

Build, flash and start the application:
```
export BOARD=your_board
make all flash term
```

(Or Skip `make flash` if you're building for `BOARD=native`.)

The `term` make target starts a terminal emulator for your board. It
connects to a default port so you can interact with the shell, usually
that is `/dev/ttyUSB0`. If your port is named differently, the
`PORT=/dev/yourport` (not to be confused with the UDP port) variable can
be used to override this.


Available LwM2M Objects
=======================

At this time, only the mandatory objects for a client are present. The
*server*, *security* and *access control* objects are taken as is from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, clarify something for me.

This statement made me understand that CoAPS is mandatory, and CoAP will not be compiled/supported. However, the waakama repository marks CoAPS compilation as optional. Also, the way the server is working, it's enabling CoAP and CoAPS (two ports). Also, even the OP of this PRs give the idea that can be tested with or without DTLS.

So, what is expected behavior for your port to RIOT? Only CoAPS or also CoAP ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoAP can be used by not specifying any keys (in this case, when LWM2M_SERVER_PSK_ID and LWM2M_SERVER_PSK_KEY are set to NULL) as that will bypass calling DTLS functions (see e.g. connection_handle_packet()). The wakaama example makes it possible to not compile with TinyDTLS so only CoAP will work, but with TinyDTLS, both will. Because of that, I did not make the effort to port the non-DTLS version.

Copy link
Contributor

@rfuentess rfuentess Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now is more clear for me.

IMHO there is also a factor to consider for RIOT: If DTLS is not going to be used, it should not be compiled in the first place.

This could help us to reduce the complexity of the testings by removing tinyDTLS stack temporally. Particularly, if all the lines with DTLS are inside of the files dtlsconnection.* . Otherwise, could be a future work to consider.

the example client in the Wakaama source tree. The *device* object was
re-implemented for RIOT (see `object_device.c`).

Adding more objects should be as easy as implmenting a "contructor"
and then incrementing the `OBJ_COUNT` in `lwm2mclient.c` and extending
`run_server()` to call the constructor and adding the instance(s) to
`objArray`.


LwM2M Test Server
=================

[Eclipse Leshan](https://github.com/eclipse/leshan#test-leshan-demos-locally)
is good for local testing. Just run it on the link local address of
the bridge interface created by `dist/tools/tapsetup/tapsetup` and add
the credentials set in `lwm2mconfig.h` via the web interface. Since the
example bootstrap server doesn't seem to support setting DTLS credentials
for the server itself via the web interface, you'll have to create a
new client config, edit `data/bootstrap.json` and set `securityMode`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a minimum example for data/bootstrap.json should be provided in your README.md.
This would make the things more easy for other users that are not well versed into the LW2M.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did, along with an explanation of how to read the file in the readme file.

`publicKeyOrId`, `secretKey` and maybe `serverPublicKey` and restart
the server.

The LwM2M demo server supports setting DTLS credentials on the *Security*
tab.

Example (Linux):
```
wget https://hudson.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar

ADDR=$(ip address show dev tapbr0 | grep inet6 |\
head -1 | awk '{print $2}' | cut -d'/' -f1)

java -jar ./leshan-server-demo.jar \
--coapshost ${ADDR} \
--coaphost ${ADDR}
```

Example bootstrap.json
----------------------

An example `bootstrap.json` file for the Leshan bootstrap server can be
found in data `data/`.

`testRIOTDevice.servers` contains a list of LwM2M
server objects that should be installed on the client
*testRIOTDevice*. `testRIOTDevice.servers.*.shortId` must match a
corresponding `testRIOTDevice.security.*.shortId`.

`testRIOTDevice.security` contains a list of LwM2M
security objects. `testRIOTDevice.security.0` in this
example specifies the bootstrap server itself and its
DTLS PSK. `testRIOTDevice.security.0.publicKeyOrId` and
`testRIOTDevice.security.0.secretKey` in this case are equivalent to
`fooTestRIOT` and `39fe6611deb7713c6069`.

`testRIOTDevice.security.1` matches the server to install on the
client. As mentioned, it's `shortId` must match the corresponding entry
in `testRIOTDevice.servers`. For simplicity's sake its PSK is identical
to the bootstrap server.


Example output
==============

For this example, set:
* `ENABLE_DEBUG=(1)` in `lwm2mconfig.h`
* `CFLAGS += -DLWM2M_WITH_LOGS` in `Makefile`
* `CFLAGS += -DDTLS_LOG_LEVEL=DTLS_LOG_CRIT` in `Makefile`

When registering directly to an LwM2M server, with DTLS, without
boostrapping, this should output something similar to this:
```
main(): This is RIOT! (Version: 2018.01-devel-943-g987f6-calamity-track1/wakaama-integration)
[lwm2m_init:64] Entering
[lwm2m_configure:264] endpointName: "testRIOTDevice", msisdn: "(null)", altPath: "(null)", numObject: 4
-> State: STATE_INITIAL
[lwm2m_step:372] timeoutP: -616140018120916932
[lwm2m_step:377] State: STATE_INITIAL
[object_getServers:741] Entering
[lwm2m_data_new:143] size: 3
[lwm2m_data_encode_bool:406] value: false
[lwm2m_data_encode_int:270] value: 10
[lwm2m_data_encode_int:270] value: 10
[lwm2m_data_decode_bool:416] Entering
[lwm2m_data_decode_bool:467] result: 1, value: false
[lwm2m_data_decode_int:280] Entering
[lwm2m_data_decode_int:335] result: 1, value: 10
[lwm2m_data_new:143] size: 1
[lwm2m_data_encode_int:270] value: 10
[lwm2m_data_decode_int:280] Entering
[lwm2m_data_decode_int:335] result: 1, value: 10
[lwm2m_data_free:161] size: 1
[lwm2m_data_new:143] size: 2
[lwm2m_data_encode_int:270] value: 300
[lwm2m_data_encode_string:195] "U"
[lwm2m_data_decode_int:280] Entering
[lwm2m_data_decode_int:335] result: 1, value: 300
[lwm2m_data_free:161] size: 2
[lwm2m_data_free:161] size: 3
[registration_start:477] State: STATE_REGISTER_REQUIRED
[object_getRegisterPayloadBufferLength:508] Entering
[object_getRegisterPayload:579] Entering
[lwm2m_data_new:143] size: 1
[lwm2m_data_encode_string:195] "coaps://[fe80::585d:b5ff:fe1e:75]"
[lwm2m_data_free:161] size: 1
[lwm2m_data_new:143] size: 1
[lwm2m_data_encode_int:270] value: 0
[lwm2m_data_decode_int:280] Entering
[lwm2m_data_decode_int:335] result: 1, value: 0
[lwm2m_data_free:161] size: 1
[transaction_new:156] method: 2, altPath: "(null)", mID: 30050, token_len: 4
[transaction_new:157] NULL
[transaction_new:235] Exiting on success
[transaction_send:351] Entering
Success: started DTLS server on port 61618
> [observe_step:482] Entering
[registration_step:1303] State: STATE_REGISTERING
[transaction_step:433] Entering
[lwm2m_step:480] Final timeoutP: -616140018120916990
[lwm2m_step:482] Final state: STATE_REGISTERING
-> State: STATE_REGISTERING
[lwm2m_data_new:143] size: 1
[lwm2m_data_encode_opaque:232] length: 11
[lwm2m_data_free:161] size: 1
[lwm2m_data_new:143] size: 1
[lwm2m_data_encode_opaque:232] length: 10
[lwm2m_data_free:161] size: 1
decrypt_verify(): found 24 bytes cleartext
-> State: STATE_REGISTERING
[lwm2m_step:372] timeoutP: 679896346613776444
[lwm2m_step:377] State: STATE_REGISTERING
[registration_getStatus:506] State: STATE_REGISTERING
[registration_getStatus:513] targetP->status: STATE_REG_PENDING
[registration_getStatus:536] reg_status: STATE_REG_PENDING
[observe_step:482] Entering
[registration_step:1303] State: STATE_REGISTERING
[transaction_step:433] Entering
[transaction_send:351] Entering
[lwm2m_step:480] Final timeoutP: 679896346613776387
[lwm2m_step:482] Final state: STATE_REGISTERING
-> State: STATE_REGISTERING
decrypt_verify(): found 22 bytes cleartext
[lwm2m_handle_packet:214] Entering
[lwm2m_handle_packet:219] Parsed: ver 1, type 2, tkl 4, code 2.01, mid 30050, Content type: 0
[lwm2m_handle_packet:220] Payload:
[transaction_handleResponse:274] Entering
[prv_handleRegistrationReply:212] Registration successful
[transaction_remove:260] Entering
[transaction_free:246] Entering
-> State: STATE_REGISTERING
[lwm2m_step:372] timeoutP: 679896346613776444
[lwm2m_step:377] State: STATE_REGISTERING
[registration_getStatus:506] State: STATE_REGISTERING
[registration_getStatus:513] targetP->status: STATE_REGISTERED
[registration_getStatus:536] reg_status: STATE_REGISTERED
[observe_step:482] Entering
[registration_step:1303] State: STATE_READY
[transaction_step:433] Entering
[lwm2m_step:480] Final timeoutP: 679896346613776444
[lwm2m_step:482] Final state: STATE_READY
```


Limitations
===========

* The host part of any URI **MUST** be a valid IPv6 address, as the
client can't resolve host names at this time.
Loading