code wiki / (root) / nx_toner_liberate.nx

nx_toner_liberate.nx source

↩ module page · 74 lines · 4499 B

1// nx_toner_liberate.nx -- S-class "toner liberation": defeat proprietary toner blocking so the operator's 2// OWN aftermarket toner works in their OWN printer. Right-to-repair / interoperability, by construction safe. 3// 4// DOCTRINE (rule #26 NEVER BRICK): liberation uses ONLY non-destructive paths -- 5// (1) the SOVEREIGN PRINT PATH: we drive the printer via open IPP, NOT the vendor driver/app, so the 6// vendor's software-layer "buy genuine" blocking simply does not apply to us. (PROVEN live: the 7// Brother printed job-id 49 to COMPLETION on 3rd-party toner while showing "Replace Toner".) 8// (2) the printer's OWN documented web setting (/general/replacetoner.html) to flip Continue-mode -- a 9// reversible config toggle via the device's validated settings UI, NOT a firmware/EEPROM write. 10// (3) GUIDANCE for the safe physical/front-panel overrides (Continue mode, reset gear, optical window). 11// We NEVER downgrade firmware, NEVER write raw NVRAM/EEPROM, NEVER touch a crypto chip. (The TN-630/660 on 12// the DCP-L2540DW has NO chip anyway -- the block is optical sensor + reset gear + a software counter.) 13// 14// This organ READS a parsed Get-Printer-Attributes response and CLASSIFIES the situation, emitting a sealed 15// verdict + which safe action applies. It performs no I/O itself (pure) -> never-brick. The actual web POST 16// / print is done by the live runners. Sovereign (imports nx_ipp_codec + the audit organs). 17// genealogy_id: project-printer-management-ipp-sclass-2026-06-20 ; license_tier: ORIGINAL 18 19import "nx_ipp_codec.nx" 20import "nx_printer_health.nx" 21import "nx_printer_waste.nx" 22 23// sealed liberation verdict 24const NX_TL_PRINTS_NOW: i64 = 1 // idle/accepting (maybe toner-warning) -> sovereign IPP prints NOW; vendor block bypassed 25const NX_TL_NEEDS_CONTINUE:i64 = 2 // hard-stopped on toner -> set Continue-mode (web or front panel) then it prints 26const NX_TL_NEEDS_RESET: i64 = 3 // "replace toner" persists on a known-good cart -> reset counter (web/front panel/gear) 27const NX_TL_UNKNOWN: i64 = 4 // can't determine from the response 28const NX_TL_N: i64 = 5 29 30func nx_tl_verdict_is_valid(v: i64) -> i64 { 31 if v <= 0 { return 0 } 32 if v >= NX_TL_N { return 0 } 33 return 1 34} 35 36// Classify. scratch = caller i64[8]. out_toner_flag[0]=1 if any toner/marker reason or supply is low/empty. 37func nx_toner_liberate(body: *u8, n: i64, scratch: *i64, out_toner_flag: *i64) -> i64 { 38 let o_state: *i64 = scratch 39 let o_sev: *i64 = ((scratch as i64) + 8) as *i64 40 let o_cnt: *i64 = ((scratch as i64) + 16) as *i64 41 let o_acc: *i64 = ((scratch as i64) + 24) as *i64 42 let sc3: *i64 = ((scratch as i64) + 32) as *i64 43 let verdict: i64 = nx_printer_diagnose(body, n, sc3, o_state, o_sev, o_cnt, o_acc) 44 45 let w_cnt: *i64 = ((scratch as i64) + 56) as *i64 46 let w_pct: *i64 = ((scratch as i64) + 64) as *i64 47 let w_dup: *i64 = ((scratch as i64) + 72) as *i64 48 let w_sc: *i64 = ((scratch as i64) + 80) as *i64 49 let supv: i64 = nx_printer_waste(body, n, w_sc, w_cnt, w_pct, w_dup) 50 51 // is toner the issue? a marker/toner reason present, or supply low/empty 52 var toner: i64 = 0 53 if nx_ipp_set_contains(body, n, "printer-state-reasons", "toner-low-warning") == 1 { toner = 1 } 54 if nx_ipp_set_contains(body, n, "printer-state-reasons", "toner-low-report") == 1 { toner = 1 } 55 if nx_ipp_set_contains(body, n, "printer-state-reasons", "toner-empty-error") == 1 { toner = 1 } 56 if nx_ipp_set_contains(body, n, "printer-state-reasons", "marker-supply-low-warning") == 1 { toner = 1 } 57 if nx_ipp_set_contains(body, n, "printer-state-reasons", "marker-supply-empty-error") == 1 { toner = 1 } 58 if supv == NX_SUP_LOW { toner = 1 } 59 if supv == NX_SUP_EMPTY { toner = 1 } 60 out_toner_flag[0] = toner 61 62 if verdict == NX_PR_UNKNOWN { return NX_TL_UNKNOWN } 63 // idle/processing + accepting (even if toner-warning/degraded) -> the sovereign path prints NOW 64 if verdict == NX_PR_CAN_PRINT { return NX_TL_PRINTS_NOW } 65 if verdict == NX_PR_DEGRADED { return NX_TL_PRINTS_NOW } 66 // BLOCKED: 67 if o_state[0] == NX_IPP_PSTATE_STOPPED { 68 if toner == 1 { return NX_TL_NEEDS_CONTINUE } // hard-stopped on toner -> Continue-mode override 69 return NX_TL_NEEDS_CONTINUE 70 } 71 // accepting==0 but not stopped, with a toner reason -> a stale "replace toner" -> reset the counter 72 if toner == 1 { return NX_TL_NEEDS_RESET } 73 return NX_TL_UNKNOWN 74}