board/sg-nfc.c: Use non-hardcoded UID

Turns out this does in fact vary between cards, even though its
actual value is unimportant.
This commit is contained in:
Tau 2018-12-17 17:09:56 -05:00
parent 9159be00a2
commit 755be05603
3 changed files with 27 additions and 11 deletions

View File

@ -215,21 +215,29 @@ static HRESULT sg_nfc_cmd_mifare_poll(
const struct sg_req_header *req, const struct sg_req_header *req,
struct sg_nfc_resp_mifare_poll *resp) struct sg_nfc_resp_mifare_poll *resp)
{ {
uint32_t uid;
HRESULT hr; HRESULT hr;
hr = nfc->ops->mifare_poll(nfc->ops_ctx); uid = 0;
hr = nfc->ops->mifare_poll(nfc->ops_ctx, &uid);
if (hr == S_OK) { if (hr == S_OK) {
if (uid == 0 || uid == -1) {
sg_nfc_dprintf(nfc, "nfc->ops->mifare_poll returned bad uid\n");
return E_UNEXPECTED;
}
sg_nfc_dprintf(nfc, "Mifare card is present\n"); sg_nfc_dprintf(nfc, "Mifare card is present\n");
sg_resp_init(&resp->resp, req, sizeof(resp->payload.some)); sg_resp_init(&resp->resp, req, sizeof(resp->payload.some));
resp->payload.some[0] = 0x01; /* Chunk size? */ resp->payload.some[0] = 0x01; /* Chunk size? */
resp->payload.some[1] = 0x10; /* Unknown */ resp->payload.some[1] = 0x10; /* Unknown */
resp->payload.some[2] = 0x04; /* Chunk size? */ resp->payload.some[2] = 0x04; /* Chunk size? */
resp->payload.some[3] = 0x52; /* UID byte 0 */ resp->payload.some[3] = uid >> 24; /* UID byte 0 */
resp->payload.some[4] = 0xCC; /* UID byte 1 */ resp->payload.some[4] = uid >> 16; /* UID byte 1 */
resp->payload.some[5] = 0x55; /* UID byte 2 */ resp->payload.some[5] = uid >> 8; /* UID byte 2 */
resp->payload.some[6] = 0x25; /* UID byte 3 */ resp->payload.some[6] = uid ; /* UID byte 3 */
return S_OK; return S_OK;
} else if (hr == S_FALSE) { } else if (hr == S_FALSE) {

View File

@ -8,7 +8,7 @@
#include "hook/iobuf.h" #include "hook/iobuf.h"
struct sg_nfc_ops { struct sg_nfc_ops {
HRESULT (*mifare_poll)(void *ctx); HRESULT (*mifare_poll)(void *ctx, uint32_t *uid);
HRESULT (*mifare_read_luid)(void *ctx, uint8_t *luid, size_t nbytes); HRESULT (*mifare_read_luid)(void *ctx, uint8_t *luid, size_t nbytes);
}; };

View File

@ -13,13 +13,14 @@
#include "hooklib/uart.h" #include "hooklib/uart.h"
#include "util/crc.h"
#include "util/dprintf.h" #include "util/dprintf.h"
#include "util/dump.h" #include "util/dump.h"
static HRESULT com12_handle_irp(struct irp *irp); static HRESULT com12_handle_irp(struct irp *irp);
static HRESULT com12_handle_irp_locked(struct irp *irp); static HRESULT com12_handle_irp_locked(struct irp *irp);
static HRESULT com12_mifare_poll(void *ctx); static HRESULT com12_mifare_poll(void *ctx, uint32_t *uid);
static HRESULT com12_mifare_read_luid(void *ctx, uint8_t *luid, size_t nbytes); static HRESULT com12_mifare_read_luid(void *ctx, uint8_t *luid, size_t nbytes);
static HRESULT com12_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b); static HRESULT com12_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b);
@ -117,7 +118,7 @@ static HRESULT com12_handle_irp_locked(struct irp *irp)
return hr; return hr;
} }
static HRESULT com12_mifare_poll(void *ctx) static HRESULT com12_mifare_poll(void *ctx, uint32_t *uid)
{ {
HRESULT hr; HRESULT hr;
FILE *f; FILE *f;
@ -152,6 +153,13 @@ static HRESULT com12_mifare_poll(void *ctx)
com12_aime_luid[i] = byte; com12_aime_luid[i] = byte;
} }
/* NOTE: We are just arbitrarily using the CRC32 of the LUID here, real
cards do not work like this! However, neither the application code nor
the network protocol care what the UID is, it just has to be a stable
unique identifier for over-the-air NFC communications. */
*uid = crc32(com12_aime_luid, sizeof(com12_aime_luid), 0);
hr = S_OK; hr = S_OK;
end: end: