code wiki / (root) / nx_iot_research_fetch.nx

nx_iot_research_fetch.nx source

↩ module page · 96 lines · 6527 B

1// nx_iot_research_fetch.nx -- SOVEREIGN multi-source web-fetch to RESEARCH how others do SMART-HOME IoT 2// PAIRING + UNIFICATION (operator 2026-06-22: "use the nishi researcher and see how others do this" -- 3// pair unpaired bulbs + unify the home IoT onto our hub, S-class). Mirrors the proven 4// nx_idam_research_fetch / nx_docpub_research_fetch pattern: own TLS-1.3 (nx_https_fetch_follow) + the 5// Mozilla CA store, saves each source to knowledge/fetched/iot_*.raw so research COMPOUNDS to the Library 6// and can be grepped to CITE (>=2-source no-hearsay). 100% sovereign (own TLS, nx_cc->nxasm, no curl/wget/gcc). 7// Idempotent have-skip (also the per-fetch mmap-leak workaround; re-run fills gaps). 8// Axes = what "pair the bulbs + unify to a sovereign hub, S-class" must learn from the field: 9// (A) WIFI PROVISIONING / ONBOARDING (how an unpaired device joins a network: WPS, Wi-Fi Easy Connect/DPP, 10// captive-portal SoftAP, the access-point pairing dance) 11// (B) DISCOVERY + LOCAL CONTROL (cloud-free hub<->device: mDNS/DNS-SD, MQTT, CoAP -- the LAN floor) 12// (C) HUBS + UNIFY STANDARDS (how others unify: Home Assistant, openHAB, Matter, Thread, Zigbee) 13// (D) NETWORK ISOLATION / IoT SECURITY (the S-class IoT-SSID/VLAN segmentation pattern) 14// (E) VENDOR / ECOSYSTEM (TP-Link et al. -- the real fleet) 15// expect_exit: 0 license_tier: ORIGINAL 16import "nx_syscalls.nx" 17import "nx_x509_trust_store.nx" 18import "nx_trust_store_load_from_certdata.nx" 19import "nx_https_fetch_follow.nx" 20const K_MAGIC_4194304: i64 = 4194304 21const K_MAGIC_8388608: i64 = 8388608 22 23func gf_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 24func gf_putn(v: i64) -> i64 { 25 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 26 var m: i64 = v 27 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 28 let d: *u8 = sys_mmap(24); var k: i64 = 0 29 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 30 var j: i64 = k - 1 31 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 32 return 0 33} 34func have_file(path: *u8) -> i64 { 35 let fd: i64 = sys_openat_rd(path) 36 if fd < 0 { return 0 } 37 sys_close(fd) 38 return 1 39} 40func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 41 if have_file(opath) == 1 { gf_puts(opath); gf_puts(" [have-skip]\n"); return 1 } 42 let status: *i64 = sys_mmap(8) as *i64 43 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 44 gf_puts(url); gf_puts(" status="); gf_putn(status[0]); gf_puts(" bytes="); gf_putn(n) 45 if n <= 0 { gf_puts(" FETCH-FAIL\n"); return 0 } 46 var gz: i64 = 0 47 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 48 if gz == 1 { gf_puts(" [GZIP-skip]\n"); return 0 } 49 let fd: i64 = sys_openat_wr(opath, 0x1a4) 50 if fd < 0 { gf_puts(" SAVE-FAIL\n"); return 0 } 51 sys_write(fd, out, n) 52 sys_close(fd) 53 gf_puts(" SAVED\n") 54 return 1 55} 56 57func main() -> i64 { 58 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 59 if r <= 0 { gf_puts("IOT: certdata load failed\n"); return 1 } 60 let store: *TrustStore = r as *TrustStore 61 gf_puts("CA roots="); gf_putn(trust_store_count(store)); gf_puts("\n") 62 let cap: i64 = K_MAGIC_8388608 63 let out: *u8 = sys_mmap(cap) 64 var ok: i64 = 0 65 66 gf_puts("== A. WIFI PROVISIONING / ONBOARDING (how an unpaired device joins) ==\n") 67 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Wi-Fi_Protected_Setup" as *u8, "knowledge/fetched/iot_a_wps.raw" as *u8, store, out, cap) 68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Wi-Fi_Easy_Connect" as *u8, "knowledge/fetched/iot_a_dpp.raw" as *u8, store, out, cap) 69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Captive_portal" as *u8, "knowledge/fetched/iot_a_captive.raw" as *u8, store, out, cap) 70 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Wireless_access_point" as *u8, "knowledge/fetched/iot_a_ap.raw" as *u8, store, out, cap) 71 72 gf_puts("== B. DISCOVERY + LOCAL CONTROL (cloud-free hub<->device LAN floor) ==\n") 73 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Multicast_DNS" as *u8, "knowledge/fetched/iot_b_mdns.raw" as *u8, store, out, cap) 74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Zero-configuration_networking" as *u8, "knowledge/fetched/iot_b_zeroconf.raw" as *u8, store, out, cap) 75 ok = ok + fetch_save("https://en.wikipedia.org/wiki/MQTT" as *u8, "knowledge/fetched/iot_b_mqtt.raw" as *u8, store, out, cap) 76 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Constrained_Application_Protocol" as *u8, "knowledge/fetched/iot_b_coap.raw" as *u8, store, out, cap) 77 78 gf_puts("== C. HUBS + UNIFY STANDARDS (how others unify the home) ==\n") 79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Home_Assistant" as *u8, "knowledge/fetched/iot_c_homeassistant.raw" as *u8, store, out, cap) 80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/OpenHAB" as *u8, "knowledge/fetched/iot_c_openhab.raw" as *u8, store, out, cap) 81 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Matter_(standard)" as *u8, "knowledge/fetched/iot_c_matter.raw" as *u8, store, out, cap) 82 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Thread_(network_protocol)" as *u8, "knowledge/fetched/iot_c_thread.raw" as *u8, store, out, cap) 83 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Zigbee" as *u8, "knowledge/fetched/iot_c_zigbee.raw" as *u8, store, out, cap) 84 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Home_automation" as *u8, "knowledge/fetched/iot_c_homeautomation.raw" as *u8, store, out, cap) 85 86 gf_puts("== D. NETWORK ISOLATION / IoT SECURITY (the S-class IoT-SSID/VLAN pattern) ==\n") 87 ok = ok + fetch_save("https://en.wikipedia.org/wiki/VLAN" as *u8, "knowledge/fetched/iot_d_vlan.raw" as *u8, store, out, cap) 88 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Network_segmentation" as *u8, "knowledge/fetched/iot_d_segmentation.raw" as *u8, store, out, cap) 89 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Internet_of_things" as *u8, "knowledge/fetched/iot_d_iot.raw" as *u8, store, out, cap) 90 91 gf_puts("== E. VENDOR / ECOSYSTEM (the real fleet) ==\n") 92 ok = ok + fetch_save("https://en.wikipedia.org/wiki/TP-Link" as *u8, "knowledge/fetched/iot_e_tplink.raw" as *u8, store, out, cap) 93 94 gf_puts("READABLE SOURCES SAVED: "); gf_putn(ok); gf_puts(" / 18\n") 95 return 0 96}