Skip to content

Commit

Permalink
Various acr 1255 changes + start of publish to maven central
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Mar 1, 2020
1 parent fb10a6e commit 837708d
Show file tree
Hide file tree
Showing 32 changed files with 515 additions and 212 deletions.
4 changes: 1 addition & 3 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 29
buildToolsVersion "29.0.3"

lintOptions {
Expand Down
1 change: 1 addition & 0 deletions api/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POM_ARTIFACT_ID=api
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ interface IAcr1255UReaderControl {

byte[] setSleepModeOption(byte option);

byte[] setAutomaticPolling(boolean on);

}
16 changes: 14 additions & 2 deletions api/src/main/java/com/github/skjolber/nfc/acs/Acr1255UReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public boolean setDefaultLEDAndBuzzerBehaviour(AcrDefaultLEDAndBuzzerBehaviour .
}


public boolean setAutoPPS(AcrCommunicationSpeed tx, AcrCommunicationSpeed rx) {
public boolean setAutomaticPICCPollingSpeed(AcrCommunicationSpeed tx, AcrCommunicationSpeed rx) {
byte[] response;
try {

Expand Down Expand Up @@ -408,7 +408,7 @@ public boolean setAutoPPS(AcrCommunicationSpeed tx, AcrCommunicationSpeed rx) {
* @return list of Max Tx Speed, Current Tx Speed, Max Rx Speed, Current Rx Speed
*/

public List<AcrCommunicationSpeed> getAutoPPS() {
public List<AcrCommunicationSpeed> getAutomaticPICCPollingSpeed() {
byte[] response;
try {
response = readerControl.getAutoPPS();
Expand Down Expand Up @@ -585,4 +585,16 @@ public boolean setSleepModeOption(int seconds) {

return readBoolean(response);
}

public boolean setAutomaticPolling(boolean on) {
byte[] response;
try {
response = readerControl.setAutomaticPolling(on);
} catch (RemoteException e) {
throw new AcrReaderException(e);
}

return readBoolean(response);
}

}
54 changes: 51 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,62 @@ buildscript {
}
}

allprojects {
plugins {
id "com.vanniktech.maven.publish" version '0.9.0' apply false
id 'com.github.ben-manes.versions' version '0.28.0' apply false
id 'org.owasp.dependencycheck' version '5.3.0' apply false
id "com.github.spotbugs" version "3.0.0" apply false
}

def buildProjects() {
subprojects.findAll { new File(it.projectDir, 'build.gradle').file }
}

def exampleProjects() {
buildProjects().findAll { it.name.endsWith("-example") || it.projectDir.path.substring(rootProject.projectDir.path.length()).contains('examples') }
}

def libraryProjects() {
buildProjects().findAll { !exampleProjects().contains(it) }
}

configure(buildProjects()) {
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'org.owasp.dependencycheck'
apply plugin: 'com.github.spotbugs'

repositories {
google()
jcenter()
}
}

configure(exampleProjects()) {
apply plugin: 'com.android.application'

}

task clean(type: Delete) {
delete rootProject.buildDir
configure(libraryProjects()) {
apply plugin: 'com.android.library'
apply plugin: 'com.vanniktech.maven.publish'
}

allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'

eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
}
}

// Tell idea to output to build/classes/main instead of /out/
idea {
module {
outputDir file('build/classes/main')
testOutputDir file('build/classes/test')
}
}
}
16 changes: 1 addition & 15 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 29
buildToolsVersion '29.0.3'

lintOptions {
Expand Down Expand Up @@ -32,15 +30,3 @@ dependencies {
testImplementation 'org.mockito:mockito-core:1.10.19'
}

task clearJar(type: Delete) {
delete 'build/outputs/core.jar'
}

task makeJar(type: Copy) {
from('build/intermediates/bundles/library/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'core.jar')
}

makeJar.dependsOn(clearJar, build)
1 change: 1 addition & 0 deletions core/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POM_ARTIFACT_ID=core
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

public class ACR1255BluetoothCommands implements ACR1255Commands, BluetoothReader.OnResponseApduAvailableListener, BluetoothReader.OnEscapeResponseAvailableListener {

private static final String TAG = ACR1255UsbCommands.class.getName();
private static final String TAG = ACR1255BluetoothCommands.class.getName();

private volatile CountDownLatch latch;
private byte[] in;
private volatile byte[] in;

private BluetoothReader reader;
private String name;
Expand Down Expand Up @@ -356,7 +356,7 @@ public byte[] getAutoPPS(int slot) throws ReaderException {
return response.getData();
}

public Boolean setSleepModeOption(int slot, byte option) throws ReaderException {
public boolean setSleepModeOption(int slot, byte option) throws ReaderException {
if (option < 0 || option > 4) throw new RuntimeException();
byte[] command = new byte[]{(byte) 0xE0, 0x00, 0x00, 0x48, option};

Expand All @@ -383,11 +383,11 @@ public CommandAPDU control(int slotNum, int controlCode, CommandAPDU request) th

@Override
public byte[] control(int slotNum, int controlCode, byte[] request) throws ReaderException {
Log.d(TAG, "Raw request: " + Utils.toHexString(request));
Log.d(TAG, "Raw control request: " + Utils.toHexString(request));
try {

in = null;
latch = new CountDownLatch(1);
this.in = null;
this.latch = new CountDownLatch(1);

reader.setOnEscapeResponseAvailableListener(this);
if (!reader.transmitEscapeCommand(request)) {
Expand All @@ -400,7 +400,7 @@ public byte[] control(int slotNum, int controlCode, byte[] request) throws Reade
throw new NfcException("Problem waiting for response");
}

Log.d(TAG, "Raw response: " + Utils.toHexString(in));
Log.d(TAG, "Raw control response: " + Utils.toHexString(in));

return in;
} catch (Exception e) {
Expand All @@ -414,7 +414,7 @@ public byte[] transmit(int slotNum, byte[] command) throws ReaderException {
}

public byte[] transmit(byte[] request) {
Log.d(TAG, "Raw request: " + Utils.toHexString(request));
Log.d(TAG, "Raw transmit request: " + Utils.toHexString(request));
try {

in = null;
Expand All @@ -431,7 +431,7 @@ public byte[] transmit(byte[] request) {
throw new NfcException("Problem waiting for response");
}

Log.d(TAG, "Raw response: " + Utils.toHexString(in));
Log.d(TAG, "Raw transmit response: " + Utils.toHexString(in));

return in;
} catch (Exception e) {
Expand Down Expand Up @@ -464,4 +464,28 @@ public void onEscapeResponseAvailable(BluetoothReader bluetoothReader, byte[] by
public String getName() {
return name;
}

public boolean setAutomaticPolling(int slot, boolean on) throws ReaderException {
byte b = (byte) (on ? 0x01 : 0x00);

CommandAPDU command = new CommandAPDU(0xE0, 0x00, 0x00, 0x40, new byte[]{b});

CommandAPDU response = control(slot, Reader.IOCTL_CCID_ESCAPE, command);

if (!isSuccess(response)) {
throw new IllegalArgumentException("Card responded with error code");
}

boolean result = response.getData()[0] == 0x01;

if (result != on) {
Log.w(TAG, "Unable to properly enable/disable automatic polling: Expected " + on + " got " + result);

return Boolean.FALSE;
} else {
Log.d(TAG, "Updated automatic polling to " + result);

return Boolean.TRUE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public interface ACR1255Commands {
public static final int LED_2_BLUE = 4;
public static final int LED_2_RED = 8;

/**
*
* Note: Defaults to 10001011
*
* @return list of resulting picc parameters.
* @throws ReaderException
*/

List<AcrAutomaticPICCPolling> setAutomaticPICCPolling(int slot, AcrAutomaticPICCPolling... picc) throws ReaderException;

List<AcrAutomaticPICCPolling> getAutomaticPICCPolling(int slot) throws ReaderException;
Expand Down Expand Up @@ -50,9 +58,11 @@ public interface ACR1255Commands {

byte[] getAutoPPS(int slot) throws ReaderException;

Boolean setSleepModeOption(int slot, byte option) throws ReaderException;
boolean setSleepModeOption(int slot, byte option) throws ReaderException;

byte[] control(int slotNum, int controlCode, byte[] command) throws ReaderException;

byte[] transmit(int slotNum, byte[] command) throws ReaderException;

boolean setAutomaticPolling(int slotNum, boolean b) throws ReaderException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public byte[] getAutoPPS(int slot) throws ReaderException {
return response.getData();
}

public Boolean setSleepModeOption(int slot, byte option) throws ReaderException {
public boolean setSleepModeOption(int slot, byte option) throws ReaderException {
if (option < 0 || option > 4) throw new RuntimeException();
byte[] command = new byte[]{(byte) 0xE0, 0x00, 0x00, 0x48, option};

Expand All @@ -360,4 +360,28 @@ public Boolean setSleepModeOption(int slot, byte option) throws ReaderException
return Boolean.TRUE;
}
}

public boolean setAutomaticPolling(int slot, boolean on) throws ReaderException {
byte b = (byte) (on ? 0x01 : 0x00);

CommandAPDU command = new CommandAPDU(0xE0, 0x00, 0x00, 0x40, new byte[]{b});

CommandAPDU response = reader.control2(slot, Reader.IOCTL_CCID_ESCAPE, command);

if (!isSuccess(response)) {
throw new IllegalArgumentException("Card responded with error code");
}

boolean result = response.getData()[0] == 0x01;

if (result != on) {
Log.w(TAG, "Unable to properly update antenna field: Expected " + on + " got " + result);

return Boolean.FALSE;
} else {
Log.d(TAG, "Updated antenna field to " + result);

return Boolean.TRUE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ public byte[] setAntennaField(boolean b) {
}

return returnValue(result, exception);


}

public byte[] getBluetoothTransmissionPower() {
Expand Down Expand Up @@ -288,4 +286,19 @@ public byte[] setSleepModeOption(byte b) {

return returnValue(result, exception);
}

public byte[] setAutomaticPolling(boolean b) {
Boolean result = null;
Exception exception = null;
try {
result = commands.setAutomaticPolling(0, b);
} catch (Exception e) {
Log.d(TAG, "Problem enabling/disabling automatic polling", e);

exception = e;
}

return returnValue(result, exception);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ public void onReaderOpen(Object r, int status) {
} else if (reader instanceof ACR1283Commands) {
acr1283Binder.setCommands((ACR1283Commands) reader);
intent.putExtra(NfcReader.EXTRA_READER_CONTROL, new Acr1283LReader(reader.getName(), acr1283Binder));
} else if (reader instanceof ACR1255UsbCommands) {
acr1255Binder.setCommands((ACR1255UsbCommands) reader);
intent.putExtra(NfcReader.EXTRA_READER_CONTROL, new Acr1255UReader(reader.getName(), acr1255Binder));
} else {
Log.d(TAG, "Not supporting reader extras");
Log.d(TAG, "Not supporting reader extras for " + r);
}
} else if (r instanceof ACR1255BluetoothCommands) {
ACR1255BluetoothCommands reader = (ACR1255BluetoothCommands) r;
acr1255Binder.setCommands(reader);
intent.putExtra(NfcReader.EXTRA_READER_CONTROL, new Acr1255UReader(reader.getName(), acr1255Binder));
} else {
Log.d(TAG, "Not supporting reader extras for " + r);
}
} else {
Log.d(TAG, "No reader extras");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,13 @@ public byte[] setLEDs(int leds) throws RemoteException {
return wrapper.setLEDs(leds);
}

@Override
public byte[] setAutomaticPolling(boolean b) throws RemoteException {
if (wrapper == null) {
return noReaderException();
}
return wrapper.setAutomaticPolling(b);
}


}
Loading

0 comments on commit 837708d

Please sign in to comment.