summaryrefslogtreecommitdiff
path: root/smcc/src/main/java/at/gv/egiz/smcc/T0CardChannel.java
diff options
context:
space:
mode:
Diffstat (limited to 'smcc/src/main/java/at/gv/egiz/smcc/T0CardChannel.java')
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/T0CardChannel.java117
1 files changed, 58 insertions, 59 deletions
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/T0CardChannel.java b/smcc/src/main/java/at/gv/egiz/smcc/T0CardChannel.java
index 5ec0b4b0..9b0ef657 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/T0CardChannel.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/T0CardChannel.java
@@ -8,80 +8,79 @@ import javax.smartcardio.CardException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
-import at.gv.egiz.smcc.util.SMCCHelper;
-
public class T0CardChannel extends LogCardChannel {
public T0CardChannel(CardChannel channel) {
-
- super(channel);
+
+ super(channel);
}
- @Override
- public ResponseAPDU transmit(CommandAPDU command) throws CardException {
-
- ResponseAPDU resp = super.transmit(command);
-
- if(resp.getSW1() == (byte)0x61) {
-
- byte[] data = executeGetResponse((byte)resp.getSW2());
-
- byte[] result = new byte[data.length + 2];
- System.arraycopy(data, 0, result, 0, data.length);
-
- // add SW "90 00"
- result[result.length-2] = (byte)0x90;
- result[result.length-1] = (byte)0x00;
-
- return new ResponseAPDU(result);
- } else {
-
- return resp;
- }
- }
-
- private byte[] executeGetResponse(byte sw2)
- throws CardException {
-
- boolean done = false;
- ByteArrayOutputStream bof = new ByteArrayOutputStream();
-
- while (!done) {
-
- CommandAPDU command = new CommandAPDU(new byte[] { (byte) 0x00,
- (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) sw2 });
-// ResponseAPDU resp = channel.transmit(command);
- ResponseAPDU resp = super.transmit(command);
-
- try {
- bof.write(resp.getData());
- } catch (IOException e) {
+ @Override
+ public ResponseAPDU transmit(CommandAPDU command) throws CardException {
- throw new CardException(
- "Error during fetching gesponse from card.", e);
- }
+ ResponseAPDU resp = super.transmit(command);
if (resp.getSW1() == (byte) 0x61) {
- // more data to be read
- sw2 = (byte) resp.getSW2();
- continue;
- }
+ byte[] initData = resp.getData();
+ byte[] data = executeGetResponse((byte) resp.getSW2());
- if (resp.getSW() == 0x9000) {
+ byte[] result = new byte[initData.length + data.length + 2];
+ System.arraycopy(initData, 0, result, 0, initData.length);
+ System.arraycopy(data, 0, result, initData.length, data.length);
- // all data read
- done = true;
+ // add SW "90 00"
+ result[result.length - 2] = (byte) 0x90;
+ result[result.length - 1] = (byte) 0x00;
+
+ return new ResponseAPDU(result);
} else {
- throw new CardException(
- "An error has occured during fetching response from card: "
- + Integer.toHexString(resp.getSW()));
+ return resp;
+ }
+ }
+
+ private byte[] executeGetResponse(byte sw2) throws CardException {
+
+ boolean done = false;
+ ByteArrayOutputStream bof = new ByteArrayOutputStream();
+
+ while (!done) {
+
+ CommandAPDU command = new CommandAPDU(new byte[] { (byte) 0x00,
+ (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) sw2 });
+ // ResponseAPDU resp = channel.transmit(command);
+ ResponseAPDU resp = super.transmit(command);
+
+ try {
+ bof.write(resp.getData());
+ } catch (IOException e) {
+
+ throw new CardException(
+ "Error during fetching gesponse from card.", e);
+ }
+
+ if (resp.getSW1() == (byte) 0x61) {
+
+ // more data to be read
+ sw2 = (byte) resp.getSW2();
+ continue;
+ }
+
+ if (resp.getSW() == 0x9000) {
+
+ // all data read
+ done = true;
+ } else {
+
+ throw new CardException(
+ "An error has occured during fetching response from card: "
+ + Integer.toHexString(resp.getSW()));
+ }
+
}
+ return bof.toByteArray();
}
- return bof.toByteArray();
-}
-
}