Skip to content

Commit a42b352

Browse files
Martijn CoenenNick Pelly
authored andcommitted
Added transfer/restore convience cmds to MF Classic tech.
Change-Id: I675993bc3aae6a741d63be458a0dfea240dd5316
1 parent 672ebb6 commit a42b352

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

core/java/android/nfc/technology/MifareClassic.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ public int getSectorSize(int sector) {
205205
return getBlockCount(sector) * 16;
206206
}
207207

208+
public int getTotalBlockCount() {
209+
int totalBlocks = 0;
210+
for (int sec = 0; sec < getSectorCount(); sec++) {
211+
totalBlocks += getSectorSize(sec);
212+
}
213+
214+
return totalBlocks;
215+
}
216+
208217
public int getBlockCount(int sector) {
209218
if (sector >= getSectorCount()) {
210219
throw new IllegalArgumentException("this card only has " + getSectorCount() +
@@ -343,9 +352,27 @@ public void decrement(int block) throws IOException {
343352
checkConnected();
344353

345354
byte addr = (byte) block;
346-
byte[] incr_cmd = { (byte) 0xC0, (byte) block };
355+
byte[] decr_cmd = { (byte) 0xC0, (byte) block };
347356

348-
transceive(incr_cmd);
357+
transceive(decr_cmd);
358+
}
359+
360+
public void transfer(int block) throws IOException {
361+
checkConnected();
362+
363+
byte addr = (byte) block;
364+
byte[] trans_cmd = { (byte) 0xB0, (byte) block };
365+
366+
transceive(trans_cmd);
367+
}
368+
369+
public void restore(int block) throws IOException {
370+
checkConnected();
371+
372+
byte addr = (byte) block;
373+
byte[] rest_cmd = { (byte) 0xC2, (byte) block };
374+
375+
transceive(rest_cmd);
349376
}
350377

351378
/**

0 commit comments

Comments
 (0)