code wiki / (root) / nx_iot_sc_broadcast_gate.nx

nx_iot_sc_broadcast_gate.nx source

↩ module page · 61 lines · 2403 B

1// nx_iot_sc_broadcast_gate.nx -- gate for the sovereign ESP-Touch broadcaster. 2// Proves (a) genSpecBytes payload + sockaddr_in byte-exactness, and (b) the REAL socket path works 3// HERE: opens a UDP socket and actually sends packets via sys_sendto (single 64B send returns 64; 4// full sequence sends 59 packets to loopback). The ONLY thing unprovable without a device is 5// over-the-air reception (a deployment seam, documented honestly, not faked green). 6// expect_exit: 0 license_tier: ORIGINAL 7import "nx_iot_sc_broadcast.nx" 8 9func main() -> i64 { 10 // ---- genSpecBytes: 10 bytes, all '1' (0x31), no overrun ---- 11 let p: *u8 = sys_mmap(32) 12 var z: i64 = 0 13 while z < 32 { p[z] = 0 as u8; z = z + 1 } 14 if nx_sc_genspec(p, 10) != 10 { return 1 } 15 var i: i64 = 0 16 while i < 10 { if p[i] != (0x31 as u8) { return 2 } i = i + 1 } 17 if p[10] != (0 as u8) { return 3 } 18 19 // ---- sockaddr_in KAT: 234.1.1.1:7001 (port 7001 = 0x1B59 -> hi 27, lo 89) ---- 20 let sa: *u8 = sys_mmap(16) 21 if nx_sc_sockaddr(sa, 234, 1, 1, 1, 7001) != 16 { return 4 } 22 if sa[0] != (2 as u8) { return 5 } 23 if sa[1] != (0 as u8) { return 6 } 24 if sa[2] != (27 as u8) { return 7 } 25 if sa[3] != (89 as u8) { return 8 } 26 if sa[4] != (234 as u8) { return 9 } 27 if sa[5] != (1 as u8) { return 10 } 28 if sa[6] != (1 as u8) { return 11 } 29 if sa[7] != (1 as u8) { return 12 } 30 var k: i64 = 8 31 while k < 16 { if sa[k] != (0 as u8) { return 13 } k = k + 1 } 32 33 // ---- REAL socket send: open + sendto a 64-byte packet to 127.0.0.1:7001 ---- 34 let fd: i64 = nx_sc_open() 35 if fd < 0 { return 20 } 36 let lo: *u8 = sys_mmap(16) 37 nx_sc_sockaddr(lo, 127, 0, 0, 1, 7001) 38 let scratch: *u8 = sys_mmap(128) 39 let r: i64 = nx_sc_send_one(fd, lo, scratch, 64) 40 if r != 64 { return 21 } 41 sys_close(fd) 42 43 // ---- full broadcast to loopback: ssid="A", pwd="B" -> n=55; reps 2 guide + 1 datum = 59 ---- 44 let ssid: *u8 = sys_mmap(8) 45 ssid[0] = 0x41 as u8 46 let pwd: *u8 = sys_mmap(8) 47 pwd[0] = 0x42 as u8 48 let bssid: *u8 = sys_mmap(8) 49 var b: i64 = 0 50 while b < 6 { bssid[b] = 0 as u8; b = b + 1 } 51 let ip: *u8 = sys_mmap(8) 52 ip[0] = 192 as u8 53 ip[1] = 168 as u8 54 ip[2] = 10 as u8 55 ip[3] = 1 as u8 56 57 let sent: i64 = nx_sc_broadcast(ssid, 1, bssid, pwd, 1, ip, 127, 0, 0, 1, 7001, 2, 1) 58 if sent != 59 { return 30 } 59 60 return 0 61}