fixing adoption with invalid WiFi Name scheme

This commit is contained in:
2026-07-11 21:57:11 +00:00
parent 3dca4afea3
commit 6b06e57a4c
4 changed files with 177 additions and 50 deletions
+42 -6
View File
@@ -360,21 +360,31 @@ static struct json_object *build_vap_table(const uf_model_t *m)
const char *radio = "ng";
const char *bssid = "00:00:00:00:00:00";
const char *vap_id = NULL;
const char *ifname = NULL;
int vlan_id = 0;
int is_11r = 0;
if (json_object_object_get_ex(vap, "essid", &v)) essid = json_object_get_string(v);
if (json_object_object_get_ex(vap, "name", &v)) vap_name = json_object_get_string(v);
if (json_object_object_get_ex(vap, "radio", &v)) radio = json_object_get_string(v);
if (json_object_object_get_ex(vap, "bssid", &v)) bssid = json_object_get_string(v);
if (json_object_object_get_ex(vap, "id", &v)) vap_id = json_object_get_string(v);
if (json_object_object_get_ex(vap, "ifname", &v)) ifname = json_object_get_string(v);
if (json_object_object_get_ex(vap, "vlan_id", &v)) vlan_id = json_object_get_int(v);
if (json_object_object_get_ex(vap, "fast_roaming_enabled", &v))
is_11r = json_object_get_boolean(v);
/* Mapear banda → interfaz wlan y canal actual */
char wlan_iface[32] = "wlan0";
char wlan_iface[32] = "phy0-ap0";
if (ifname && ifname[0])
snprintf(wlan_iface, sizeof(wlan_iface), "%s", ifname);
int channel = 6;
for (int j = 0; j < m->radio_map_len; j++) {
if (strcmp(m->radio_map[j].band, radio) == 0) {
int idx = 0;
sscanf(m->radio_map[j].device, "radio%d", &idx);
snprintf(wlan_iface, sizeof(wlan_iface), "wlan%d", idx);
if (!ifname || !ifname[0])
snprintf(wlan_iface, sizeof(wlan_iface), "phy%d-ap0", idx);
radio_stats_t rs;
if (sysinfo_radio(wlan_iface, &rs) == 0 && rs.channel)
channel = rs.channel;
@@ -390,7 +400,8 @@ static struct json_object *build_vap_table(const uf_model_t *m)
/* Clientes conectados a esta VAP */
struct json_object *sta_tbl =
clients_build_sta_table(wlan_iface, radio, channel, vap_name);
clients_build_sta_table(wlan_iface, radio, channel, vap_name,
vlan_id, is_11r);
int num_sta = json_object_array_length(sta_tbl);
/* Calcular tx_power del radio correspondiente */
@@ -408,6 +419,8 @@ static struct json_object *build_vap_table(const uf_model_t *m)
json_object_new_string(vap_name));
json_object_object_add(o, "radio",
json_object_new_string(radio));
if (vlan_id > 0)
json_object_object_add(o, "vlan_id", json_object_new_int(vlan_id));
json_object_object_add(o, "up",
json_object_new_boolean(iface_st.up));
json_object_object_add(o, "channel",
@@ -448,6 +461,25 @@ static struct json_object *build_vap_table(const uf_model_t *m)
return arr;
}
/* Build the device-level station table UniFi uses for client ownership. */
static struct json_object *collect_sta_table(struct json_object *vap_table)
{
struct json_object *all = json_object_new_array();
int vap_count = json_object_array_length(vap_table);
for (int i = 0; i < vap_count; i++) {
struct json_object *vap = json_object_array_get_idx(vap_table, i);
struct json_object *stations;
if (!json_object_object_get_ex(vap, "sta_table", &stations) ||
!json_object_is_type(stations, json_type_array))
continue;
int count = json_object_array_length(stations);
for (int j = 0; j < count; j++)
json_object_array_add(all, json_object_get(
json_object_array_get_idx(stations, j)));
}
return all;
}
/* ═══════════════════════════════════════════════════════════════════
build_payload — ensamblado completo del JSON inform
═══════════════════════════════════════════════════════════════════ */
@@ -546,8 +578,12 @@ static char *build_payload(const openuf_state_t *st,
build_port_table(root, m);
build_eth_table(root, m);
/* ── VAPs con clientes WiFi (sta_table anidado) ─────────────── */
json_object_object_add(root, "vap_table", build_vap_table(m));
/* Publish both per-VAP and device-level station views. */
struct json_object *vap_table = build_vap_table(m);
struct json_object *sta_table = collect_sta_table(vap_table);
int station_count = json_object_array_length(sta_table);
json_object_object_add(root, "vap_table", vap_table);
json_object_object_add(root, "sta_table", sta_table);
/* ── Vecinos LLDP para topología visual ─────────────────────── */
json_object_object_add(root, "lldp_table", lldp_read_neighbors());
@@ -555,7 +591,7 @@ static char *build_payload(const openuf_state_t *st,
/* Contadores globales */
json_object_object_add(root, "bytes_r", json_object_new_int(0));
json_object_object_add(root, "bytes_d", json_object_new_int(0));
json_object_object_add(root, "num_sta", json_object_new_int(0));
json_object_object_add(root, "num_sta", json_object_new_int(station_count));
const char *s = json_object_to_json_string(root);