code wiki / (root) / nx_iot_discover.nx

nx_iot_discover.nx

buildroot/runtime/nx_iot_discover.nx

11124 B231 linesdepth 2pulls 3 transitivereach 2 importersview sourcekind librarytopic iot
docsdependenciesstructsconstsfunctions

about

nx_iot_discover.nx -- universal multi-vendor device DISCOVERY brain. Roadmap: NISHI_IOT_HUB_ROADMAP.md Epoch 1 (DISCOVER), rung D1. Operator ask (2026-06-22): "it needs a discovery mechanism like all the hardware discovery" -- find EVERY device on the LAN and figure out what each one is, WITHOUT knowing brands in advance. This is the DISCOVERY ORCHESTRATOR that ties the existing thin organs into one pass: a captured datagram (raw bytes + source port + source IP + optional MAC) goes IN; a classified, de-duplicated logical device in the anchor registry comes OUT. It composes -- it duplicates nothing: - nx_iot_local_kasa : decrypt the autokey-XOR :9999 replies + confirm sysinfo (the one wire format nx_iot_announce's first-byte classifier could not read) - nx_iot_classify : fuse 4 signals (reply / OUI / port / SSID) -> vendor - nx_iot_anchor : idempotent adopt keyed by stable hardware id -> re-discovery RE-ADOPTS (no duplicate-on-repair) The live socket sweep (rung D2) calls nx_iot_disc_ingest once per captured datagram; this brain has NO sockets so it is deterministic, portable across every nxc2 backend, and hard-gateable with canned beacons. NEVER-BRICK (CLAUDE.md #26): discovery is READ-ONLY classification plus an ADDITIVE in-memory registry adopt (soft-state, #13). It emits no device write of any kind -- brick-safe by construction; there is no firmware path here to prove safe because none exists. UNKNOWN is a FIRST-CLASS result (no silent drop): an unrecognised device still anchors + gets a logical id, so the hub can active-probe / build a driver for it later (operator's "build it autonomously" path). genealogy_id: NISHI_IOT_HUB_ROADMAP.md Epoch 1 + project-iot-hub-multi-vendor-kickoff-2026-05-16 license_tier: ORIGINAL nx_capability_claims: needs: [pointer_arithmetic] provides: [universal_discovery_ingest, kasa_reply_decode, fused_vendor_classify, dedup_by_hardware_id, unknown_is_first_class, measured_duplicates_prevented] safety: [no_unchecked_deref, no_floating_point, no_syscall,

dependencies 3 imports · 2 importers

nx_iot_classify.nx nx_iot_anchor.nx nx_iot_local_kasa.nx nx_iot_discover.nx nx_iot_discover_test.nx nx_iot_softap_discover_test.nx

imports: nx_iot_classify.nxnx_iot_anchor.nxnx_iot_local_kasa.nx

imported by: nx_iot_discover_test.nxnx_iot_softap_discover_test.nx

structs

none

consts

68const NX_IOT_DISC_UNKNOWN: i64 = 0
69const NX_IOT_DISC_NEW: i64 = 1 // newly discovered + anchored
70const NX_IOT_DISC_READOPTED: i64 = 2 // known device re-seen -> same logical id, no dup
71const NX_IOT_DISC_FULL: i64 = 3 // registry at capacity
72const NX_IOT_DISC_BAD_ARG: i64 = 4
73const NX_IOT_DISC_N: i64 = 5

functions

75func nx_iot_disc_verdict_is_valid(v: i64) -> i64
called by 1: main
88func nx_iot_disc_to_plain(raw: *u8, n: i64, src_port: i64,
110func nx_iot_disc_classify(plain: *u8, plain_n: i64, src_port: i64,
132func nx_iot_disc_ingest(reg: *IotAnchorReg, metas: *IotDeviceMeta, blob: *u8,
170func nx_iot_disc_duplicates_prevented(reg: *IotAnchorReg) -> i64
182func nx_iot_disc_classify_softap(ssid: *u8, ssid_n: i64,
198func nx_iot_disc_softap_pairable(vendor: i64, auth_open: i64) -> i64
211func nx_iot_disc_ingest_softap(reg: *IotAnchorReg, metas: *IotDeviceMeta, blob: *u8,