use of org.openecard.common.ifd.scio.SCIOATR in project open-ecard by ecsec.
the class TerminalInfo method getStatus.
@Nonnull
public IFDStatusType getStatus() throws SCIOException {
IFDStatusType status = new IFDStatusType();
status.setIFDName(getName());
status.setConnected(true);
// set slot status type
SlotStatusType stype = new SlotStatusType();
status.getSlotStatus().add(stype);
boolean cardPresent = isCardPresent();
stype.setCardAvailable(cardPresent);
stype.setIndex(BigInteger.ZERO);
// get card status and stuff
if (isConnected()) {
SCIOATR atr = channel.getChannel().getCard().getATR();
stype.setATRorATS(atr.getBytes());
} else if (cardPresent) {
// not connected, but card is present
try {
SingleThreadChannel ch = cm.openMasterChannel(getName());
SCIOATR atr = ch.getChannel().getCard().getATR();
stype.setATRorATS(atr.getBytes());
} catch (NoSuchTerminal ex) {
String msg = "Failed to connect card as terminal disappeared.";
throw new SCIOException(msg, SCIOErrorCode.SCARD_E_UNKNOWN_READER, ex);
}
}
// ifd status completely constructed
return status;
}
use of org.openecard.common.ifd.scio.SCIOATR in project open-ecard by ecsec.
the class NFCCard method getATR.
@Override
public SCIOATR getATR() {
// build ATR according to PCSCv2-3, Sec. 3.1.3.2.3.1
if (histBytes == null) {
return new SCIOATR(new byte[0]);
} else {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// Initial Header
out.write(0x3B);
// T0
out.write(0x80 | (histBytes.length & 0xF));
// TD1
out.write(0x80);
// TD2
out.write(0x01);
// ISO14443A: The historical bytes from ATS response.
// ISO14443B: 1-4=Application Data from ATQB, 5-7=Protocol Info Byte from ATQB, 8=Higher nibble = MBLI from ATTRIB command Lower nibble (RFU) = 0
// TODO: check that the HiLayerResponse matches the requirements for ISO14443B
out.write(histBytes, 0, histBytes.length);
// TCK: Exclusive-OR of bytes T0 to Tk
byte[] preATR = out.toByteArray();
byte chkSum = 0;
for (int i = 1; i < preATR.length; i++) {
chkSum ^= preATR[i];
}
out.write(chkSum);
byte[] atr = out.toByteArray();
return new SCIOATR(atr);
}
}
Aggregations