code wiki / _hdl_build / nx_iot_ctl_lib.nx

nx_iot_ctl_lib.nx

buildroot/runtime/_hdl_build/nx_iot_ctl_lib.nx

26897 B618 linesdepth 7pulls 14 transitivereach 2 importersview sourcekind librarytopic iot
docsdependenciesstructsconstsfunctions

about

nx_iot_ctl_lib.nx -- sovereign HOME-ELECTRONICS identification LIB (no main). THE MEASURED DEFECT THIS CLOSES (2026-07-25, measured on the real LAN before a line was written): the live `nx_printer_ctl survey` classifies EVERY host on 192.168.8 as "web-device" because its port profile is four hardcoded printer/web ports (7125/10088/80/443). It cannot tell a smart plug from a NAS. Meanwhile a full vendor-routing brain -- nx_iot_classify, built and gate-proven back in June (fused reply > OUI > port > SSID over Kasa / Tuya / WiZ / MagicHome / Yeelight) -- has been sitting STRANDED in the tree, never wired to anything live. This lib is the wiring, not a re-derivation. TWO DESIGN LAWS ARE MECHANISED HERE: 1. DATA-DRIVEN, NOT HARDCODED (rule 11). The service table is a MANIFEST: port / proto / vendor / kind / label rows, loaded from `iot_services.conf` with a compiled-in fail-safe default set (rule 14: a missing/unreadable conf degrades to the defaults, it never leaves the organ blind). Adding a vendor's port is a conf edit, not a rebuild. MANIFEST ORDER IS PRECEDENCE: the first matching row decides a host's kind, so specificity is expressed as data too. 2. AN INSTRUMENT MUST DECLARE WHAT IT CANNOT SEE (the cynical-instruments law: unproven == absent; a synthetic pass is a stub). A TCP connect sweep STRUCTURALLY CANNOT find a UDP-only service -- WiZ bulbs live on UDP 38899 and would be silently reported as "not there", which reads identically to "no WiZ bulbs exist". So every emitted scan carries `udp_ports_unswept` plus an explicit note that absence there is not evidence of absence. The manifest tracks proto per row precisely so this stays honest as it grows. NEVER-BRICK (rule 26, ABSOLUTE): this lib is IDENTIFICATION ONLY. Its single active probe is Kasa `get_sysinfo` -- a READ. There is no write verb, no set_stainfo credential push, no firmware/OTA path, no raw command passthrough. A device cannot be altered through any code path in this file; nx_iot_ctl_gate proves it mechanically. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 5 imports · 2 importers

nx_syscalls.nx nx_lan_scan.nx nx_iot_classify.nx nx_iot_local_kasa.nx nx_moonraker_io.nx nx_iot_ctl_lib.nx nx_iot_ctl.nx nx_iot_ctl_gate.nx

imports: nx_syscalls.nxnx_lan_scan.nxnx_iot_classify.nxnx_iot_local_kasa.nxnx_moonraker_io.nx

imported by: nx_iot_ctl.nxnx_iot_ctl_gate.nx

structs

none

consts

42const IOTC_MAGIC_65535: i64 = 65535
43const IOTC_MAGIC_9999: i64 = 9999
44const IOTC_MAGIC_6668: i64 = 6668
45const IOTC_MAGIC_6667: i64 = 6667
46const IOTC_MAGIC_55443: i64 = 55443
47const IOTC_MAGIC_5577: i64 = 5577
48const IOTC_MAGIC_38899: i64 = 38899
49const IOTC_MAGIC_7125: i64 = 7125
50const IOTC_MAGIC_10088: i64 = 10088
51const IOTC_MAGIC_1883: i64 = 1883
52const IOTC_MAGIC_8123: i64 = 8123
55const IOTC_OUT: i64 = 32768
56const IOTC_RESP: i64 = 8192
57const IOTC_SCRATCH: i64 = 4096
60const IOTC_V_BAD: i64 = 0
61const IOTC_V_SERVICES: i64 = 1
62const IOTC_V_SCAN: i64 = 2
63const IOTC_V_PROBE: i64 = 3
64const IOTC_V_CONTRACT: i64 = 4
67const IOTC_KIND_UNKNOWN: i64 = 0
68const IOTC_KIND_PLUG: i64 = 1
69const IOTC_KIND_BULB: i64 = 2
70const IOTC_KIND_PRINTER: i64 = 3
71const IOTC_KIND_HUB: i64 = 4
72const IOTC_KIND_WEB: i64 = 5
73const IOTC_KIND_N: i64 = 6
76const IOTC_PROTO_TCP: i64 = 1
77const IOTC_PROTO_UDP: i64 = 2
82const IOTM_BASE: i64 = 8
83const IOTM_ROW: i64 = 64
84const IOTM_LABEL: i64 = 32
85const IOTM_MAXLBL: i64 = 31
86const IOTM_MAX: i64 = 32
87const IOTM_BYTES: i64 = 4096

