Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions general/package/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ source "$BR2_EXTERNAL_GENERAL_PATH/package/linux-patcher/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/majestic-fonts/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/majestic-webui/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/majestic/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/matter/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/mavfwd/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/mbedtls-openipc/Config.in"
source "$BR2_EXTERNAL_GENERAL_PATH/package/mini/Config.in"
Expand Down
60 changes: 60 additions & 0 deletions general/package/matter/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# Copyright (c) OpenIPC https://openipc.org MIT License
#
# Config.in — Kconfig entry for the matter package
#

config BR2_PACKAGE_MATTER
bool "matter"
depends on BR2_USE_MMU
depends on BR2_TOOLCHAIN_HAS_THREADS
help
OpenIPC Matter-compatible IP camera server.

Implements a subset of the Matter 1.2 specification sufficient
to make an IP camera discoverable and controllable by Matter
controllers (Apple Home, Google Home, Amazon Alexa, etc.):

- Clusters: OnOff, LevelControl, BasicInformation,
OccupancySensing, Identify
- WriteAttribute support
- mDNS announcement (PTR + SRV + TXT records)
- TCP commissioning stub (PASE / PBKDFParamRequest)
- RTSP stream URL as a Matter attribute
- Client connection limit and 30 s receive timeout

Designed for OpenIPC IP cameras and other resource-constrained
embedded Linux targets (uClibc / musl / glibc).
No external libraries required — pure C99 / POSIX.

https://openipc.org

if BR2_PACKAGE_MATTER

config BR2_PACKAGE_MATTER_RTSP_URL
string "Default RTSP stream URL"
default "rtsp://127.0.0.1:554/stream"
help
RTSP URL written into /etc/matter.conf as the default stream
source. Can be overridden at runtime by editing that file or
by passing the URL as the first argument to matter-server.

config BR2_PACKAGE_MATTER_PORT
int "Matter TCP port"
range 1 65535
default 5540
help
TCP port the Matter server listens on. 5540 is the default
port defined by the Matter specification.
Written into /etc/matter.conf; can be overridden at runtime.

config BR2_PACKAGE_MATTER_INIT_STARTLEVEL
int "Init script start level"
range 10 99
default 90
help
Numeric prefix of the SysV-style init script installed under
/etc/init.d. Higher numbers start later in the boot sequence.
90 ensures the network is up before the Matter server starts.

endif
83 changes: 83 additions & 0 deletions general/package/matter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# OpenIPC Matter IP Camera Server

