+// Mifare Memory Structure: up to 32 Sectors with 4 blocks each (1k and 2k cards),
+// plus evtl. 8 sectors with 16 blocks each (4k cards)
+uint8_t mfNumBlocksPerSector(uint8_t sectorNo) {
+ if (sectorNo < 32)
+ return 4;
+ else
+ return 16;
+}
+
+uint8_t mfFirstBlockOfSector(uint8_t sectorNo) {
+ if (sectorNo < 32)
+ return sectorNo * 4;
+ else
+ return 32 * 4 + (sectorNo - 32) * 16;
+}
+
+uint8_t mfSectorTrailer(uint8_t blockNo) {
+ if (blockNo < 32*4) {
+ return (blockNo | 0x03);
+ } else {
+ return (blockNo | 0x0f);
+ }
+}
+
+bool mfIsSectorTrailer(uint8_t blockNo) {
+ return (blockNo == mfSectorTrailer(blockNo));
+}
+
+uint8_t mfSectorNum(uint8_t blockNo) {
+ if (blockNo < 32 * 4)
+ return blockNo / 4;
+ else
+ return 32 + (blockNo - 32 * 4) / 16;
+
+}