Skip to content

Commit 82d8c02

Browse files
committed
fix(discovery): correct modern protocol status offset to 0x8A
Status code is at offset 0x8A, not 0x90. The old offset was reading the LAN mode flag byte instead. Also corrects serial number field size from 130 to 128 bytes to match actual packet layout.
1 parent 7497ffd commit 82d8c02

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/api/PrinterDiscovery.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ describe('PrinterDiscovery', () => {
6969
buffer.writeUInt16BE(commandPort, 0x84);
7070
buffer.writeUInt16BE(vendorId, 0x86);
7171
buffer.writeUInt16BE(productId, 0x88);
72-
buffer.writeUInt16BE(productType, 0x8C);
73-
buffer.writeUInt16BE(eventPort, 0x8E);
74-
buffer.writeUInt16BE(statusCode, 0x90);
72+
buffer.writeUInt16BE(statusCode, 0x8a);
73+
buffer.writeUInt16BE(productType, 0x8c);
74+
buffer.writeUInt16BE(eventPort, 0x8e);
7575

7676
// Write serial number (UTF-8, null-terminated)
7777
buffer.write(serialNumber, 0x92, 'utf8');
78-
buffer.fill(0, 0x92 + serialNumber.length, 0x92 + 130);
78+
buffer.fill(0, 0x92 + serialNumber.length, 0x92 + 128);
7979

8080
return buffer;
8181
};

src/api/PrinterDiscovery.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,17 @@ export class PrinterDiscovery {
479479
/**
480480
* Parses modern protocol (276-byte) discovery responses.
481481
*
482-
* Modern protocol structure:
483-
* - Printer name: 0x00, 132 bytes, UTF-8
482+
* Modern protocol structure (276 bytes / 0x114):
483+
* - Printer name: 0x00, 128 bytes, UTF-8 (+ 4 bytes padding at 0x80)
484484
* - Command port: 0x84, uint16 BE
485485
* - Vendor ID: 0x86, uint16 BE
486486
* - Product ID: 0x88, uint16 BE
487+
* - Status code: 0x8A, uint16 BE
487488
* - Product type: 0x8C, uint16 BE
488489
* - Event port: 0x8E, uint16 BE
489-
* - Status code: 0x90, uint16 BE
490-
* - Serial number: 0x92, 130 bytes, UTF-8
490+
* - LAN mode: 0x90, uint8 (0=cloud, 1=LAN-only)
491+
* - Reserved: 0x91, uint8
492+
* - Serial number: 0x92, 128 bytes, UTF-8 (+ 2 bytes padding)
491493
*
492494
* @param buffer The response buffer (276 bytes)
493495
* @param rinfo Remote address information
@@ -509,15 +511,15 @@ export class PrinterDiscovery {
509511
const commandPort = buffer.readUInt16BE(0x84);
510512
const vendorId = buffer.readUInt16BE(0x86);
511513
const productId = buffer.readUInt16BE(0x88);
512-
const productType = buffer.readUInt16BE(0x8C);
513-
const eventPort = buffer.readUInt16BE(0x8E);
514+
const statusCode = buffer.readUInt16BE(0x8a);
515+
const productType = buffer.readUInt16BE(0x8c);
516+
const eventPort = buffer.readUInt16BE(0x8e);
514517

515518
// Extract status
516-
const statusCode = buffer.readUInt16BE(0x90);
517519
const status = this.mapStatusCode(statusCode);
518520

519521
// Extract serial number (UTF-8, null-terminated)
520-
const serialNumber = buffer.toString('utf8', 0x92, 0x92 + 130).replace(/\0.*$/, '');
522+
const serialNumber = buffer.toString('utf8', 0x92, 0x92 + 128).replace(/\0.*$/, '');
521523

522524
// Detect model
523525
const model = this.detectModernModel(name, productType);

0 commit comments

Comments
 (0)