LED management in prplOS: TR-181 Device.LEDs and tr181-led
Grow through practice
No need to finish reading — test nowOne line: an LED is not a few GPIOs; it is a remotely manageable TR-181 object tree.
tr181-ledhides the/sys/class/ledsdetails behindDevice.LEDs.
Component and version
- Component:
prpl-foundation/components/core/plugins/tr181-led - Current main:
97ae806(2026-09-23, defaults: preserve sysfs LED state at startup) - Latest release in the changelog:
v0.8.3(2024-08-19) - License: BSD-2-Clause-Patent
It is not OpenWrt's leds script; it is a TR-181 data model + AMX plugin.
Data model: Device.LEDs
odl/tr181-led_mapping.odl has one key mapping:
%config {
%global "proxy-object.'Device.LEDs.'" = "LEDs.";
}
The plugin uses the short LEDs. path internally and exposes the standard Device.LEDs. path on the bus / to remote management.
Device.LEDs has three main parts:
BrightnessLimiter: global brightness cap,0..100;LED[]: one instance per LED;CycleElement[]: the lighting sequence for each LED.
Key LED.{i} parameters:
| Parameter | Purpose |
|---|---|
Alias | unique key, write-once |
Enable | power this LED on/off |
Name | sysfs LED name (unique) |
Status | Disabled / InUse / Controlled / Error |
Reason | textual purpose, e.g. “Broadband Down” |
CyclePeriodRepetitions | remaining cycles; -1 = infinite |
Location / RelativeX/YPosition | panel position |
MaxBrightness | from hardware/driver |
CycleElementNumberOfEntries | number of lighting steps |
A CycleElement describes “how to light for a period”:
Order: sequence;Color: RGB hex, e.g.FF0088;Brightness: percentage,-1means unchanged;Duration: duration in ms;FadeInterval: transition time from the previous step in ms.
The full cycle length is the sum of all Duration values.
Why not just write sysfs
Carrier CPE needs LEDs that are remotely manageable, descriptive, and composable:
- multi-color: one RGB LED, or red/green/blue monochrome LEDs overlaid;
- blink/pulse: frequency, duty cycle and intensity are configurable;
- state:
Disabled,InUse,Controlled,Error; - remote management: TR-181 paths can be driven by ACS/USP/Web UI.
tr181-led provides that abstraction while still writing sysfs underneath.
Implementation: four key files
src/led_main.c
- stores
dm/parser/default_led_path; led_initmaps anLEDinstance to sysfs devices;led_deinit_all/take_ledmanage thecontrolledstate;- one LED can map to multiple underlying LEDs (color overlay).
src/led_device.c
hex_to_rgbparses colors;led_sysfs_writecallsmod-led-common'sled-sysfs-writeviaamxm_execute_function;led_set_modewritestrigger/mode;led_set_fadeusestimer+delay_on/delay_off(half each);led_validate_colors/led_apply_colorshandle a single LED or R/G/B overlay.
src/led_cycle.c
led_valid_state requires all of:
Status == "InUse"
CyclePeriodRepetitions != 0
CycleElementNumberOfEntries != 0
at least one CycleElement.Enable == true
LED.Enable == true
Then element_start_next advances with a timer:
- find the next enabled
CycleElement; - update
CurrentCycleElement.CycleElementReferencein a transaction; - apply color/brightness/fade;
- decrement
CyclePeriodRepetitionswhen > 0; - if state is invalid, stop the timer and set brightness to 0.
mod-led-common
The module that actually writes sysfs. Plugin config:
so-dir = "/usr/lib/amx/tr181-led/modules"
so-name = "mod-led-common"
mod-name = "common-behavior"
So tr181-led does not open() sysfs directly; it goes through an AMX module, which is easier to reuse and test.
Permissions: why CAP_DAC_OVERRIDE
The documentation states the plugin runs as tr181_app and keeps only CAP_DAC_OVERRIDE, because it must write /sys/class/leds.
This is the usual trade-off for user-space hardware management:
- not root;
- still able to bypass sysfs file permissions;
- ACL files (
acl/) control who may change LEDs over the bus.
Design analysis
What is good
- Declarative effects:
Order/Duration/Color/Brightness/FadeIntervalinstead of hard-coded blinking in C; - Multi-color abstraction: single LED or R/G/B overlay;
- Hardware limits:
MaxBrightnessfrom the driver,BrightnessLimiteras a global cap; - Readable state:
Status+CurrentCycleElementtell remote management what is active; - Persistence:
%persistent+ ODL storage, restored after reboot.
Cost and boundaries
- sysfs dependency: LED names,
trigger,delay_on/off,max_brightnessdepend on kernel/driver; - user-space timers: each cycle step uses
amxp_timer; jitter is worse than a hardware blink engine; - color overlay sync: the doc requires the low-level driver to synchronize overlays; user space can only approximate;
Controlledsemantics: hardware-controlled LEDs are not monitorable and should have no CycleElement entries;- incomplete documentation:
led_main_documentation.mdhas many empty sections;Suspend/ULED[]depend on the actual ODL/version (⚠️).
Difference from OpenWrt
A common OpenWrt approach is:
/sys/class/leds + procd/rc.local + scripts
tr181-led is:
Device.LEDs (TR-181) → AMX data model → mod-led-common → sysfs
The former is simpler and fine for home routers; the latter adds a model but gains remote management, uniform semantics, and multi-color/effect descriptions.
Docker virtual-node test
tr181-led ships mock LEDs (test/common/mock_leds), so no real /sys/class/leds is needed.
On top of amx-base, add libamxm / libsahtrace, then run the upstream unit tests:
docker build -f examples/led/Dockerfile -t amx-led-test .
docker run --rm amx-led-test
Measured result:
- 4 test suites / 14 tests / 0 failures
- valgrind: 0 errors
- covers sysfs device lookup, brightness/color/fade, cycle state machine, module loading and start/stop
This is a unit-test virtual node, not a full prplOS node: no
ubus/procd, real driver, or remote-management path.
Repo: amx-greeter-demo/examples/led.
Verification status (site mission)
- ✅ source/docs: component path, commit, ODL, mapping,
led_main/device/cycle; - ✅ semantics:
Device.LEDsmapping,CycleElement,led_valid_state,CAP_DAC_OVERRIDEare backed by source/docs; - ✅ Docker virtual node: upstream 4 suites / 14 tests on mock LEDs, 0 failures;
- ⚠️ not a full prplOS run: no
ubus/procd, real driver, or remote-management path; - ❓ to confirm:
Suspend/ULED[]version differences and per-driver fade/pulse capabilities.
One sentence
tr181-ledturns LEDs from “sysfs knobs” into a “TR-181 object tree”: remotely manageable, descriptive, multi-color; the cost is permissions, timers and hardware differences.
Source: tr181-led (
97ae806) Virtual-node test: amx-greeter-demo/examples/led Related: prplOS vs OpenWrt · From UCI to a data model · AMXRT is a runtime Series: prplOS Official Code Walkthrough & Testing.
Comments 0
No comments yet — be the first!