Part of the [OpenIPC](https://openipc.org) project — open-source firmware and tooling for IP cameras and embedded Linux devices.

## Overview

A minimal, self-contained Matter-compatible server for IP cameras, written in C (POSIX / C99). It implements a subset of the Matter 1.2 specification sufficient to make an IP camera discoverable and controllable by Matter controllers (Apple Home, Google Home, Amazon Alexa, etc.) without depending on the official Matter SDK.

## Features

- **Matter Interaction Model** over TCP (port 5540)
- **Clusters**: OnOff, LevelControl, BasicInformation, OccupancySensing, Identify
- **mDNS announcement** — broadcasts `_matter._tcp.local` every 30 seconds (port 5353)
- **RTSP URL attribute** — exposes the camera stream URL as a Matter attribute
- **Motion detection simulation** — periodically toggles OccupancySensing::Occupancy
- **Simplified PASE commissioning stub** — responds to PBKDFParamRequest with StatusReport OK
- **Statistics thread** — logs device status every 60 seconds
- Multi-client TCP server with per-client threads
- No external dependencies — pure C99 / POSIX

## Build

```sh
gcc -Wall -Wextra -O2 -pthread matter-server.c -o matter-server
```

For embedded targets (e.g. OpenIPC buildroot):

```sh
$(CROSS_COMPILE)gcc -Wall -Wextra -O2 -pthread matter-server.c -o matter-server
```

## Usage

```sh
./matter-server [rtsp_url] [port]
```

**Examples:**

```sh
# Default RTSP URL and port 5540
./matter-server

# Custom RTSP stream
./matter-server rtsp://192.168.1.100:554/stream

# Custom RTSP stream and port
./matter-server rtsp://192.168.1.100:554/stream 5540
```

## Matter Device Parameters

| Parameter | Value |
|----------------|------------|
| Vendor ID | `0xFFF1` |
| Product ID | `0x8001` |
| Device Type | `0x0043` (Video Camera) |
| Discriminator | `3840` |
| Passcode | `20202021` |
| TCP Port | `5540` |

## Supported Clusters

| Cluster ID | Name | Supported Attributes / Commands |
|------------|-------------------|---------------------------------------------|
| `0x0028` | BasicInformation | VendorName, ProductName, NodeLabel, HWVersion, SWVersion |
| `0x0003` | Identify | Identify command |
| `0x0006` | OnOff | OnOff attribute; On / Off / Toggle commands |
| `0x0008` | LevelControl | CurrentLevel attribute; MoveToLevel command |
| `0x0406` | OccupancySensing | Occupancy attribute (simulated) |

## Notes

- This is a **prototype implementation** — PASE/CASE cryptography (SPAKE2+) is stubbed out. The server accepts commissioning requests but does not perform real cryptographic handshakes.
- The TLV parser uses a simplified byte-scan heuristic, not a full recursive TLV decoder.
- Intended for development, testing, and integration on OpenIPC-based hardware.

## License

This software is part of the OpenIPC project and is distributed under the MIT License.

Copyright (c) OpenIPC Contributors https://openipc.org tech@openipc.eu
104 changes: 104 additions & 0 deletions general/package/matter/files/S90matter
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/sh
# SPDX-License-Identifier: MIT
# Copyright (c) OpenIPC https://openipc.org tech@openipc.eu
#
# S90matter — SysV init script for the OpenIPC Matter IP camera server.
#
# Part of the OpenIPC firmware ecosystem.
#
# Targets: IP cameras, routers, NVR, embedded Linux
# Standard: C99 / POSIX.1-2008 (uClibc / musl / glibc)
#
# Sources /etc/matter.conf, exports MATTER_* environment variables,
# and manages the matter-server daemon via start-stop-daemon.
#
### BEGIN INIT INFO
# Provides: matter-server
# Required-Start: $network $local_fs
# Required-Stop: $network $local_fs
# Default-Start: S
# Default-Stop: 0 6
# Short-Description: OpenIPC Matter IP Camera Server
# Description: Starts the OpenIPC Matter-compatible IP camera server.
# Announces the device via mDNS and handles Matter
# Interaction Model commands over TCP port 5540.
### END INIT INFO

DAEMON=/usr/sbin/matter-server
NAME=matter-server
PIDFILE=/var/run/matter-server.pid
CONFIG=/etc/matter.conf

# Default runtime parameters — override in /etc/matter.conf
MATTER_RTSP_URL="rtsp://127.0.0.1:554/stream"
MATTER_PORT=5540
MATTER_VENDOR_NAME="OpenIPC"
MATTER_PRODUCT_NAME="OpenIPC IP Camera"
MATTER_NODE_LABEL="IP Camera"
MATTER_HW_VERSION="HW-1.0"
MATTER_SW_VERSION="SW-1.0.0"

# Load site-specific configuration if present
[ -f "$CONFIG" ] && . "$CONFIG"

# Export all MATTER_* variables so the daemon inherits them
export MATTER_RTSP_URL MATTER_PORT \
MATTER_VENDOR_NAME MATTER_PRODUCT_NAME MATTER_NODE_LABEL \
MATTER_HW_VERSION MATTER_SW_VERSION

start() {
echo -n "Starting $NAME: "
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo "already running (pid $(cat "$PIDFILE"))"
return 0
fi
start-stop-daemon -S -b -m -p "$PIDFILE" \
-x "$DAEMON" -- "$MATTER_RTSP_URL" "$MATTER_PORT"
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "OK"
else
echo "FAILED"
fi
return $RETVAL
}

stop() {
echo -n "Stopping $NAME: "
if [ ! -f "$PIDFILE" ]; then
echo "not running"
return 0
fi
start-stop-daemon -K -q -p "$PIDFILE"
RETVAL=$?
rm -f "$PIDFILE"
if [ $RETVAL -eq 0 ]; then
echo "OK"
else
echo "FAILED"
fi
return $RETVAL
}

status() {
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo "$NAME is running (pid $(cat "$PIDFILE"))"
return 0
else
echo "$NAME is not running"
return 1
fi
}

case "$1" in
start) start ;;
stop) stop ;;
restart) stop; sleep 1; start ;;
status) status ;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

