タグが NXP タグ (UID は 0x04 で始まる) であることがわかったら、
最初に GET_VERSION コマンドを送信します。このコマンドが成功すると、タグが EV1 以降 (MIFARE Ultralight EV1、NTAG21x) であることがわかります。それ以外の場合は、第 1 世代のタグ (MIFARE Ultralight、Ultralight C、NTAG203) であると想定できます。
タグが EV1 タグの場合は、GET_VERSION コマンドへの応答を分析して続行できます。これにより、製品タイプ (NTAG または Ultralight EV1) だけでなく、製品のサブタイプ、製品バージョン、およびストレージ サイズ (正確なチップ タイプを特定できるようになります) が明らかになります。
+------------+------+---------+-----------+------- -------+
| | チップ | タイプ | サブタイプ | バージョン | 収納サイズ |
+------------+------+---------+-----------+------- -------+
| | NTAG210 | 0x04 | 0x01 | 0x01 0x00 | 0x0B |
| | NTAG212 | 0x04 | 0x01 | 0x01 0x00 | 0x0E |
| | NTAG213 | 0x04 | 0x02 | 0x01 0x00 | 0x0F |
| | NTAG213F | 0x04 | 0x04 | 0x01 0x00 | 0x0F |
| | NTAG215 | 0x04 | 0x02 | 0x01 0x00 | 0x11 |
| | NTAG216 | 0x04 | 0x02 | 0x01 0x00 | 0x13 |
| | NTAG216F | 0x04 | 0x04 | 0x01 0x00 | 0x13 |
+------------+------+---------+-----------+------- -------+
| | NT3H1101 | 0x04 | 0x02 | 0x01 0x01 | 0x13 |
| | NT3H1101W0 | 0x04 | 0x05 | 0x02 0x01 | 0x13 |
| | NT3H2111W0 | 0x04 | 0x05 | 0x02 0x02 | 0x13 |
| | NT3H2101 | 0x04 | 0x02 | 0x01 0x01 | 0x15 |
| | NT3H1201W0 | 0x04 | 0x05 | 0x02 0x01 | 0x15 |
| | NT3H2211W0 | 0x04 | 0x05 | 0x02 0x02 | 0x15 |
+------------+------+---------+-----------+------- -------+
| | MF0UL1101 | 0x03 | 0x01 | 0x01 0x00 | 0x0B |
| | MF0ULH1101 | 0x03 | 0x02 | 0x01 0x00 | 0x0B |
| | MF0UL2101 | 0x03 | 0x01 | 0x01 0x00 | 0x0E |
| | MF0ULH2101 | 0x03 | 0x02 | 0x01 0x00 | 0x0E |
+------------+------+---------+-----------+------- -------+
タグが EV1 タグでない場合は、AUTHENTICATE (パート 1) コマンドを送信できます。このコマンドが成功すると、タグが MIFARE Ultralight C であることがわかります。それ以外の場合は、タグが Ultralight または NTAG203 であると想定できます。
MIFARE Ultralight と NTAG203 を区別するために、Ultralight に存在しないページを読み取ろうとすることができます (たとえば、41 ページを読み取ります)。
NfcA
またはMifareUltralight
(タグで利用可能な場合) タグ テクノロジを使用して、タグにコマンドを送信できます。
boolean testCommand(NfcA nfcA, byte[] command) throws IOException {
final boolean leaveConnected = nfcA.isConnected();
boolean commandAvailable = false;
if (!leaveConnected) {
nfcA.connect();
}
try {
byte[] result = nfcA.transceive(command);
if ((result != null) &&
(result.length > 0) &&
!((result.length == 1) && ((result[0] & 0x00A) == 0x000))) {
// some response received and response is not a NACK response
commandAvailable = true;
// You might also want to check if you received a response
// that is plausible for the specific command before you
// assume that the command is actualy available and what
// you expected...
}
} catch (IOException e) {
// IOException (including TagLostException) could indicate that
// either the tag is no longer in range or that the command is
// not supported by the tag
}
try {
nfcA.close();
} catch (Exception e) {}
if (leaveConnected) {
nfcA.connect();
}
return commandAvailable;
}
コマンドがタグでサポートされていない場合、一部の NFC スタックはIOException
(通常は) を生成することに注意してください。TagLostException
NACK 応答またはIOException
サポートされていないコマンドの受信に関係なく、他のコマンドを送信し続ける前にタグの状態をリセットするために、後でタグを切断して再接続する必要があります。