2018-11-21 02:29:40 +01:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
2019-02-26 03:56:45 +01:00
|
|
|
|
|
|
|
#include "aimeio/aimeio.h"
|
2018-11-21 02:29:40 +01:00
|
|
|
|
|
|
|
#include "board/sg-led.h"
|
|
|
|
#include "board/sg-nfc.h"
|
2019-02-26 19:48:52 +01:00
|
|
|
#include "board/sg-reader.h"
|
2018-11-21 02:29:40 +01:00
|
|
|
|
|
|
|
#include "cardhook/_com12.h"
|
|
|
|
|
|
|
|
#include "hook/iohook.h"
|
|
|
|
|
|
|
|
static HRESULT com12_handle_irp(struct irp *irp);
|
2018-12-17 23:09:56 +01:00
|
|
|
static HRESULT com12_mifare_poll(void *ctx, uint32_t *uid);
|
2019-02-25 23:23:04 +01:00
|
|
|
static HRESULT com12_mifare_read_luid(
|
|
|
|
void *ctx,
|
|
|
|
uint32_t uid,
|
|
|
|
uint8_t *luid,
|
|
|
|
size_t nbytes);
|
2019-02-26 03:55:49 +01:00
|
|
|
static void com12_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b);
|
2018-11-21 02:29:40 +01:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2019-02-26 19:48:52 +01:00
|
|
|
static struct sg_reader com12_reader;
|
2018-11-21 02:29:40 +01:00
|
|
|
|
2019-02-26 03:56:45 +01:00
|
|
|
HRESULT com12_hook_init(void)
|
2018-11-21 02:29:40 +01:00
|
|
|
{
|
2019-02-26 03:56:45 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = aime_io_init();
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-02-26 19:48:52 +01:00
|
|
|
sg_reader_init(&com12_reader, 12, &com12_nfc_ops, &com12_led_ops, NULL);
|
2018-11-21 02:29:40 +01:00
|
|
|
|
2019-02-26 03:56:45 +01:00
|
|
|
return iohook_push_handler(com12_handle_irp);
|
2018-11-21 02:29:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT com12_handle_irp(struct irp *irp)
|
|
|
|
{
|
|
|
|
assert(irp != NULL);
|
|
|
|
|
2019-02-26 19:48:52 +01:00
|
|
|
return sg_reader_handle_irp(&com12_reader, irp);
|
2018-11-21 02:29:40 +01:00
|
|
|
}
|
|
|
|
|
2018-12-17 23:09:56 +01:00
|
|
|
static HRESULT com12_mifare_poll(void *ctx, uint32_t *uid)
|
2018-11-21 02:29:40 +01:00
|
|
|
{
|
2019-02-26 03:56:45 +01:00
|
|
|
return aime_io_mifare_poll(0, uid);
|
2018-11-21 02:29:40 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 23:23:04 +01:00
|
|
|
static HRESULT com12_mifare_read_luid(
|
|
|
|
void *ctx,
|
|
|
|
uint32_t uid,
|
|
|
|
uint8_t *luid,
|
2019-02-26 03:56:45 +01:00
|
|
|
size_t luid_size)
|
2018-11-21 02:29:40 +01:00
|
|
|
{
|
2019-02-26 03:56:45 +01:00
|
|
|
return aime_io_mifare_read_luid(0, uid, luid, luid_size);
|
2018-11-21 02:29:40 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 03:55:49 +01:00
|
|
|
static void com12_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b)
|
2018-11-21 02:29:40 +01:00
|
|
|
{
|
2019-02-26 03:56:45 +01:00
|
|
|
aime_io_led_set_color(0, r, g, b);
|
2018-11-21 02:29:40 +01:00
|
|
|
}
|