reboot action reboots Accesspoint (#26)
Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -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 |
|
| **L2 Discovery** | UDP broadcast + multicast every 10s | `announce.c` → port 10001 |
|
||||||
| **Adoption** | AES-128-CBC handshake with the controller | `inform.c` → `handle_response()` |
|
| **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()` |
|
| **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()` |
|
| **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()` |
|
| **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
|
apk -r del openuf
|
||||||
|
|
||||||
# Install new version
|
# Install new version
|
||||||
apk add openuf-0.4.0-r1.apk --allow-untrusted
|
apk add openuf-0.4.0-r3.apk --allow-untrusted
|
||||||
|
|
||||||
# Configure
|
# Configure
|
||||||
vi /etc/openuf/openuf.conf
|
vi /etc/openuf/openuf.conf
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
#define OPENUF_CONFIG_H
|
#define OPENUF_CONFIG_H
|
||||||
|
|
||||||
/* ─── Build-time defaults (override with /etc/openuf/openuf.conf) ─── */
|
/* ─── 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_STATE_FILE "/etc/openuf/state.json"
|
||||||
#define OPENUF_CONF_FILE "/etc/openuf/openuf.conf"
|
#define OPENUF_CONF_FILE "/etc/openuf/openuf.conf"
|
||||||
|
|
||||||
|
|||||||
+22
-4
@@ -797,12 +797,21 @@ static char *parse_packet(const unsigned char *data, size_t data_len,
|
|||||||
return copy;
|
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
|
Process JSON command from the controller
|
||||||
═══════════════════════════════════════════════════════════════════
|
═══════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
_type == "noop" → do nothing
|
_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 == "setstate" → apply radio_table + vap_table via UCI
|
||||||
_type == "setparam" → change a single parameter
|
_type == "setparam" → change a single parameter
|
||||||
*/
|
*/
|
||||||
@@ -813,7 +822,8 @@ static void handle_response(openuf_state_t *st,
|
|||||||
{
|
{
|
||||||
struct json_object *v;
|
struct json_object *v;
|
||||||
const char *type = "noop";
|
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);
|
type = json_object_get_string(v);
|
||||||
|
|
||||||
LOG("Handling response type: %s", type);
|
LOG("Handling response type: %s", type);
|
||||||
@@ -846,6 +856,14 @@ static void handle_response(openuf_state_t *st,
|
|||||||
return;
|
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 ────────────────────────────────────────────────── */
|
/* ── setparam ────────────────────────────────────────────────── */
|
||||||
if (!strcmp(type, "setparam")) {
|
if (!strcmp(type, "setparam")) {
|
||||||
int received_adoption_key = 0;
|
int received_adoption_key = 0;
|
||||||
@@ -991,12 +1009,12 @@ static void handle_response(openuf_state_t *st,
|
|||||||
|
|
||||||
} else if (!strcmp(cmd, "reboot")) {
|
} else if (!strcmp(cmd, "reboot")) {
|
||||||
strcpy(action_out, "reboot");
|
strcpy(action_out, "reboot");
|
||||||
system("reboot &");
|
reboot_openwrt();
|
||||||
|
|
||||||
} else if (!strcmp(cmd, "reset")) {
|
} else if (!strcmp(cmd, "reset")) {
|
||||||
strcpy(action_out, "reset");
|
strcpy(action_out, "reset");
|
||||||
system("rm -f " OPENUF_STATE_FILE);
|
system("rm -f " OPENUF_STATE_FILE);
|
||||||
system("reboot &");
|
reboot_openwrt();
|
||||||
|
|
||||||
} else if (!strcmp(cmd, "locate")) {
|
} else if (!strcmp(cmd, "locate")) {
|
||||||
/* Blink LED — on OpenWrt: echo 1 > /sys/class/leds/.../trigger */
|
/* Blink LED — on OpenWrt: echo 1 > /sys/class/leds/.../trigger */
|
||||||
|
|||||||
+2
-2
@@ -181,8 +181,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
state_save(&state);
|
state_save(&state);
|
||||||
|
|
||||||
printf("[openuf] Starting model=%-8s MAC=%s IP=%s\n",
|
printf("[openuf] Starting version=%s model=%-8s MAC=%s IP=%s\n",
|
||||||
model->model, mac_str, ip_str);
|
OPENUF_VERSION, model->model, mac_str, ip_str);
|
||||||
printf("[openuf] Controller: %s\n", state.inform_url);
|
printf("[openuf] Controller: %s\n", state.inform_url);
|
||||||
printf("[openuf] Adopted: %s\n", state.adopted ? "yes" : "no");
|
printf("[openuf] Adopted: %s\n", state.adopted ? "yes" : "no");
|
||||||
printf("[openuf] LLDP available: %s\n",
|
printf("[openuf] LLDP available: %s\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user