board/sg-nfc.c: Pass UID consistently

If we receive it from the upper ops layer then we should send it
back as well.
This commit is contained in:
Tau 2019-02-25 17:23:04 -05:00
parent bbe085b73d
commit 8606d17699
3 changed files with 30 additions and 7 deletions

View File

@ -44,10 +44,12 @@ static HRESULT sg_nfc_cmd_mifare_read_block(
static HRESULT sg_nfc_mifare_read_block_1( static HRESULT sg_nfc_mifare_read_block_1(
const struct sg_nfc *nfc, const struct sg_nfc *nfc,
uint32_t uid,
uint8_t *block); uint8_t *block);
static HRESULT sg_nfc_mifare_read_block_2( static HRESULT sg_nfc_mifare_read_block_2(
const struct sg_nfc *nfc, const struct sg_nfc *nfc,
uint32_t uid,
uint8_t *block); uint8_t *block);
static HRESULT sg_nfc_cmd_dummy( 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, const struct sg_nfc_req_mifare_read_block *req,
struct sg_nfc_resp_mifare_read_block *resp) struct sg_nfc_resp_mifare_read_block *resp)
{ {
uint32_t uid;
if (req->req.payload_len != sizeof(req->payload)) { if (req->req.payload_len != sizeof(req->payload)) {
sg_nfc_dprintf(nfc, "%s: Payload size is incorrect\n", __func__); sg_nfc_dprintf(nfc, "%s: Payload size is incorrect\n", __func__);
return E_FAIL; 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)); sg_resp_init(&resp->resp, &req->req, sizeof(resp->block));
switch (req->payload.block_no) { switch (req->payload.block_no) {
case 1: 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: 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 0:
case 3: case 3:
@ -299,6 +308,7 @@ static HRESULT sg_nfc_cmd_mifare_read_block(
static HRESULT sg_nfc_mifare_read_block_1( static HRESULT sg_nfc_mifare_read_block_1(
const struct sg_nfc *nfc, const struct sg_nfc *nfc,
uint32_t uid,
uint8_t *block) uint8_t *block)
{ {
memcpy(block, sg_nfc_block_1, sizeof(sg_nfc_block_1)); 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( static HRESULT sg_nfc_mifare_read_block_2(
const struct sg_nfc *nfc, const struct sg_nfc *nfc,
uint32_t uid,
uint8_t *block) uint8_t *block)
{ {
HRESULT hr; 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)) { if (FAILED(hr)) {
return hr; return hr;

View File

@ -9,7 +9,11 @@
struct sg_nfc_ops { struct sg_nfc_ops {
HRESULT (*mifare_poll)(void *ctx, uint32_t *uid); 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 { struct sg_nfc {

View File

@ -21,7 +21,11 @@ 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, uint32_t *uid); 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 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 = { static const struct sg_nfc_ops com12_nfc_ops = {
@ -170,7 +174,11 @@ end:
return hr; 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(luid != NULL);
assert(nbytes == sizeof(com12_aime_luid)); assert(nbytes == sizeof(com12_aime_luid));