1 package de.dhbwloe.campusapp.nfcreader;
3 import android.nfc.tech.IsoDep;
5 import de.dhbwloe.campusapp.nfcreader.MifareDESFire.CommunicationError;
6 import de.dhbwloe.campusapp.nfcreader.MifareDESFire.DesfireManufacturingData;
7 import de.dhbwloe.campusapp.nfcreader.MifareDESFire.MifareDESFireWrapper;
8 import de.dhbwloe.campusapp.nfcreader.MifareDESFire.ValueFileSettings;
10 import java.text.DecimalFormat;
13 * Created by stefan on 20.01.16.
15 public class DHBWCard {
18 // public static final byte GET_VERSION_INFO = (byte) 0x60;
19 // public static final byte GET_APPLICATION_DIRECTORY = (byte) 0x6A;
20 // public static final byte GET_ADDITIONAL_FRAME = (byte) 0xAF;
21 // public static final byte SELECT_APPLICATION = (byte) 0x5A;
22 // public static final byte READ_DATA = (byte) 0xBD;
23 // public static final byte READ_RECORD = (byte) 0xBB;
24 // public static final byte GET_FILES = (byte) 0x6F;
25 // public static final byte GET_FILE_SETTINGS = (byte) 0xF5;
27 // public static final byte INIT_AUTH = (byte) 0x0a;
28 // public static final byte FINISH_AUTH = (byte) 0xAF;
30 // public static final byte GET_KEY_VERSION = (byte) 0x64;
32 private MifareDESFireWrapper nfcCard;
34 public DHBWCard(IsoDep tag) {
35 this.nfcCard = new MifareDESFireWrapper(tag);
40 * Reads the current uniqueid on the card.
41 * Throws a UndefinedResponseException if the card returns an unexpected response (e.g. used another card)
43 * @return Returns the unique id
44 * @throws UndefinedResponseException
46 public int readUniqueId() throws UndefinedResponseException, CommunicationError {
47 // Select application for balance
48 DesfireManufacturingData manufacturingData = nfcCard.readManufacturingData();
49 return manufacturingData.uid;
53 * Reads the current balance on the card.
54 * Throws a UndefinedResponseException if the card returns an unexpected response (e.g. used another card)
56 * @return Returns the balance
57 * @throws UndefinedResponseException
59 public int readBalance() throws UndefinedResponseException, CommunicationError {
60 // Select application for balance
61 nfcCard.selectApplication("5F 84 15");
62 int value = nfcCard.readValueFile("01");
68 * Reads the last transaction by reading the limited credit value
69 * @return Returns the last transaction of the card
70 * @throws UndefinedResponseException
72 public int readLastTransaction() throws UndefinedResponseException, CommunicationError {
73 nfcCard.selectApplication("5F 84 15");
74 ValueFileSettings valueFileSettings = (ValueFileSettings) nfcCard.readFileSettings("01");
75 return valueFileSettings.getLimitedCreditValue() / 10;