From a5dd66f77d874601005807a73cb0f38475e39296 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 23 Dec 2009 15:26:57 +0000 Subject: [PATCH] put MifareSectorNumber type in a new mifare_common.h header. API changed: mifare_classic_format_sector() now takes a MifareSectorNumber in argument. --- Makefile.am | 4 ++-- configure.ac | 4 +++- mad.h | 3 +-- mifare_classic.c | 4 ++-- mifare_classic.h | 4 +++- mifare_common.h | 26 ++++++++++++++++++++++++++ 6 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 mifare_common.h diff --git a/Makefile.am b/Makefile.am index 2bc857b..82d9d53 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,13 +1,13 @@ ACLOCAL_AMFLAGS = -I m4 -AM_CFLAGS = -I. -std=c99 @LIBNFC_CFLAGS@ +AM_CFLAGS = -I. @LIBNFC_CFLAGS@ AM_LDFLAGS = @LIBNFC_LIBS@ lib_LTLIBRARIES = libfreefare.la libfreefare_la_SOURCES = mifare_classic.c mad.c mifare_application.c -libfreefare_la_HEADERS = mifare_classic.h mad.h mifare_application.h +libfreefare_la_HEADERS = mifare_common.h mifare_classic.h mad.h mifare_application.h libfreefare_ladir = $(includedir) pkgconfigdir = $(libdir)/pkgconfig diff --git a/configure.ac b/configure.ac index cd8ef5c..3bd56eb 100644 --- a/configure.ac +++ b/configure.ac @@ -30,9 +30,11 @@ AC_CHECK_FUNCS([memset]) AC_CHECK_HEADERS([endian.h sys/endian.h]) if test $ac_cv_header_endian_h = "no" -a $ac_cv_header_sys_endian_h = "no"; then - AC_MSG_ERROR([Can't locate header endian.h.]); + AC_MSG_ERROR(["Can't locate header endian.h."]); fi +CFLAGS="$CFLAGS -std=c99" + # Checks for pkg-config modules. PKG_CHECK_MODULES([LIBNFC], [libnfc], [], [AC_MSG_ERROR([libnfc is mandatory.])]) diff --git a/mad.h b/mad.h index cd7934d..085df14 100644 --- a/mad.h +++ b/mad.h @@ -19,10 +19,9 @@ #ifndef __MIFARE_APPLICATION_DIRECTORY_H__ #define __MIFARE_APPLICATION_DIRECTORY_H__ +#include #include -typedef uint8_t MifareSectorNumber; - struct mad_aid { uint8_t function_cluster_code; uint8_t application_code; diff --git a/mifare_classic.c b/mifare_classic.c index 27c84bd..f59b602 100644 --- a/mifare_classic.c +++ b/mifare_classic.c @@ -655,9 +655,9 @@ mifare_classic_get_data_block_permission (MifareClassicTag tag, const MifareClas * Reset a MIFARE target sector to factory default. */ int -mifare_classic_format_sector (MifareClassicTag tag, const MifareClassicBlockNumber block) +mifare_classic_format_sector (MifareClassicTag tag, const MifareSectorNumber sector) { - MifareClassicBlockNumber first_sector_block = (block / 4) * 4; + MifareClassicBlockNumber first_sector_block = sector * 4; /* * Check that the current key allow us to rewrite data and trailer blocks. */ diff --git a/mifare_classic.h b/mifare_classic.h index 40cacd6..6c24b91 100644 --- a/mifare_classic.h +++ b/mifare_classic.h @@ -23,6 +23,8 @@ #include #include +#include + struct mifare_classic_tag; typedef struct mifare_classic_tag *MifareClassicTag; @@ -52,7 +54,7 @@ int mifare_classic_transfer (MifareClassicTag tag, const MifareClassicBlockNumb int mifare_classic_get_trailer_block_permission (MifareClassicTag tag, const MifareClassicBlockNumber block, const uint16_t permission, const MifareClassicKeyType key_type); int mifare_classic_get_data_block_permission (MifareClassicTag tag, const MifareClassicBlockNumber block, const unsigned char permission, const MifareClassicKeyType key_type); -int mifare_classic_format_sector (MifareClassicTag tag, const MifareClassicBlockNumber block); +int mifare_classic_format_sector (MifareClassicTag tag, const MifareSectorNumber sector); void mifare_classic_trailer_block (MifareClassicBlock *block, const MifareClassicKey key_a, const uint8_t ab_0, const uint8_t ab_1, const uint8_t ab_2, const uint8_t ab_tb, const uint8_t gpb, const MifareClassicKey key_b); /* MIFARE Classic Access Bits */ diff --git a/mifare_common.h b/mifare_common.h new file mode 100644 index 0000000..4db7a00 --- /dev/null +++ b/mifare_common.h @@ -0,0 +1,26 @@ +/*- + * Copyright (C) 2009, Romain Tartiere, Romuald Conty. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * 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 Lesser General Public License + * along with this program. If not, see + * + * $Id$ + */ +#ifndef __MIFARE_COMMON_H__ +#define __MIFARE_COMMON_H__ + +#include + +typedef uint8_t MifareSectorNumber; + +#endif /* !__MIFARE_COMMON_H__ */