functions

89func iotm_new() -> *u8
called by 2: mainmain calls 1: sys_mmap
95func iotm_count(m: *u8) -> i64 { let hdr: *i64 = m as *i64; return hdr[0] }
96func iotm_row(m: *u8, i: i64) -> *u8
100func iotm_port(m: *u8, i: i64) -> i64 { let r: *i64 = iotm_row(m, i) as *i64; return r[0] }
101func iotm_vendor(m: *u8, i: i64) -> i64 { let r: *i64 = iotm_row(m, i) as *i64; return r[1] }
called by 2: mainiotc_emit_services calls 1: iotm_row
102func iotm_kind(m: *u8, i: i64) -> i64 { let r: *i64 = iotm_row(m, i) as *i64; return r[2] }
103func iotm_proto(m: *u8, i: i64) -> i64 { let r: *i64 = iotm_row(m, i) as *i64; return r[3] }
104func iotm_label(m: *u8, i: i64) -> *u8
110func iotm_add(m: *u8, port: i64, vendor: i64, kind: i64, proto: i64, label: *u8) -> i64
142func iotm_defaults(m: *u8) -> i64
called by 2: mainiotm_load calls 2: iotm_addiotm_count
164func iotc_is_space(c: i64) -> i64
called by 1: iotm_parse
170func iotc_word_eq(buf: *u8, s: i64, e: i64, lit: *u8) -> i64
190func iotc_word_num(buf: *u8, s: i64, e: i64) -> i64
called by 1: iotm_parse
203func iotc_vendor_of(buf: *u8, s: i64, e: i64) -> i64
called by 1: iotm_parse calls 1: iotc_word_eq
211func iotc_kind_of(buf: *u8, s: i64, e: i64) -> i64
called by 1: iotm_parse calls 1: iotc_word_eq
222func iotm_parse(m: *u8, buf: *u8, n: i64) -> i64
306func iotm_load(m: *u8, path: *u8) -> i64
320func iotc_kind_name(k: i64) -> *u8
328func iotc_vendor_name(v: i64) -> *u8
336func iotc_proto_name(p: i64) -> *u8
called by 1: iotc_emit_services
342func iotc_streq(a: *u8, b: *u8) -> i64
called by 2: mainiotc_verb_id
350func iotc_verb_id(v: *u8) -> i64
called by 2: mainmain calls 1: iotc_streq
359func iotc_cat(d: *u8, o: i64, s: *u8) -> i64
364func iotc_catn(d: *u8, o: i64, v: i64) -> i64
375func iotc_cat_ip(d: *u8, o: i64, ipv4: i64) -> i64
387func iotc_emit_services(out: *u8, m: *u8, from_conf: i64) -> i64
423func iotc_scan(m: *u8, base24: i64, budget_per_port: i64, mask: *i64) -> i64
445func iotc_mask_row(m: *u8, bits: i64) -> i64
called by 2: mainiotc_emit_scan calls 1: iotm_count
457func iotc_mask_vendor(m: *u8, bits: i64) -> i64
473func iotc_emit_scan(out: *u8, m: *u8, prefix: *u8, base24: i64, mask: *i64, from_conf: i64) -> i64
543func iotc_kasa_probe(ipv4: i64, port: i64, plain: *u8, plain_cap: i64) -> i64
565func iotc_probe_err(code: i64) -> *u8
called by 1: iotc_emit_probe
572func iotc_emit_probe(out: *u8, ipv4: i64, port: i64, pn: i64, plain: *u8) -> i64
601func iotc_emit_contract(out: *u8, m: *u8, from_conf: i64) -> i64
called by 1: main calls 3: iotc_catiotc_catniotm_count