use of org.openecard.common.interfaces.RecognitionException in project open-ecard by ecsec.
the class Recognizer method recognizeSlot.
private ConnectionHandleType recognizeSlot() {
RecognitionInfo rInfo = null;
RecognitionInfo currentInfo = handle.getRecognitionInfo();
if (currentInfo == null || currentInfo.getCardIdentifier() == null) {
LOG.error("Current recognition info or CardIdentifier is null.");
} else if (env.getCIFProvider().needsRecognition(handle.getRecognitionInfo().getCardIdentifier())) {
try {
CardRecognition cr = env.getRecognition();
rInfo = cr.recognizeCard(handle.getContextHandle(), handle.getIFDName(), handle.getSlotIndex());
} catch (RecognitionException ex) {
// ignore, card is just unknown
}
}
if (rInfo != null) {
ConnectionHandleType newHandle = HandlerUtils.copyHandle(handle);
newHandle.getRecognitionInfo().setCardType(rInfo.getCardType());
// Remove card identifier (ATR/ATS) as TR-03112-4 states that this should contain the ATR/ATS for unknown
// cards and the ICCSN or something similar for known cards. Until we extract the ICCSN just remove the ATR.
newHandle.getRecognitionInfo().setCardIdentifier(null);
return newHandle;
} else {
return null;
}
}
use of org.openecard.common.interfaces.RecognitionException in project open-ecard by ecsec.
the class CardRecognitionImpl method waitForExclusiveCardAccess.
/**
* This method tries to get exclusive card access until it is granted.
* The waiting delay between the attempts is determined by the fibonacci numbers.
*
* @param slotHandle slot handle specifying the card to get exclusive access for
* @param ifdName Name of the IFD in which the card is inserted
*/
private void waitForExclusiveCardAccess(byte[] slotHandle, String ifdName) throws RecognitionException {
String resultMajor;
int i = 2;
do {
// try to get exclusive card access for the recognition run
BeginTransaction trans = new BeginTransaction();
trans.setSlotHandle(slotHandle);
BeginTransactionResponse resp = (BeginTransactionResponse) env.getDispatcher().safeDeliver(trans);
resultMajor = resp.getResult().getResultMajor();
if (!resultMajor.equals(ECardConstants.Major.OK)) {
String resultMinor = resp.getResult().getResultMinor();
if (ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE.equals(resultMinor)) {
throw new RecognitionException("Card is not available anymore.");
}
// could not get exclusive card access, wait in increasingly longer intervals and retry
try {
long waitInSeconds = fibonacci(i);
i++;
LOG.debug("Could not get exclusive card access. Trying again in {} seconds.", waitInSeconds);
if (i == 6 && gui != null) {
MessageDialog dialog = gui.obtainMessageDialog();
String message = LANG.translationForKey("message", AppVersion.getName(), ifdName);
String title = LANG.translationForKey("error", ifdName);
dialog.showMessageDialog(message, title, DialogType.WARNING_MESSAGE);
}
Thread.sleep(1000 * waitInSeconds);
} catch (InterruptedException e) {
// ignore
}
}
} while (!resultMajor.equals(ECardConstants.Major.OK));
}
Aggregations