2

Android フォン (Nexus 4) にさまざまな NfcV コマンドを実装しようとしています。現在、これらのタグを使用しています。データシートによると、「Be Quiet」コマンドをサポートする必要があります。

残念ながら、以下のソース コードを正しく動作させることができません。「Stay Quiet」コマンドの後の「Inventory」コマンドと「Read Single Block」コマンドは、両方のコマンドがアドレス指定されていないため失敗することが予想されますが、Quiet 状態のタグは無視する必要があります。しかし、タグから UID またはペイロードを含む正しい答えが得られます。

また、"Stay Quiet" コマンドを実行すると、"Tag was lost" という例外が発生します。ただし、ISO 15693-3 によれば、タグはこのコマンドに応答しないはずであり、とにかくこの例外につながる可能性があります。

それでも、このコードの「Stay Quiet」コマンドに何か問題があると思いますが、何が原因かわかりません。

どんな助けでも大歓迎です。

ソースコード:

            NfcV nfcv = NfcV.get(mtag);


                try{
                    nfcv.connect();                                                             //Connect
                } catch(IOException e){
                    mUIDs = mUIDs + "\nConnection Error 1";
                }


                byte[] response1 = {(byte) 0x00};
                try{
                    byte[] UIDreq1 = InventoryRequest();                                        //Inventory Request
                    response1 = nfcv.transceive(UIDreq1);
                } catch(IOException e){
                    mUIDs = mUIDs + "\nInventory Error 1";
                }
                mUIDs = mUIDs +"\n" + bytesToHex(response1);
                byte[] UID = response2UID(response1);
                mUIDs = mUIDs + "\n" + bytesToHex(UID);


                try{
                    byte[] command = ReadSingleBlockUnadressed((byte) 0x04);                    //Reading Single Block
                    byte[] data = nfcv.transceive(command);
                    mUIDs = mUIDs +"\n"+bytesToHex(data);
                }catch(IOException e){
                    Log.e("Reading Single Block", e.getMessage());
                    mUIDs = mUIDs + "\nReading Error";
                }


                try{
                    try{
                        byte[] command = StayQuiet(UID);                                        //Stay Quiet, SHOULD FAIL
                        nfcv.transceive(command);
                    }catch(TagLostException e){
                        Log.e("Stay Quiet", e.getMessage());
                        mUIDs = mUIDs + "\nTag was lost.";
                    }
                    }catch(IOException x){
                    mUIDs = mUIDs + "\nStay Quiet Error";
                }


                try{
                    byte[] command = ReadSingleBlockUnadressed((byte) 0x04);                    //Reading Single Block
                    byte[] data = nfcv.transceive(command);
                    mUIDs = mUIDs +"\n"+bytesToHex(data);
                }catch(IOException e){
                    Log.e("Reading Single Block", e.getMessage());
                    mUIDs = mUIDs + "\nReading Error";
                }

                try{
                    byte[] UIDreq2 = InventoryRequest();                                        //Inventory Request, SHOULD FAIL
                    byte[] response2 = nfcv.transceive(UIDreq2);
                    mUIDs = mUIDs +"\n" + bytesToHex(response2);
                } catch(IOException e){
                    mUIDs = mUIDs + "\nInventory Error 2";
                }


                try{
                    nfcv.close();                                                               //Disconnect
                } catch(IOException x){
                    mUIDs = mUIDs + "\nDisconnection Error 1";
                }


                mTagTextView.setText(mUIDs);

次の機能を使用します。

final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
    char[] hexChars = new char[bytes.length * 2];
    int v;
    for ( int j = 0; j < bytes.length; j++ ) {
        v = bytes[j] & 0xFF;
        hexChars[j * 2] = hexArray[v >>> 4];
        hexChars[j * 2 + 1] = hexArray[v & 0x0F];
    }
    return new String(hexChars);
}
private byte[] response2UID(byte[] response){
    byte[] UID = new byte[response.length-2];
    for(int i = 2; i < response.length; i++){
        UID[i-2]=response[i];
    }
    return UID;
}

private byte[] ReadSingleBlockUnadressed(byte blocknumber){
    return new byte[] {(byte) 0x00, (byte) 0x20, blocknumber};
}
private byte[] StayQuiet(byte[] UID){
    byte[] beQuiet = new byte[] {(byte) 0x04, (byte) 0x02}; 
    byte[] command = combine(beQuiet, UID);
    return command;
}

private byte[] InventoryRequest(){
    return new byte[] { (byte) 0x24, (byte) 0x01, (byte) 0x00};
}
4

1 に答える 1

2

STAY QUITE コマンドを送信すると、タグが選択された状態から選択されていない状態になります。

次に、フラグ値 0x00 を指定して READ SINGLE BLOCK コマンドを送信します。

ISO/IEC 15693-3 規格によれば、これは Select_flag (ビット 5) がゼロであることを意味します。標準では、このビットの使用法を次のように定義しています。

Bit 5 = 0: Request shall be executed by any VICC according to the
setting of Address_flag

Bit 5 = 1: Request shall be executed only by VICC in selected state

Address_flag は次のように定義されています (値はゼロです)。

Bit 6 = 0: Request is not addressed. UID field is not present. It shall be
executed by any VICC.

Bit 6 = 1: Request is addressed. UID field is present. It shall be
executed only by the VICC whose UID matches the UID
specified in the request.

READ SINGLE BLOCK コマンドで使用したフラグを使用して、タグが選択されていなくてもタグに応答するように指示しました。それが機能する理由です。

ユースケースでは、Select_flag (ビット 5) を 1 に、Address_flag を 0 にします。

ISO/IEC 15693-3 標準を確認することをお勧めします。そのコピーはオンラインでここにあります: http://www.waazaa.org/download/fcd-15693-3.pdf

ところで、NFC サービスがタグの存在を常にチェックしているため、「タグが失われました」という例外が発生します。ISO15693 の場合、INVENTORY はすべての ISO15693 タグが理解できる数少ないコマンドの 1 つであるため、おそらく裏で INVENTORY コマンドを送信することによってそうします。

これを制御することはできないため、タグを黙らせようとする試みを妨害する可能性があります。

于 2013-11-05T11:57:22.650 に答える