code wiki / (root) / nx_toner_continue.nx

nx_toner_continue.nx source

↩ module page · 84 lines · 3995 B

1// nx_toner_continue.nx -- SOVEREIGN network override for the proprietary toner block. Drives the printer's 2// OWN web form (POST /general/replacetoner.html, field B5c0: 1=Continue, 2=Stop) to force Continue-mode, so 3// the printer never hard-stops on aftermarket/low toner. This is a reversible CONFIG TOGGLE via the device's 4// own validated settings UI -- NOT a firmware/EEPROM/NVRAM write -> never-brick (#26) by construction. 5// 6// MODE default = 1 (Continue). Applying Continue when already Continue is an idempotent no-op that proves 7// the network-override capability without changing device state. Sovereign HTTP (reuses transport helpers). 8// genealogy_id: project-printer-management-ipp-sclass-2026-06-20 ; license_tier: ORIGINAL 9 10import "nx_syscalls.nx" 11import "nx_connect.nx" // bounded connect: a raw sys_connect hangs ~127s on a black-holed host 12import "nx_ipp_transport.nx" 13const K_MAGIC_65536: i64 = 65536 14 15const MODE: i64 = 1 // 1 = Continue (defeat the hard-stop), 2 = Stop (vendor default) 16 17func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 18func pn(v: i64) -> i64 { 19 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 20 var m: i64 = v 21 let t: *u8 = sys_mmap(24); var k: i64 = 0 22 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 23 let b: *u8 = sys_mmap(24); var i: i64 = 0 24 while i < k { b[i] = t[k - 1 - i]; i = i + 1 } 25 sys_write(1, b, k); return 0 26} 27 28func main() -> i64 { 29 let a: i64 = 192 30 let b: i64 = 168 31 let c: i64 = 8 32 let d: i64 = 127 33 p("=== SET toner mode -> ") 34 if MODE == 1 { p("CONTINUE (defeat hard-stop)") } else { p("STOP (vendor default)") } 35 p(" via the printer's own web form ===\n") 36 37 // x-www-form-urlencoded body matching the live form (pageid=13, reject=1, B5c0=mode) 38 let body: *u8 = sys_mmap(128) 39 var bl: i64 = 0 40 bl = nx_ipt_puts(body, bl, "pageid=13&postif_registration_reject=1&B5c0=") 41 bl = nx_ipt_puti(body, bl, MODE) 42 43 let req: *u8 = sys_mmap(512) 44 var o: i64 = 0 45 o = nx_ipt_puts(req, o, "POST /general/replacetoner.html HTTP/1.1\r\nHost: ") 46 o = nx_ipt_puti(req, o, a); req[o] = 46 as u8; o = o + 1 47 o = nx_ipt_puti(req, o, b); req[o] = 46 as u8; o = o + 1 48 o = nx_ipt_puti(req, o, c); req[o] = 46 as u8; o = o + 1 49 o = nx_ipt_puti(req, o, d) 50 o = nx_ipt_puts(req, o, "\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ") 51 o = nx_ipt_puti(req, o, bl) 52 o = nx_ipt_puts(req, o, "\r\nConnection: close\r\n\r\n") 53 var i: i64 = 0 54 while i < bl { req[o] = body[i]; o = o + 1; i = i + 1 } 55 56 let fd: i64 = sys_socket(AF_INET, SOCK_STREAM, 0) 57 if fd < 0 { p("socket fail\n"); sys_exit(1); return 1 } 58 sys_set_socket_timeout(fd, 6) 59 let dest: *u8 = sys_mmap(16) 60 nx_ipt_sockaddr(dest, a, b, c, d, 80) 61 if nx_connect_bounded(fd, dest, 16, NX_CONN_DEFAULT_MS) != 0 { p("connect fail\n"); sys_close(fd); sys_exit(1); return 1 } 62 nx_ipt_send_all(fd, req, o) 63 let resp: *u8 = sys_mmap(K_MAGIC_65536) 64 var total: i64 = 0 65 var keep: i64 = 1 66 while keep == 1 { 67 if total >= K_MAGIC_65536 { keep = 0 } 68 else { 69 let r: i64 = sys_read(fd, ((resp as i64) + total) as *u8, K_MAGIC_65536 - total) 70 if r <= 0 { keep = 0 } 71 else { total = total + r } 72 } 73 } 74 sys_close(fd) 75 let body2: *u8 = sys_mmap(K_MAGIC_65536) 76 let out2: *i64 = sys_mmap(16) as *i64 77 let v: i64 = nx_ipt_extract_body(resp, total, body2, K_MAGIC_65536, out2) 78 p("override POST -> transport="); p(nx_ipt_verdict_name(v)); p(" http="); pn(out2[0]); p("\n") 79 if v == NX_IPT_OK { 80 if out2[0] == 200 { p("RESULT: printer accepted the Continue-mode setting over the network (sovereign, no auth, no firmware).\n") } 81 else { if out2[0] == 302 { p("RESULT: accepted (redirect after POST = success).\n") } else { p("RESULT: see http code above.\n") } } 82 } 83 sys_exit(0); return 0 84}