From 05c7e304271bcf88901da3782fcd3f28a0c7c9cf Mon Sep 17 00:00:00 2001 From: laforge Date: Tue, 8 Nov 2005 08:34:15 +0000 Subject: use autoconf/automake git-svn-id: https://svn.gnumonks.org/trunk/librfid@1658 e0336214-984f-0b4b-a45f-81c69e1f0ede --- rfid_proto_mifare_classic.c | 148 -------------------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 rfid_proto_mifare_classic.c (limited to 'rfid_proto_mifare_classic.c') diff --git a/rfid_proto_mifare_classic.c b/rfid_proto_mifare_classic.c deleted file mode 100644 index 10de288..0000000 --- a/rfid_proto_mifare_classic.c +++ /dev/null @@ -1,148 +0,0 @@ - -/* Mifare Classic implementation, PCD side. - * - * (C) 2005 by Harald Welte - * - */ - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include "rfid_iso14443_common.h" - - -#define MIFARE_UL_CMD_WRITE 0xA2 -#define MIFARE_UL_CMD_READ 0x30 - -/* FIXME */ -#define MIFARE_CL_READ_FWT 100 -#define MIFARE_CL_WRITE_FWT 100 - -static int -mfcl_read(struct rfid_protocol_handle *ph, unsigned int page, - unsigned char *rx_data, unsigned int *rx_len) -{ - unsigned char rx_buf[16]; - unsigned int real_rx_len = sizeof(rx_buf); - unsigned char tx[2]; - int ret; - - if (page > MIFARE_CL_PAGE_MAX) - return -EINVAL; - - tx[0] = MIFARE_CL_CMD_READ; - tx[1] = page & 0xff; - - 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; - - if (real_rx_len < *rx_len) - *rx_len = real_rx_len; - - memcpy(rx_data, rx_buf, *rx_len); - - return ret; -} - -static int -mfcl_write(struct rfid_protocol_handle *ph, unsigned int page, - unsigned char *tx_data, unsigned int tx_len) -{ - unsigned int i; - unsigned char tx[18]; - unsigned char rx[1]; - unsigned int rx_len; - int ret; - - if (tx_len != 16 || page > MIFARE_CL_PAGE_MAX) - return -EINVAL; - - tx[0] = MIFARE_CL_CMD_WRITE16; - tx[1] = page & 0xff; - - memcpy(tx+2, tx_data, 16); - - ret = ph->l2h->l2->fn.transcieve(ph->l2h, RFID_MIFARE_FRAME, tx, - sizeof(tx), rx, &rx_len, - MIFARE_CL_WRITE_FWT, 0); - - if (ret < 0) - return ret; - - if (rx[0] != MIFARE_UL_RESP_ACK) - return -EIO; - - return ret; -} - -static struct rfid_protocol_handle * -mfcl_init(struct rfid_layer2_handle *l2h) -{ - struct rfid_protocol_handle *ph; - ph = malloc(sizeof(struct rfid_protocol_handle)); - return ph; -} - -static int mfcl_fini(struct rfid_protocol_handle *ph) -{ - free(ph); - return 0; -} - -struct rfid_protocol rfid_protocol_mfcl = { - .id = RFID_PROTOCOL_MIFARE_CLASSIC, - .name = "Mifare Classic", - .fn = { - .init = &mfcl_init, - .read = &mfcl_read, - .write = &mfcl_write, - .fini = &mfcl_fini, - }, -}; - -int mfcl_set_key(struct rfid_protocol_handle *ph, unsigned char *key) -{ - if (!ph->l2h->rh->reader->mifare_classic.setkey) - return -ENODEV; - - return ph->l2h->rh->reader->mifare_classic.setkey(ph->l2h->rh, key); -} - -int mfcl_auth(struct rfid_protocol_handle *ph, u_int8_t cmd, u_int8_t block) -{ - u_int32_t serno = *((u_int32_t *)ph->l2h->uid); - - if (!ph->l2h->rh->reader->mifare_classic.auth) - return -ENODEV; - - return ph->l2h->rh->reader->mifare_classic.auth(ph->l2h->rh, cmd, - serno, block); -} -- cgit v1.2.3