forked from Hay1tsme/segatools
board/sg-reader.c: Push down aimeio.dll calls
This is kind of a layer break but the alternative is way too much boilerplate to deal with.
This commit is contained in:
parent
458bf5b3de
commit
27663b4b19
@ -1,8 +1,11 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "aimeio/aimeio.h"
|
||||
|
||||
#include "board/sg-led.h"
|
||||
#include "board/sg-nfc.h"
|
||||
#include "board/sg-reader.h"
|
||||
@ -18,19 +21,41 @@ static HRESULT sg_reader_handle_irp_locked(
|
||||
struct sg_reader *reader,
|
||||
struct irp *irp);
|
||||
|
||||
void sg_reader_init(
|
||||
struct sg_reader *reader,
|
||||
unsigned int port_no,
|
||||
const struct sg_nfc_ops *nfc_ops,
|
||||
const struct sg_led_ops *led_ops,
|
||||
void *ops_ctx)
|
||||
{
|
||||
assert(reader != NULL);
|
||||
assert(nfc_ops != NULL);
|
||||
assert(led_ops != NULL);
|
||||
static HRESULT sg_reader_mifare_poll(void *ctx, uint32_t *uid);
|
||||
|
||||
sg_nfc_init(&reader->nfc, 0x00, nfc_ops, ops_ctx);
|
||||
sg_led_init(&reader->led, 0x08, led_ops, ops_ctx);
|
||||
static HRESULT sg_reader_mifare_read_luid(
|
||||
void *ctx,
|
||||
uint32_t uid,
|
||||
uint8_t *luid,
|
||||
size_t luid_size);
|
||||
|
||||
static void sg_reader_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
static const struct sg_nfc_ops sg_reader_nfc_ops = {
|
||||
.mifare_poll = sg_reader_mifare_poll,
|
||||
.mifare_read_luid = sg_reader_mifare_read_luid,
|
||||
};
|
||||
|
||||
static const struct sg_led_ops sg_reader_led_ops = {
|
||||
.set_color = sg_reader_led_set_color,
|
||||
};
|
||||
|
||||
HRESULT sg_reader_init(
|
||||
struct sg_reader *reader,
|
||||
unsigned int port_no)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
assert(reader != NULL);
|
||||
|
||||
hr = aime_io_init();
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
sg_nfc_init(&reader->nfc, 0x00, &sg_reader_nfc_ops, reader);
|
||||
sg_led_init(&reader->led, 0x08, &sg_reader_led_ops, reader);
|
||||
|
||||
InitializeCriticalSection(&reader->lock);
|
||||
|
||||
@ -39,6 +64,16 @@ void sg_reader_init(
|
||||
reader->uart.written.nbytes = sizeof(reader->written_bytes);
|
||||
reader->uart.readable.bytes = reader->readable_bytes;
|
||||
reader->uart.readable.nbytes = sizeof(reader->readable_bytes);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
bool sg_reader_match_irp(const struct sg_reader *reader, const struct irp *irp)
|
||||
{
|
||||
assert(reader != NULL);
|
||||
assert(irp != NULL);
|
||||
|
||||
return uart_match_irp(&reader->uart, irp);
|
||||
}
|
||||
|
||||
HRESULT sg_reader_handle_irp(struct sg_reader *reader, struct irp *irp)
|
||||
@ -48,10 +83,6 @@ HRESULT sg_reader_handle_irp(struct sg_reader *reader, struct irp *irp)
|
||||
assert(reader != NULL);
|
||||
assert(irp != NULL);
|
||||
|
||||
if (!uart_match_irp(&reader->uart, irp)) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
EnterCriticalSection(&reader->lock);
|
||||
hr = sg_reader_handle_irp_locked(reader, irp);
|
||||
LeaveCriticalSection(&reader->lock);
|
||||
@ -101,3 +132,22 @@ static HRESULT sg_reader_handle_irp_locked(
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT sg_reader_mifare_poll(void *ctx, uint32_t *uid)
|
||||
{
|
||||
return aime_io_mifare_poll(0, uid);
|
||||
}
|
||||
|
||||
static HRESULT sg_reader_mifare_read_luid(
|
||||
void *ctx,
|
||||
uint32_t uid,
|
||||
uint8_t *luid,
|
||||
size_t luid_size)
|
||||
{
|
||||
return aime_io_mifare_read_luid(0, uid, luid, luid_size);
|
||||
}
|
||||
|
||||
static void sg_reader_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
aime_io_led_set_color(0, r, g, b);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "board/sg-led.h"
|
||||
@ -18,11 +19,10 @@ struct sg_reader {
|
||||
struct sg_led led;
|
||||
};
|
||||
|
||||
void sg_reader_init(
|
||||
HRESULT sg_reader_init(
|
||||
struct sg_reader *reader,
|
||||
unsigned int port_no,
|
||||
const struct sg_nfc_ops *nfc_ops,
|
||||
const struct sg_led_ops *led_ops,
|
||||
void *ops_ctx);
|
||||
unsigned int port_no);
|
||||
|
||||
bool sg_reader_match_irp(const struct sg_reader *reader, const struct irp *irp);
|
||||
|
||||
HRESULT sg_reader_handle_irp(struct sg_reader *reader, struct irp *irp);
|
||||
|
@ -1,12 +1,7 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "aimeio/aimeio.h"
|
||||
|
||||
#include "board/sg-led.h"
|
||||
#include "board/sg-nfc.h"
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "cardhook/_com12.h"
|
||||
@ -14,22 +9,6 @@
|
||||
#include "hook/iohook.h"
|
||||
|
||||
static HRESULT com12_handle_irp(struct irp *irp);
|
||||
static HRESULT com12_mifare_poll(void *ctx, uint32_t *uid);
|
||||
static HRESULT com12_mifare_read_luid(
|
||||
void *ctx,
|
||||
uint32_t uid,
|
||||
uint8_t *luid,
|
||||
size_t nbytes);
|
||||
static void com12_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
static const struct sg_nfc_ops com12_nfc_ops = {
|
||||
.mifare_poll = com12_mifare_poll,
|
||||
.mifare_read_luid = com12_mifare_read_luid,
|
||||
};
|
||||
|
||||
static const struct sg_led_ops com12_led_ops = {
|
||||
.set_color = com12_led_set_color,
|
||||
};
|
||||
|
||||
static struct sg_reader com12_reader;
|
||||
|
||||
@ -37,14 +16,12 @@ HRESULT com12_hook_init(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
hr = aime_io_init();
|
||||
hr = sg_reader_init(&com12_reader, 12);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
sg_reader_init(&com12_reader, 12, &com12_nfc_ops, &com12_led_ops, NULL);
|
||||
|
||||
return iohook_push_handler(com12_handle_irp);
|
||||
}
|
||||
|
||||
@ -52,24 +29,9 @@ static HRESULT com12_handle_irp(struct irp *irp)
|
||||
{
|
||||
assert(irp != NULL);
|
||||
|
||||
if (!sg_reader_match_irp(&com12_reader, irp)) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
return sg_reader_handle_irp(&com12_reader, irp);
|
||||
}
|
||||
|
||||
static HRESULT com12_mifare_poll(void *ctx, uint32_t *uid)
|
||||
{
|
||||
return aime_io_mifare_poll(0, uid);
|
||||
}
|
||||
|
||||
static HRESULT com12_mifare_read_luid(
|
||||
void *ctx,
|
||||
uint32_t uid,
|
||||
uint8_t *luid,
|
||||
size_t luid_size)
|
||||
{
|
||||
return aime_io_mifare_read_luid(0, uid, luid, luid_size);
|
||||
}
|
||||
|
||||
static void com12_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
aime_io_led_set_color(0, r, g, b);
|
||||
}
|
||||
|
@ -3,33 +3,13 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "aimeio/aimeio.h"
|
||||
|
||||
#include "board/sg-led.h"
|
||||
#include "board/sg-nfc.h"
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "divahook/_com10.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
#include "idzhook/_com10.h"
|
||||
|
||||
static HRESULT com10_handle_irp(struct irp *irp);
|
||||
static HRESULT com10_mifare_poll(void *ctx, uint32_t *uid);
|
||||
static HRESULT com10_mifare_read_luid(
|
||||
void *ctx,
|
||||
uint32_t uid,
|
||||
uint8_t *luid,
|
||||
size_t nbytes);
|
||||
static void com10_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
static const struct sg_nfc_ops com10_nfc_ops = {
|
||||
.mifare_poll = com10_mifare_poll,
|
||||
.mifare_read_luid = com10_mifare_read_luid,
|
||||
};
|
||||
|
||||
static const struct sg_led_ops com10_led_ops = {
|
||||
.set_color = com10_led_set_color,
|
||||
};
|
||||
|
||||
static struct sg_reader com10_reader;
|
||||
|
||||
@ -37,14 +17,12 @@ HRESULT com10_hook_init(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
hr = aime_io_init();
|
||||
hr = sg_reader_init(&com10_reader, 10);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
sg_reader_init(&com10_reader, 10, &com10_nfc_ops, &com10_led_ops, NULL);
|
||||
|
||||
return iohook_push_handler(com10_handle_irp);
|
||||
}
|
||||
|
||||
@ -52,24 +30,9 @@ static HRESULT com10_handle_irp(struct irp *irp)
|
||||
{
|
||||
assert(irp != NULL);
|
||||
|
||||
if (!sg_reader_match_irp(&com10_reader, irp)) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
return sg_reader_handle_irp(&com10_reader, irp);
|
||||
}
|
||||
|
||||
static HRESULT com10_mifare_poll(void *ctx, uint32_t *uid)
|
||||
{
|
||||
return aime_io_mifare_poll(0, uid);
|
||||
}
|
||||
|
||||
static HRESULT com10_mifare_read_luid(
|
||||
void *ctx,
|
||||
uint32_t uid,
|
||||
uint8_t *luid,
|
||||
size_t luid_size)
|
||||
{
|
||||
return aime_io_mifare_read_luid(0, uid, luid, luid_size);
|
||||
}
|
||||
|
||||
static void com10_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
aime_io_led_set_color(0, r, g, b);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user