4 * Copyright (C) 2014 Jakob Wenzel
7 * Jakob Wenzel <jakobwenzel92@gmail.com>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 package de.dhbwloe.campusapp.nfcreader.cardreader;
25 import android.os.Bundle;
26 import android.util.Log;
28 import com.codebutler.farebot.Utils;
29 import com.codebutler.farebot.card.desfire.DesfireException;
30 import com.codebutler.farebot.card.desfire.DesfireFileSettings;
31 import com.codebutler.farebot.card.desfire.DesfireProtocol;
33 public class IntercardReader implements ICardReader {
34 private static final String TAG = IntercardReader.class.getName();
37 public NfcCardData readCard(DesfireProtocol card) throws DesfireException {
38 NfcCardData valuedata = new NfcCardData();
39 valuedata.setUniqueId(card.getManufacturingData().uid);
42 int[] appList = card.getAppList();
43 for(int i = 0; i < appList.length; i++) {
44 for(int j = 0; j < 10; j++) {
46 DesfireFileSettings settings = Utils.selectAppFile(card, appList[i], j);
47 if(settings != null) {
48 Bundle bundle = new Bundle();
49 bundle.putString("type", settings.getFileTypeName());
50 boolean hasValue = false;
51 if (settings instanceof DesfireFileSettings.ValueDesfireFileSettings) {
52 DesfireFileSettings.ValueDesfireFileSettings value = (DesfireFileSettings.ValueDesfireFileSettings) settings;
53 bundle.putInt("value", value.value);
55 bundle.putByte("limited", value.limitedCreditEnabled);
56 bundle.putInt("max", value.upperLimit);
57 bundle.putInt("min", value.lowerLimit);
58 } else if (settings instanceof DesfireFileSettings.StandardDesfireFileSettings) {
59 DesfireFileSettings.StandardDesfireFileSettings value = (DesfireFileSettings.StandardDesfireFileSettings) settings;
60 bundle.putInt("size", value.fileSize);
61 } else if (settings instanceof DesfireFileSettings.RecordDesfireFileSettings) {
62 DesfireFileSettings.RecordDesfireFileSettings value = (DesfireFileSettings.RecordDesfireFileSettings) settings;
63 bundle.putInt("records", value.curRecords);
64 bundle.putInt("size", value.recordSize);
65 bundle.putInt("max", value.maxRecords);
70 bundle.putInt("data", card.readValue(j));
73 } catch (Exception e) {
76 byte[] bytes = card.readFile(j);
77 bundle.putByteArray("file", bytes);
79 } catch (Exception e) {
82 byte[] bytes = card.readRecord(j);
83 bundle.putByteArray("record", bytes);
85 } catch (Exception e) {
88 valuedata.appendPlainData(appList[i], j, bundle);
90 } catch (Exception e) {
96 } catch (Exception e) {