diff --git a/board/bpreader.c b/board/bpreader.c index c9be995..27945e7 100644 --- a/board/bpreader.c +++ b/board/bpreader.c @@ -51,7 +51,6 @@ static CRITICAL_SECTION bp_lock; static uint8_t bp_written_bytes[520]; static uint8_t bp_readable_bytes[520]; static uint8_t last_cmd = 0; -static uint16_t read_ct = 0; HRESULT bpreader_init(struct bpreader_config *cfg, uint16_t port) { @@ -72,7 +71,7 @@ HRESULT bpreader_init(struct bpreader_config *cfg, uint16_t port) InitializeCriticalSection(&bp_lock); HRESULT hr = aime_card_populate(&card, cfg->access_code_bytes, sizeof(cfg->access_code_bytes)); - //memcpy_s(card.sectors[0].blocks[1].bytes, sizeof(card.sectors[0].blocks[1].bytes), sec1, sizeof(sec1)); + memcpy_s(card.sectors[0].blocks[1].bytes, sizeof(card.sectors[0].blocks[1].bytes), sec1, sizeof(sec1)); if (FAILED(hr)) { return hr; @@ -112,7 +111,7 @@ static HRESULT bp_handle_irp_locked(struct irp *irp) return hr; } -#if 0 +#ifdef READER_DEBUG if (irp->op == IRP_OP_WRITE) { dprintf("WRITE:\n"); dump_iobuf(&bp_uart.written); @@ -120,33 +119,23 @@ static HRESULT bp_handle_irp_locked(struct irp *irp) #endif if (irp->op == IRP_OP_WRITE) { - read_ct = 0; if (bp_uart.written.bytes[0] == 0x55) { dprintf("Reader: Hello\n"); bp_uart.written.pos = 0; // consume the written buffer } else if (bp_uart.written.bytes[3] == 0x00) { bp_uart.written.pos = 0; // consume the written buffer + } else { + hr = crack_bpreader_request(); } return hr; } - - else if (irp->op == IRP_OP_READ) { - if (!read_ct) { - hr = crack_bpreader_request(); - } else { - // We need a delay here in order to properly - // "timeout" the DLL's read request. - Sleep(1); - } - read_ct++; - } if (FAILED(hr)) { dprintf("Reader: HR failed %lX\n", hr); } -#if 0 +#ifdef READER_DEBUG if (irp->op == IRP_OP_READ) { dprintf("READABLE:\n"); dump_iobuf(&bp_uart.readable); @@ -171,43 +160,43 @@ static HRESULT crack_bpreader_request() { switch(header.cmd) { case 0x06: - // dprintf("Reader: Cmd 0x06\n"); return bpreader_unk_06_cmd(); case 0x08: - // dprintf("Reader: Cmd 0x08\n"); return bpreader_unk_08_cmd(); case 0x12: - // dprintf("Reader: Cmd 0x12\n"); +#ifdef READER_DEBUG + dprintf("Reader: Cmd 0x12\n"); +#endif return bpreader_generic_cmd(0x13); case 0x18: - // dprintf("Reader: Initialize\n"); return bpreader_init_cmd(); case 0x0C: - dprintf("Reader: Cmd 0x0C\n"); return bpreader_unk_0c_cmd(); case 0x0E: + // TODO: Reader output +#ifdef READER_DEBUG dprintf("Reader: Set Output\n"); +#endif return bpreader_generic_cmd(0x0F); case 0x32: - // dprintf("Reader: Cmd 0x32\n"); +#ifdef READER_DEBUG + dprintf("Reader: Cmd 0x32\n"); +#endif return bpreader_generic_cmd(0x33); case 0x40: - // dprintf("Reader: Read Mifare\n"); return bpreader_send_mifare_cmd(); case 0x44: - dprintf("Reader: Cmd 0x44\n"); return bpreader_unk_44_cmd(); case 0x4A: - // dprintf("Reader: Poll Card\n"); return bpreader_poll_card_cmd(); case 0xA0: @@ -215,11 +204,9 @@ static HRESULT crack_bpreader_request() { break; case 0x52: - //dprintf("Reader: Cmd 0x52\n"); return bpreader_unk_52_cmd(); case 0x54: - dprintf("Reader: Cmd 0x54\n"); return bpreader_unk_54_cmd(); default: @@ -286,6 +273,7 @@ static HRESULT bpreader_generic_cmd(uint32_t resp_code) static HRESULT bpreader_init_cmd() { + dprintf("Reader: Initialize\n"); //uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x02, 0xFE, 0xD5, 0x19, 0x12, 0x00 }; uint8_t buff[9] = { 0x00 }; struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x02, 0xFE, 0xD5, 0x19 }; @@ -323,7 +311,10 @@ static HRESULT bpreader_set_output_cmd() } static HRESULT bpreader_poll_card_cmd() -{ +{ +#ifdef READER_DEBUG + dprintf("Reader: Poll Card\n"); +#endif struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x03, 0xFD, 0xD5, 0x4B }; struct bpreader_poll_banapass_data data = { 0x00 }; uint8_t buff[32] = { 0x00 }; @@ -363,6 +354,9 @@ static HRESULT bpreader_poll_card_cmd() static HRESULT bpreader_unk_08_cmd() { +#ifdef READER_DEBUG + dprintf("Reader: Cmd 0x08\n"); +#endif struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x03, 0xFD, 0xD5, 0x09 }; uint8_t buff[10] = { 0x00 }; uint8_t bfr_data[1] = { 0x00 }; @@ -382,6 +376,7 @@ static HRESULT bpreader_unk_08_cmd() static HRESULT bpreader_unk_54_cmd() { + dprintf("Reader: Cmd 0x54\n"); struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x03, 0xFD, 0xD5, 0x55 }; uint8_t buff[10] = { 0x00 }; uint8_t bfr_data[1] = { 0x00 }; @@ -401,6 +396,9 @@ static HRESULT bpreader_unk_54_cmd() static HRESULT bpreader_unk_06_cmd() { +#ifdef READER_DEBUG + dprintf("Reader: Cmd 0x06\n"); +#endif //uint8_t hdr[] = { 0x00, 0x00, 0xFF, 0x0a, 0xf6, 0xd5, 0x07 } //uint8_t data[] = { 0xff, 0x3f, 0x0e, 0xf1, 0xff, 0x3f, 0x0e, 0xf1, 0xaa, 0x00 }; struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x0a, 0xF6, 0xD5, 0x07 }; @@ -430,6 +428,7 @@ static HRESULT bpreader_unk_06_cmd() static HRESULT bpreader_unk_0c_cmd() { + dprintf("Reader: Cmd 0x0C\n"); //uint8_t hdr[] = uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x05, 0xFB, 0xD5, 0x0D }; //uint8_t data[] = { 0x00, 0x06, 0x00, 0x18, 0x00 }; struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x0a, 0xF6, 0xD5, 0x0D }; @@ -500,6 +499,9 @@ static HRESULT bpreader_send_mifare_cmd() static HRESULT bpreader_unk_52_cmd() { +#ifdef READER_DEBUG + dprintf("Reader: Cmd 0x52\n"); +#endif struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x04, 0xFC, 0xD5, 0x53 }; uint8_t buff[10] = { 0x00 }; uint8_t bfr_data[2] = { 0x01, 0x00 }; @@ -519,6 +521,7 @@ static HRESULT bpreader_unk_52_cmd() static HRESULT bpreader_unk_44_cmd() { + dprintf("Reader: Cmd 0x44\n"); struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x04, 0xFC, 0xD5, 0x45 }; uint8_t buff[10] = { 0x00 }; uint8_t bfr_data[2] = { 0x01, 0x00 };