From b0fef13efe84d8601a9496098429b4a080e20c9e Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 29 May 2005 18:05:31 +0000 Subject: move librfid to new location in repository git-svn-id: https://svn.gnumonks.org/trunk/librfid@1181 e0336214-984f-0b4b-a45f-81c69e1f0ede --- rfid_iso14443_common.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 rfid_iso14443_common.c (limited to 'rfid_iso14443_common.c') diff --git a/rfid_iso14443_common.c b/rfid_iso14443_common.c new file mode 100644 index 0000000..aacb45d --- /dev/null +++ b/rfid_iso14443_common.c @@ -0,0 +1,41 @@ +static unsigned int fsdi_table[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 }; + +int iso14443_fsdi_to_fsd(unsigned int *fsd, unsigned char fsdi) +{ + /* ISO 14443-4:2000(E) Section 5.1. */ + if (fsdi > sizeof(fsdi_table)/sizeof(unsigned int)) + return -1; + + *fsd = fsdi_table[fsdi]; + return 0; +} + +int iso14443_fsd_to_fsdi(unsigned char *fsdi, unsigned int fsd) +{ + int i; + + for (i = 0; i < sizeof(fsdi_table)/sizeof(unsigned int); i++) { + if (fsdi_table[i] == fsd) { + *fsdi = i; + return 0; + } + } + + return -1; +} + +/* calculate the fsd that is equal or the closest smaller value + * that can be coded as fsd */ +unsigned int iso14443_fsd_approx(unsigned int fsd) +{ + unsigned int tbl_size = sizeof(fsdi_table)/sizeof(unsigned int); + int i; + + for (i = tbl_size-1; i >= 0; i--) { + if (fsdi_table[i] <= fsd) + return fsdi_table[i]; + } + /* not reached: return smallest possible FSD */ + return fsdi_table[0]; +} + -- cgit v1.2.3