← All posts

How AMX calls UCI: CLI, libuci and backend modules

Grow through practice

No need to finish reading — test now

“Calling UCI from AMX” is not one API; it is three different levels of integration. Choosing the wrong level leads either to shell-script patches or to a blocked event loop.

1. Shell

Fastest for debugging and init scripts:

uci set network.lan.ipaddr='192.168.1.1'
uci commit network
/etc/init.d/network reload
  • set writes a delta under /tmp/.uci;
  • commit writes /etc/config/network;
  • reload makes the service reread configuration; it does not reload kernel modules.

2. C + libuci

A backend module can use libuci directly:

#include <uci.h>

static int set_lan_ip(const char *value)
{
    struct uci_context *ctx = uci_alloc_context();
    struct uci_ptr ptr;
    int rc = -1;

    if (uci_lookup_ptr(ctx, &ptr, "network.lan.ipaddr", true) != UCI_OK)
        goto out;

    ptr.value = value;
    if (uci_set(ctx, &ptr) != UCI_OK)
        goto out;
    if (uci_commit(ctx, &ptr.pkg, false) != UCI_OK)
        goto out;

    rc = 0;
out:
    uci_free_context(ctx);
    return rc;
}

Notes:

  • uci_set does not necessarily persist immediately;
  • commit needs the package pointer;
  • new options may need to be created first;
  • do not call system("uci ...") inside a uloop callback; keep libuci file I/O off the hot path.

3. AMX UCI backend module

This is the normal prplOS pattern:

TR-181 object change
  → UCI backend module (listening to dm:object-changed)
  → libuci set/commit
  → /etc/config/network
  → netifd applies it

For example, tr181-routing uses mod-routing-uci for static/OS-level routes; BGP/OSPF use mod-routing-bird2. ODL defines the model; it does not execute UCI commands.

A module is responsible for:

  1. observing object/parameter changes;
  1. translating TR-181 semantics into UCI sections/options;
  1. committing through libuci;
  1. handling failures and rollback boundaries.

Which level?

ScenarioChoice
Temporary debuggingshell uci
Custom C servicelibuci
prplOS management planeAMX + UCI backend module
Inside uloop callbackdo not block; defer or offload

Series: Inside prplOS: AMX Runtime (Guide) Related: Where the AMX data model lives · UCI backend example · From UCI to a data model

Practice

Found this useful?

I write about AI agents × embedded / edge AI. Subscribe, or email me a concrete problem.

Guestbook →Subscribe (RSS)Support

Comments 0

No comments yet — be the first!

No login required; name is optional.