lekki targets the client role of OMA LwM2M 1.0.2 / 1.1.1 over
CoAP/UDP with DTLS-PSK, scoped to what a poll-based industrial gateway
needs. This document is the honest ledger of where it deliberately
diverges from a strict reading of the specs, why, and how each deviation
is contained. It is the reference the in-code conformance.md comments
point at.
Scope out of the box (never implemented, by design): LwM2M Bootstrap,
Queue Mode, non-UDP bindings (TCP/SMS/NIDD), Access Control (object /2),
OSCORE, and Write-Composite. Single LwM2M server only. Observe/Notify is
implemented behind the default-off observe feature (Step L13) — see
Observe below for its documented deviations; without the feature the
v1 refusal behavior is preserved exactly.
| Operation | Status | Notes |
|---|---|---|
| Register / Update / De-register | ✅ full | Update at ~50 % lifetime; any Update error ⇒ full re-Register. Object lists too large for one datagram ride client Block1 (RFC 7959) — one block in flight at a time, 2.31 per intermediate block, any mid-transfer error restarts the whole transfer through the normal escalation. |
| Read (GET) | ✅ full | Resource reads negotiate text/opaque/TLV; under lwm2m11 every read shape (resource, riid, instance, object) also serves SenML CBOR/JSON (112/110) on Accept. Instance/object reads default to TLV. Accept: application/octet-stream is served for single values and resource instances whose value is Opaque; a whole multiple resource (no riid) or any non-Opaque value draws 4.06 — the latter decided by the writer after the handler emits, never treated as handler misuse. |
| Write-replace (PUT) / Write-partial (POST) | ✅ with 1 deviation | See Replace vs. partial below. Payloads: text/opaque/TLV; under lwm2m11 also SenML CBOR/JSON (112/110) at resource, resource-instance, and instance level (atomic — any bad record ⇒ one 4.00; see SenML parsing), and a single-record SenML-CBOR vd blob streams over Block1 (see Streamed SenML blob writes). Without the feature, SenML writes ⇒ 4.15. |
| Execute (POST) | ✅ full | Plain-text arglist parsed. |
| Create (POST) / Delete (DELETE) | ✅ full | Client-assigned IID returned on Create. Create accepts TLV only — a SenML Create ⇒ 4.15 (pack names would choose the new IID rather than echo the request; deferred until a real hub exercises it). |
| Discover (GET + Accept: link-format) | ✅ full | dim on multiple resources; ver unquoted; assigned pmin/pmax per link under observe. |
| Write-Attributes (PUT + query) | ✅ pmin/pmax under observe; |
See Notification attributes below. Without the feature, everything is validated-then-ignored (the v1 behavior). |
| Read-Composite (FETCH) | ✅ under lwm2m11 |
SenML CBOR/JSON; non-atomic. Refused (4.05) without the feature. |
| Write-Composite (iPATCH) | ❌ refused | 4.05 — see Write-Composite. |
| Observe / Cancel-Observe / Notify | ✅ under observe, with deviations |
Single-path observe on resource/instance/object; poll-and-diff change detection; pmin/pmax honored. See Observe. Without the feature: refused with a plain 2.05 (Leshan-verified safe). |
Send (/dp) |
❌ not implemented | Not needed by the pull model. |
RFC 7641 semantics with these documented properties and deviations:
- All notifications are CON (this library never originates NON) — which is also what makes RST-based passive cancellation work: ThingsBoard's Cancel Observe puts nothing on the wire and relies on the device RSTing.
- Change detection is poll-and-diff: each observed path is re-read
on its own cadence and a notification goes out when the rendered
bytes change (FNV-1a-64 digest + length). The sampling cadence is
max(pmin, min_sample_interval)—min_sample_interval(default 1 s) floors it, because pmin defaults to 0 and sub-second re-reads of a Modbus-backed facade are not viable. The effective floor on notification rate is thereforemin_sample_interval, even when pmin says less. - One client-wide monotonic sequence counter, never reset (masked to 24 bits on the wire). A per-observation counter that restarts on re-observe or CID rebind trips RFC 7641 §3.4 freshness and makes Californium silently discard notifications for 128 s.
- Single-path observe only: resource, instance, or object.
Resource-instance (
/o/i/r/ri) observe and Observe-Composite are refused. Root observe is refused by shape (4.05, like a root GET). - Bounded: at most
max_observations(default 16; 0 restores the refusal behavior exactly — the kill switch), and a rendered body overmax_notification_body(default 8192) is refused at register time / evicted with an error notification at sample time. Every refusal is served as the plain 2.05 without the option — legal per RFC 7641 §4.1 — and surfaced locally asClientEvent::ObserveEndedwith a typed reason, because on the wire a refusal is indistinguishable from "Observe not deployed". - Lifecycle: observations survive registration Updates and DTLS
CID rebinds (the sequence continues); they are cleared on a full
re-Register and on
Resumed/NewSessionepochs (the server dropped its side either way). While offline nothing is originated; on return each observation sends at most one catch-up carrying the latest value. - Max-Age rides on the initial response and every notification: the effective pmax when assigned, else the CoAP default 60.
- Oversized notification bodies ride Block2 (Observe + ETag + Size2 on block 0); continuation GETs are ordinary requests on the existing Block2 path.
Write-Composite (iPATCH) returns 4.05. A MAY-support operation for
a 1.1 client; refusal is spec-legal.
Under observe: pmin/pmax are validated, stored per path in the
registry's attribute store, applied with TS §5.1.2 per-attribute,
most-specific-wins inheritance (an effective pmax < pmin drops
pmax), emitted by Discover at the level they are assigned, and dropped
with their subtree on instance Delete.
gt/lt/st/epmin/epmax remain validated then discarded —
value-change conditions are out of scope; an inconsistent set still
draws the TS-mandated 4.00, a consistent one 2.04.
Without the feature, all seven keys are validated-then-ignored (the v1
behavior, byte-identical).
ThingsBoard wraps every RPC write in SenML-CBOR when the client
advertises ct="11542 112" — including multi-kilobyte opaque blobs,
which then arrive over Block1. The block-wise layer therefore streams
exactly one SenML shape: a single-record CBOR pack whose only value
field is a definite-length vd byte string, targeting a resource-level
PUT. The record header is parsed off block 0 and only the blob bytes
reach the object's write_chunk, offsets blob-relative; the size cap
applies to the blob, not the envelope.
Leshan's serializer (and therefore ThingsBoard's) emits the value
first and the name after the blob — [{vd: …, n: "/33001/0/1"}],
pinned from a live capture and by the leshan_e2e blob test — so the
record's name is generally unknown until the final block. Fields that
trail the blob are buffered (≤ 512 bytes; more is not a name and draws
4.13) and parsed at transfer end; the resolved name must equal the
request's Uri-Path. The finale — write_chunk(last) inside the
transaction bracket — runs only after that validation, so a lying name
aborts with 4.00 and nothing commits; the blob bytes already staged are
overwritten by the next offset-0 chunk, like any abandoned transfer.
When the name precedes the blob it is validated on block 0 instead
(fail-fast). Multi-record packs, non-vd values, SenML-JSON, and a
record header that does not fit the first block are refused with 4.13;
envelopes that lie about the blob length draw 4.00 mid-transfer.
An instance-level PUT (Write-replace) writes every resource present in the payload but does not reset omitted resources to their defaults — facade objects expose no reset hook. Leshan's instance writes always carry the full writable set, so the observable difference is nil in practice; a server that relied on omission-clears-to-default would see a divergence.
Write /5/0/0 (Package) with a non-empty payload returns 4.05 — this
client is pull-only (/5/0/9 = 0, /5/0/8 = [1] CoAPS), and RID 0 is a
registry-mandatory writable resource, so refusing it is the deviation.
The spec's reset forms are honored: a zero-length / NUL Package write
and an empty-string Package-URI write both reset State→0 / Result→0.
Firmware errors surface only via the Update Result resource, never as a
CoAP error on the triggering Write (a syntactically valid but unusable
URI still gets 2.04, then Result := 7 asynchronously).
RFC 7252 places no upper bound on how long a client waits for a separate
response after an empty ACK. lekki waits one further MAX_TRANSMIT_WAIT
(~93 s at defaults) and then fails the exchange — an unattended device
must not hang a registration attempt forever on a server that ACKed and
vanished.
The server-role dedup cache guarantees replay-not-re-execute for
duplicates arriving within RFC 7252 EXCHANGE_LIFETIME (247 s at
defaults), up to dedup_capacity entries (default 2470 ≈ 10 req/s
across the window, ~60 KiB). Beyond that sustained rate the cache evicts
oldest-first and dedup becomes best-effort; the application-layer
backstop (write-seq + last-writer-wins) covers idempotent points but
not non-idempotent COMMAND/pulse points. Deployments actuating such
points must keep hub write rates under the configured guaranteed rate.
Constrained devices lower dedup_capacity; the guaranteed rate scales as
capacity / 247 s.
- Indefinite-length CBOR arrays/maps/strings are rejected — Leshan and this library both emit definite lengths.
- JSON parsing accepts only flat SenML record objects (no nested containers, which no SenML label carries); surrogate-pair escapes are decoded, lone surrogates rejected.
- Records are context-aware: a name-only FETCH pack and a value pack use
the same media type, decoded by dedicated paths —
decode_paths(FETCH bodies; values tolerated and ignored) anddecode_values(Write bodies; every record must carry exactly one well-formed value). - Write packs are atomic, unlike composite reads' per-path omit rule: any malformed record fails the whole pack with one 4.00, and decode completes before the write transaction opens.
- Value-field rules on writes: JSON numbers are classified by the
lexeme (no fraction/exponent ⇒ integer, falling back to float past
i64 range); the reader then coerces integral floats into integer
resources and integers into float resources (the wire's Int/Float
split is an encoding inference, not a type assertion).
vdis base64url without padding, strictly (=rejected) per RFC 8428. CBOR half-precision (f16)vvalues are rejected — no known LwM2M peer emits them.t/bt/sand unknown labels are accepted-ignored. - Structured formats over Block1 are refused with 4.13 — Block1 uploads
stream chunk-by-chunk to
write_chunkand cannot be decoded incrementally — except the streamed SenML-CBOR blob write (see Streamed SenML blob writes above): a single-record pack whose one value is a definite-lengthvdbyte string streams, because the blob bytes are contiguous on the wire. TLV, text, SenML-JSON, multi-record packs and non-vdvalues over Block1 stay 4.13; a SenML write of any other shape must fit one datagram.
- Fuzzing (
fuzz/,cargo +nightly fuzz, nightly CI): seven lanes —coap_parse,block_opt,tlv_parse,senml_paths,exchange(stateful datagram sequences, now including locally-originated notifications and cancels),blockwise(Block1/Block2 state machine- notification chunking),
observe(a whole registered client under an adversarial op stream). Seed corpora infuzz/seeds/. Release gate: 72 h finding-free on the release revision.
- notification chunking),
- Robustness replay (
crates/lekki-testkit/tests/robustness.rs): a registered client survives a storm of malformed / adversarial datagrams (truncations, bit-flips, bad options, hostile Block1) and still serves a legitimate request; duplicate CON reads are deduped. The observe suite (tests/observe_loop.rs, featureobserve) adds the RFC 7641 scenario matrix — the 93 s phantom-timeout guard, seq continuity across re-observe/CID-rebind, passive cancel via RST, random-MID RST storms, offline catch-up semantics. - Interop: verified against Eclipse Leshan (pinned demo image,
crates/lekki-testkit/). Second-server interop against Coiote (T-07) is pending an account — the DTLS reconnect ladder (CID → resume → full handshake) and composite behavior have so far been validated only against Leshan/Californium; re-verify CID negotiation and SenML acceptance against Coiote before first customer ship.
All unsafe lives in lekki-mbedtls (the DTLS FFI). It is audited in
one place — see that crate's module docs (dtls.rs) for the
raw-pointer-ownership discipline: BIO/timer/DRBG/entropy contexts are
each owned by exactly one raw pointer (Box::into_raw … Box::from_raw
in Drop) because the C side stores copies for the transport's whole life,
so every Rust-side access reborrows from the same pointer (issue #4). The
core lekki crate is #![forbid(unsafe_code)]-clean (pure-Rust codec +
state machines).