diff --git a/board/sg-nfc.c b/board/sg-nfc.c index 9936879..a9bacbc 100644 --- a/board/sg-nfc.c +++ b/board/sg-nfc.c @@ -44,10 +44,12 @@ static HRESULT sg_nfc_cmd_mifare_read_block( static HRESULT sg_nfc_mifare_read_block_1( const struct sg_nfc *nfc, + uint32_t uid, uint8_t *block); static HRESULT sg_nfc_mifare_read_block_2( const struct sg_nfc *nfc, + uint32_t uid, uint8_t *block); static HRESULT sg_nfc_cmd_dummy( @@ -261,22 +263,29 @@ static HRESULT sg_nfc_cmd_mifare_read_block( const struct sg_nfc_req_mifare_read_block *req, struct sg_nfc_resp_mifare_read_block *resp) { + uint32_t uid; + if (req->req.payload_len != sizeof(req->payload)) { sg_nfc_dprintf(nfc, "%s: Payload size is incorrect\n", __func__); return E_FAIL; } - sg_nfc_dprintf(nfc, "Read block %i\n", req->payload.block_no); + uid = (req->payload.uid[0] << 24) | + (req->payload.uid[1] << 16) | + (req->payload.uid[2] << 8) | + (req->payload.uid[3] ) ; + + sg_nfc_dprintf(nfc, "Read uid %08x block %i\n", uid, req->payload.block_no); sg_resp_init(&resp->resp, &req->req, sizeof(resp->block)); switch (req->payload.block_no) { case 1: - return sg_nfc_mifare_read_block_1(nfc, resp->block); + return sg_nfc_mifare_read_block_1(nfc, uid, resp->block); case 2: - return sg_nfc_mifare_read_block_2(nfc, resp->block); + return sg_nfc_mifare_read_block_2(nfc, uid, resp->block); case 0: case 3: @@ -299,6 +308,7 @@ static HRESULT sg_nfc_cmd_mifare_read_block( static HRESULT sg_nfc_mifare_read_block_1( const struct sg_nfc *nfc, + uint32_t uid, uint8_t *block) { memcpy(block, sg_nfc_block_1, sizeof(sg_nfc_block_1)); @@ -308,11 +318,12 @@ static HRESULT sg_nfc_mifare_read_block_1( static HRESULT sg_nfc_mifare_read_block_2( const struct sg_nfc *nfc, + uint32_t uid, uint8_t *block) { HRESULT hr; - hr = nfc->ops->mifare_read_luid(nfc->ops_ctx, &block[6], 10); + hr = nfc->ops->mifare_read_luid(nfc->ops_ctx, uid, &block[6], 10); if (FAILED(hr)) { return hr; diff --git a/board/sg-nfc.h b/board/sg-nfc.h index 9d91cd2..e3307b2 100644 --- a/board/sg-nfc.h +++ b/board/sg-nfc.h @@ -9,7 +9,11 @@ struct sg_nfc_ops { 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, + uint32_t uid, + uint8_t *luid, + size_t nbytes); }; struct sg_nfc { diff --git a/cardhook/_com12.c b/cardhook/_com12.c index 2e32547..b4adc6b 100644 --- a/cardhook/_com12.c +++ b/cardhook/_com12.c @@ -21,7 +21,11 @@ static HRESULT com12_handle_irp(struct irp *irp); static HRESULT com12_handle_irp_locked(struct irp *irp); 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, + uint32_t uid, + uint8_t *luid, + size_t nbytes); static HRESULT com12_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b); static const struct sg_nfc_ops com12_nfc_ops = { @@ -170,7 +174,11 @@ end: return hr; } -static HRESULT com12_mifare_read_luid(void *ctx, uint8_t *luid, size_t nbytes) +static HRESULT com12_mifare_read_luid( + void *ctx, + uint32_t uid, + uint8_t *luid, + size_t nbytes) { assert(luid != NULL); assert(nbytes == sizeof(com12_aime_luid));