Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MeshCore Protocol Specification

Section 2: Header

Overview

The header is the first byte of every MeshCore packet. It encodes three fields using bit packing: the route type (2 bits), the payload type (4 bits), and the protocol version (2 bits).

Bit Layout

  Bit:  7   6   5   4   3   2   1   0
      +---+---+---+---+---+---+---+---+
      | V1  V0| P3  P2  P1  P0| R1  R0|
      +---+---+---+---+---+---+---+---+
             |         |           |
             |         |           +-- Route Type (bits 0-1)
             |         +-------------- Payload Type (bits 2-5)
             +------------------------ Protocol Version (bits 6-7)

The header byte value is computed as:

header = (version << 6) | (payload_type << 2) | route_type

And fields are extracted as:

route_type   = header & 0x03
payload_type = (header >> 2) & 0x0F
version      = (header >> 6) & 0x03

Route Type (bits 0-1)

The route type determines how the packet is routed through the mesh and whether transport codes are present.

ValueNameTransport CodesDescription
0x00TRANSPORT_FLOODYes (4 bytes)Flood routing with transport codes for regional scoping
0x01FLOODNoStandard flood routing; path is built up by intermediate nodes
0x02DIRECTNoDirect routing; path is supplied by the sender
0x03TRANSPORT_DIRECTYes (4 bytes)Direct routing with transport codes

Transport codes MUST be present in the wire format when route type is 0x00 or 0x03, and MUST NOT be present when route type is 0x01 or 0x02.

Payload Type (bits 2-5)

The payload type identifies the structure of the payload data.

ValueNameDescription
0x00REQUESTEncrypted request (dest_hash + src_hash + MAC + ciphertext)
0x01RESPONSEEncrypted response to REQ or ANON_REQ
0x02TXT_MSGEncrypted text message
0x03ACKSimple acknowledgment (4-byte CRC)
0x04ADVERTNode identity advertisement
0x05GRP_TXTEncrypted group text message
0x06GRP_DATAEncrypted group datagram
0x07ANON_REQAnonymous request (full public key instead of hash)
0x08PATHEncrypted returned path information
0x09TRACEPath trace with per-hop SNR collection
0x0AMULTIPARTOne part of a multi-packet sequence
0x0BCONTROLControl/discovery packet
0x0C(reserved)Reserved for future use
0x0D(reserved)Reserved for future use
0x0E(reserved)Reserved for future use
0x0FRAW_CUSTOMCustom raw bytes for application-defined payloads

Implementations SHOULD silently discard packets with reserved payload type values (0x0C-0x0E) unless they have explicit support for extended types.

Protocol Version (bits 6-7)

ValueNameDescription
0x00V1Current version: 1-byte src/dest hashes, 2-byte MAC
0x01V2Reserved for future use
0x02V3Reserved for future use
0x03V4Reserved for future use

Implementations MUST support version 0x00 (V1). Implementations SHOULD reject packets with unrecognized version values.

Special Header Values

The header value 0xFF is used internally as a “do not retransmit” marker. This is an in-memory sentinel only and MUST NOT appear on the wire. A header of 0xFF would decode as version=3, payload_type=0x0F (RAW_CUSTOM), route_type=3 (TRANSPORT_DIRECT).

Encoding Examples

Header ByteBinaryVersionPayload TypeRoute Type
0x0100 000000 01V1 (0)REQUEST (0)FLOOD (1)
0x0500 000001 01V1 (0)RESPONSE (1)FLOOD (1)
0x0900 000010 01V1 (0)TXT_MSG (2)FLOOD (1)
0x0D00 000011 01V1 (0)ACK (3)FLOOD (1)
0x1100 000100 01V1 (0)ADVERT (4)FLOOD (1)
0x0C00 000011 00V1 (0)ACK (3)TRANSPORT_FLOOD (0)
0x0E00 000011 10V1 (0)ACK (3)DIRECT (2)
0x0F00 000011 11V1 (0)ACK (3)TRANSPORT_DIRECT (3)
0x4D01 000011 01V2 (1, reserved)ACK (3)FLOOD (1)

Cross-References

Reference Implementation

  • Packet::getRouteType() in src/Packet.hheader & 0x03
  • Packet::getPayloadType() in src/Packet.h(header >> 2) & 0x0F
  • Packet::getPayloadVer() in src/Packet.h(header >> 6) & 0x03
  • Packet::hasTransportCodes() in src/Packet.h — route type 0x00 or 0x03
  • Route type constants in src/Packet.h
  • Payload type constants in src/Packet.h