CcidTransceiver: Adjust line lengths
100 characters with exceptions made for CLI commands, URIs and imports. Some of this is existing code, but for the sake of consistency, we'll wrap all at 100 characters. Function arguments: when this happens, if we put the closing `)` on its own line (like `}` in code blocks), it visually stands out better for indicating where the function call ends.
This commit is contained in:
committed by
Vincent Breitmoser
parent
fec3f85fad
commit
0fcd77d61d
@@ -219,7 +219,8 @@ public class CcidTransceiver {
|
|||||||
* @param levelParam Level parameter
|
* @param levelParam Level parameter
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public synchronized CcidDataBlock sendXfrBlock(byte[] payload, short levelParam) throws UsbTransportException {
|
private synchronized CcidDataBlock sendXfrBlock(byte[] payload, short levelParam)
|
||||||
|
throws UsbTransportException {
|
||||||
long startTime = SystemClock.elapsedRealtime();
|
long startTime = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
int l = payload.length;
|
int l = payload.length;
|
||||||
@@ -256,12 +257,16 @@ public class CcidTransceiver {
|
|||||||
ignoredBytes = usbConnection.bulkTransfer(
|
ignoredBytes = usbConnection.bulkTransfer(
|
||||||
usbBulkIn, inputBuffer, inputBuffer.length, DEVICE_SKIP_TIMEOUT_MILLIS);
|
usbBulkIn, inputBuffer, inputBuffer.length, DEVICE_SKIP_TIMEOUT_MILLIS);
|
||||||
if (ignoredBytes > 0) {
|
if (ignoredBytes > 0) {
|
||||||
Timber.e("Skipped " + ignoredBytes + " bytes: " + toHexString(inputBuffer, 0, ignoredBytes));
|
Timber.e(
|
||||||
|
"Skipped " + ignoredBytes + " bytes: "
|
||||||
|
+ toHexString(inputBuffer, 0, ignoredBytes)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} while (ignoredBytes > 0);
|
} while (ignoredBytes > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CcidDataBlock receiveDataBlock(byte expectedSequenceNumber) throws UsbTransportException {
|
private CcidDataBlock receiveDataBlock(byte expectedSequenceNumber)
|
||||||
|
throws UsbTransportException {
|
||||||
CcidDataBlock response;
|
CcidDataBlock response;
|
||||||
do {
|
do {
|
||||||
response = receiveDataBlockImmediate(expectedSequenceNumber);
|
response = receiveDataBlockImmediate(expectedSequenceNumber);
|
||||||
@@ -274,7 +279,8 @@ public class CcidTransceiver {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CcidDataBlock receiveDataBlockImmediate(byte expectedSequenceNumber) throws UsbTransportException {
|
private CcidDataBlock receiveDataBlockImmediate(byte expectedSequenceNumber)
|
||||||
|
throws UsbTransportException {
|
||||||
/*
|
/*
|
||||||
* Some USB CCID devices (notably NitroKey 3) may time-out and need a subsequent poke to
|
* Some USB CCID devices (notably NitroKey 3) may time-out and need a subsequent poke to
|
||||||
* carry on communications. No particular reason why the number 3 was chosen. If we get a
|
* carry on communications. No particular reason why the number 3 was chosen. If we get a
|
||||||
@@ -285,7 +291,9 @@ public class CcidTransceiver {
|
|||||||
Timber.d("Receive data block immediate seq=%d", expectedSequenceNumber);
|
Timber.d("Receive data block immediate seq=%d", expectedSequenceNumber);
|
||||||
int readBytes;
|
int readBytes;
|
||||||
do {
|
do {
|
||||||
readBytes = usbConnection.bulkTransfer(usbBulkIn, inputBuffer, inputBuffer.length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS);
|
readBytes = usbConnection.bulkTransfer(
|
||||||
|
usbBulkIn, inputBuffer, inputBuffer.length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS
|
||||||
|
);
|
||||||
Timber.d("Received " + readBytes + " bytes: " + toHexString(inputBuffer));
|
Timber.d("Received " + readBytes + " bytes: " + toHexString(inputBuffer));
|
||||||
} while ((readBytes <= 0) && (attempts-- > 0));
|
} while ((readBytes <= 0) && (attempts-- > 0));
|
||||||
|
|
||||||
@@ -294,12 +302,17 @@ public class CcidTransceiver {
|
|||||||
}
|
}
|
||||||
if (inputBuffer[0] != (byte) MESSAGE_TYPE_RDR_TO_PC_DATA_BLOCK) {
|
if (inputBuffer[0] != (byte) MESSAGE_TYPE_RDR_TO_PC_DATA_BLOCK) {
|
||||||
if (expectedSequenceNumber != inputBuffer[6]) {
|
if (expectedSequenceNumber != inputBuffer[6]) {
|
||||||
throw new UsbTransportException("USB-CCID error - bad CCID header, type " + inputBuffer[0] + " (expected " +
|
throw new UsbTransportException(
|
||||||
MESSAGE_TYPE_RDR_TO_PC_DATA_BLOCK + "), sequence number " + inputBuffer[6] + " (expected " +
|
"USB-CCID error - bad CCID header, type " + inputBuffer[0] + " (expected " +
|
||||||
expectedSequenceNumber + ")");
|
MESSAGE_TYPE_RDR_TO_PC_DATA_BLOCK + "), sequence number " + inputBuffer[6]
|
||||||
|
+ " (expected " +
|
||||||
|
expectedSequenceNumber + ")"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new UsbTransportException("USB-CCID error - bad CCID header type " + inputBuffer[0]);
|
throw new UsbTransportException(
|
||||||
|
"USB-CCID error - bad CCID header type " + inputBuffer[0]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
CcidDataBlock result = CcidDataBlock.parseHeaderFromBytes(inputBuffer);
|
CcidDataBlock result = CcidDataBlock.parseHeaderFromBytes(inputBuffer);
|
||||||
|
|
||||||
@@ -313,9 +326,13 @@ public class CcidTransceiver {
|
|||||||
System.arraycopy(inputBuffer, CCID_HEADER_LENGTH, dataBuffer, 0, bufferedBytes);
|
System.arraycopy(inputBuffer, CCID_HEADER_LENGTH, dataBuffer, 0, bufferedBytes);
|
||||||
|
|
||||||
while (bufferedBytes < dataBuffer.length) {
|
while (bufferedBytes < dataBuffer.length) {
|
||||||
readBytes = usbConnection.bulkTransfer(usbBulkIn, inputBuffer, inputBuffer.length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS);
|
readBytes = usbConnection.bulkTransfer(
|
||||||
|
usbBulkIn, inputBuffer, inputBuffer.length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS
|
||||||
|
);
|
||||||
if (readBytes < 0) {
|
if (readBytes < 0) {
|
||||||
throw new UsbTransportException("USB error - failed reading response data! Header: " + result);
|
throw new UsbTransportException(
|
||||||
|
"USB error - failed reading response data! Header: " + result
|
||||||
|
);
|
||||||
}
|
}
|
||||||
System.arraycopy(inputBuffer, 0, dataBuffer, bufferedBytes, readBytes);
|
System.arraycopy(inputBuffer, 0, dataBuffer, bufferedBytes, readBytes);
|
||||||
bufferedBytes += readBytes;
|
bufferedBytes += readBytes;
|
||||||
@@ -329,14 +346,20 @@ public class CcidTransceiver {
|
|||||||
private void sendRaw(byte[] data, int offset, int length) throws UsbTransportException {
|
private void sendRaw(byte[] data, int offset, int length) throws UsbTransportException {
|
||||||
int tr1;
|
int tr1;
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
tr1 = usbConnection.bulkTransfer(usbBulkOut, data, offset, length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS);
|
tr1 = usbConnection.bulkTransfer(
|
||||||
|
usbBulkOut, data, offset, length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
byte[] dataToSend = Arrays.copyOfRange(data, offset, offset+length);
|
byte[] dataToSend = Arrays.copyOfRange(data, offset, offset+length);
|
||||||
tr1 = usbConnection.bulkTransfer(usbBulkOut, dataToSend, dataToSend.length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS);
|
tr1 = usbConnection.bulkTransfer(
|
||||||
|
usbBulkOut, dataToSend, dataToSend.length, DEVICE_COMMUNICATE_TIMEOUT_MILLIS
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tr1 != length) {
|
if (tr1 != length) {
|
||||||
throw new UsbTransportException("USB error - failed to transmit data (" + tr1 + "/" + length + ")");
|
throw new UsbTransportException(
|
||||||
|
"USB error - failed to transmit data (" + tr1 + "/" + length + ")"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +405,9 @@ public class CcidTransceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new AutoValue_CcidTransceiver_CcidDataBlock(
|
return new AutoValue_CcidTransceiver_CcidDataBlock(
|
||||||
getDataLength(), getSlot(), getSeq(), getStatus(), getError(), getChainParameter(), data);
|
getDataLength(), getSlot(), getSeq(), getStatus(), getError(),
|
||||||
|
getChainParameter(), data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte getIccStatus() {
|
byte getIccStatus() {
|
||||||
@@ -398,7 +423,8 @@ public class CcidTransceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isStatusSuccess() {
|
boolean isStatusSuccess() {
|
||||||
return getIccStatus() == ICC_STATUS_SUCCESS && getCommandStatus() == COMMAND_STATUS_SUCCESS;
|
return getIccStatus() == ICC_STATUS_SUCCESS
|
||||||
|
&& getCommandStatus() == COMMAND_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user