I'm developing an application in Java, where I want to send a URL in an NDEF message, which then gets opened on a mobile device. I was able to do this through the acr1252u's Card Emulation Mode with Mifare Ultralight for a URL for example "http://www.google.com" since this fits in the emulated card's memory, which if I understand correctly is 52 bytes, but I would like to send a much longer URL (around 350-550 bytes), which probably is not possible with HCE on this device. The acr1252 supports peer-to-peer comms as well, but not sure how I could use it to serve the task. Could anyone please point me in a direction that could help me in this persuit?
The code I used for shorter URL using HCE:
public static void main(String[] args) throws CardException {
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
CardTerminal terminal = terminals.get(0);
Card device = terminal.connect("DIRECT");
enterHostCardEmulation(device);
byte[] ndef = new byte[] {(byte) 0xE1, 0x10, 0x06, 0x00,
0x03, 0x0F, (byte) 0xD1, 0x01,
0x0B, 0x55, 0x01, 0x67,
0x6F, 0x6F, 0x67, 0x6C,
0x65, 0x2E, 0x63, 0x6F,
0x6D, (byte) 0xFE, 0x00, 0x00};
byte[] response = writeCardEmulationData(device, (byte) 0x01, (byte) 0x00, ndef);
System.out.println("response: " + byteArrayToHex(response));
}
private static byte[] writeCardEmulationData(Card device, byte nfcMode, byte startOffset, byte[] dataToWrite) {
byte[] command = new byte[9+dataToWrite.length];
command[0] = (byte) 0xE0; // Class
command[1] = 0x00; // INS
command[2] = 0x00; // P1
command[3] = 0x60; // P2
command[4] = (byte) (dataToWrite.length + 0x04); // Length + 4
command[5] = 0x01;
command[6] = nfcMode;
command[7] = startOffset;
command[8] = (byte) dataToWrite.length;
System.arraycopy(dataToWrite, 0, command, 9, dataToWrite.length);
System.out.println(byteArrayToHex(command));
try {
return device.transmitControlCommand(SCARD_CTL_CODE(3500), command);
} catch (CardException e) {
e.printStackTrace();
return null;
}
}
private static void enterHostCardEmulation(Card device) {
try {
System.out.println("NFC device: " + device);
byte[] hceCommand = new byte[] {(byte) 0xE0, 0x00, 0x00, 0x40, 0x03, 0x01, 0x00, 0x00};
byte[] hceResponse = device.transmitControlCommand(SCARD_CTL_CODE(3500), hceCommand);
System.out.println("enter HCE response: " + byteArrayToHex(hceResponse));
} catch (CardException e) {
e.printStackTrace();
}
}
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
public static String byteArrayToHex(byte[] byteArr) {
char[] hexChars = new char[byteArr.length * 2];
for (int j = 0; j < byteArr.length; j++) {
int v = byteArr[j] & 0xFF;
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
}
return new String(hexChars);
}
public static int SCARD_CTL_CODE(int command) {
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
if (isWindows) {
return 0x00310000 | (command << 2);
} else {
return 0x42000000 | command;
}
}