-
Notifications
You must be signed in to change notification settings - Fork 5
Description
I have been trying to implement a CSMP server. Naturally, the first step in doing so is code that can parse TLVs from the CoAP payload. Everything is working okay there, except when the sample application creates Vendor Defined TLVs.
Per the draft spec, the Vendor Defined TLV:
- follows the same format as a Standard TLV (that is, it consists of
Type | Length | Value
) Type
is 127Value
contains one or more SubTLVs of the formatSubType | Length | Value
- SubType 1 is reserved to indicate Vendor Private Enterprise Number
Therefore, I would expect a Vendor Defined TLV to look like:
7F # Type: 127
__ # Length (of all following content)
01 # SubType 1
__ # Length of encoded Vendor PEN
____ # Vendor PEN
... # Other SubTLVs
However, src/csmptlv/csmptlv.c
does not follow that format. Instead, it writes the Vendor Defined TLV as Type | Vendor PEN | SubType | Length | Value
.
csmp-agent-lib/src/csmptlv/csmptlv.c
Lines 37 to 51 in 9ef5400
if (tlvid.vendor != 0) { | |
rv = ProtobufVarint_encodeUINT32(p_cur,len - used,CSMP_TYPE_VENDOR); | |
p_cur += rv; used += rv; | |
if ((rv == 0) || (used > len)) { | |
DPRINTF("csmptlv_write error: (rv == 0) || (used=%d > len=%ld)\n", used, len); | |
return 0; | |
} | |
rv = ProtobufVarint_encodeUINT32(p_cur,len - used,tlvid.vendor); | |
p_cur += rv; used += rv; | |
if ((rv == 0) || (used > len)) { | |
DPRINTF("csmptlv_write error: (rv == 0) || (used=%d > len=%ld)\n", used, len); | |
return 0; | |
} | |
} |
7F # Type: 127
____ # Vendor PEN
... # One SubTLV (SubType | Length | Value)
This inconsistency breaks the assumption that the CoAP payload is merely the concatenation of Type | Length | Value
TLVs.
Is csmp-agent-lib out of compliance with the open specification? Or does the open specification not reflect how the Vendor Defined TLV actually looks?