ULCP: Framing and Common Semantics
This chapter defines the ULCP wire format and the semantics every device implements whatever else it supports: the frame layout, the command grammar, the property model, the classes of state a device holds, how a host attaches and synchronizes, and the numeric registries for status codes, reset codes, and capabilities. The subsystem chapters that follow build on it.
ULCP is inspired by the Spinel protocol from OpenThread, but it is not Spinel and does not aim for wire compatibility with it. The protocol assumes reliable, in-order delivery of frames, as well as a way to assert flow control. A frame the transport loses anyway ends the session it belonged to (see Lost Frames). The framing mechanism depends on the underlying transport:
- Asynchronous serial links (UART, USB-CDC) use HDLC-Lite as Spinel does, with the two rules in HDLC-Lite on a ULCP Link.
- BLE uses the GATT frame transport defined in ULCP over BLE.
- A reliable, in-order byte stream standing in for a serial link—a TCP connection to a bridged port, say—uses the same HDLC-Lite framing.
- A local stream socket between two processes on one host—a Unix domain socket—uses HDLC-Lite as well; see Local Sockets.
In this chapter, the device is the side that owns the transceiver and the host is the side that attaches to it over the local link (see Local Control Protocol). A local link is either that connection or the one to the device’s own interface; an administrator over the mesh is not on one.
The protocol version is 6.1. Which subsystems a device implements is
discovered through PROP_CAPS, never through the version number; see
Minimum Requirements for what a device is required
to implement in order to be a ULCP device at all.
Data Representation
Spinel, being a low-level protocol between two devices which are likely to have a little-endian architecture, uses little-endian representations exclusively for all integers smaller than four bytes. For implementation convenience, values larger than four bytes (EUI64, IPv6 addresses, etc.) are stored as they are traditionally represented (typically, but not always, big-endian).
Packed Unsigned Integers
Certain types of integers, such as command or property identifiers, usually have a value on the wire that is less than 127. However, in order to not preclude the use of values larger than 255, we would need to add an extra byte. Doing this would add an extra byte to all packets, which can add up in terms of bandwidth. To address this, Spinel uses Packed Unsigned Integers, or PUIs.
The PUI format used in Spinel is based on the unsigned integer format in EXI, except that we limit the maximum value to the largest value that can be encoded in three bytes. The maximum value that can be encoded is 2,097,151.
For all values less than 127, the packed form of the number is simply a single byte which directly represents the number. For values larger than 127, the following process is used to encode the value:
- The unsigned integer is broken up into n 7-bit chunks and placed into n bytes, leaving the most significant bit of each byte unused.
- Order the bytes from least-significant to most-significant. (Little-endian)
- Clear the most significant bit of the most significant byte. Set the most significant bit on all other bytes.
Where n is the smallest number of 7-bit chunks you can use to represent the given value.
Take the value 1337, for example:
1337 => 0x0539
=> [39 0A]
=> [B9 0A]
To decode the value, you collect the 7-bit chunks until you find a byte with the most significant bit clear.
Frame Format
A ULCP frame is the concatenation of the following elements:
- A header comprising a single byte.
- A command identifier.
- A command-defined payload, which may be empty.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| HEADER | COMMAND ID | PAYLOAD ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of a typical ULCP frame
Since the size of the frame is part of the framing mechanism, it is omitted from the frame.
A frame is at most 300 octets long, header and command identifier included, on every link and in both directions. A sender MUST NOT send a longer one, and a receiver MUST be able to take one of that length. A transport that carries longer frames, such as the GATT service, does not raise this limit.
Frame Header
Each frame has the following format:
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| FLG | RESERVED | TID |
+---+---+---+---+---+---+---+---+
Figure: Header Format
FLG: Flag
The Flag (FLG) field in the two most significant bits of the header byte is
always set to the value two (or 10 in binary). Any frame received with these
bits set to any other value SHALL NOT be considered a ULCP frame.
RESERVED: Reserved
These three bits must always be set to zero and the entire frame ignored if set to any other value. They may be assigned a meaning (such as an interface identifier) in a future version of this protocol.
TID: Transaction Identifier
The Transaction Identifier (TID) field in the three least significant bits of the header is used for correlating responses to the commands which generated them. This allows for up to seven host-issued commands to be in flight at once.
When a command is sent from the host, any reply to that command sent by the device will use the same value for the TID. When the host receives a frame that matches the TID of the command it sent, it can easily recognize that frame as the actual response to that command.
The zero value of TID is used for commands to which a correlated response is not expected or needed, such as for unsolicited update commands sent to the host from the device.
Note that while the frame format is symmetric between the frames being sent to the device versus frames being sent from the device, the behaviors are not. The device MUST NOT send a frame with a non-zero TID that is not a response to a frame it had recently received with that same TID. All unsolicited or asynchronous commands originating from the device MUST use TID zero (0).
Command ID
The command identifier is a 7-bit unsigned integer encoded from 0 to 127. The most significant bit is not set and the frame must be ignored if it is set.
Payload
The command payload follows the command identifier in a ULCP frame, containing the serialization of any arguments that the indicated command may require. The exact composition of a command payload is determined by the specific command identifier being used and MUST be empty if the command has no arguments.
Commands
This chapter defines the commands that operate on the protocol itself—
resets, sessions, liveness, and the property grammar. The remaining commands are
defined with the subsystem they act on: CMD_STR_SEND and CMD_STR_RECV
in Frame Transport, CMD_QUEUE_DRAIN in
Tethered Host Services, CMD_ANNOUNCE in
Device Identity, the four state-management commands
in Saved State, and the three bus-access commands
in I2C Bus Access. The complete numeric allocation is
in the Command and Property Index.
| Id | Mnemonic | Dir | Description |
|---|---|---|---|
| 0 | CMD_NOP | Host->Device | No-Operation |
| 1 | CMD_RST | Host->Device | Reset the device |
| 2 | CMD_PROP_GET | Host->Device | Get property value |
| 3 | CMD_PROP_SET | Host->Device | Set property value |
| 4 | CMD_PROP_INSERT | Host->Device | Insert an item into a multi-value property |
| 5 | CMD_PROP_REMOVE | Host->Device | Remove an item from a multi-value property |
| 6 | CMD_PROP_IS | Device->Host | Property value notification |
| 7 | CMD_PROP_INSERTED | Device->Host | Item-inserted notification |
| 8 | CMD_PROP_REMOVED | Device->Host | Item-removed notification |
| 16 | CMD_REBOOT | Host->Device | Restart the device’s hardware |
| 17 | CMD_DFU | Host->Device | Enter bootloader firmware-update mode |
| 19 | CMD_ANNOUNCE | Host->Device | Announce the device now |
| 21 | CMD_PROP_MULTI_GET | Host->Device | Get several property values |
| 22 | CMD_PROP_MULTI_SET | Host->Device | Set several property values in order |
| 23 | CMD_PROP_ARE | Device->Host | Multiple property value notification |
| 24 | CMD_SESSION_DID_END | Device->Host | A serial link’s session has ended |
| 25 | CMD_I2C_TRANSFER | Host->Device | One I2C transaction |
| 26 | CMD_I2C_RESULT | Device->Host | Read data or scanned addresses |
| 27 | CMD_I2C_SCAN | Host->Device | Probe a range of I2C addresses |
| 28 | CMD_SESSION_START | Host->Device | Start a new session on this link |
| 29 | CMD_SESSION_DID_START | Device->Host | The new session has started |
The multi-property commands (21–23) are gated by CAP_CMD_MULTI,
CMD_REBOOT, CMD_DFU, and CMD_FACTORY_RESET by CAP_REBOOT,
CMD_ANNOUNCE by CAP_ADVERT, and the
bus-access commands (25–27) by CAP_I2C (see
Capabilities); everything else is unconditional.
CMD 0: (Host -> Device) CMD_NOP
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD_NOP |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^ HEADER ^ COMMAND ^
Figure: Structure of CMD_NOP
No-Operation. Commands the device to reply with a STATUS_OK code. This is
primarily used for liveness checks.
The command payload for this command SHOULD be empty. The receiver MUST ignore any non-empty command payload.
There is no error condition for this command.
CMD 1: (Host -> Device) CMD_RST
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD_RST |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_RST
Reset device. Commands the device to perform a software reset. Due to the nature of
this command, the TID is ignored. The host should instead wait for a
CMD_PROP_IS command from the device indicating PROP_LAST_STATUS has been set
to STATUS_RESET_SOFTWARE (see Status Codes).
The command payload SHOULD be empty, and it SHOULD NOT be processed.
If an error occurs, the value of the emitted PROP_LAST_STATUS will be set
accordingly to the status code for the error.
CMD 2: (Host -> Device) CMD_PROP_GET
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI, 1-3 bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_GET
Get property value. Commands the device to emit a CMD_PROP_IS command for the
given property identifier.
The payload for this command is the property identifier encoded in the packed unsigned integer format described in Packed Unsigned Integers.
If an error occurs, the value of the emitted PROP_LAST_STATUS will be set
accordingly to the status code for the error.
CMD 3: (Host -> Device) CMD_PROP_SET
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI, 1-3 bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NEW PROPERTY VALUE ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_SET
Set property value. Commands the device to set the given property to the specific
given value, replacing any previous value, and to emit a CMD_PROP_IS command
for that property indicating the new authoritative value if successful.
The payload for this command is the property identifier encoded in the packed unsigned integer format described in Packed Unsigned Integers, followed by the property value. The exact format of the property value is defined by the property.
If an error occurs, the value of the emitted PROP_LAST_STATUS will be set
accordingly to the status code for the error.
The value reported by that CMD_PROP_IS need not be the value written: a
device that adjusts a write to what it can honor reports the result, and
that result is the property’s value. A write fails only by way of
PROP_LAST_STATUS—a differing value is a successful write, not a
rejected one.
CMD 4: (Host -> Device) CMD_PROP_INSERT
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI, 1-3 bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ITEM VALUE ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_INSERT
Insert item into property. Commands the device to add the given item to the
given multi-value property, and to emit a CMD_PROP_INSERTED command for
that property if successful.
The payload for this command is the property identifier encoded in the packed unsigned integer format, followed by exactly one item encoded in the property’s item form (see Multi-Value Properties). The item is not preceded by a length prefix, regardless of whether the property uses item length prefixes in its multi-item value form; the framing layer bounds the item.
If the item is already present the command fails with STATUS_ALREADY,
except where a property defines replacement semantics for matching items
(see, e.g., PROP_HOST_PEER_KEYS). If the property exists but is not a
multi-value property, the command fails with STATUS_INVALID_ARGUMENT.
If an error occurs, the value of the emitted PROP_LAST_STATUS will be set
accordingly to the status code for the error.
CMD 5: (Host -> Device) CMD_PROP_REMOVE
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI, 1-3 bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ITEM SELECTOR ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_REMOVE
Remove item from property. Commands the device to remove the item matching the
given selector from the given multi-value property, and to emit a
CMD_PROP_REMOVED command for that property if successful.
The payload for this command is the property identifier encoded in the packed unsigned integer format, followed by an item selector. Each multi-value property documents its selector form; unless stated otherwise it is the full item value.
If no matching item is present, the command fails with
STATUS_ITEM_NOT_FOUND. If the property exists but is not a multi-value
property, the command fails with STATUS_INVALID_ARGUMENT.
If an error occurs, the value of the emitted PROP_LAST_STATUS will be set
accordingly to the status code for the error.
CMD 6: (Device -> Host) CMD_PROP_IS
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI, 1-3 bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| CURRENT PROPERTY VALUE ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_IS
Property value notification. This command can be sent by the device in response to a previous command from the host, or it can be sent by the device in an unsolicited fashion to notify the host of various state changes asynchronously.
The payload for this command is the property identifier encoded in the packed unsigned integer format described in Packed Unsigned Integers, followed by the current value of the given property.
CMD 7: (Device -> Host) CMD_PROP_INSERTED
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI, 1-3 bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| REPORTED ITEM ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_INSERTED
Item-inserted notification. Sent by the device in response to a successful
CMD_PROP_INSERT (with the TID of that command), or unsolicited with a TID
of zero when the device adds an item to a multi-value property for its own
reasons.
The payload is the property identifier followed by the inserted item as the device reports it (see Multi-Value Properties)—never in a form containing key material.
CMD 8: (Device -> Host) CMD_PROP_REMOVED
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI, 1-3 bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| REPORTED ITEM ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_REMOVED
Item-removed notification. Sent by the device in response to a successful
CMD_PROP_REMOVE (with the TID of that command), or unsolicited with a TID
of zero when the device removes an item from a multi-value property for its
own reasons.
The payload is the property identifier followed by the removed item as the device reports it.
CMD 16: (Host -> Device) CMD_REBOOT
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD_REBOOT |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_REBOOT
Restart the device. Commands the device to power-cycle its hardware, keeping every piece of state it has persisted: the saved snapshot, the device identity, the pairing PIN, and all bonds survive, and the device comes back configured as it was.
This differs from CMD_RST, which returns protocol state to
its post-reset values with the device still running, and from
CMD_FACTORY_RESET, which erases
that state before restarting. Between the three, this is the one that
changes nothing—it is how a host clears a condition the protocol cannot
name.
The command payload SHOULD be empty and MUST be ignored. A device that
restarts sends no response: the reboot drops the transport link, and
the TID is therefore irrelevant. A host treats the ensuing disconnect (and
the device’s subsequent reappearance announcing STATUS_RESET_POWER_ON)
as completion, and MUST NOT wait for a PROP_LAST_STATUS.
This command is only available on devices advertising CAP_REBOOT.
A device without it answers STATUS_UNIMPLEMENTED—which is the only
response this command ever produces, and the only thing that distinguishes
a device that declined from one that is already restarting.
CMD 17: (Host -> Device) CMD_DFU
Enter the platform’s bootloader for a firmware update. The payload is empty
or one UINT8 selecting the DFU method:
| Value | Method |
|---|---|
| 0 | Default DFU |
| 1 | Serial/USB-CDC DFU |
| 2 | UF2 (file-copy) DFU |
| 3 | BLE DFU |
An empty payload selects Default. The default is fixed by the platform,
independent of the command’s transport. XIAO nRF52 and SenseCAP Solar use
BLE; T-Echo, T1000-E, and Wio Tracker L1 use UF2.
Other mode values are undefined. Entering the bootloader is a restart into
it, so this command is only available on devices advertising CAP_REBOOT;
a device without it answers STATUS_UNIMPLEMENTED. There is no discovery
property for the methods; the device decides whether its supported
bootloader can enter the requested mode.
The device answers with CMD_PROP_IS(PROP_LAST_STATUS):
| Status | Meaning |
|---|---|
STATUS_OK | Prepared to enter DFU after transmitting this response |
STATUS_UNIMPLEMENTED | The platform or its supported bootloader cannot enter this method |
STATUS_INVALID_ARGUMENT | The mode is undefined |
STATUS_PARSE_ERROR | The payload contains more than one byte |
Other failure statuses report preparation failures and leave the application running. Before returning success, the device MUST complete all fallible preparation, including persisting replay-counter state. It MUST NOT enter DFU until the complete matching response has transmitted. Queue acceptance alone is insufficient. Failed, canceled, or expired response transmission MUST leave the application running and invalidate the pending action and any retained success response. Completion of another response, or of an earlier transport generation, MUST NOT authorize entry.
A direct request MUST use a nonzero TID. A direct TID-zero request records
STATUS_INVALID_ARGUMENT without entering DFU. Over
Node Management, the TID is zero and the
ordinary token-correlated response confirms acceptance. This command does
not use reset-command acknowledgment semantics.
DFU entry preserves saved configuration, identity, bonds, and pairing credentials. Unsaved application state is lost. Existing administrative authentication and authorization apply. Bootloader residency and exit behavior are bootloader-defined; automatic return to UMSH is not promised. The command enters DFU only and does not transfer or install firmware.
A host MUST report success only upon receiving STATUS_OK. Timeout or
disconnect before that response leaves entry unconfirmed and MUST NOT
cause an automatic new DFU command. Hosts SHOULD warn that the device may
remain inaccessible indefinitely, and that BLE updating requires an
updater within Bluetooth range. Older firmware’s STATUS_INVALID_COMMAND
is treated as unsupported. This additive command does not change the
protocol version.
CMD 21: (Host -> Device) CMD_PROP_MULTI_GET
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | PROP_KEY (PUI) | PROP_KEY ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_MULTI_GET
Get several property values at once. Commands the device to reply with a
single CMD_PROP_ARE carrying one entry for each
requested property, in request order.
The payload is one or more property identifiers, each encoded in the packed unsigned integer format, one after another with no delimiters.
Fetching continues past failures: a property that cannot be fetched
occupies its position in the reply as a PROP_LAST_STATUS entry whose
value is the status code a CMD_PROP_GET of that property would have
produced. Position, not the entry’s key, identifies which request an
entry answers.
This command is available only on devices advertising CAP_CMD_MULTI.
On any other device it is an unrecognized command,
STATUS_INVALID_COMMAND.
Battery diagnostics define a shared acquisition group: when a device implements those properties, supported battery readings within one multi-get use one acquisition pass, including duplicate keys. This does not make other properties atomic or imply simultaneous hardware measurements.
CMD 22: (Host -> Device) CMD_PROP_MULTI_SET
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | ENTRY | ENTRY | ENTRY ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_MULTI_SET
Set several property values in order. The payload is a sequence of entries, each the combined length of its key and value encoded as a packed unsigned integer, followed by that many octets—the property identifier as a packed unsigned integer, then the value:
+--------------+---------------------------+--------------------+
| LENGTH (PUI) | PROP_KEY (PUI, 1-3 bytes) | VALUE (remainder) |
+--------------+---------------------------+--------------------+
Figure: CMD_PROP_MULTI_SET Entry Format
The device applies each entry exactly as a CMD_PROP_SET of that
property would, strictly in payload order, stopping at the first entry
that fails. Mutation Atomicity applies to each
entry alone: the sequence is not a transaction, and a failure partway
leaves the earlier entries applied.
The reply is a single CMD_PROP_ARE containing, for
each applied entry in order, the property and its reported value—
exactly what the CMD_PROP_IS answering a lone CMD_PROP_SET would
carry—and, for the failing entry, a PROP_LAST_STATUS entry carrying
the error, after which the reply ends. Entries past the failure are not
executed and contribute nothing; a reply whose every entry is a success
covers the entire request.
This command is available only on devices advertising CAP_CMD_MULTI.
On any other device it is an unrecognized command,
STATUS_INVALID_COMMAND.
CMD 23: (Device -> Host) CMD_PROP_ARE
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD | ENTRY | ENTRY | ENTRY ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_PROP_ARE
Multiple property value notification. The payload is a sequence of
entries in the same encoding as CMD_PROP_MULTI_SET: a combined
key-and-value length as a packed unsigned integer, the property
identifier, and the value as the device reports it—under the same
reporting rules as CMD_PROP_IS, so key material never appears (see
Multi-Value Properties).
The device emits this command only in response to CMD_PROP_MULTI_GET
or CMD_PROP_MULTI_SET, with the TID of that command. It MUST NOT
be emitted unsolicited: asynchronous updates use CMD_PROP_IS and its
companions, one property at a time.
CMD 24: (Device -> Host) CMD_SESSION_DID_END
0 1 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | 0 | CMD | REASON
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_SESSION_DID_END
Reports that the device has ended a serial link’s session.
The device has discarded the link’s session state and
will answer no request the link sent before it. Until the link starts a
new session with CMD_SESSION_START, the device
sends the link nothing else and discards its requests unanswered. The
one request it still acts on is a write to
PROP_UART_WINDOW, which governs the link rather
than its session: the new session’s first frame goes out under it.
The device sends it with TID 0, on the link whose session ended and on no other. A connection link’s session ends when the connection closes, so the command is not sent there, and it is never sent over the administrative binding, which has no session.
REASON is a packed unsigned integer. It is diagnostic—a host’s obligation is the same for every value:
| Value | Meaning |
|---|---|
| 0 | A frame sent to the device on the link was lost |
| 1 | The device discarded a frame it owed the link (see A Link That Stops Reading) |
Unassigned values are reserved. A host MUST treat an unrecognized reason as it treats the others, never as a parse failure.
Where the link cannot take the frame when it is due, the device owes it, and sends it before anything else once the link takes output again.
A host or application that receives it abandons every request it has outstanding on the link. To go on using the link, it starts a new session.
CMD 28: (Host -> Device) CMD_SESSION_START
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_SESSION_START
Starts a new session on the local link it arrives on, ending the one in progress if there is one. On a serial link it is how a host or application opens a session with a boundary it can recognize, and how it goes on after its session ends. A connection link’s session is its connection, so a host there has no need of it, but the device answers it there the same way.
The payload SHOULD be empty, and the device MUST ignore it. A host sends it with a non-zero TID, so that a device that does not implement it can say so.
The device discards the link’s session state, answers no request it
received on the link before this one, and replies with
CMD_SESSION_DID_START. Nothing outside the
link’s session state changes: the host domain, the device domain, and
PROP_LAST_STATUS are untouched. On a host link this is an attach
without the transport event. Over the administrative binding, which has
no session, the device answers STATUS_NOT_PERMITTED.
A device of minor version 0 answers it with STATUS_INVALID_COMMAND and
changes nothing. A host that receives this carries on without the
command.
Starting a Session
On a serial link, a host or application:
- SHOULD open its session with
CMD_SESSION_STARTrather than rely on the session the link already has. A host that has just started cannot otherwise tell whether the link still holds answers owed to an earlier run. A device never requires it: a serial link has a session from the moment the device starts. - MUST send it to go on using the link after
CMD_SESSION_DID_END. - MUST send it when a frame sent to it is lost, or when it meets any other session-level error it cannot otherwise recover from. A reply that never comes is one.
Having sent it, a host or application:
- Ignores every frame until
CMD_SESSION_DID_STARTarrives. Every frame before the reply belongs to the session that ended. The one exception isPROP_LAST_STATUScarryingSTATUS_INVALID_COMMANDand the request’s TID, from a device that predates the command. - Sends no other request until then. The reply is therefore the boundary: every answer after it is to a request sent after it.
- Sends the request again after a short wait if no reply comes, for as long as it takes. A request or its reply can be lost with neither end seeing a damaged frame: the device may still be starting, or the link may have been disconnected.
- Ignores a
CMD_SESSION_DID_STARTthat arrives when it is not waiting for one. That reply answers a request that was sent again, and the link delivers in order, so the device handled the request before anything the host sent since.
The value of the TID plays no part in this; the reply carries it because every answer does.
CMD 29: (Device -> Host) CMD_SESSION_DID_START
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 0| RES | TID | CMD |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: Structure of CMD_SESSION_DID_START
The device’s answer to CMD_SESSION_START,
carrying its TID. The payload is empty. It is the first frame of the new
session: everything the device sends the link after it belongs to that
session, and nothing it sent before does.
A host that receives it runs the post-attach procedure again (see Attach, Detach, and Synchronization): whatever it held in session state went with the session that ended.
None of the three session commands is a reset code, and
none of them disturbs PROP_LAST_STATUS. The two report different
losses: STATUS_RESET_POWER_ON means the host domain went with the
session and must be reprovisioned in full, whereas a session’s end costs
only session state. A reboot ends every session, so recording the
narrower fact over the broader one would lose the distinction that
governs recovery.
Properties and Streams
A property is a piece of device state with a value the host can read and, where the property allows it, write. A stream is a packet-like flow that is not modeled as state; streams share the property identifier space and are carried by their own commands (see Frame Transport).
Note
The properties marked as supporting
Ismeans that the property may be emitted asynchronously. All properties that supportGetorSetwill emit anIsto respond with the current/new value of that property.A multi-value property marked as supporting
InsertedorRemovedmay likewise emit those asynchronously, reporting one item the device added or dropped for its own reasons rather than the whole value. A host that tolerates an unsolicitedIsmust tolerate these as well.
Multi-Value Properties
A multi-value property holds an unordered set of items rather than a
single value. PROP_CAPS is one, and is constant; the key, peer, and
filter tables of the device and host domains are mutable ones.
The host writes items (CMD_PROP_SET, CMD_PROP_INSERT) in the
property’s item form. When the device reports items (CMD_PROP_IS,
CMD_PROP_INSERTED, CMD_PROP_REMOVED), it reports them exactly as
written—except where the item form contains symmetric key material. Such
a property documents its reported form instead: the entry with its
key material omitted, or a value derived from it (a group key is
reported as its derived short group
ID), so that
secrets can never be read back (see Provisioning
Security).
The commands valid on a mutable multi-value property are:
CMD_PROP_GET—the device replies withCMD_PROP_ISwhose value is the concatenation of all items as reported. If the property is documented as having an item length prefix, each item is preceded by its length in octets encoded as a packed unsigned integer; properties whose reported items are fixed-size omit the prefix.CMD_PROP_SET—replaces the entire contents with the items encoded in the value, each in item form (with the same length-prefix rule). Setting an empty value clears the property. Success is reported with aCMD_PROP_IScarrying the new complete value as reported.CMD_PROP_INSERT/CMD_PROP_REMOVE—add or remove one item, as defined above.
Hosts manipulating large tables SHOULD prefer Insert/Remove over
whole-table Set, since a full table may not fit comfortably in one frame
on all transports.
Mutation Atomicity
State-changing operations in this protocol are transactional and fail closed:
- The device MUST validate a complete request before changing any state.
A whole-table
CMD_PROP_SETwhose value contains any invalid item fails without applying any of it. - Whole-table replacement is atomic: no observer of device behavior (frame filtering, acknowledgment decisions) sees a mixture of the old and new contents.
- Operations that include durable writes—
CMD_SAVE,CMD_CLEAR, installing or generating the device identity, and settingPROP_BLE_PAIRING_PIN—MUST NOT report success before the durable write has completed. - On any failure, the prior live and durable state remains unchanged, and
the device MUST NOT emit
CMD_PROP_IS,CMD_PROP_INSERTED, orCMD_PROP_REMOVEDnotifications describing a partially applied change. - Host replacement is atomic in the same sense: at no point may the device operate with a mixture of the old and new hosts’ keys, filters, or policy. It involves no durable write, so it cannot fail partway.
Atomicity is per operation, not per sequence. Establishing a host domain is several property writes, and an interruption between them leaves a mixture of old and new—bounded by the fact that a host-key change resets the domain first and a reboot empties it. A host repairs this the same way it provisions in the first place: by writing everything again.
Core Properties
These properties exist on every device and are not gated by any capability.
| Id | Mnemonic | Commands | Description |
|---|---|---|---|
| 0 | PROP_LAST_STATUS | Get, Is | Last status |
| 1 | PROP_PROTOCOL_VERSION | Get | Protocol version |
| 2 | PROP_DEV_VERSION | Get | Device version string |
| 3 | PROP_INTERFACE_TYPE | Get | Interface type |
| 4 | PROP_DEV_MODEL | Get | Hardware model |
| 5 | PROP_CAPS | Get | Capabilities |
| 6 | PROP_UPTIME | Get | Seconds since boot |
| 7 | PROP_RESET_REASON | Get | Why the device last started |
| 8 | PROP_PANIC_MESSAGE | Get | The previous boot’s crash record |
PROP 0: PROP_LAST_STATUS
- Type: Single-Value, Read-Only
- Asynchronous Updates: Yes
- Required: REQUIRED
- Value Type: PUI + STRING(opt.)
- Units: Enumeration
- Post-Reset Value: Reset Reason Code
This property describes the status code of the last device operation. For many
commands, failure is indicated by emitting CMD_PROP_IS for this property with
a TID matching the failing command. It is generally not necessary to ever fetch
the value of this property explicitly, as it is often emitted directly as an
error response. It is also occasionally emitted as a success response with a
value of STATUS_OK.
Upon device reset, this property MUST be emitted with a status code indicating the reset reason.
Upon receiving an asynchronous update to PROP_LAST_STATUS with a status code
that indicates a reset, the host SHALL assume that the device has been reset and
that all properties have reverted to their defined after-reset values.
See Status Codes for the complete list of status codes.
PROP 1: PROP_PROTOCOL_VERSION
- Type: Single-Value, Constant
- Asynchronous Updates: No
- Required: REQUIRED
- Scope: Device
- Value Type: UINT8, UINT8
- Post-Reset Value: 6, 1
Describes the ULCP version information. This property contains two fields:
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MAJOR_VERSION | MINOR_VERSION |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure: PROP_PROTOCOL_VERSION Value Format
MAJOR_VERSION- The major version number is used to identify backward incompatible differences between protocol versions.
MINOR_VERSION- The minor version number is used to identify backward-compatible differences between protocol versions. A mismatch between the advertised minor version number and the minor version that is supported by the host SHOULD NOT be fatal to the operation of the host.
This document describes major version 6, minor version 1 of this protocol.
A host compares the major version alone. Minor version 1 adds
CMD_SESSION_START; a device of minor version 0
answers it with STATUS_INVALID_COMMAND, and a host that receives this
carries on without it.
PROP 2: PROP_DEV_VERSION
- Type: Single-Value, Constant
- Asynchronous Updates: No
- Required: REQUIRED
- Scope: Device
- Value Type: STRING
- Post-Reset Value: Implementation-Specific
Contains a zero-terminated ASCII string which describes the firmware currently running on the device.
The value of this string MUST be different for every firmware release.
The format of the string is not strictly defined, but it is intended to present similarly to the “User-Agent” string from HTTP. The following format is RECOMMENDED:
STACK-NAME/STACK-VERSION[BUILD-INFO][; OTHER-INFO][; BUILD-DATE]
The hardware the firmware is running on belongs in
PROP_DEV_MODEL, not here.
PROP 3: PROP_INTERFACE_TYPE
- Type: Single-Value, Constant
- Asynchronous Updates: No
- Required: REQUIRED
- Scope: NLI
- Value Type: PUI
- Units: Enumeration
- Post-Reset Value: Implementation-Specific
This unsigned packed integer identifies the network protocol implemented by this device. It must return the value 8.
PROP 4: PROP_DEV_MODEL
- Type: Single-Value, Constant
- Asynchronous Updates: No
- Required: OPTIONAL
- Scope: Device
- Value Type: STRING
- Post-Reset Value: Implementation-Specific
Contains a zero-terminated ASCII string naming the hardware model the device
is, such as Seeed SenseCAP T1000-E. Where
PROP_DEV_VERSION describes the firmware a device runs,
this describes the thing it runs on, and the two change independently: the
same firmware release covers several models, and a model outlives every
release built for it.
Firmware built for one specific board SHOULD implement this. A device whose hardware has no fixed identity—a simulator, or an implementation that runs on whatever it is compiled for—SHOULD omit the property rather than return an empty or invented string. A host MUST treat a refused get as “this device does not name its hardware” and continue.
The value SHOULD name the product as its vendor does, so that a host can
match it against an external hardware description. It is intended for display
and for lookup, and is deliberately not an identifier: a host that needs to
make decisions based on what a device can do has
PROP_CAPS for that.
PROP 5: PROP_CAPS
- Type: Multiple-Value, Constant
- Has Item Length Prefix: No
- Asynchronous Updates: No
- Required: REQUIRED
- Scope: NLI
- Item Type: PUI
- Units: Enumeration
- Post-Reset Value: Implementation-Specific
Describes the supported capabilities of this device. Encoded as a list of packed unsigned integers. See Capabilities for a list of values.
PROP 6: PROP_UPTIME
- Type: Single-Value, Read-Only
- Asynchronous Updates: No
- Required: OPTIONAL
- Scope: Device
- Value Type: UINT32
- Units: Seconds
- Post-Reset Value: 0
Seconds elapsed since the device last booted, truncated toward zero. A device that runs long enough to exhaust the range saturates rather than wrapping, so the value never falsely reports a recent restart.
This dates what PROP_LAST_STATUS describes: the
reset code says why the device last started, and this says how long ago.
Read together they distinguish a node that came up cleanly weeks back
from one that is restarting under a fault and reporting the same code
each time.
Only a power cycle or a genuine restart resets it. CMD_RST returns
protocol state to its post-reset values without rebooting the device, and
MUST NOT reset this property; neither does a host attaching or
detaching.
A device with no monotonic clock to answer from SHOULD omit the property rather than report a fabricated value. A host MUST treat a refused get as “this device does not report its uptime” and continue.
PROP 7: PROP_RESET_REASON
- Type: Single-Value, Read-Only
- Asynchronous Updates: No
- Required: OPTIONAL
- Scope: Device
- Value Type: PUI + STRING(opt.)
- Units: Enumeration
- Post-Reset Value: Reset Reason Code
The reset code that PROP_LAST_STATUS
carried when the device started, kept for as long as the device runs.
PROP_LAST_STATUS gives it up to the first operation after a reset; this
holds it, and reading it changes nothing, so a host can learn why a device
last restarted whenever it attaches.
The code MAY be followed by a string describing the reset in the hardware’s own terms, such as the reset-cause register of the device’s processor. Its content is implementation-specific and meant for a person diagnosing the device; a host MUST NOT parse it.
Only a genuine restart changes the value. CMD_RST and CMD_RESTORE
return protocol state to its post-reset values without restarting the
device and MUST NOT change it; neither does a host attaching,
detaching, or ending a session.
A host MUST treat a refused get as “this device does not report its reset reason” and continue.
PROP 8: PROP_PANIC_MESSAGE
- Type: Single-Value, Read-Only
- Asynchronous Updates: No
- Required: OPTIONAL
- Scope: Device
- Value Type: STRING
- Post-Reset Value: Implementation-Specific
The message the firmware recorded as the previous boot ended in a crash:
a panic’s text and source location, or where a watchdog found the
firmware stuck. It is empty when the device last started for any other
reason. Same lifetime as
PROP_RESET_REASON: it changes only on a genuine
restart.
The device MAY truncate the message, and a host MUST NOT assume it is complete. A device that does not record crash messages SHOULD omit the property rather than report it empty, so that an empty value always means there was nothing to record.
State Classes
Every piece of device state belongs to exactly one of three classes. The classes determine what survives a host attach, a change of host, and a power cycle.
Session State
State that belongs to one local link’s session. Every local link has a
session (see Sessions). The attached host’s holds transaction (TID) correlation,
transport reassembly buffers, and the session-scoped properties
PROP_MAC_PROMISCUOUS, PROP_MAC_BACKHAUL, and
PROP_NODE_MSG_LISTEN,
and exists only while a host is attached. The device’s own
interface’s holds its transaction correlation and
transport state alone.
Session state is at its defaults whenever a session begins, and is discarded when one ends. Resetting it never affects radio operation.
Device Domain
State that belongs to the device itself, independent of which host is attached:
- the device identity keypair (independently persisted; never part of the saved snapshot—see Saved State)
- the device identity’s group keys (
PROP_DEV_GROUP_KEYS) and peer list (PROP_DEV_PEERS) - the RF configuration (
PROP_PHY_*), includingPROP_PHY_ENABLED, and the duty-cycle limit - the human-readable device name (
PROP_DEV_NAME) - live battery telemetry (
PROP_BATTERY), whenCAP_BATTERYis present - device behavior settings (property identifiers 70–95): the repeater
forwarding mode (
PROP_MAC_REPEATER_MODE), with the rest of the range reserved for future definition (further repeater policy, positioning, periodic advertisement of the device identity, and similar) - the administrator list (
PROP_DEV_ADMINS) authorizing node management over the mesh - transport configuration such as
PROP_BLE_PAIRING_PIN
The RF configuration is deliberately device-domain: a site repeater keeps its frequency and regulatory limits no matter which phone pairs with it. An attached host may still reconfigure it at any time.
Host Domain
State that belongs to the currently configured tethered host identity:
PROP_HOST_KEYitself- the host’s group keys and peer keys
- the receive filter table and acknowledgment-delegation policy
- the inbound queue: its configuration and its contents
The host domain is volatile across a power cycle, and only across a power cycle. It MUST NOT be persisted: it is not part of the saved snapshot, and at power-on every host-domain property takes its documented default.
It emphatically does survive a disconnect. A detached radio keeps filtering, queueing and acknowledging on behalf of its host—that is the entire value of the host domain, and nothing about the host going out of range changes what the host wants done. What bounds it is the rule that only one device answers for an identity at a time: a detached radio stands down after a lease or when its queue fills with held messages, and resets the host domain when it hears the host identity elsewhere.
The two together give the host a simple rule with no detection in it: a host MUST establish its complete host domain on every tethered attach, writing every part of it rather than reasoning about what the device already holds. Key material cannot be compared anyway—the key tables never read it back (see Provisioning Security), so a peer’s pairwise keys can be replaced without changing anything the host can observe. Where the device is already provisioned as asked, the rewrite is redundant; that is preferable to depending on a signal that would also have to cover partial provisioning, another administrator’s intervention, and future device behavior. A boot generation or reset indication MAY be used to skip the rewrite as an optimization, never to decide whether it is needed.
Property Allocation
Property and stream identifiers are allocated by state class and subsystem:
| Range | Class |
|---|---|
| 0–31 | Core protocol state |
| 32–47 | Radio control (PROP_PHY_*) |
| 48–63 | Session-scoped and global protocol state |
| 64–95 | Device domain |
| 96–111 | Host domain (PROP_HOST_*) |
| 112–127 | Streams (STR_*) |
| 4608–4863 | Extended radio control |
| 4864–5119 | Extended device and transport configuration |
Unassigned identifiers in these ranges are reserved. The identifiers in use are listed in the Command and Property Index.
Attach, Detach, and Synchronization
How attach and detach are detected is defined by the transport binding:
- BLE—enabling/disabling notifications on Frame Out, as specified in ULCP over BLE.
- USB-CDC—assertion and deassertion of DTR on the ULCP interface.
- TCP—establishment and closure of the connection.
- Local socket—establishment and closure of the connection.
- Bare UART—the transport has no attach event. A device with no way to detect host presence MAY treat the host as permanently attached, in which case it never enters detached operation and offline assistance (Inbound Queueing, Acknowledgment Delegation) is unavailable on that transport. Either way, the link has a session from the moment the device starts (see Sessions).
On attach, the device MUST reset session state (see State Classes) and MUST NOT modify the device or host domains in any way. In particular, the PHY is not disabled and no property outside session state changes value. The device MUST NOT emit any frame before attach, and the attach itself produces no unsolicited notification: a session that begins at attach holds nothing from before it.
Because attach no longer implies any known default state, the host synchronizes by fetching, not by assuming. The following post-attach procedure is RECOMMENDED:
CMD_PROP_GETforPROP_LAST_STATUS. If it returns a reset code (see Reset Codes), the device has reset since the last host command, so any state that is not restored from saved state (notably queue contents) has been lost.CMD_PROP_GETforPROP_HOST_KEY. An empty value is the ordinary case after a power cycle—the host domain does not survive one—and the host simply provisions. A value matching the host’s own identity means its provisioning is still live from before the disconnect. Any other value means another host has taken the radio over since this host last attached; the queue and provisioning belong to that identity, and this host must decide whether to take the radio over (see Host Replacement) before doing anything else.CMD_PROP_GETfor the device-domain properties the host depends on (PROP_SAVED, thePROP_PHY_*configuration), and forPROP_HOST_RX_QUEUE_COUNT.- Establish the complete host domain (see Host Domain): write
PROP_HOST_KEY, the key tables, the filter table and the delegation policy in full. The key tables are read back only to find entries the host no longer wants, which it removes; entries it does want are written whether or not the device reports them, since key material is not readable and so cannot be compared. - Issue
CMD_QUEUE_DRAINwhen actually ready to process backlogged traffic.
More generally, a host MUST tolerate unsolicited CMD_PROP_IS,
CMD_PROP_INSERTED, and CMD_PROP_REMOVED notifications at any time
while attached, updating its view of the affected property accordingly:
device state can change for reasons the host did not initiate, and
publication of the new authoritative value is how the protocol reports
that.
A request from another binding is one such reason. Whatever a request changes, the device MUST publish to everyone else listening—an attached host, and the device’s own interface— whether the request came from one of them or from a Node Management administrator. Each property the answer reports goes out unsolicited, one at a time, as the answer reported it; the status that closes the request goes to the requester alone. This holds for every property: a property’s Asynchronous Updates entry describes the changes the device makes for its own reasons. A fire-and-forget request (TID 0) on a local binding is not answered, and what it changes need not be published.
A host that starts a new session runs this procedure again once
CMD_SESSION_DID_START arrives.
On detach, the device discards session state, keeps operating with the current device- and host-domain state, and begins detached operation: accepted frames are queued rather than delivered, and acknowledgment delegation (if enabled) becomes active.
Sessions
Every local link has a session, which holds its session state. How a session begins and ends depends on whether the link is a connection that either end can close:
- Connection links: BLE, a TCP connection the device serves itself, and a local socket. A session begins at attach and ends at detach. These transports deliver every frame whole and in order, so when one does not, the transport or the other end has failed, and whichever end finds a lost frame ends the session: a host by detaching, the device by closing the connection.
- Serial links: a UART, USB-CDC, and a stream standing in for a
serial link, which the device sees as the serial link it is. Either end
can see a damaged frame, and neither can close the link. A session
begins at attach where the transport has an attach event, and when the
device starts where it has none. It ends at detach, or when the device
ends it with
CMD_SESSION_DID_END, and a host or application starts a new one withCMD_SESSION_START.
A device never requires CMD_SESSION_START before it serves a link:
every link has a session from attach, or from the moment the device
starts. A session the device has ended stays ended until the link starts
a new one.
CMD_RST and CMD_RESTORE
in its reset form start the requesting link’s session over in place. The
reset code that completes either one is the first frame of the new
session, as CMD_SESSION_DID_START is.
A Link That Stops Reading
A host, or an application on the device’s own interface, asserts flow control by not reading: the transport’s own backpressure—notification pacing over BLE, an unread USB endpoint, a full TCP window, XON and XOFF on a UART—holds back the device’s output. A device serves more than one link, so it does not let that hold the rest of it back for long:
- A live
CMD_STR_RECVthe transport cannot take at once MAY be discarded. It is lost as though on the air, and a sender that asked for an acknowledgment retransmits. The device counts it inPROP_STAT_HOST_RX_DROPPED. - Any other frame for the link MAY be discarded once the link has
refused output for 5 seconds, and from then on until it takes output
again. The device counts each one discarded for a host in
PROP_STAT_HOST_OUT_DROPPED. ACMD_QUEUE_DRAINcut short this way ends without its completion, and the frames it did not deliver stay queued.
An answer or a publication discarded this way is a frame the device owed
the link and did not send, and it ends the link’s session (see Lost
Frames). A live CMD_STR_RECV is not owed in this sense
and ends nothing. A node
message is never discarded this
way; it waits for the link.
Lost Frames
ULCP assumes the transport delivers every frame whole and in order. When it does not, the two ends no longer agree on what has been asked and answered: a lost request is never answered, a lost answer leaves its request outstanding forever, and a lost publication leaves the reader’s view of the device wrong. Nothing short of a new session puts them back in step.
A frame is lost when an end knows a frame was sent to it and its transport could not hand that frame to ULCP whole. Why the transport failed does not matter, and neither does which transport it is:
- On HDLC-Lite: a frame whose FCS fails, a frame too short to carry one, an aborted escape, or a frame longer than the receiver can hold. Marked text, fill, and an unescaped XON or XOFF are not frames, and are not lost, and neither is what is left of a wake preamble after a sleep.
- Over BLE: a frame discarded in reassembly, for any of the reasons given there, and a reassembled frame the transport could not accept.
A frame that reached ULCP whole and whose contents ULCP does not understand—an unknown command, a property a newer protocol version defines—is not lost. It is answered as this chapter specifies, and the session stands.
An uncorrectable error in a received frame is the same as corruption: the frame is lost. Either end that finds a lost frame ends the session, in the way its link allows (see Sessions):
- On a connection link, a host detaches and the device closes the connection.
- On a serial link, the device ends the session with
CMD_SESSION_DID_ENDand reason 0. A host or application MUST start a new session withCMD_SESSION_START, as it also does for any other session-level error it cannot otherwise recover from (see Starting a Session).
The device does the same when it does not send a frame it owed a link,
an answer or a publication, as in A Link That Stops
Reading: it closes the connection of a connection link,
and ends a serial link’s session with CMD_SESSION_DID_END and reason 1.
Local Sockets
A device that runs as a process—a virtual radio hosted beside the application that attaches to it—may serve ULCP on a local stream socket, such as a Unix domain socket:
- Framing: HDLC-Lite, as on a serial link.
- Attach and detach: a connection opening is an attach, and its closing is a detach.
- One host at a time: a new connection replaces the current one, which the device closes first. A host that went away without closing never holds the device against its successor.
- Security binding: access to the socket. The device MUST place the socket where the operating system lets only the processes entitled to the device reach it—a file in a directory private to those processes—which stands in for physical possession.
HDLC-Lite on a ULCP Link
Three rules apply to every ULCP link framed with HDLC-Lite—a serial link, a stream standing in for one, a local socket—in both directions:
- XON and XOFF are never frame content. HDLC-Lite escapes XON
(
0x11) and XOFF (0x13) inside a frame so that a link can use them. An unescaped one belongs to no frame: a receiver ignores it wherever it falls, between frames or inside one, and the frame around it is unaffected. What a link does with the two octets is flow control; a link that does nothing with them still ignores them. - Marked text. A frame whose first octet is
0x23(#) is marked text, not a ULCP frame. The receiver discards everything up to the next flag octet, with no escape processing and no FCS. This is how a device puts diagnostic text on a link between frames. - Fill. A frame whose first octet is
0xFFis fill, not a ULCP frame. The receiver discards everything up to the next flag octet, as for marked text, and it is not a lost frame. Fill is what a wake preamble is made of.
Marked text MUST NOT contain the flag octet (0x7E, ~), XON, or
XOFF; a writer replaces them. Nothing else about its content matters.
No frame begins with the marker or with fill: a ULCP header is
10000ttt in binary, and it takes at least two damaged bits to turn one
into 0x23 and four to turn one into 0xFF. Marked text is not
protected. A line whose marker is damaged is read as a
lost frame, and a frame whose header is damaged into the
marker is skipped; the reply that never comes is what reveals it. Text a
device cannot mark, such as what a boot loader prints, is read as a lost
frame too, and it comes with a restart, which ends the session anyway.
These rules belong to ULCP and not to HDLC-Lite in general: the internet bridge tunnel frames with HDLC-Lite and carries no marked text.
Flow Control on a UART
A ULCP link carried on a UART without hardware flow control uses XON and XOFF. This is a property of the transport, whoever is reading: a host attached over a UART and an application on the device’s own interface alike. Not reading is no flow control on a UART: octets the reader does not take are lost.
No capability announces it. Flow control belongs to the link, not to the
device, and a reader learns whether its link has it by setting
PROP_UART_WINDOW, which it does in any case
before it starts reading. A device that does not implement flow control
answers STATUS_PROP_NOT_FOUND, and its link behaves as though it had
none.
- The reader controls what the device sends with XON (
0x11), which permits the device to send, and XOFF (0x13), which withdraws the permission, both sent outside frames. The device takes whatever it is sent, waking for it if it sleeps, so it sends neither. - With a window of W, each XON permits W further octets on the wire, counted from its receipt and not added to whatever was left of the previous permission. The device then waits for the next XON. At boot the device has no permission.
- With a window of 0, a permission has no limit, and the device starts permitted. This is plain XON/XOFF; a reader that sends neither octet sees the link behave as though it had no flow control. A serial driver’s own software flow control sends the two octets with no wake preamble, so it serves only a device known not to sleep.
- After XOFF, the device sends at most the octets it had already handed to its UART. A device SHOULD keep that to 16 octets or fewer. An XOFF that needs a wake preamble reaches the device after it, and the device may send for that long first.
- A reader that does not know the device’s state—one that has just
started, say—sends XOFF, sets the window, sends
CMD_SESSION_START, and only then sends XON. The device acts on what it receives in order, so the window is in force before the first octet it permits.
A window serves a reader whose buffer is small. Without one, a reader with a 64-octet buffer cannot send XOFF in time unless it is polled every few milliseconds; with one, it grants only what its buffer holds and needs no timing at all. A window also means that a reader that has stopped or been disconnected stops receiving by itself.
What the device does with output it is not permitted to send is what it does for any link that is not reading (see A Link That Stops Reading).
PROP 5010: PROP_UART_WINDOW
- Type: Single-Value, Read-Write
- Asynchronous Updates: No
- Required: REQUIRED on a UART link with flow control
- Scope: Link
- Value Type: UINT16
- Units: Octets
- Post-Reset Value: 0, or the saved value
The window of the UART link the request arrives on, saved with the
device domain. Each UART link has its own, and only the reader on that
link reads or sets it. A request from a link that is not a UART, or from
an administrator over the mesh, is answered with STATUS_NOT_PERMITTED.
Setting the window to the value it already has writes nothing to
non-volatile storage. A new window takes effect at the next XON.
Waking a Device on a UART
A device may sleep while it listens on a UART and wake on activity on the line. Waking costs it the octets that wake it and those that arrive before its UART runs again. No capability announces whether a device sleeps, so every reader on a UART follows these rules:
- The reader. A reader MUST send a wake preamble ahead of the
first frame, XON, or XOFF it sends on the link, and ahead of any it
sends after it has sent nothing for 100 ms. The preamble is
0xFFoctets, at least 8 of them and enough to last at least 5 ms, and then a flag: at 115200 baud, 58 octets of0xFFand a flag. A reader MAY send one ahead of any frame, XON, or XOFF. - Inside a frame. A preamble ends in a flag, so it never goes inside a frame. A reader MUST NOT pause for 100 ms or more inside one.
- The device. A device that sleeps MUST stay awake for at least 250 ms after the last octet it received, and for as long as it is sending.
- After a sleep. When a device may have slept since it last received, what it receives before the next flag is what is left of a preamble. It is not a frame, it is not a lost frame, and it is not XON or XOFF.
The preamble is fill, so a device that was awake discards
it. A 0xFF octet has one falling edge, its start bit, so a UART that
starts partway through the run aligns on a real octet. It has one rising
edge, so a device that wakes on a count of edges counts one for each
octet, and eight is enough for a device that needs several.
The Device’s Own Interface
A device may have an interface of its own, served beside any attached host with the commands a host uses. It is either built into the device—a screen and keyboard, or a menu—or an application: a microcontroller wired to the device over a UART, framed with HDLC-Lite and paced with XON and XOFF. The interface is a binding of its own:
- Authority. Whoever is holding the device has physical possession, which is a serial link’s security binding (see Provisioning Security). The interface may provision key material, the device identity’s private key included.
- Reach. The device domain, and node
messaging. The host’s session state, the host
domain, the raw PHY stream, and the receive queue belong to whichever
host is tethered, and the device answers the interface’s writes to
them with
STATUS_NOT_PERMITTED, as it answers an administrator’s. Node management’s one host-domain write, the host releasing the device, does not extend to the interface. - A local binding. The device answers every request that carries a non-zero TID exactly once.
- A session of its own. The interface’s session holds its outstanding requests, and it begins and ends apart from the host’s. An application’s UART is a serial link, whose session begins when the device starts. A built-in interface is carried inside the device, and how it learns of output the device could not deliver is the implementation’s.
- Not an attach. Its requests reset nothing of the host’s session and displace no attached host. It does not affect what the device advertises over BLE.
- Publications. The interface hears everything the device publishes, whether or not a host is attached, including what an attached host or an administrator changes. What the interface changes reaches an attached host the same way (see Attach, Detach, and Synchronization).
What the interface changes is saved as anything set at the device is (see Changes Made at the Device).
Provisioning Security
Provisioning moves real key material onto the device, within the limits of the security boundary: group keys and per-peer symmetric keys—and the device identity’s own private key— but never the host’s private key. The rules:
- All symmetric key material, and the device identity private key, is
write-only.
CMD_PROP_GETand all device-emitted notifications report key-bearing properties without their secrets (see Multi-Value Properties): peer public keys withoutK_ENC/K_MIC, short group IDs instead of group keys, and never the device private key. This holds for both identities’ key tables. These read-backs let the host verify what is provisioned after a reconnect without any secret ever crossing the link a second time— which matters because more than one host may be able to attach over the radio’s lifetime (transport bonds are possession credentials, not identity credentials), and a later host must not be able to extract an earlier host’s keys. - Commands that carry key material—
CMD_PROP_SETandCMD_PROP_INSERTfor the key tables, and any set ofPROP_DEV_PRIVATE_KEY—MUST NOT be carried over a transport that does not meet the requirements of the transport’s security binding: physical possession for serial transports, access to the socket for a local socket, or an encrypted bonded LESC link as specified in ULCP over BLE. - A compromised or stolen device exposes the provisioned groups, the provisioned pairwise conversations, and its own device identity, but cannot impersonate the host to any new peer, cannot sign as the host, and cannot decrypt traffic for peers or groups that were never provisioned.
- Hosts SHOULD provision the minimum useful set of peers and groups, SHOULD remove entries that are no longer needed, and SHOULD prefer on-device generation of the device identity over installing one.
- A device advertising
CAP_SAVEMUST store persisted key material in the most protected storage available to it.
Status Codes
Status codes are used for PROP_LAST_STATUS. When a command generates a status
code, it is returned via a CMD_PROP_IS with a property of PROP_LAST_STATUS
and the TID of command it is referring to.
| Id | Name |
|---|---|
| 0 | STATUS_OK |
| 1 | STATUS_FAILURE |
| 2 | STATUS_UNIMPLEMENTED |
| 3 | STATUS_INVALID_ARGUMENT |
| 4 | STATUS_INVALID_STATE |
| 5 | STATUS_INVALID_COMMAND |
| 7 | STATUS_INTERNAL_ERROR |
| 9 | STATUS_PARSE_ERROR |
| 10 | STATUS_IN_PROGRESS |
| 11 | STATUS_NOMEM |
| 12 | STATUS_BUSY |
| 13 | STATUS_PROP_NOT_FOUND |
| 18 | STATUS_CCA_FAILURE |
| 19 | STATUS_ALREADY |
| 20 | STATUS_ITEM_NOT_FOUND |
| 21 | STATUS_CURSOR_INVALID |
| 22 | STATUS_NOT_PERMITTED |
| 23 | STATUS_GROUP_NOT_FOUND |
| 24 | STATUS_NO_DEVICE |
| 25 | STATUS_NACK |
| 26 | STATUS_BUS_ERROR |
| 27 | STATUS_NO_ACK |
| 32 | STATUS_DUTY_LIMIT |
STATUS_OK- Indicates that the operation has completed successfully.
STATUS_FAILURE- Indicates that the operation has failed for an unspecified reason. The use of this status code SHOULD be avoided. If a more specific status code exists that better explains the failure, then that status code MUST be used instead.
STATUS_UNIMPLEMENTED- Indicates that the given operation has not been implemented.
STATUS_INVALID_ARGUMENT- Indicates that an argument to the given operation is invalid. The value may be out of range or improperly formatted. This status code is also returned when setting an invalid value to a property.
STATUS_INVALID_STATE- Indicates that the given operation is invalid for the current state of the device.
STATUS_INVALID_COMMAND- The given command id is not recognized.
STATUS_INTERNAL_ERROR- An internal runtime error has occurred.
STATUS_PARSE_ERROR- An error has occurred while parsing the command.
STATUS_IN_PROGRESS- Indicates that the operation was started but has not completed, and completion will be reported asynchronously.
STATUS_NOMEM- The operation has been prevented due to memory pressure.
STATUS_BUSY- The device is currently performing a mutually exclusive operation. This status
differs from
STATUS_INVALID_STATEin that it will resolve spontaneously. STATUS_PROP_NOT_FOUND- The given property key is not recognized.
STATUS_ALREADY- The requested state is already in effect; in particular, the item passed
to
CMD_PROP_INSERTis already present in the property. STATUS_ITEM_NOT_FOUND- The item or selector passed to
CMD_PROP_REMOVEdoes not match any item in the property; or the value written by aCMD_PROP_SETnames an item of another property that does not exist, as a write ofPROP_WIFI_NETWORKnames an entry of the known-network table. It is distinct fromSTATUS_INVALID_ARGUMENTbecause a host acts on it differently: the value is well-formed and the item it names has merely to be created first. STATUS_CURSOR_INVALID- The cursor presented in a Node Management continuation is not one the device can honor—it does not parse, it was issued for a different request, or the response it continues is no longer retained. The administrator restarts the read from an initial, cursor-less request.
STATUS_NOT_PERMITTED- The property or command exists, but the binding the request arrived
over is not allowed to perform it—in particular, a Node
Management write to a property
reserved to the tethered host. Distinct from
STATUS_PROP_NOT_FOUNDandSTATUS_INVALID_COMMAND: the operation would be accepted from a binding with the standing to ask. STATUS_GROUP_NOT_FOUND- The request names a group by its short group
ID and the
device holds no group key that derives it. Distinct from
STATUS_ITEM_NOT_FOUND, which concerns an item of the property being written, and fromSTATUS_INVALID_ARGUMENT: the value is well formed, and the group has only to be provisioned first (PROP_DEV_GROUP_KEYS). STATUS_NO_DEVICE- An I2C transfer was addressed to a
peripheral that did not acknowledge its address: nothing answered on
the bus. Distinct from
STATUS_ITEM_NOT_FOUND, which is the bus itself not being one the device offers. STATUS_NACK- The peripheral acknowledged its address but refused a data octet of the transfer. Operations before the refused one have completed.
STATUS_BUS_ERROR- The bus failed under the transaction: arbitration was lost, a bus error or overrun occurred, a line stayed stuck, or the transaction outlasted the device’s deadline. The device may attempt bus recovery.
STATUS_NO_ACK- A node message that requested an acknowledgment was sent, and none arrived before the device stopped waiting for it. The message may or may not have reached its destination.
STATUS_CCA_FAILURE- The packet was not sent due to a CCA failure. This status code is only emitted when sending data to a packet stream with a TID other than zero.
STATUS_DUTY_LIMIT- The packet cannot be sent because it would exceed the currently set duty-cycle limit.
Reset Codes
All status codes which fall into the inclusive range of 112-127 are considered
reset codes. These codes are emitted asynchronously after a device reset and
provide a way to differentiate different causes of resets. If the first command
the host sends to the device after a reset is to fetch PROP_LAST_STATUS, then
the reset code MUST be returned.
PROP_RESET_REASON, where implemented, keeps the code
after that.
Note
On a device holding a saved snapshot, the post-reset value of every saved property is its saved value rather than the documented default. A host MUST NOT assume that a reset implies documented factory defaults; it should fetch or explicitly set the properties it depends on. Without a snapshot the documented post-reset values apply unconditionally.
| Id | Name |
|---|---|
| 112 | STATUS_RESET_POWER_ON |
| 113 | STATUS_RESET_EXTERNAL |
| 114 | STATUS_RESET_SOFTWARE |
| 115 | STATUS_RESET_RESTORED |
| 116 | STATUS_RESET_CRASH |
| 117 | STATUS_RESET_ASSERT |
| 118 | STATUS_RESET_OTHER |
| 119 | STATUS_RESET_UNKNOWN |
| 120 | STATUS_RESET_WATCHDOG |
| 121 | STATUS_RESET_BROWNOUT |
Of these defined reset codes, only STATUS_RESET_POWER_ON,
STATUS_RESET_EXTERNAL, STATUS_RESET_SOFTWARE, and
STATUS_RESET_RESTORED are emitted during normal operation. All other
reset codes generally indicate some sort of software bug or hardware
failure.
Unexpected or unrequested resets are always an indication of a problem, no matter what the code value is.
The end of a session is not one of these. It costs the host what it
established in session state and nothing more, so it leaves
PROP_LAST_STATUS alone (see Sessions). Every reset code
above ends every session; the end of a session implies none of them.
STATUS_RESET_POWER_ON- Cold power-on start.
STATUS_RESET_EXTERNAL- External device reset. This is generally caused by RESET pin on the device being asserted.
STATUS_RESET_SOFTWARE- Software-requested orderly reset. This is generally caused by the host
sending the device
CMD_RST. STATUS_RESET_RESTORED- Protocol reset into the saved snapshot, emitted when a device completes
CMD_RESTOREin its reset form (seeCMD_RESTORE). Unlike the other reset codes, this one does not indicate a hardware or firmware restart: the transport link and attach state survive it. STATUS_RESET_CRASH- Unrecoverable software execution failure, like a segmentation fault or a stack overflow.
STATUS_RESET_ASSERT- Software invariant property not respected.
STATUS_RESET_OTHER- Unspecified cause.
STATUS_RESET_UNKNOWN- Failure while recovering cause of reset.
STATUS_RESET_WATCHDOG- Watchdog timer expired, forcing a reset.
STATUS_RESET_BROWNOUT- The supply voltage fell below what the device can run at, and the
hardware held it in reset until the supply recovered. A device whose
hardware cannot tell a brownout from a power-on reset reports
STATUS_RESET_POWER_ON.
Capabilities
Capabilities are how a device can advertise support for specific behaviors and
functionalities. They can be fetched via the PROP_CAPS property.
Each capability is defined by the chapter that specifies the behavior it grants:
| Code | Name | Requires | Defined in |
|---|---|---|---|
| 8 | CAP_WRITABLE_RAW_STREAM | — | Frame Transport |
| 16 | CAP_PHY_DUTY_LIMIT | — | Radio Control |
| 32 | CAP_HOST_FILTER | — | Tethered Host Services |
| 33 | CAP_HOST_RX_QUEUE | CAP_HOST_FILTER | Tethered Host Services |
| 34 | CAP_HOST_KEYS | CAP_HOST_FILTER | Tethered Host Services |
| 35 | CAP_HOST_AUTO_ACK | CAP_HOST_KEYS, CAP_HOST_RX_QUEUE | Tethered Host Services |
| 36 | CAP_SAVE | — | Saved State |
| 37 | CAP_DEV_IDENTITY | — | Device Domain |
| 38 | CAP_DEV_NAME | — | Device Domain |
| 39 | CAP_BATTERY | — | Device Domain |
| 40 | CAP_REPEATER | CAP_DEV_IDENTITY | Device Domain |
| 41 | CAP_IDENT | CAP_DEV_IDENTITY | Device Domain |
| 42 | CAP_ALERT | — | Device Domain |
| 43 | CAP_ADMIN | CAP_DEV_IDENTITY, CAP_CMD_MULTI | Node Management |
| 44 | CAP_TIME | — | Device Domain |
| 45 | CAP_GNSS | CAP_TIME | Device Domain |
| 46 | CAP_ADVERT | CAP_DEV_IDENTITY | Device Domain |
| 47 | CAP_ILLUMINANCE | — | Device Domain |
| 48 | CAP_MAC_BACKHAUL | CAP_DEV_IDENTITY | Tethered Host Services |
| 49 | CAP_CMD_MULTI | — | Framing and Common Semantics |
| 50 | CAP_BLE | — | BLE Binding |
| 51 | CAP_REBOOT | — | Framing and Common Semantics |
| 52 | CAP_STATS | — | Radio Control |
| 53 | CAP_WIFI_SCAN | — | Wi-Fi |
| 54 | CAP_WIFI | CAP_WIFI_SCAN | Wi-Fi |
| 55 | CAP_IPV4 | — | IP Connectivity |
| 56 | CAP_IPV6 | — | IP Connectivity |
| 57 | CAP_WIFI_AP | CAP_WIFI_SCAN | Wi-Fi |
| 58 | CAP_BRIDGE_CLIENT | CAP_DEV_IDENTITY; IP family requirement in prose | Bridge Client |
| 59 | CAP_DISPLAY_MOTION_WAKE | — | Device Services |
| 60 | CAP_I2C | — | I2C Bus Access |
| 61 | CAP_TEMPERATURE | — | Device Domain |
| 62 | CAP_MESHCORE_FORWARDER | CAP_REPEATER | Device Domain |
| 63 | CAP_LAN_BEARER | — | IP Multicast |
| 67 | CAP_NODE_MSG | CAP_DEV_IDENTITY | Node Messaging |
| 515 | CAP_PHY_LORA | — | Radio Control |
A device MUST NOT advertise a capability without also advertising the
capabilities it requires. Apart from the multi-property commands, which
CAP_CMD_MULTI gates, CMD_REBOOT, CMD_DFU, and
CMD_FACTORY_RESET, which CAP_REBOOT gates,
CMD_ANNOUNCE, which CAP_ADVERT gates, and the bus-access commands,
which CAP_I2C gates, the
commands and status codes defined in this chapter are unconditional and
need no capability; a device that defines no
mutable multi-value properties simply has nothing to apply
CMD_PROP_INSERT/CMD_PROP_REMOVE to.