Matter smart-home protocol
README.md

matter #

Matter smart-home protocol.

Overview #

Matter is the smart-home standard that lets a light, a lock or a thermostat from one vendor be commissioned and controlled by a controller from another, over IP. Commissioning is the step that gives a new device its network credentials and an operational certificate from the controller's fabric, the set of nodes that share one root of trust. A cluster is a standard group of attributes and commands on a device, such as On/Off. matter implements the parts of the Matter Core Specification a controller needs to commission a device and send it commands:

  • TLV encoding and decoding, with every tag form (anonymous, context-specific, common and implicit profile, fully qualified);
  • message framing, with AES-CCM encryption on secure sessions;
  • PASE, the passcode-authenticated session establishment over SPAKE2+ (a password-authenticated key exchange: both sides derive a session key from the setup passcode printed on the device without sending it), run as two I/O-free state machines, Matter.Session for the commissioner and Matter.Device for the device, with their control tables in Matter.Pase_control;
  • CASE, the certificate-authenticated session establishment over node operational certificates, as message codecs and the four steps of the exchange (the state machines drive PASE only);
  • the DNS-SD records a Matter browse yields, and their parsers.

The matter-eio library runs a PASE session and device commands over UDP, and browses mDNS for devices. The matter command-line tool has three commands: discover lists devices, commission opens a PASE session, and control sends on, off or toggle to an On/Off cluster.

Installation #

Install with opam:

$ opam install matter

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install matter

Usage #

open Matter.Tlv

(* Create elements *)
let elem =
  structure
    [ ctx_int 1 42; ctx_string 2 "hello"; ctx_bool 3 true ]

(* Encode to binary *)
let binary = encode_one elem

(* Decode from binary *)
let elements =
  match decode binary with
  | Ok elements -> elements
  | Error e -> Fmt.failwith "%a" pp_error e

API #

  • Matter.Tlv encodes and decodes TLV elements, with value, container and context-tagged constructors.
  • Matter.Msg frames messages and names the protocol and opcode identifiers, with helpers for the On/Off and Administrator Commissioning clusters.
  • Matter.Pase, Matter.Pase_event and Matter.Pase_control are PASE: the SPAKE2+ steps, the events a session reads off a datagram, and the control tables written from the specification.
  • Matter.Session and Matter.Device are the two sides of PASE commissioning as state machines.
  • Matter.Case is CASE.
  • Matter.Crypto re-exports the nox-crypto primitives.
  • Matter.Discovery is the DNS-SD record model a browse yields, and Matter_eio.Discovery the mDNS browse itself.

Licence #

ISC License. See LICENSE.md for details.