ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
lwm2m_tlv.h File Reference

The OMA LightweightM2M TLV data format (PROTOCORE_ENABLE_LWM2M): a zero-heap writer and reader for application/vnd.oma.lwm2m+tlv. More...

#include "protocore_config.h"

Go to the source code of this file.

Detailed Description

The OMA LightweightM2M TLV data format (PROTOCORE_ENABLE_LWM2M): a zero-heap writer and reader for application/vnd.oma.lwm2m+tlv.

TLV is not an IETF format. It is specified by the Open Mobile Alliance in OMA-TS-LightweightM2M_Core-V1_2-20201110-A sec 7.4.5. The octets travel as a CoAP payload (RFC 7252), tagged by the Content-Format Option (RFC 7252 sec 5.10.3); LwM2M Core sec 7.4 Table 7.4.-1 pairs the media type application/vnd.oma.lwm2m+tlv with the numeric Content-Format 11542.

LwM2M Core sec 7.4.5 Table 7.4.5.-1 lays one entry out as Type(1) Identifier(1-2) Length(0-3) Value(n):

  • Type bits 7-6 indicate the type of Identifier: 00 Object Instance, whose Value holds one or more Resource TLVs; 01 Resource Instance with Value, for use within a multiple Resource TLV; 10 multiple Resource, whose Value holds one or more Resource Instance TLVs; 11 Resource with Value.
  • Type bit 5 indicates the Length of the Identifier: 0 is 8 bits, 1 is 16 bits.
  • Type bits 4-3 indicate the type of Length: 00 is no Length field and the Value is the length bits 2-0 give, 01 an 8-bit Length field, 10 a 16-bit one, 11 a 24-bit one, and in those three "Bits 2-0 MUST be ignored".
  • Type bits 2-0 are a 3-bit unsigned integer holding the Length of the Value. Identifier and Length are unsigned integers in network byte order, so the maximum Value is 16.7 MB.

LwM2M Core Appendix C Table C.-2 gives the Value forms: Integer is a binary signed integer in network byte order and two's complement representation, 1, 2, 4 or 8 octets; Float is binary32 or binary64, and this writer emits binary64; Boolean is an 8-bit unsigned integer 0 or 1 whose "Length of a Boolean value MUST always be 1 byte"; String is UTF-8 of Length octets; Opaque is Length octets as they stand.

The writer emits entries into a caller buffer and fails closed: the first entry that does not fit poisons the cursor, so a finish reports 0 rather than a truncated payload. The reader is a cursor over a caller buffer that decodes the entry at its head and advances past it, pointing at the Value where it lies rather than copying it.

No slot member: the module keeps one writer cursor and one reader cursor, so no call names a row.

The module exports one symbol, Lwm2mTlv. Everything in lwm2m_tlv.c has internal linkage.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file lwm2m_tlv.h.