exit $?
53 changes: 53 additions & 0 deletions general/package/matter/files/matter.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Copyright (c) OpenIPC https://openipc.org MIT License
#
# matter.conf — Matter IP camera server runtime configuration
#

# =============================================================================
# Network
# =============================================================================

# RTSP stream URL served by this camera.
# The value is passed to matter-server as argv[1] and is also exposed
# as a Matter attribute readable by controllers.
# Typical formats:
# rtsp://127.0.0.1:554/stream (majestic / minihttp, loopback)
# rtsp://192.168.1.100:554/ch0 (external address)
# rtsp://user:pass@127.0.0.1:554/0 (with authentication)
MATTER_RTSP_URL="rtsp://127.0.0.1:554/stream"

# TCP port the Matter server listens on.
# 5540 is the default port defined by the Matter specification.
# Change only if you run multiple Matter devices on the same host.
MATTER_PORT=5540

# =============================================================================
# Matter Device Identity (BasicInformation cluster)
# These strings are reported to Matter controllers during commissioning
# and are readable at any time via the ReadAttribute command.
# =============================================================================

# Human-readable vendor name (max 64 characters).
# Reported as BasicInformation::VendorName (attribute 0x0001).
MATTER_VENDOR_NAME="OpenIPC"

# Human-readable product name (max 64 characters).
# Reported as BasicInformation::ProductName (attribute 0x0003).
MATTER_PRODUCT_NAME="OpenIPC IP Camera"

# Node label — a user-assigned name shown in controller apps (max 64 chars).
# Reported as BasicInformation::NodeLabel (attribute 0x0005).
# Writable by Matter controllers via WriteAttribute.
# Examples: "Front Door", "Garage", "Baby Room"
MATTER_NODE_LABEL="IP Camera"

# Hardware version string (max 32 characters).
# Reported as BasicInformation::HardwareVersionString (attribute 0x000D).
# Typically reflects the PCB revision of the camera module.
MATTER_HW_VERSION="HW-1.0"

# Software / firmware version string (max 32 characters).
# Reported as BasicInformation::SoftwareVersionString (attribute 0x000F).
# Should match the running OpenIPC firmware version.
MATTER_SW_VERSION="SW-1.0.0"
50 changes: 50 additions & 0 deletions general/package/matter/matter.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
################################################################################
#
# Copyright (c) OpenIPC https://openipc.org MIT License
#
# matter — Matter 1.2-compatible IP camera server
#
################################################################################

MATTER_LICENSE = MIT
MATTER_LICENSE_FILES = README.md

MATTER_RTSP_URL = $(call qstrip,$(BR2_PACKAGE_MATTER_RTSP_URL))
MATTER_PORT = $(call qstrip,$(BR2_PACKAGE_MATTER_PORT))
MATTER_STARTLEVEL = $(call qstrip,$(BR2_PACKAGE_MATTER_INIT_STARTLEVEL))

define MATTER_EXTRACT_CMDS
cp -avr $(MATTER_PKGDIR)/src/* $(@D)/
endef

define MATTER_BUILD_CMDS
$(MAKE) \
CC="$(TARGET_CC)" \
STRIP="$(TARGET_STRIP)" \
CFLAGS="$(TARGET_CFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS) \
-pthread \
-Wl,--gc-sections \
-Wl,--strip-all" \
ARCH_FLAGS="" \
-C $(@D)
endef

define MATTER_INSTALL_TARGET_CMDS
$(INSTALL) -m 755 -d $(TARGET_DIR)/usr/sbin
$(INSTALL) -m 755 $(@D)/matter-server \
$(TARGET_DIR)/usr/sbin/matter-server

$(INSTALL) -m 755 -d $(TARGET_DIR)/etc/init.d
$(INSTALL) -m 755 $(MATTER_PKGDIR)/files/S90matter \
$(TARGET_DIR)/etc/init.d/S$(MATTER_STARTLEVEL)matter

$(INSTALL) -m 644 -D $(MATTER_PKGDIR)/files/matter.conf \
$(TARGET_DIR)/etc/matter.conf
$(SED) 's|rtsp://127.0.0.1:554/stream|$(MATTER_RTSP_URL)|' \
$(TARGET_DIR)/etc/matter.conf
$(SED) 's|^MATTER_PORT=5540|MATTER_PORT=$(MATTER_PORT)|' \
$(TARGET_DIR)/etc/matter.conf
endef

$(eval $(generic-package))
Loading