summaryrefslogtreecommitdiff
path: root/rfid_proto_mifare_classic.c
diff options
context:
space:
mode:
authorlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2005-10-23 20:03:56 +0000
committerlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2005-10-23 20:03:56 +0000
commitb9e8c17d8c4f28938c7cb0a665a1f21232ebdf66 (patch)
treed4d3004078f2de09d76f2798fba06d4eecc25a77 /rfid_proto_mifare_classic.c
parent5fc01ff6f98d72219420bc29fb59d2d6eb93e887 (diff)
make "frametype" a parameter of transcieve functions
git-svn-id: https://svn.gnumonks.org/trunk/librfid@1559 e0336214-984f-0b4b-a45f-81c69e1f0ede
Diffstat (limited to 'rfid_proto_mifare_classic.c')
-rw-r--r--rfid_proto_mifare_classic.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/rfid_proto_mifare_classic.c b/rfid_proto_mifare_classic.c
index 474f554..10de288 100644
--- a/rfid_proto_mifare_classic.c
+++ b/rfid_proto_mifare_classic.c
@@ -28,9 +28,8 @@
#include <rfid/rfid.h>
#include <rfid/rfid_protocol.h>
#include <rfid/rfid_layer2.h>
-//#include <rfid/rfid_layer2_iso14443b.h>
+#include <rfid/rfid_protocol_mifare_classic.h>
-//#include <rfid/rfid_asic.h>
#include <rfid/rfid_reader.h>
#include "rfid_iso14443_common.h"
@@ -40,8 +39,8 @@
#define MIFARE_UL_CMD_READ 0x30
/* FIXME */
-#define MIFARE_UL_READ_FWT 100
-#define MIFARE_UL_WRITE_FWT 100
+#define MIFARE_CL_READ_FWT 100
+#define MIFARE_CL_WRITE_FWT 100
static int
mfcl_read(struct rfid_protocol_handle *ph, unsigned int page,
@@ -52,14 +51,15 @@ mfcl_read(struct rfid_protocol_handle *ph, unsigned int page,
unsigned char tx[2];
int ret;
- if (page > 7)
+ if (page > MIFARE_CL_PAGE_MAX)
return -EINVAL;
- tx[0] = MIFARE_UL_CMD_READ;
+ tx[0] = MIFARE_CL_CMD_READ;
tx[1] = page & 0xff;
- ret = ph->l2h->l2->fn.transcieve(ph->l2h, tx, sizeof(tx), rx_buf,
- &real_rx_len, MIFARE_UL_READ_FWT, 0);
+ ret = ph->l2h->l2->fn.transcieve(ph->l2h, RFID_MIFARE_FRAME, tx,
+ sizeof(tx), rx_buf, &real_rx_len,
+ MIFARE_CL_READ_FWT, 0);
if (ret < 0)
return ret;
@@ -77,24 +77,28 @@ mfcl_write(struct rfid_protocol_handle *ph, unsigned int page,
unsigned char *tx_data, unsigned int tx_len)
{
unsigned int i;
- unsigned char tx[6];
+ unsigned char tx[18];
unsigned char rx[1];
unsigned int rx_len;
int ret;
- if (tx_len != 4 || page > 7)
+ if (tx_len != 16 || page > MIFARE_CL_PAGE_MAX)
return -EINVAL;
- tx[0] = MIFARE_UL_CMD_WRITE;
+ tx[0] = MIFARE_CL_CMD_WRITE16;
tx[1] = page & 0xff;
- for (i = 0; i < 4; i++)
- tx[2+i] = tx_data[i];
+ memcpy(tx+2, tx_data, 16);
- ret = ph->l2h->l2->fn.transcieve(ph->l2h, tx, sizeof(tx), rx,
- &rx_len, MIFARE_UL_WRITE_FWT, 0);
+ ret = ph->l2h->l2->fn.transcieve(ph->l2h, RFID_MIFARE_FRAME, tx,
+ sizeof(tx), rx, &rx_len,
+ MIFARE_CL_WRITE_FWT, 0);
- /* FIXME:look at RX, check for ACK/NAK */
+ if (ret < 0)
+ return ret;
+
+ if (rx[0] != MIFARE_UL_RESP_ACK)
+ return -EIO;
return ret;
}
personal git repositories of Harald Welte. Your mileage may vary