1
0
mirror of synced 2024-11-27 23:10:49 +01:00

bpreader: it's ugly but it passes the check for pokken

This commit is contained in:
Kevin Trocolli 2023-03-20 03:33:46 -04:00
parent 7223aa6181
commit cfde84b00b

View File

@ -83,8 +83,7 @@ static HRESULT bp_handle_irp_locked(struct irp *irp)
{
HRESULT hr;
if (irp->op == IRP_OP_OPEN) {
dprintf("BNG Reader: Starting backend\n");
dprintf("Reader: Baudrate %ld\n", bp_uart.baud.BaudRate);
dprintf("Reader: Starting backend\n");
}
hr = uart_handle_irp(&bp_uart, irp);
@ -96,10 +95,6 @@ static HRESULT bp_handle_irp_locked(struct irp *irp)
dprintf("WRITE:\n");
dump_iobuf(&bp_uart.written);
}
if (irp->op == IRP_OP_READ) {
dprintf("READ:\n");
dump_iobuf(&bp_uart.readable);
}
#endif
if (irp->op == IRP_OP_WRITE) {
write_ct = 0;
@ -114,34 +109,70 @@ static HRESULT bp_handle_irp_locked(struct irp *irp)
}
else {
last_cmd = bp_uart.written.bytes[3];
dump_iobuf(&bp_uart.written);
dprintf("Reader: Wrote Cmd %X\n", last_cmd);
return hr;
}
}
if (irp->op == IRP_OP_READ) {
dprintf("Reader: last_cmd %d write_ct %d\n", last_cmd, write_ct);
dprintf("Reader: last_cmd %02X write_ct %d\n", last_cmd, write_ct);
switch (last_cmd) {
case 0x03:
dprintf("Reader: Initalize Reader\n");
uint8_t buff_init[] = { 00, 00, 0xFF, 00, 0xFF, 00, 00, 00, 0xFF, 0x02, 0xFE, 0xD5, 0x19, 0x12, 0x00};
iobuf_write(&bp_uart.readable, buff_init, sizeof(buff_init));
case 0x02:
dprintf("Reader: Unknown 0x02\n");
if (!write_ct) {
uint8_t buff[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x05,
0xfb, 0xd5, 0x0d, 0x00, 0x06, 0x00, 0x18, 0x00 };
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
}
bp_uart.written.pos = 0;
break;
case 0x06:
dprintf("Reader: Unknown 0x06\n");
uint8_t buff_unk6_r1[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00 };
uint8_t buff_unk6_r2[] = { 0xFF, 0x02, 0xFE, 0xD5, 0x33, 0xF8, 0x00 };
case 0x03:
if (!write_ct) {
dprintf("Reader: Unknown 0x06 first write\n");
iobuf_write(&bp_uart.readable, buff_unk6_r1, sizeof(buff_unk6_r1));
}
else {
dprintf("Reader: Unknown 0x06 other write\n");
iobuf_write(&bp_uart.readable, buff_unk6_r2, sizeof(buff_unk6_r2));
dprintf("Reader: Initalize Reader\n");
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x02,
0xFE, 0xD5, 0x19, 0x12, 0x00 };
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
}
bp_uart.written.pos = 0;
break;
case 0x04:
case 0x06:
if (!write_ct && bp_uart.written.bytes[6] == 0x0e && last_cmd == 0x04) {
dprintf("Reader: Unknown second 0x04\n");
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x02,
0xFE, 0xD5, 0x0F, 0x1C, 0x00 };
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
}
else if (!write_ct) {
dprintf("Reader: Unknown 0x06/0x04\n");
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x02,
0xFE, 0xD5, 0x33, 0xF8, 0x00 };
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
}
bp_uart.written.pos = 0;
break;
case 0x05:
if (!write_ct) {
dprintf("Reader: Unknown 0x05\n");
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x03,
0xFD, 0xD5, 0x09, 0x00, 0x22, 0x00 };
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
}
bp_uart.written.pos = 0;
break;
case 0x12:
if (!write_ct) {
dprintf("Reader: Unknown 0x12\n");
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x0a,
0xf6, 0xd5, 0x07, 0xff, 0x3f, 0x0e, 0xf1, 0xff, 0x3f, 0x0e, 0xf1, 0xaa, 0x00 };
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
}
bp_uart.written.pos = 0;
break;
default:
@ -152,6 +183,17 @@ static HRESULT bp_handle_irp_locked(struct irp *irp)
write_ct++;
}
bp_uart.written.pos = 0;
if (FAILED(hr)) {
dprintf("Reader: HR failed %lX", hr);
}
#if 0
if (irp->op == IRP_OP_READ) {
dprintf("READ:\n");
dump_iobuf(&bp_uart.readable);
}
#endif
bp_uart.written.pos = 0; // consume the written buffer
return hr;
}