nx_iot_softap_discover_test.nx source
↩ module page · 117 lines · 5619 B
1// nx_iot_softap_discover_test.nx -- gate for SoftAP (pairing-mode) discovery.
2//
3// Grounded in a REAL Wi-Fi scan taken 2026-06-22 on the operator's LAN
4// (Intel AX211, netsh wlan show networks mode=bssid). The operator powered
5// on unpaired lights and asked to "show their ability to be paired".
6//
7// The scan's pairable device is the operator's TP-Link Kasa HS210:
8// SSID TP-LINK_HS210_C209 Authentication: Open BSSID d8:0d:17:a1:c2:09
9// Two independent signals (SSID prefix "TP-LINK_" + OUI d8:0d:17) classify
10// it KASA. Real neighbour APs from the same scan are the negative controls.
11//
12// Coverage:
13// - HS210 open SoftAP -> KASA, pairable, NEW (the real unpaired light)
14// - NEG: West_Family_Upstairs (WPA3 mesh AP) -> UNKNOWN, NOT pairable,
15// NOT anchored (we never provision a neighbour's router)
16// - NEG / liar-kill: an OPEN but non-IoT AP -> UNKNOWN, NOT pairable
17// (proves "pairable" is NOT just "open" -- it must be a known device)
18// - NEG: ATTu9skIKP (WPA2 neighbour) -> UNKNOWN, NOT pairable
19// - UNIFY: the SAME HS210, later seen ON-LAN (Kasa :9999 reply, same MAC
20// hwid) -> RE-ADOPTED to the SAME logical id (one identity across
21// pairing-mode and on-LAN -- no duplicate when it joins the network)
22// - MEASURED: duplicates_prevented == 1 over the 2 real adopt events
23// - NEG: bad arg (hwid_n=0) on a pairable device -> DISC_BAD_ARG, no change
24//
25// expect_exit: 0
26//
27// license_tier: ORIGINAL
28
29import "nx_syscalls_x86_64.nx"
30import "nx_iot_discover.nx"
31
32func main() -> i64 {
33 let reg: *IotAnchorReg = sys_mmap(64) as *IotAnchorReg
34 let metas: *IotDeviceMeta = sys_mmap(512) as *IotDeviceMeta
35 let blob: *u8 = sys_mmap(512)
36 let qv: *i64 = sys_mmap(8) as *i64
37 let dv: *i64 = sys_mmap(8) as *i64
38 let plain: *u8 = sys_mmap(512)
39 if nx_iot_anchor_init(reg, 8) != 0 { return 10 }
40
41 // ===== Real unpaired light: TP-LINK_HS210_C209 (Open SoftAP) =====
42 let macHS: *u8 = sys_mmap(8)
43 macHS[0] = 0xD8 as u8
44 macHS[1] = 0x0D as u8
45 macHS[2] = 0x17 as u8
46 macHS[3] = 0xA1 as u8
47 macHS[4] = 0xC2 as u8
48 macHS[5] = 0x09 as u8
49 let lh: i64 = nx_iot_disc_ingest_softap(reg, metas, blob, "TP-LINK_HS210_C209", 18, macHS, 1, "d8:0d:17:a1:c2:09", 17, 1, 1000, qv, dv)
50 if lh != 1 { return 20 }
51 if qv[0] != NX_IOT_VENDOR_KASA { return 21 }
52 if dv[0] != NX_IOT_DISC_NEW { return 22 }
53 if nx_iot_anchor_count(reg) != 1 { return 23 }
54
55 // ===== NEG: West_Family_Upstairs (WPA3 home AP, BSSID 00:11:32..) =
56 let macWF: *u8 = sys_mmap(8)
57 macWF[0] = 0x00 as u8
58 macWF[1] = 0x11 as u8
59 macWF[2] = 0x32 as u8
60 macWF[3] = 0x9D as u8
61 macWF[4] = 0xDE as u8
62 macWF[5] = 0xEB as u8
63 let lw: i64 = nx_iot_disc_ingest_softap(reg, metas, blob, "West_Family_Upstairs", 20, macWF, 1, "00:11:32:9d:de:eb", 17, 0, 1100, qv, dv)
64 if lw != 0 { return 30 }
65 if qv[0] != NX_IOT_VENDOR_UNKNOWN { return 31 }
66 if nx_iot_anchor_count(reg) != 1 { return 32 }
67
68 // ===== NEG / liar-kill: an OPEN but non-IoT AP ===================
69 // Open auth alone must NOT make it pairable -- it must be a known device.
70 let macF: *u8 = sys_mmap(8)
71 macF[0] = 0x11 as u8
72 macF[1] = 0x22 as u8
73 macF[2] = 0x33 as u8
74 macF[3] = 0x44 as u8
75 macF[4] = 0x55 as u8
76 macF[5] = 0x66 as u8
77 let lf: i64 = nx_iot_disc_ingest_softap(reg, metas, blob, "FreeCoffeeWiFi", 14, macF, 1, "11:22:33:44:55:66", 17, 1, 1200, qv, dv)
78 if lf != 0 { return 40 }
79 if qv[0] != NX_IOT_VENDOR_UNKNOWN { return 41 }
80 if nx_iot_anchor_count(reg) != 1 { return 42 }
81
82 // ===== NEG: ATTu9skIKP (WPA2 neighbour) =========================
83 let lna: i64 = nx_iot_disc_ingest_softap(reg, metas, blob, "ATTu9skIKP", 10, macF, 0, "att-neighbour-0001", 18, 0, 1300, qv, dv)
84 if lna != 0 { return 50 }
85 if qv[0] != NX_IOT_VENDOR_UNKNOWN { return 51 }
86 if nx_iot_anchor_count(reg) != 1 { return 52 }
87
88 // ===== UNIFY: the same HS210, later seen ON-LAN (:9999) =========
89 // Build a Kasa sysinfo cipher reply; ingest via the on-LAN UDP path
90 // with the SAME MAC hwid. Must RE-ADOPT logical 1 (no duplicate).
91 let ksys: *u8 = sys_mmap(256)
92 let kL: i64 = nx_iot_kasa_puts_z(ksys, 0, "{\"system\":{\"get_sysinfo\":{\"mic_type\":\"IOT.SMARTPLUGSWITCH\",\"relay_state\":1}}}")
93 let kcipher: *u8 = sys_mmap(256)
94 nx_iot_kasa_encrypt(ksys, kL, kcipher)
95 let lon: i64 = nx_iot_disc_ingest(reg, metas, blob, kcipher, kL, NX_IOT_KASA_PORT, 0xC0A80878, macHS, 1, "d8:0d:17:a1:c2:09", 17, 2000, plain, 512, qv, dv)
96 if lon != 1 { return 60 }
97 if dv[0] != NX_IOT_DISC_READOPTED { return 61 }
98 if qv[0] != NX_IOT_VENDOR_KASA { return 62 }
99 if nx_iot_anchor_count(reg) != 1 { return 63 }
100
101 // ===== MEASURED EXCEED ==========================================
102 // 2 real adopt events (SoftAP NEW + on-LAN READOPT), 1 distinct device.
103 // The 3 non-pairable sightings never reached the registry. A dedup-free
104 // app would show 2 rows; we keep 1. duplicates_prevented = 1.
105 if nx_iot_anchor_naive_adopts(reg) != 2 { return 70 }
106 if nx_iot_anchor_count(reg) != 1 { return 71 }
107 if nx_iot_disc_duplicates_prevented(reg) != 1 { return 72 }
108
109 // ===== NEG: bad arg on a pairable device ========================
110 let cbefore: i64 = nx_iot_anchor_count(reg)
111 let bad: i64 = nx_iot_disc_ingest_softap(reg, metas, blob, "TP-LINK_HS210_C209", 18, macHS, 1, "d8:0d:17:a1:c2:09", 0, 1, 9000, qv, dv)
112 if bad != -1 { return 80 }
113 if dv[0] != NX_IOT_DISC_BAD_ARG { return 81 }
114 if nx_iot_anchor_count(reg) != cbefore { return 82 }
115
116 return 0
117}