usb: respect automatic PPS feature flag

If the feature flag is set, don't do PPS negotiation. Closes #2219
This commit is contained in:
Vincent Breitmoser
2018-03-22 15:51:35 +01:00
parent a9c5d47104
commit 1e7ed06698
4 changed files with 22 additions and 1 deletions

View File

@@ -36,6 +36,8 @@ abstract class CcidDescription {
// dwFeatures Masks
private static final int FEATURE_AUTOMATIC_VOLTAGE = 0x00008;
private static final int FEATURE_AUTOMATIC_PPS = 0x00080;
private static final int FEATURE_EXCHANGE_LEVEL_TPDU = 0x10000;
private static final int FEATURE_EXCHAGE_LEVEL_SHORT_APDU = 0x20000;
private static final int FEATURE_EXCHAGE_LEVEL_EXTENDED_APDU = 0x40000;
@@ -130,6 +132,10 @@ abstract class CcidDescription {
}
}
boolean hasAutomaticPps() {
return hasFeature(FEATURE_AUTOMATIC_PPS);
}
private boolean hasFeature(int feature) {
return (getFeatures() & feature) != 0;
}

View File

@@ -258,6 +258,10 @@ public class CcidTransceiver {
}
}
public boolean hasAutomaticPps() {
return usbCcidDescription.hasAutomaticPps();
}
/** Corresponds to 6.2.1 RDR_to_PC_DataBlock. */
@AutoValue
public abstract static class CcidDataBlock {

View File

@@ -54,7 +54,10 @@ public class T1TpduProtocol implements CcidTransportProtocol {
// TODO: set checksum from atr
blockFactory = new T1TpduBlockFactory(BlockChecksumAlgorithm.LRC);
performPpsExchange();
boolean skipPpsExchange = ccidTransceiver.hasAutomaticPps();
if (!skipPpsExchange) {
performPpsExchange();
}
}
private void performPpsExchange() throws UsbTransportException {

View File

@@ -269,6 +269,14 @@ public class CcidTransceiverTest {
assertArrayEquals(Hex.decode(responseData), ccidDataBlock.getData());
}
@Test
public void testReturnsCorrectAutoPpsFlag() throws Exception {
CcidDescription description = CcidDescription.fromValues((byte) 0, (byte) 7, 3, 65722);
CcidTransceiver ccidTransceiver = new CcidTransceiver(usbConnection, usbBulkIn, usbBulkOut, description);
assertTrue(ccidTransceiver.hasAutomaticPps());
}
private void verifyDialog() {
assertTrue(expectReplies.isEmpty());
assertFalse(expectRepliesVerify.isEmpty());