diff --git a/board/config.c b/board/config.c index 3e0156b..32d6a73 100644 --- a/board/config.c +++ b/board/config.c @@ -14,3 +14,15 @@ void io4_config_load(struct io4_config *cfg, const wchar_t *filename) cfg->enable = GetPrivateProfileIntW(L"io4", L"enable", 1, filename); } + +void k92x0249_config_load(struct k92x0249_config *cfg, const wchar_t *filename) +{ + assert(cfg != NULL); + assert(filename != NULL); + wchar_t wserial[17]; + + cfg->read_button = GetPrivateProfileIntW(L"reader", L"read_button", VK_RETURN, filename); + GetPrivateProfileStringW(L"reader", L"card_serial", L"7020392000000000", wserial, _countof(wserial), filename); + + wcstombs_s(NULL, cfg->serial, sizeof(cfg->serial), wserial, sizeof(cfg->serial) - 1); +} diff --git a/board/config.h b/board/config.h index 9a4f07f..8ba43a8 100644 --- a/board/config.h +++ b/board/config.h @@ -4,5 +4,7 @@ #include #include "board/io4.h" +#include "board/k92x0249.h" void io4_config_load(struct io4_config *cfg, const wchar_t *filename); +void k92x0249_config_load(struct k92x0249_config *cfg, const wchar_t *filename); diff --git a/board/k92x0249.c b/board/k92x0249.c index 6da4f7a..5ee8e27 100644 --- a/board/k92x0249.c +++ b/board/k92x0249.c @@ -7,6 +7,7 @@ #include #include "board/k92x0249.h" +#include "board/config.h" #include "jvs/jvs-bus.h" #include "jvs/jvs-cmd.h" @@ -17,7 +18,9 @@ // JVS card reader, A/B/C vairants -static const uint8_t k92x0249_ident[] = "TAITO CORP.;RFID CTRL P.C.B.;Ver1.11;"; // non-AICC: TAITO CORP.;JVS Reader;Ver1.00; +static const uint8_t k92x0249_ident[] = "TAITO CORP.;RFID CTRL P.C.B.;Ver1.00;"; +static const uint8_t card_uid[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00 }; +static struct k92x0249_config cfg; static uint8_t k92x0249_features[] = { // Misc. SW @@ -57,17 +60,16 @@ static HRESULT k92x0249_cmd_get_jvs_version(struct k92x0249 *k92x0249, struct co static HRESULT k92x0249_cmd_get_comm_version(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf); static HRESULT k92x0249_cmd_get_features(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf); static HRESULT k92x0249_cmd_write_gpio1(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf); -static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf); -static HRESULT k92x0249_cmd_nesica_read(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf); +static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf); void k92x0249_init( struct k92x0249 *k92x0249, struct jvs_node *next, - const struct k92x0249_ops *ops, void *ops_ctx) { assert(k92x0249 != NULL); - assert(ops != NULL); + + k92x0249_config_load(&cfg, L".\\taitools.ini"); k92x0249->jvs.next = next; k92x0249->jvs.transact = k92x0249_transact; @@ -75,7 +77,6 @@ void k92x0249_init( k92x0249->jvs.sense_out = true; k92x0249->addr = 0xFF; k92x0249->state = IDLE; - k92x0249->ops = ops; k92x0249->ops_ctx = ops_ctx; } @@ -120,9 +121,6 @@ static HRESULT k92x0249_cmd( struct iobuf *resp) { struct k92x0249 *k92x0249; - uint8_t req_len; - - iobuf_read_8(req, &req_len); // Read the length for variable-length commands k92x0249 = (struct k92x0249 *)ctx; @@ -152,15 +150,14 @@ static HRESULT k92x0249_cmd( return k92x0249_cmd_write_gpio1(k92x0249, req, resp); case JVS_CMD_READ_MISC_SWITCHES: // used to check reader state? - return k92x0249_cmd_read_misc_switches(k92x0249, req, req_len, resp); - - case JVS_CMD_TAITO_NESICA_READ: - return k92x0249_cmd_nesica_read(k92x0249, req, req_len, resp); + return k92x0249_cmd_read_misc_switches(k92x0249, req, resp); default: - dprintf("K92X0249: Node %02x: Unhandled command byte %02x\n", + dprintf("K92X0249: Node %02x: Unhandled command byte @ %02X %02x\n", k92x0249->addr, + req->pos, req->bytes[req->pos]); + dump_const_iobuf(req); return E_NOTIMPL; } @@ -181,11 +178,7 @@ static HRESULT k92x0249_cmd_reset(struct k92x0249 *k92x0249, struct const_iobuf dprintf("K92X0249: Reset (param %02x)\n", req.unknown); k92x0249->addr = 0xFF; - k92x0249->jvs.sense_out = false; // ? - - if (k92x0249->ops->reset != NULL) { - k92x0249->ops->reset(k92x0249->ops_ctx); - } + k92x0249->jvs.sense_out = false; /* No ack for this since it really is addressed to everybody */ @@ -330,31 +323,66 @@ static HRESULT k92x0249_cmd_get_features(struct k92x0249 *k92x0249, struct const static HRESULT k92x0249_cmd_write_gpio1(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf) { - uint8_t state; - HRESULT hr = iobuf_read_8(req_buf, &state); // set reader state + uint8_t unk; + uint8_t num_io; + uint8_t io_state[255]; + HRESULT hr = iobuf_read_8(req_buf, &unk); + if (FAILED(hr)) { + return hr; + } + + hr = iobuf_read_8(req_buf, &num_io); if (FAILED(hr)) { return hr; } - k92x0249->state = state; + hr = iobuf_read(req_buf, io_state, num_io); - dprintf("K92X0249: Set state %02X", state); - return iobuf_write_8(resp_buf, 0x01); /* Write report byte */ + if (FAILED(hr)) { + return hr; + } + + if (k92x0249->state != io_state[0]) { + dprintf("K92X0249: Update state %02X\n", io_state[0]); + } + + k92x0249->state = io_state[0]; + hr = iobuf_write_8(resp_buf, 0x01); /* Write report byte */ + + if (FAILED(hr)) { + return hr; + } + + hr = iobuf_write(resp_buf, card_uid, 8); + + if (FAILED(hr)) { + return hr; + } + + return iobuf_write(resp_buf, cfg.serial, 16); } -static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf) +static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf) { - uint8_t req[255]; + uint8_t cmd; + uint8_t num_switches; + uint8_t switches[255]; HRESULT hr; - -#if 0 - dprintf("K92X0249: Read misc switches\n"); - dump_const_iobuf(req_buf); -#endif - // data bytes: 01 61 32 01 80 - hr = iobuf_read(req_buf, &req, req_len - 1); // duno what these bytes mean... + hr = iobuf_read_8(req_buf, &cmd); + + if (FAILED(hr)) { + return hr; + } + + hr = iobuf_read_8(req_buf, &num_switches); + + if (FAILED(hr)) { + return hr; + } + + hr = iobuf_read(req_buf, switches, num_switches); if (FAILED(hr)) { return hr; @@ -366,14 +394,10 @@ static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct return hr; } - if (k92x0249->state == POLL_NESICA && (GetAsyncKeyState(VK_RETURN) & 0x8000)) { + if (k92x0249->state == POLL_AICC && (GetAsyncKeyState(cfg.read_button) & 0x8000)) { + dprintf("K92X0249: Detect Card\n"); return iobuf_write_8(resp_buf, BLUE_NESICA | CARD_TOUCHED | SUCCESS); } return iobuf_write_8(resp_buf, NO_CARD); /* Write status byte */ } - -static HRESULT k92x0249_cmd_nesica_read(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf) -{ - return iobuf_write_8(resp_buf, 0x01); /* Write status byte */ -} diff --git a/board/k92x0249.h b/board/k92x0249.h index d8aaf4d..d036d5c 100644 --- a/board/k92x0249.h +++ b/board/k92x0249.h @@ -4,20 +4,18 @@ #include "jvs/jvs-bus.h" #pragma pack(push,1) -struct k92x0249_ops { - void (*reset)(void *ctx); - void (*write_led)(void *ctx, uint32_t state); - void (*poll_card)(void *ctx, char *serial); -}; - struct k92x0249 { struct jvs_node jvs; uint8_t state; uint8_t addr; - const struct k92x0249_ops *ops; void *ops_ctx; }; +struct k92x0249_config { + uint8_t read_button; + char serial[17]; +}; + #pragma pack(pop) enum k92x0249_state { @@ -42,7 +40,6 @@ enum k92x0249_card_status { void k92x0249_init( struct k92x0249 *k92x0249, struct jvs_node *next, - const struct k92x0249_ops *ops, void *ops_ctx); struct jvs_node *k92x0249_to_jvs_node(struct k92x0249 *k92x0249); diff --git a/dist/siva/taitools.ini b/dist/siva/taitools.ini index c39d9bb..f972edc 100644 --- a/dist/siva/taitools.ini +++ b/dist/siva/taitools.ini @@ -4,11 +4,11 @@ d_drive=d_drive [netenv] enable=1 -[gfx] -enable=0 - [dns] default=localhost [cert] path=client.p12 + +[reader] +card_serial=7020392000000000 diff --git a/jvs/jvs-util.c b/jvs/jvs-util.c index f99c3c4..cf6705e 100644 --- a/jvs/jvs-util.c +++ b/jvs/jvs-util.c @@ -59,8 +59,7 @@ void jvs_crack_request( iobuf_flip(&segments, &decode); - //segments.pos = 2; - segments.pos = 1; // We want to pass the length to the dispatch as well + segments.pos = 2; encode.bytes = resp_bytes; encode.nbytes = sizeof(resp_bytes); @@ -73,11 +72,6 @@ void jvs_crack_request( while (segments.pos + 1 < segments.nbytes) { hr = dispatch_fn(dispatch_ctx, &segments, &encode); - if (segments.nbytes != segments.pos + 1) { - dprintf("JVS: Unconsumed buffer!\n"); - dump_const_iobuf(&segments); - } - if (FAILED(hr)) { break; } diff --git a/sivahook/config.c b/sivahook/config.c index c0de305..a5c6535 100644 --- a/sivahook/config.c +++ b/sivahook/config.c @@ -32,5 +32,4 @@ void siva_hook_config_load( idmac_config_load(&cfg->idmac, filename); platform_config_load(&cfg->platform, filename); siva_dll_config_load(&cfg->dll, filename); - gfx_config_load(&cfg->gfx, filename); } \ No newline at end of file diff --git a/sivahook/config.h b/sivahook/config.h index 93f890e..3731a64 100644 --- a/sivahook/config.h +++ b/sivahook/config.h @@ -6,14 +6,12 @@ #include "idmac/config.h" #include "platform/config.h" -#include "gfxhook/config.h" #include "board/config.h" struct siva_hook_config { struct idmac_config idmac; struct platform_config platform; struct siva_dll_config dll; - struct gfx_config gfx; }; void siva_hook_config_load( diff --git a/sivahook/dllmain.c b/sivahook/dllmain.c index bd8abb8..5e134e0 100644 --- a/sivahook/dllmain.c +++ b/sivahook/dllmain.c @@ -7,16 +7,10 @@ #include "hook/process.h" #include "hooklib/serial.h" -#include "hooklib/spike.h" #include "hooklib/cursor.h" #include "idmac/idmac.h" -#include "gfxhook/gfx.h" -#include "gfxhook/d3d9.h" -#include "gfxhook/d3d11.h" -#include "gfxhook/dxgi.h" - #include "sivahook/fastio.h" #include "sivahook/reader.h" #include "sivahook/config.h" @@ -46,11 +40,6 @@ static DWORD CALLBACK siva_pre_startup(void) /* Hook Win32 APIs */ serial_hook_init(); - gfx_hook_init(&siva_hook_cfg.gfx); - gfx_d3d9_hook_init(&siva_hook_cfg.gfx, siva_hook_mod); - gfx_d3d11_hook_init(&siva_hook_cfg.gfx, siva_hook_mod); - gfx_dxgi_hook_init(&siva_hook_cfg.gfx, siva_hook_mod); - /* Initialize emulation hooks */ hr = platform_hook_init( @@ -86,8 +75,6 @@ static DWORD CALLBACK siva_pre_startup(void) cursor_hook_init(); /* Initialize debug helpers */ - spike_hook_init(L".\\taitools.ini"); - dprintf("--- End siva_pre_startup ---\n"); /* Jump to EXE start address */ diff --git a/sivahook/reader.c b/sivahook/reader.c index 75e1dce..21d57b8 100644 --- a/sivahook/reader.c +++ b/sivahook/reader.c @@ -10,14 +10,6 @@ #include "util/dprintf.h" -static void reader_jvs_write_led(void *ctx, uint32_t state); -static void reader_jvs_poll_card(void *ctx, char *serial); - -static const struct k92x0249_ops siva_jvs_reader_ops = { - .write_led = reader_jvs_write_led, - .poll_card = reader_jvs_poll_card, -}; - static struct k92x0249 siva_jvs_reader; HRESULT siva_reader_init(struct jvs_node **out) @@ -28,18 +20,8 @@ HRESULT siva_reader_init(struct jvs_node **out) dprintf("Siva Nesica Reader: Init\n"); - k92x0249_init(&siva_jvs_reader, NULL, &siva_jvs_reader_ops, NULL); + k92x0249_init(&siva_jvs_reader, NULL, NULL); *out = k92x0249_to_jvs_node(&siva_jvs_reader); return S_OK; } - -static void reader_jvs_write_led(void *ctx, uint32_t state) -{ - -} - -static void reader_jvs_poll_card(void *ctx, char *serial) -{ - -}