diff --git a/README.md b/README.md index edc9d7e..b3fa1ee 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Daemon that makes an OpenWrt router appear as a UniFi AP to UniFi Network contro | --- | --- | --- | | **L2 Discovery** | UDP broadcast + multicast every 10s | `announce.c` → port 10001 | | **Adoption** | AES-128-CBC handshake with the controller | `inform.c` → `handle_response()` | +| **Remote reboot** | Reboots OpenWrt when requested by the controller | `inform.c` → `handle_response()` | | **Firmware spoofing** | Persists and reports the target version requested by an upgrade | `inform.c` → `handle_response()` | | **WiFi Config** | Creates WiFi networks from the controller via UCI | `wlan.c` → `wlan_apply_config()` | | **Band Steering** | 802.11k/v Neighbor Reports + BSS Transition | `wlan.c` → `apply_vap()` | @@ -75,7 +76,7 @@ apk del wpad-basic-mbedtls && apk add wpad-mbedtls && /etc/init.d/network restar apk -r del openuf # Install new version -apk add openuf-0.4.0-r1.apk --allow-untrusted +apk add openuf-0.4.0-r3.apk --allow-untrusted # Configure vi /etc/openuf/openuf.conf diff --git a/src/config.h b/src/config.h index 6824b8d..e381051 100644 --- a/src/config.h +++ b/src/config.h @@ -2,7 +2,7 @@ #define OPENUF_CONFIG_H /* ─── Build-time defaults (override with /etc/openuf/openuf.conf) ─── */ -#define OPENUF_VERSION "0.3-C" +#define OPENUF_VERSION "0.4.0-r1" #define OPENUF_STATE_FILE "/etc/openuf/state.json" #define OPENUF_CONF_FILE "/etc/openuf/openuf.conf" diff --git a/src/inform.c b/src/inform.c index 1d4c9ce..443680e 100644 --- a/src/inform.c +++ b/src/inform.c @@ -797,12 +797,21 @@ static char *parse_packet(const unsigned char *data, size_t data_len, return copy; } +static void reboot_openwrt(void) +{ + LOG("Controller requested an OpenWrt reboot"); + int status = system("/sbin/reboot"); + if (status != 0) + LOG("OpenWrt reboot command failed with status=%d", status); +} + /* ═══════════════════════════════════════════════════════════════════ Process JSON command from the controller ═══════════════════════════════════════════════════════════════════ _type == "noop" → do nothing - _type == "cmd" → set-adopt / reboot / reset / locate + _type == "reboot" → reboot OpenWrt + _type == "cmd" → set-adopt / legacy reboot / reset / locate _type == "setstate" → apply radio_table + vap_table via UCI _type == "setparam" → change a single parameter */ @@ -813,7 +822,8 @@ static void handle_response(openuf_state_t *st, { struct json_object *v; const char *type = "noop"; - if (json_object_object_get_ex(resp, "_type", &v)) + if (json_object_object_get_ex(resp, "_type", &v) && + json_object_is_type(v, json_type_string)) type = json_object_get_string(v); LOG("Handling response type: %s", type); @@ -846,6 +856,14 @@ static void handle_response(openuf_state_t *st, return; } + /* Modern controllers send reboot as a top-level response type rather + * than wrapping it in {"_type":"cmd","cmd":"reboot"}. */ + if (!strcmp(type, "reboot")) { + strcpy(action_out, "reboot"); + reboot_openwrt(); + return; + } + /* ── setparam ────────────────────────────────────────────────── */ if (!strcmp(type, "setparam")) { int received_adoption_key = 0; @@ -991,12 +1009,12 @@ static void handle_response(openuf_state_t *st, } else if (!strcmp(cmd, "reboot")) { strcpy(action_out, "reboot"); - system("reboot &"); + reboot_openwrt(); } else if (!strcmp(cmd, "reset")) { strcpy(action_out, "reset"); system("rm -f " OPENUF_STATE_FILE); - system("reboot &"); + reboot_openwrt(); } else if (!strcmp(cmd, "locate")) { /* Blink LED — on OpenWrt: echo 1 > /sys/class/leds/.../trigger */ diff --git a/src/main.c b/src/main.c index 0089cb0..32e2fbb 100644 --- a/src/main.c +++ b/src/main.c @@ -181,8 +181,8 @@ int main(int argc, char *argv[]) } state_save(&state); - printf("[openuf] Starting model=%-8s MAC=%s IP=%s\n", - model->model, mac_str, ip_str); + printf("[openuf] Starting version=%s model=%-8s MAC=%s IP=%s\n", + OPENUF_VERSION, model->model, mac_str, ip_str); printf("[openuf] Controller: %s\n", state.inform_url); printf("[openuf] Adopted: %s\n", state.adopted ? "yes" : "no"); printf("[openuf] LLDP available: %s\n",