use of org.openecard.common.ifd.scio.SCIOException 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.SCIOException in project open-ecard by ecsec.
the class PCSCTerminals method list.
public List<SCIOTerminal> list(State state, boolean firstTry) throws SCIOException {
LOG.trace("Entering list().");
try {
CardTerminals.State scState = convertState(state);
// get terminals with the specified state from the SmartcardIO
List<CardTerminal> scList = terminals.list(scState);
ArrayList<SCIOTerminal> list = convertTerminals(scList);
LOG.trace("Leaving list().");
return Collections.unmodifiableList(list);
} catch (CardException ex) {
SCIOErrorCode code = getCode(ex);
if (code == SCIOErrorCode.SCARD_E_NO_READERS_AVAILABLE) {
LOG.debug("No reader available exception.");
return Collections.emptyList();
} else if (code == SCIOErrorCode.SCARD_E_NO_SERVICE || code == SCIOErrorCode.SCARD_E_SERVICE_STOPPED) {
if (firstTry) {
LOG.debug("No service available exception, reloading PCSC and trying again.");
reloadFactory();
return list(state, false);
} else {
LOG.debug("No service available exception, returning empty list.");
return Collections.emptyList();
}
}
String msg = "Failed to retrieve list from terminals instance.";
LOG.error(msg, ex);
throw new SCIOException(msg, code, ex);
}
}
use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.
the class NFCCardTerminal method connect.
@Override
public synchronized SCIOCard connect(SCIOProtocol protocol) throws SCIOException, IllegalStateException {
if (nfcCard == null || nfcCard.isodep == null) {
String msg = "No tag present.";
LOG.warn(msg);
throw new SCIOException(msg, SCIOErrorCode.SCARD_E_NO_SMARTCARD);
}
try {
if (!nfcCard.isodep.isConnected()) {
nfcCard.isodep.connect();
// start thread which is monitoring the availability of the card
Thread nfcAvailableTask = new Thread(new NFCCardMonitoring((this)));
nfcAvailableTask.start();
}
} catch (IOException e) {
nfcCard = null;
String msg = "No connection can be established.";
LOG.warn(msg, e);
// TODO: check if error code is correct
throw new SCIOException(msg, SCIOErrorCode.SCARD_E_NO_SMARTCARD, e);
}
return nfcCard;
}
use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.
the class NFCFactory method setNFCTag.
/**
* Set the nfc tag in the nfc card terminal.
*
* @param tag
* @param timeout current timeout for transceive(byte[]) in milliseconds.
*/
public static void setNFCTag(Tag tag, int timeout) {
IsoDep isoDepTag = IsoDep.get(tag);
isoDepTag.setTimeout(timeout);
try {
// standard nfc terminal
terminals.getIntegratedNfcTerminal().setTag(isoDepTag, timeout);
} catch (SCIOException ex) {
LOG.warn(ex.getMessage(), ex);
}
}
use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.
the class PCSCChannel method transmit.
@Override
public CardResponseAPDU transmit(byte[] command) throws SCIOException {
try {
CommandAPDU convertCommand = new CommandAPDU(command);
ResponseAPDU response = channel.transmit(convertCommand);
return new CardResponseAPDU(response.getBytes());
} catch (CardException ex) {
String msg = "Failed to transmit APDU to the card in terminal '%s'.";
throw new SCIOException(String.format(msg, card.getTerminal().getName()), getCode(ex), ex);
}
}
Aggregations