2023-01-03 05:35:53 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
#include "hook/iobuf.h"
|
|
|
|
#include "hook/iohook.h"
|
|
|
|
|
|
|
|
#include "hooklib/uart.h"
|
|
|
|
#include "hooklib/fdshark.h"
|
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
#include "util/dump.h"
|
2023-04-13 08:30:56 +02:00
|
|
|
#include "util/hexstr.h"
|
2023-03-16 06:45:39 +01:00
|
|
|
|
2023-01-03 05:35:53 +01:00
|
|
|
#include "board/bpreader.h"
|
|
|
|
|
2023-03-27 10:03:23 +02:00
|
|
|
const uint8_t BPREADER_CMD_GO_NEXT[6] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00 };
|
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
static HRESULT bp_handle_irp(struct irp *irp);
|
|
|
|
static HRESULT bp_handle_irp_locked(struct irp *irp);
|
2023-03-24 07:46:38 +01:00
|
|
|
static HRESULT crack_bpreader_request();
|
2023-04-13 08:30:56 +02:00
|
|
|
static size_t build_bpreader_response(
|
|
|
|
const uint8_t *data,
|
|
|
|
const size_t len_data,
|
|
|
|
struct bpreader_cmd_header *resp_header,
|
|
|
|
uint8_t *response,
|
|
|
|
const size_t resp_size);
|
|
|
|
|
2023-07-11 05:21:36 +02:00
|
|
|
static HRESULT bpreader_generic_cmd(uint32_t resp_code);
|
|
|
|
static HRESULT bpreader_poll_card_cmd();
|
|
|
|
static HRESULT bpreader_init_cmd();
|
|
|
|
static HRESULT bpreader_set_output_cmd();
|
2023-03-16 06:45:39 +01:00
|
|
|
|
|
|
|
static struct bpreader_config *config;
|
|
|
|
static struct uart bp_uart;
|
|
|
|
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;
|
2023-03-24 07:46:38 +01:00
|
|
|
static uint16_t read_ct = 0;
|
2023-03-16 06:45:39 +01:00
|
|
|
|
|
|
|
HRESULT bpreader_init(struct bpreader_config *cfg, uint16_t port)
|
|
|
|
{
|
|
|
|
config = cfg;
|
|
|
|
if (!config->enable) {
|
|
|
|
return S_OK;
|
|
|
|
}
|
2023-07-11 05:21:36 +02:00
|
|
|
if (cfg->port > 0) {
|
2023-03-16 06:45:39 +01:00
|
|
|
port = cfg->port;
|
|
|
|
}
|
|
|
|
|
|
|
|
uart_init(&bp_uart, port);
|
|
|
|
bp_uart.written.bytes = bp_written_bytes;
|
|
|
|
bp_uart.written.nbytes = sizeof(bp_written_bytes);
|
|
|
|
bp_uart.readable.bytes = bp_readable_bytes;
|
|
|
|
bp_uart.readable.nbytes = sizeof(bp_readable_bytes);
|
|
|
|
InitializeCriticalSection(&bp_lock);
|
|
|
|
|
|
|
|
dprintf("Reader: Init\n");
|
|
|
|
return iohook_push_handler(bp_handle_irp);
|
|
|
|
}
|
2023-01-03 05:35:53 +01:00
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
static HRESULT bp_handle_irp(struct irp *irp)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
assert(irp != NULL);
|
|
|
|
|
|
|
|
if (uart_match_irp(&bp_uart, irp)) {
|
|
|
|
EnterCriticalSection(&bp_lock);
|
|
|
|
hr = bp_handle_irp_locked(irp);
|
|
|
|
LeaveCriticalSection(&bp_lock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return iohook_invoke_next(irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2023-01-03 05:35:53 +01:00
|
|
|
}
|
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
static HRESULT bp_handle_irp_locked(struct irp *irp)
|
2023-01-03 05:35:53 +01:00
|
|
|
{
|
2023-03-16 06:45:39 +01:00
|
|
|
HRESULT hr;
|
|
|
|
if (irp->op == IRP_OP_OPEN) {
|
2023-03-20 08:33:46 +01:00
|
|
|
dprintf("Reader: Starting backend\n");
|
2023-03-16 06:45:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hr = uart_handle_irp(&bp_uart, irp);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
2023-03-24 07:46:38 +01:00
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
#if 0
|
|
|
|
if (irp->op == IRP_OP_WRITE) {
|
|
|
|
dprintf("WRITE:\n");
|
|
|
|
dump_iobuf(&bp_uart.written);
|
|
|
|
}
|
|
|
|
#endif
|
2023-03-24 07:46:38 +01:00
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
if (irp->op == IRP_OP_WRITE) {
|
2023-03-24 07:46:38 +01:00
|
|
|
read_ct = 0;
|
2023-03-16 06:45:39 +01:00
|
|
|
if (bp_uart.written.bytes[0] == 0x55) {
|
|
|
|
dprintf("Reader: Hello\n");
|
2023-03-24 07:46:38 +01:00
|
|
|
bp_uart.written.pos = 0; // consume the written buffer
|
2023-03-16 06:45:39 +01:00
|
|
|
}
|
|
|
|
else if (bp_uart.written.bytes[3] == 0x00) {
|
2023-03-24 07:46:38 +01:00
|
|
|
bp_uart.written.pos = 0; // consume the written buffer
|
2023-03-16 06:45:39 +01:00
|
|
|
}
|
2023-03-24 07:46:38 +01:00
|
|
|
return hr;
|
2023-03-16 06:45:39 +01:00
|
|
|
}
|
2023-03-20 08:33:46 +01:00
|
|
|
|
2023-03-24 07:46:38 +01:00
|
|
|
else if (irp->op == IRP_OP_READ) {
|
|
|
|
if (!read_ct) {
|
2023-04-13 08:30:56 +02:00
|
|
|
//dump_iobuf(&bp_uart.written);
|
2023-03-24 07:46:38 +01:00
|
|
|
hr = crack_bpreader_request();
|
2023-07-11 05:21:36 +02:00
|
|
|
if (!FAILED(hr)) {
|
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
return hr;
|
|
|
|
}
|
2023-03-24 07:46:38 +01:00
|
|
|
}
|
|
|
|
switch (bp_uart.written.bytes[3]) {
|
2023-03-20 08:33:46 +01:00
|
|
|
case 0x02:
|
2023-03-24 07:46:38 +01:00
|
|
|
if (!read_ct) {
|
|
|
|
dprintf("Reader: Unknown 0x02\n");
|
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x05,
|
|
|
|
0xFB, 0xD5, 0x0D, 0x00, 0x06, 0x00, 0x18, 0x00 };
|
2023-03-20 08:33:46 +01:00
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
|
|
|
}
|
|
|
|
|
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
break;
|
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
case 0x03:
|
2023-03-24 07:46:38 +01:00
|
|
|
if (!read_ct) {
|
|
|
|
dprintf("Reader: Unknown 0x03\n");
|
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x02,
|
2023-03-20 08:33:46 +01:00
|
|
|
0xFE, 0xD5, 0x19, 0x12, 0x00 };
|
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
|
|
|
}
|
2023-03-16 06:45:39 +01:00
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
break;
|
|
|
|
|
2023-03-20 08:33:46 +01:00
|
|
|
case 0x04:
|
2023-03-24 07:46:38 +01:00
|
|
|
if (!read_ct && bp_uart.written.bytes[6] == 0x0E && last_cmd == 0x04) {
|
2023-03-20 08:33:46 +01:00
|
|
|
dprintf("Reader: Unknown second 0x04\n");
|
2023-03-24 07:46:38 +01:00
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x02,
|
2023-03-20 08:33:46 +01:00
|
|
|
0xFE, 0xD5, 0x0F, 0x1C, 0x00 };
|
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
2023-03-19 06:15:40 +01:00
|
|
|
}
|
2023-03-24 07:46:38 +01:00
|
|
|
else if (!read_ct) {
|
|
|
|
dprintf("Reader: Unknown 0x04\n");
|
|
|
|
uint8_t buff[] = { 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 0x06:
|
|
|
|
if (!read_ct) {
|
|
|
|
dprintf("Reader: Unknown 0x06\n");
|
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x02,
|
2023-03-20 08:33:46 +01:00
|
|
|
0xFE, 0xD5, 0x33, 0xF8, 0x00 };
|
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
2023-03-19 06:15:40 +01:00
|
|
|
}
|
2023-03-20 08:33:46 +01:00
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x05:
|
2023-03-24 07:46:38 +01:00
|
|
|
if (!read_ct) {
|
2023-03-20 08:33:46 +01:00
|
|
|
dprintf("Reader: Unknown 0x05\n");
|
2023-03-24 07:46:38 +01:00
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x03,
|
2023-03-20 08:33:46 +01:00
|
|
|
0xFD, 0xD5, 0x09, 0x00, 0x22, 0x00 };
|
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
|
|
|
}
|
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
break;
|
2023-03-24 07:46:38 +01:00
|
|
|
|
|
|
|
case 0x0E:
|
|
|
|
if (!read_ct) {
|
|
|
|
dprintf("Reader: Unknown 0x0E\n");
|
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xff, 0x02,
|
|
|
|
0xfe, 0xd5, 0x33, 0xf8, 0x00 };
|
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
|
|
|
}
|
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
break;
|
2023-03-20 08:33:46 +01:00
|
|
|
|
|
|
|
case 0x12:
|
2023-03-24 07:46:38 +01:00
|
|
|
if (!read_ct) {
|
2023-03-20 08:33:46 +01:00
|
|
|
dprintf("Reader: Unknown 0x12\n");
|
2023-03-24 07:46:38 +01:00
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x0a,
|
2023-03-20 08:33:46 +01:00
|
|
|
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;
|
2023-03-16 06:45:39 +01:00
|
|
|
break;
|
2023-03-24 07:46:38 +01:00
|
|
|
|
|
|
|
case 0x14:
|
|
|
|
if (!read_ct) {
|
|
|
|
dprintf("Reader: Unknown 0x14\n");
|
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x20, 0xE0, 0xD5, 0xA1,
|
|
|
|
0x00, 0x1D, 0x07, // Unknown
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // IDm
|
|
|
|
0x00, 0x00, 0x01, // Unknown
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // IDm
|
|
|
|
0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Unknown
|
|
|
|
0x00, 0x00 };
|
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
|
|
|
}
|
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x18:
|
|
|
|
if (!read_ct) {
|
|
|
|
dprintf("Reader: Unknown 0x18\n");
|
|
|
|
uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x0D,
|
|
|
|
0xF3, 0xD5, 0x07, 0xDC, 0xF4, 0x3F, 0x11, 0x4D, 0x85, 0x61, 0xF1, 0x26,
|
|
|
|
0x6A, 0x87, 0xC9, 0x00 };
|
|
|
|
hr = iobuf_write(&bp_uart.readable, buff, sizeof(buff));
|
|
|
|
}
|
|
|
|
bp_uart.written.pos = 0;
|
|
|
|
break;
|
2023-01-03 05:35:53 +01:00
|
|
|
|
2023-03-16 06:45:39 +01:00
|
|
|
default:
|
|
|
|
dprintf("Reader: Unknown Command %02X\n", last_cmd);
|
|
|
|
dump_iobuf(&bp_uart.written);
|
|
|
|
break;
|
|
|
|
}
|
2023-03-24 07:46:38 +01:00
|
|
|
read_ct++;
|
2023-03-16 06:45:39 +01:00
|
|
|
}
|
2023-03-20 08:33:46 +01:00
|
|
|
|
|
|
|
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
|
2023-03-16 06:45:39 +01:00
|
|
|
|
2023-03-20 08:33:46 +01:00
|
|
|
bp_uart.written.pos = 0; // consume the written buffer
|
2023-03-16 06:45:39 +01:00
|
|
|
return hr;
|
2023-03-24 07:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT crack_bpreader_request() {
|
|
|
|
struct bpreader_cmd_header header = { bp_uart.written.bytes[0], bp_uart.written.bytes[1], bp_uart.written.bytes[2],
|
|
|
|
bp_uart.written.bytes[3], bp_uart.written.bytes[4], bp_uart.written.bytes[5], bp_uart.written.bytes[6],
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(header.padding0_00 == 0);
|
|
|
|
assert(header.padding1_00 == 0);
|
|
|
|
assert(header.padding2_ff == 0xFF);
|
|
|
|
assert(header.d_identifier == 0xD4);
|
|
|
|
|
|
|
|
switch(header.cmd) {
|
|
|
|
case 0x06:
|
|
|
|
dprintf("Reader: Cmd 0x06\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08:
|
|
|
|
dprintf("Reader: Cmd 0x08\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x12:
|
|
|
|
dprintf("Reader: Cmd 0x12\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x18:
|
|
|
|
dprintf("Reader: Initialize\n");
|
2023-07-11 05:21:36 +02:00
|
|
|
// return bpreader_init_cmd(); FIXME
|
2023-03-24 07:46:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0C:
|
|
|
|
dprintf("Reader: Cmd 0x0C\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0E:
|
|
|
|
dprintf("Reader: Set Output\n");
|
2023-07-11 05:21:36 +02:00
|
|
|
return bpreader_generic_cmd(0x0F);
|
2023-03-24 07:46:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x32:
|
|
|
|
dprintf("Reader: Cmd 0x32\n");
|
2023-07-11 05:21:36 +02:00
|
|
|
//return bpreader_generic_cmd(0x33);
|
2023-03-24 07:46:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x40:
|
2023-04-13 08:30:56 +02:00
|
|
|
dprintf("Reader: Read Banapass\n"); // 01 30 00 -> Chip ID; 01 30 01 -> Thing after chip ID; 01 30 02 -> Access Code 01 60 30 -> send key a
|
2023-03-24 07:46:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4A:
|
2023-04-13 08:30:56 +02:00
|
|
|
dprintf("Reader: Poll Card\n");
|
2023-07-11 05:21:36 +02:00
|
|
|
return bpreader_poll_card_cmd();
|
2023-03-24 07:46:38 +01:00
|
|
|
|
|
|
|
case 0xA0:
|
|
|
|
dprintf("Reader: Read Felica\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dprintf("Reader: Unknown command 0x%02x\n", header.cmd);
|
|
|
|
}
|
|
|
|
|
2023-07-11 05:21:36 +02:00
|
|
|
return (HRESULT)-1;
|
2023-03-27 10:03:23 +02:00
|
|
|
}
|
|
|
|
|
2023-04-13 08:30:56 +02:00
|
|
|
static size_t build_bpreader_response(
|
|
|
|
const uint8_t *data,
|
|
|
|
const size_t len_data,
|
|
|
|
struct bpreader_cmd_header *resp_header,
|
|
|
|
uint8_t *response,
|
|
|
|
const size_t resp_size)
|
|
|
|
{
|
|
|
|
// TODO: Account for escape characters
|
|
|
|
if (resp_size < 9) {
|
|
|
|
dprintf("Reader: build_bpreader_response resp_size less then 9\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t full_resp_len = len_data + 2 + 7; // calculate full response length
|
|
|
|
uint8_t final_checksum = 0; // initialize checksum
|
|
|
|
|
|
|
|
resp_header->data_len = len_data + 2;
|
|
|
|
resp_header->header_checksum = 0xFF - ((0xFF + len_data + 2) & 0xFF);
|
|
|
|
|
|
|
|
memcpy_s(response, resp_size, resp_header, sizeof(*resp_header)); // Copy header
|
2023-07-11 05:21:36 +02:00
|
|
|
if (len_data > 0) {
|
|
|
|
memcpy_s(&response[7], resp_size - 7, data, len_data); // copy data if there's any
|
|
|
|
}
|
2023-04-13 08:30:56 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < full_resp_len; i++) {
|
|
|
|
final_checksum = (final_checksum + response[i]) & 0xFF; // Calculate checksum
|
|
|
|
}
|
|
|
|
|
|
|
|
response[full_resp_len - 2] = 0xFF - final_checksum; // Assign checksum
|
|
|
|
return full_resp_len;
|
|
|
|
}
|
|
|
|
|
2023-07-11 05:21:36 +02:00
|
|
|
static HRESULT bpreader_generic_cmd(uint32_t resp_code)
|
|
|
|
{
|
|
|
|
//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, resp_code };
|
|
|
|
size_t resp_len = 0;
|
|
|
|
|
|
|
|
resp_len = build_bpreader_response((uint8_t *){0}, 0, &header, buff, sizeof(buff));
|
|
|
|
|
|
|
|
if (resp_len > 0) {
|
|
|
|
HRESULT hr = iobuf_write(&bp_uart.readable, buff, resp_len);
|
|
|
|
//dump_iobuf(&bp_uart.readable);
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
dprintf("Reader: No data to return in bpreader_generic_cmd (0x%2X response code)!\n", resp_code);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT bpreader_init_cmd()
|
|
|
|
{
|
|
|
|
//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 };
|
|
|
|
size_t resp_len = 0;
|
|
|
|
|
|
|
|
resp_len = build_bpreader_response((uint8_t *){0}, 0, &header, buff, sizeof(buff));
|
|
|
|
|
|
|
|
if (resp_len > 0) {
|
|
|
|
HRESULT hr = iobuf_write(&bp_uart.readable, buff, resp_len);
|
|
|
|
dump_iobuf(&bp_uart.readable);
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
dprintf("Reader: No data to return in bpreader_init_cmd!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT bpreader_set_output_cmd()
|
|
|
|
{
|
|
|
|
//uint8_t buff[] = { 0x00, 0x00, 0xFF, 0x02, 0xFE, 0xD5, 0x0F, 0x1C, 0x00 };
|
|
|
|
uint8_t buff[9] = { 0x00 };
|
|
|
|
struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x02, 0xFE, 0xD5, 0x0F };
|
|
|
|
size_t resp_len = 0;
|
|
|
|
|
|
|
|
resp_len = build_bpreader_response((uint8_t *){0}, 0, &header, buff, sizeof(buff));
|
|
|
|
|
|
|
|
if (resp_len > 0) {
|
|
|
|
HRESULT hr = iobuf_write(&bp_uart.readable, buff, resp_len);
|
|
|
|
dump_iobuf(&bp_uart.readable);
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
dprintf("Reader: No data to return in bpreader_set_output_cmd!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT bpreader_poll_card_cmd()
|
2023-04-13 08:30:56 +02:00
|
|
|
{
|
|
|
|
struct bpreader_cmd_header header = { 0x00, 0x00, 0xFF, 0x03, 0xFD, 0xD5, 0x4B };
|
|
|
|
struct bpreader_poll_banapass_data data = { 0x00 };
|
|
|
|
uint8_t buff[32] = { 0x00 };
|
|
|
|
int data_len = 1;
|
|
|
|
size_t resp_len = 0;
|
|
|
|
|
|
|
|
if (GetAsyncKeyState(VK_RETURN) & 0x8000) {
|
|
|
|
dprintf("Reader: Touch card %ls\n", config->access_code);
|
|
|
|
|
|
|
|
data.card_present = 0x01;
|
|
|
|
data.unknown1 = 0x01;
|
|
|
|
data.atqa[0] = 0x00;
|
|
|
|
data.atqa[1] = 0x04;
|
|
|
|
data.sak = 0x08;
|
|
|
|
data.unknown5 = 0x04;
|
|
|
|
memcpy_s(data.serial_number, sizeof(data.serial_number), config->chip_id_bytes, 4);
|
|
|
|
data_len = sizeof(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
resp_len = build_bpreader_response((uint8_t *)&data, data_len, &header, buff, sizeof(buff));
|
|
|
|
|
|
|
|
if (resp_len > 0) {
|
|
|
|
HRESULT hr = iobuf_write(&bp_uart.readable, buff, resp_len);
|
|
|
|
dump_iobuf(&bp_uart.readable);
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
} else {
|
2023-07-11 05:21:36 +02:00
|
|
|
dprintf("Reader: No data to return in bpreader_poll_card_cmd!\n");
|
2023-04-13 08:30:56 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2023-01-03 05:35:53 +01:00
|
|
|
}
|