nx_iot_smartconfig_gate.nx source
↩ module page · 66 lines · 2357 B
1// nx_iot_smartconfig_gate.nx -- KAT for the sovereign ESP-Touch v1 encoder.
2// Pins byte-exactness against the Espressif spec (sovereignly fetched sc_java_*.raw):
3// - CRC-8/MAXIM check value crc8("123456789") == 0xA1 (the canonical CRC-8/Dallas test)
4// - guide code U8s == 515,514,513,512
5// - every datum code's MIDDLE U8 == 296 + index (the 0x01<<8 + seqHeader + EXTRA_LEN rule)
6// - the nibble encoding of a known value (totalLen=11) lands in the low nibble
7// - the exact U8 count for a known (ssid,bssid,pwd,ip)
8// expect_exit: 0 license_tier: ORIGINAL
9import "nx_syscalls_x86_64.nx"
10import "nx_iot_smartconfig.nx"
11
12func main() -> i64 {
13 // ---- CRC-8/MAXIM KAT ----
14 let s9: *u8 = "123456789" as *u8
15 if nx_sc_crc8(s9, 9) != 0xA1 { return 1 }
16 if nx_sc_crc8(s9, 0) != 0 { return 2 }
17
18 // ---- encode KAT: ssid="A", bssid=00:00:00:00:00:00, pwd="B", ip=192.168.10.1 ----
19 let ssid: *u8 = sys_mmap(8)
20 ssid[0] = 0x41 as u8
21 let pwd: *u8 = sys_mmap(8)
22 pwd[0] = 0x42 as u8
23 let bssid: *u8 = sys_mmap(8)
24 var z: i64 = 0
25 while z < 6 { bssid[z] = 0 as u8; z = z + 1 }
26 let ip: *u8 = sys_mmap(8)
27 ip[0] = 192 as u8
28 ip[1] = 168 as u8
29 ip[2] = 10 as u8
30 ip[3] = 1 as u8
31 let out: *i64 = sys_mmap(512 * 8) as *i64
32
33 let n: i64 = nx_sc_encode(ssid, 1, bssid, pwd, 1, ip, out, 512)
34 // totalLen = 9+1+1 = 11; datum codes = totalLen+6 = 17; U8 count = 4 + 17*3 = 55
35 if n != 55 { return 10 }
36
37 // guide code
38 if out[0] != 515 { return 11 }
39 if out[1] != 514 { return 12 }
40 if out[2] != 513 { return 13 }
41 if out[3] != 512 { return 14 }
42
43 // middle-U8 invariant across ALL 17 datum codes: out[5 + 3k] == 296 + k
44 var k: i64 = 0
45 while k <= 16 {
46 if out[5 + 3 * k] != (296 + k) { return 15 }
47 k = k + 1
48 }
49
50 // index-0 datum byte = totalLen = 11 -> dataHi=0, dataLo=11 (the value nibbles, +40 offset)
51 if ((out[4] - 40) & 0xf) != 0 { return 16 }
52 if ((out[6] - 40) & 0xf) != 11 { return 17 }
53
54 // index-1 datum byte = pwdLen = 1 -> dataHi=0, dataLo=1
55 if ((out[7] - 40) & 0xf) != 0 { return 18 }
56 if ((out[9] - 40) & 0xf) != 1 { return 19 }
57
58 // all lengths are valid packet sizes (>= 40, the EXTRA_LEN floor)
59 var j: i64 = 4
60 while j < n {
61 if out[j] < 40 { return 20 }
62 j = j + 1
63 }
64
65 return 0
66}