mirror of
https://github.com/ruvnet/RuView
synced 2026-07-28 18:21:42 +00:00
ADR-110: ESP32-C6 firmware extension (#764)
Closes the firmware-side ADR-110 design at v0.7.0-esp32 after a 38-iter /loop SOTA sprint. Headline (bench, COM9+COM12 ESP32-C6): - 99.56% cross-board RX, 104.1 µs smoothed offset stdev (≤100 µs §2.4 target met) - 3.95× EMA suppression, 1.4 ppm crystal skew preserved 4 firmware releases: v0.6.7 / v0.6.8 / v0.6.9 / v0.7.0-esp32. 42 ADR-110 unit tests, 1761 v2 workspace tests, full Firmware CI + QEMU green.
This commit is contained in:
@@ -20,6 +20,11 @@
|
||||
# FUZZ_JOBS=4 # Parallel fuzzing jobs
|
||||
|
||||
CC = clang
|
||||
# ADR-110: -DCONFIG_CSI_FRAME_HE_TAGGING=1 enables the byte-18/19 HE path
|
||||
# in csi_collector.c so the fuzzer exercises that code as well as the
|
||||
# legacy zero-fill path. CONFIG_SOC_WIFI_HE_SUPPORT is left UNSET to
|
||||
# exercise the legacy S3 branch (sig_mode/cwb/stbc). Add it to CFLAGS for
|
||||
# a parallel HE-stub build if you want fuzz coverage of the C6 branch.
|
||||
CFLAGS = -fsanitize=fuzzer,address,undefined -g -O1 \
|
||||
-Istubs -I../main \
|
||||
-DCONFIG_CSI_NODE_ID=1 \
|
||||
@@ -28,6 +33,7 @@ CFLAGS = -fsanitize=fuzzer,address,undefined -g -O1 \
|
||||
-DCONFIG_CSI_TARGET_IP=\"192.168.1.1\" \
|
||||
-DCONFIG_CSI_TARGET_PORT=5500 \
|
||||
-DCONFIG_ESP_WIFI_CSI_ENABLED=1 \
|
||||
-DCONFIG_CSI_FRAME_HE_TAGGING=1 \
|
||||
-Wno-unused-function
|
||||
|
||||
STUBS_SRC = stubs/esp_stubs.c
|
||||
@@ -37,9 +43,22 @@ MAIN_DIR = ../main
|
||||
FUZZ_DURATION ?= 30
|
||||
FUZZ_JOBS ?= 1
|
||||
|
||||
.PHONY: all clean run_serialize run_edge run_nvs run_all
|
||||
.PHONY: all clean run_serialize run_edge run_nvs run_all test_adr110 run_adr110 host_tests
|
||||
|
||||
all: fuzz_serialize fuzz_edge fuzz_nvs
|
||||
all: fuzz_serialize fuzz_edge fuzz_nvs test_adr110
|
||||
|
||||
# --- ADR-110 encoding unit tests ---
|
||||
# Host-side, no libFuzzer needed — plain C99 deterministic table tests
|
||||
# for mac_to_eui64() and PPDU-type → ADR-018 byte 18 mapping.
|
||||
# Builds with stock cc/gcc/clang — runs in CI on Ubuntu.
|
||||
test_adr110: test_adr110_encoding.c
|
||||
cc -std=c99 -Wall -Wextra -o $@ $<
|
||||
|
||||
run_adr110: test_adr110
|
||||
./test_adr110
|
||||
|
||||
host_tests: run_adr110
|
||||
@echo "ADR-110 host tests passed"
|
||||
|
||||
# --- Serialize fuzzer ---
|
||||
# Tests csi_serialize_frame() with random wifi_csi_info_t inputs.
|
||||
@@ -75,5 +94,5 @@ run_nvs: fuzz_nvs
|
||||
run_all: run_serialize run_edge run_nvs
|
||||
|
||||
clean:
|
||||
rm -f fuzz_serialize fuzz_edge fuzz_nvs
|
||||
rm -f fuzz_serialize fuzz_edge fuzz_nvs test_adr110
|
||||
rm -rf corpus_serialize/ corpus_edge/ corpus_nvs/
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
"""ADR-110 multi-board live capture — 802.15.4 sync + TWT + HE-LTF.
|
||||
|
||||
Captures from up to 3 ESP32-C6 boards simultaneously, resets them
|
||||
together so the leader election starts from a clean slate, then
|
||||
records 35 s of serial output to per-port log files and prints
|
||||
a summary of the time-sync state machine, TWT events, and CSI
|
||||
metadata at the end.
|
||||
"""
|
||||
import serial
|
||||
import threading
|
||||
import time
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
PORTS = ['COM6', 'COM9', 'COM12']
|
||||
DURATION_SECONDS = 35
|
||||
OUTPUT_DIR = Path(__file__).parent / 'witness-3board'
|
||||
OUTPUT_DIR.mkdir(exist_ok=True)
|
||||
|
||||
|
||||
def capture(port: str, results: dict):
|
||||
"""Reset and capture from one port for DURATION_SECONDS."""
|
||||
try:
|
||||
ser = serial.Serial(port, 115200, timeout=1)
|
||||
# Hard reset via DTR/RTS pulse.
|
||||
ser.setDTR(False); ser.setRTS(True); time.sleep(0.05)
|
||||
ser.setDTR(False); ser.setRTS(False)
|
||||
ser.reset_input_buffer()
|
||||
buf = bytearray()
|
||||
start = time.time()
|
||||
while time.time() - start < DURATION_SECONDS:
|
||||
data = ser.read(4096)
|
||||
if data:
|
||||
buf.extend(data)
|
||||
ser.close()
|
||||
log_path = OUTPUT_DIR / f'{port}.log'
|
||||
log_path.write_bytes(bytes(buf))
|
||||
text = bytes(buf).decode('utf-8', errors='replace')
|
||||
results[port] = text
|
||||
print(f'[{port}] {len(buf)} bytes captured -> {log_path}')
|
||||
except Exception as e:
|
||||
print(f'[{port}] ERROR: {e}')
|
||||
results[port] = None
|
||||
|
||||
|
||||
# Launch 3 capture threads — actual concurrent reset + capture.
|
||||
results = {}
|
||||
threads = [threading.Thread(target=capture, args=(p, results)) for p in PORTS]
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
|
||||
# ── Analyze ────────────────────────────────────────────────────────────
|
||||
|
||||
def grep_pattern(text: str, pattern: str, n: int = 8):
|
||||
rx = re.compile(pattern)
|
||||
return [L.strip() for L in (text or '').split('\n') if rx.search(L)][:n]
|
||||
|
||||
|
||||
print('\n' + '='*78)
|
||||
print('ADR-110 multi-board capture summary')
|
||||
print('='*78)
|
||||
|
||||
|
||||
for port in PORTS:
|
||||
text = results.get(port)
|
||||
if not text:
|
||||
print(f'\n--- {port}: NO DATA ---')
|
||||
continue
|
||||
print(f'\n--- {port} ---')
|
||||
|
||||
# Boot banner
|
||||
for L in grep_pattern(text, r'main: ESP32-C6.*Node ID', 2):
|
||||
print(f' banner : {L}')
|
||||
|
||||
# Time-sync init (802.15.4 path — known broken D1)
|
||||
for L in grep_pattern(text, r'c6_ts:.*(init done|promot|stepping down|tx fail)', 4):
|
||||
print(f' c6_ts : {L}')
|
||||
|
||||
# ESP-NOW sync (D1 workaround, working path)
|
||||
for L in grep_pattern(text, r'c6_espnow:.*(init done|promot|stepping down|tx#\d)', 6):
|
||||
print(f' c6_espnow: {L}')
|
||||
|
||||
# WiFi mode + connect status
|
||||
for L in grep_pattern(text, r'(wifi:mode|wifi:state|Retrying WiFi|got ip|Connected to WiFi)', 6):
|
||||
print(f' wifi : {L}')
|
||||
|
||||
# TWT events
|
||||
for L in grep_pattern(text, r'c6_twt|itwt|TWT', 5):
|
||||
print(f' twt : {L}')
|
||||
|
||||
# CSI callbacks
|
||||
for L in grep_pattern(text, r'CSI cb #\d+.*len=', 5):
|
||||
print(f' csi_cb : {L}')
|
||||
|
||||
# 11ax MAC firmware
|
||||
for L in grep_pattern(text, r'mac_version:HAL_MAC_ESP32AX', 2):
|
||||
print(f' he-mac : {L}')
|
||||
|
||||
|
||||
# Cross-board leader election summary
|
||||
print('\n' + '='*78)
|
||||
print('Leader election analysis')
|
||||
print('='*78)
|
||||
eui_re = re.compile(r'EUI=([0-9a-fA-F]+)')
|
||||
euis = {}
|
||||
for port in PORTS:
|
||||
text = results.get(port) or ''
|
||||
m = eui_re.search(text)
|
||||
if m:
|
||||
euis[port] = int(m.group(1), 16)
|
||||
print(f' {port} EUI=0x{m.group(1).lower()} -> {"LEADER" if False else "candidate"}')
|
||||
|
||||
if len(euis) >= 2:
|
||||
lowest_port = min(euis, key=euis.get)
|
||||
print(f'\n lowest EUI -> expected leader: {lowest_port} (0x{euis[lowest_port]:016x})')
|
||||
|
||||
# Did a "stepping down" log appear on the non-lowest boards?
|
||||
for port in PORTS:
|
||||
if port == lowest_port:
|
||||
continue
|
||||
text = results.get(port) or ''
|
||||
if 'stepping down' in text:
|
||||
print(f' {port}: [OK] stepped down (heard leader beacon)')
|
||||
elif port in euis:
|
||||
print(f' {port}: [FAIL] did NOT step down — investigate (own EUI=0x{euis[port]:016x}, expected leader=0x{euis[lowest_port]:016x})')
|
||||
@@ -60,6 +60,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
uint8_t channel;
|
||||
int8_t noise_floor;
|
||||
uint8_t out_buf_scale; /* Controls output buffer size: 0-255. */
|
||||
/* ADR-110: fuzz the new HE-branch + legacy-branch input fields too so
|
||||
* the byte 18/19 encoding code path is exercised. */
|
||||
uint8_t he_inputs[2] = {0}; /* cur_bb_format (4 bits) + second (4 bits) packed */
|
||||
uint8_t legacy_inputs = 0; /* sig_mode (2) + cwb (1) + stbc (1) packed */
|
||||
|
||||
fuzz_read(&cursor, &remaining, &test_case, 1);
|
||||
fuzz_read(&cursor, &remaining, &iq_len_raw, 2);
|
||||
@@ -67,6 +71,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
fuzz_read(&cursor, &remaining, &channel, 1);
|
||||
fuzz_read(&cursor, &remaining, &noise_floor, 1);
|
||||
fuzz_read(&cursor, &remaining, &out_buf_scale, 1);
|
||||
fuzz_read(&cursor, &remaining, he_inputs, 2);
|
||||
fuzz_read(&cursor, &remaining, &legacy_inputs, 1);
|
||||
|
||||
/* --- Test case 0: Normal operation with fuzz-controlled values --- */
|
||||
|
||||
@@ -75,6 +81,15 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
info.rx_ctrl.rssi = rssi;
|
||||
info.rx_ctrl.channel = channel & 0x0F; /* 4-bit field */
|
||||
info.rx_ctrl.noise_floor = noise_floor;
|
||||
/* ADR-110: feed both branch families. Only the active branch (chosen
|
||||
* at compile time by CONFIG_SOC_WIFI_HE_SUPPORT) will read its fields;
|
||||
* the other set is set-but-not-read. Both must be assignable without
|
||||
* triggering UBSAN bitfield-overflow. */
|
||||
info.rx_ctrl.cur_bb_format = he_inputs[0] & 0x0F; /* 0..15 valid input space */
|
||||
info.rx_ctrl.second = he_inputs[1] & 0x0F;
|
||||
info.rx_ctrl.sig_mode = legacy_inputs & 0x03;
|
||||
info.rx_ctrl.cwb = (legacy_inputs >> 2) & 0x01;
|
||||
info.rx_ctrl.stbc = (legacy_inputs >> 3) & 0x01;
|
||||
|
||||
/* Use remaining fuzz data as I/Q buffer content. */
|
||||
uint16_t iq_len;
|
||||
|
||||
@@ -73,3 +73,13 @@ static mmwave_state_t s_stub_mmwave = {0};
|
||||
esp_err_t mmwave_sensor_init(int tx, int rx) { (void)tx; (void)rx; return ESP_ERR_NOT_FOUND; }
|
||||
bool mmwave_sensor_get_state(mmwave_state_t *s) { if (s) *s = s_stub_mmwave; return false; }
|
||||
const char *mmwave_type_name(mmwave_type_t t) { (void)t; return "None"; }
|
||||
|
||||
/* ADR-110 iter 38 — fuzz-harness stub for c6_sync_espnow_is_valid.
|
||||
* Real implementation lives in main/c6_sync_espnow.c; the fuzz target
|
||||
* (`fuzz_serialize`) only links csi_collector.c against esp_stubs.c, so
|
||||
* iter-11's `if (c6_sync_espnow_is_valid()) flags |= (1 << 4);` needs a
|
||||
* symbol here or `clang -fsanitize=fuzzer` fails with an undefined-reference
|
||||
* linker error. Returning false means the bit-4 cross-node-sync-valid flag
|
||||
* stays 0 in fuzz inputs, which is the natural fuzz semantic. */
|
||||
#include <stdbool.h>
|
||||
bool c6_sync_espnow_is_valid(void) { return false; }
|
||||
|
||||
@@ -62,14 +62,28 @@ static inline esp_err_t esp_timer_delete(esp_timer_handle_t h) { (void)h; return
|
||||
|
||||
/* ---- esp_wifi_types.h ---- */
|
||||
|
||||
/** Minimal rx_ctrl fields needed by csi_serialize_frame. */
|
||||
/** Minimal rx_ctrl fields needed by csi_serialize_frame.
|
||||
*
|
||||
* ADR-110: the HE-tagging path in csi_collector.c references either
|
||||
* (CONFIG_SOC_WIFI_HE_SUPPORT branch) cur_bb_format, second
|
||||
* (legacy / S3 branch) sig_mode, cwb, stbc
|
||||
*
|
||||
* Both sets are unconditionally declared here so a single stub builds
|
||||
* for either branch — the Makefile picks which side via -D flags. */
|
||||
typedef struct {
|
||||
signed rssi : 8;
|
||||
unsigned channel : 4;
|
||||
unsigned noise_floor : 8;
|
||||
unsigned rx_ant : 2;
|
||||
/* Padding to fill out the struct so it compiles. */
|
||||
unsigned _pad : 10;
|
||||
signed rssi : 8;
|
||||
unsigned channel : 4;
|
||||
unsigned noise_floor : 8;
|
||||
unsigned rx_ant : 2;
|
||||
/* ADR-110 HE-branch fields (CONFIG_SOC_WIFI_HE_SUPPORT path) */
|
||||
unsigned cur_bb_format : 4; /**< 0=11b 1=11g/a 2=HT 3=VHT 4=HE-SU 5=HE-MU 6=HE-ER-SU 7=HE-TB */
|
||||
unsigned second : 4; /**< secondary 40 MHz channel offset */
|
||||
/* ADR-110 legacy-branch fields (pre-HE chips) */
|
||||
unsigned sig_mode : 2; /**< 0=non-HT 1=HT 3=VHT */
|
||||
unsigned cwb : 1; /**< 0=20 MHz 1=40 MHz */
|
||||
unsigned stbc : 1; /**< STBC flag */
|
||||
/* Padding to keep alignment predictable. */
|
||||
unsigned _pad : 18;
|
||||
} wifi_pkt_rx_ctrl_t;
|
||||
|
||||
/** Minimal wifi_csi_info_t needed by csi_serialize_frame. */
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* @file test_adr110_encoding.c
|
||||
* @brief Host-side unit tests for ADR-110 pure functions.
|
||||
*
|
||||
* Covers the two encoding paths that don't need ESP-IDF runtime:
|
||||
* 1. mac_to_eui64() — IEEE EUI-64 from MAC-48 (c6_timesync.c)
|
||||
* 2. PPDU-type → ADR-018 byte 18 mapping for both HE-capable and
|
||||
* legacy paths (csi_collector.c)
|
||||
*
|
||||
* Build (Linux/macOS/Windows with any C99 compiler):
|
||||
* cc -std=c99 -Wall -o test_adr110 test_adr110_encoding.c && ./test_adr110
|
||||
*
|
||||
* Or in WSL on this Windows box:
|
||||
* gcc -std=c99 -Wall -o test_adr110 test_adr110_encoding.c && ./test_adr110
|
||||
*
|
||||
* Exits 0 on all-pass, prints which assertion failed otherwise.
|
||||
*
|
||||
* Why a separate host test file rather than extending the existing fuzz
|
||||
* harness: fuzzers want random bytes; these are deterministic table-driven
|
||||
* checks for tiny pure functions where libFuzzer adds no signal.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* ──────────────────────────────────────────────────────────────────────
|
||||
* System under test — copied verbatim from the firmware. If the
|
||||
* firmware copy changes, this test must be updated and the new behavior
|
||||
* attested by re-running the test before the firmware change merges.
|
||||
* ────────────────────────────────────────────────────────────────────── */
|
||||
|
||||
/* From firmware/esp32-csi-node/main/c6_timesync.c — fallback path used only
|
||||
* when esp_read_mac(..., ESP_MAC_IEEE802154) fails. The primary C6 path
|
||||
* reads 8 bytes directly (the eFuse-provided EUI-64). */
|
||||
static uint64_t mac48_to_eui64(const uint8_t mac[6])
|
||||
{
|
||||
return ((uint64_t)mac[0] << 56) | ((uint64_t)mac[1] << 48) |
|
||||
((uint64_t)mac[2] << 40) | ((uint64_t)0xFF << 32) |
|
||||
((uint64_t)0xFE << 24) | ((uint64_t)mac[3] << 16) |
|
||||
((uint64_t)mac[4] << 8 ) | (uint64_t)mac[5];
|
||||
}
|
||||
|
||||
/* Pack 8-byte EUI-64 buffer (as returned by ESP_MAC_IEEE802154) into u64. */
|
||||
static uint64_t eui64_bytes_to_u64(const uint8_t eui[8])
|
||||
{
|
||||
return ((uint64_t)eui[0] << 56) | ((uint64_t)eui[1] << 48) |
|
||||
((uint64_t)eui[2] << 40) | ((uint64_t)eui[3] << 32) |
|
||||
((uint64_t)eui[4] << 24) | ((uint64_t)eui[5] << 16) |
|
||||
((uint64_t)eui[6] << 8 ) | (uint64_t)eui[7];
|
||||
}
|
||||
|
||||
/* From firmware/esp32-csi-node/main/csi_collector.c — HE-capable branch.
|
||||
* Returns the ADR-018 byte-18 PPDU type. */
|
||||
static uint8_t ppdu_type_he(uint8_t cur_bb_format)
|
||||
{
|
||||
switch (cur_bb_format) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2: return 0; /* 11b/g/a/HT bucket */
|
||||
case 3: return 0; /* VHT */
|
||||
case 4: return 1; /* HE-SU */
|
||||
case 5: return 2; /* HE-MU */
|
||||
case 6: return 1; /* HE-ER-SU collapses to HE-SU */
|
||||
case 7: return 3; /* HE-TB */
|
||||
default: return 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
/* From csi_collector.c — legacy (non-HE) branch. */
|
||||
static uint8_t ppdu_type_legacy(uint8_t sig_mode)
|
||||
{
|
||||
switch (sig_mode) {
|
||||
case 0: return 0; /* non-HT */
|
||||
case 1: return 0; /* HT */
|
||||
case 3: return 0; /* VHT */
|
||||
default: return 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
/* ──────────────────────────────────────────────────────────────────────
|
||||
* Test harness
|
||||
* ────────────────────────────────────────────────────────────────────── */
|
||||
|
||||
static int g_failed = 0;
|
||||
static int g_passed = 0;
|
||||
|
||||
#define CHECK_EQ_U64(label, got, expected) do { \
|
||||
if ((got) == (expected)) { g_passed++; } \
|
||||
else { \
|
||||
g_failed++; \
|
||||
printf("FAIL: %s — got=0x%016llx expected=0x%016llx\n", \
|
||||
(label), (unsigned long long)(got), \
|
||||
(unsigned long long)(expected)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_EQ_U8(label, got, expected) do { \
|
||||
if ((uint8_t)(got) == (uint8_t)(expected)) { g_passed++; } \
|
||||
else { \
|
||||
g_failed++; \
|
||||
printf("FAIL: %s — got=0x%02x expected=0x%02x\n", \
|
||||
(label), (unsigned)(got), (unsigned)(expected)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* ──────────────────────────────────────────────────────────────────────
|
||||
* EUI-64 tests
|
||||
*
|
||||
* IEEE 802 MAC-48 → EUI-64 spec: insert 0xFFFE between bytes 3 and 4
|
||||
* of the MAC. ADR-110's c6_timesync.c does exactly that, leaving the
|
||||
* U/L bit in byte 0 untouched (the c6 EUI then matches what `esp_read_mac
|
||||
* ESP_MAC_IEEE802154` returns).
|
||||
* ────────────────────────────────────────────────────────────────────── */
|
||||
|
||||
static void test_eui64_fallback_zero_mac(void)
|
||||
{
|
||||
uint8_t mac[6] = {0, 0, 0, 0, 0, 0};
|
||||
/* mac48_to_eui64 inserts FFFE → 00 00 00 FF FE 00 00 00 */
|
||||
CHECK_EQ_U64("mac48->eui64 zero", mac48_to_eui64(mac), 0x000000FFFE000000ULL);
|
||||
}
|
||||
|
||||
static void test_eui64_fallback_all_ones(void)
|
||||
{
|
||||
uint8_t mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
/* FF FF FF FF FE FF FF FF */
|
||||
CHECK_EQ_U64("mac48->eui64 all-ones", mac48_to_eui64(mac), 0xFFFFFFFFFEFFFFFFULL);
|
||||
}
|
||||
|
||||
static void test_eui64_fallback_byte_order(void)
|
||||
{
|
||||
uint8_t mac[6] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
|
||||
CHECK_EQ_U64("mac48->eui64 byte order", mac48_to_eui64(mac), 0x112233FFFE445566ULL);
|
||||
}
|
||||
|
||||
/* Primary path: 8-byte EUI-64 from ESP_MAC_IEEE802154 packed unchanged.
|
||||
* Verified by esptool's chip_id output on the real C6 hardware:
|
||||
* COM6: BASE MAC 20:6e:f1:17:27:8c, MAC_EXT ff:fe →
|
||||
* full EUI: 20:6e:f1:ff:fe:17:27:8c → 0x206EF1FFFE17278C
|
||||
* COM9: BASE MAC 20:6e:f1:17:05:3c, MAC_EXT ff:fe →
|
||||
* full EUI: 20:6e:f1:ff:fe:17:05:3c → 0x206EF1FFFE17053C
|
||||
*
|
||||
* Note COM9's EUI is numerically smaller — it wins the leader election. */
|
||||
static void test_eui64_from_native_com6(void)
|
||||
{
|
||||
uint8_t eui[8] = {0x20, 0x6e, 0xf1, 0xff, 0xfe, 0x17, 0x27, 0x8c};
|
||||
CHECK_EQ_U64("native eui64 COM6", eui64_bytes_to_u64(eui), 0x206EF1FFFE17278CULL);
|
||||
}
|
||||
|
||||
static void test_eui64_from_native_com9(void)
|
||||
{
|
||||
uint8_t eui[8] = {0x20, 0x6e, 0xf1, 0xff, 0xfe, 0x17, 0x05, 0x3c};
|
||||
CHECK_EQ_U64("native eui64 COM9", eui64_bytes_to_u64(eui), 0x206EF1FFFE17053CULL);
|
||||
}
|
||||
|
||||
static void test_eui64_leader_election_order(void)
|
||||
{
|
||||
uint8_t com6[8] = {0x20, 0x6e, 0xf1, 0xff, 0xfe, 0x17, 0x27, 0x8c};
|
||||
uint8_t com9[8] = {0x20, 0x6e, 0xf1, 0xff, 0xfe, 0x17, 0x05, 0x3c};
|
||||
uint64_t a = eui64_bytes_to_u64(com6);
|
||||
uint64_t b = eui64_bytes_to_u64(com9);
|
||||
/* Lowest EUI wins → COM9 should be leader when both boards online. */
|
||||
if (b < a) { g_passed++; }
|
||||
else { g_failed++; printf("FAIL: leader-election order — expected COM9 < COM6\n"); }
|
||||
}
|
||||
|
||||
/* ──────────────────────────────────────────────────────────────────────
|
||||
* PPDU-type encoding tests — HE-capable branch (C6/C5)
|
||||
* ────────────────────────────────────────────────────────────────────── */
|
||||
|
||||
static void test_ppdu_he_legacy_bucket(void)
|
||||
{
|
||||
CHECK_EQ_U8("he 0 → 0 (11b)", ppdu_type_he(0), 0);
|
||||
CHECK_EQ_U8("he 1 → 0 (11g/a)", ppdu_type_he(1), 0);
|
||||
CHECK_EQ_U8("he 2 → 0 (HT)", ppdu_type_he(2), 0);
|
||||
CHECK_EQ_U8("he 3 → 0 (VHT)", ppdu_type_he(3), 0);
|
||||
}
|
||||
|
||||
static void test_ppdu_he_su(void)
|
||||
{
|
||||
CHECK_EQ_U8("he 4 → 1 (HE-SU)", ppdu_type_he(4), 1);
|
||||
CHECK_EQ_U8("he 6 → 1 (HE-ER-SU)", ppdu_type_he(6), 1);
|
||||
}
|
||||
|
||||
static void test_ppdu_he_mu(void)
|
||||
{
|
||||
CHECK_EQ_U8("he 5 → 2 (HE-MU)", ppdu_type_he(5), 2);
|
||||
}
|
||||
|
||||
static void test_ppdu_he_tb(void)
|
||||
{
|
||||
CHECK_EQ_U8("he 7 → 3 (HE-TB)", ppdu_type_he(7), 3);
|
||||
}
|
||||
|
||||
static void test_ppdu_he_out_of_range(void)
|
||||
{
|
||||
CHECK_EQ_U8("he 8 → 0xFF (unknown)", ppdu_type_he(8), 0xFF);
|
||||
CHECK_EQ_U8("he 15 → 0xFF (unknown)", ppdu_type_he(15), 0xFF);
|
||||
}
|
||||
|
||||
/* ──────────────────────────────────────────────────────────────────────
|
||||
* PPDU-type encoding tests — legacy (S3/etc) branch
|
||||
* ────────────────────────────────────────────────────────────────────── */
|
||||
|
||||
static void test_ppdu_legacy_known(void)
|
||||
{
|
||||
CHECK_EQ_U8("legacy sig_mode 0 → 0 (non-HT)", ppdu_type_legacy(0), 0);
|
||||
CHECK_EQ_U8("legacy sig_mode 1 → 0 (HT)", ppdu_type_legacy(1), 0);
|
||||
CHECK_EQ_U8("legacy sig_mode 3 → 0 (VHT)", ppdu_type_legacy(3), 0);
|
||||
}
|
||||
|
||||
static void test_ppdu_legacy_unknown(void)
|
||||
{
|
||||
CHECK_EQ_U8("legacy sig_mode 2 → 0xFF", ppdu_type_legacy(2), 0xFF);
|
||||
CHECK_EQ_U8("legacy sig_mode 5 → 0xFF", ppdu_type_legacy(5), 0xFF);
|
||||
}
|
||||
|
||||
/* ──────────────────────────────────────────────────────────────────────
|
||||
* main
|
||||
* ────────────────────────────────────────────────────────────────────── */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_eui64_fallback_zero_mac();
|
||||
test_eui64_fallback_all_ones();
|
||||
test_eui64_fallback_byte_order();
|
||||
test_eui64_from_native_com6();
|
||||
test_eui64_from_native_com9();
|
||||
test_eui64_leader_election_order();
|
||||
|
||||
test_ppdu_he_legacy_bucket();
|
||||
test_ppdu_he_su();
|
||||
test_ppdu_he_mu();
|
||||
test_ppdu_he_tb();
|
||||
test_ppdu_he_out_of_range();
|
||||
|
||||
test_ppdu_legacy_known();
|
||||
test_ppdu_legacy_unknown();
|
||||
|
||||
printf("\n%d passed, %d failed\n", g_passed, g_failed);
|
||||
return g_failed == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user