ISO15693のメモリブロック情報は1加算する

現在、ISO15693規格のRFID VICCにアクセスするためのライブラリィを書いているが、かなりはまったので書いておく。

NFCとNFCラベルプリンタ RL-700S
@touchRLさんの資料によると、本機で印刷したRFIDラベルのブロック数は28、ブロックサイズは4(byte)とある。なのでそれを定数としてデータの読書をしても良いのだが、せっかくわざわざNDEFを使わずにISO15693にフルアクセスしようとしているのだから本規格のコマンドの一つである"Get System Information"を実装して実際のRFIDのメモリ構造を取得してみた。

ISO15693Tag.java (まだ作りかけ)
public GetSystemInformationResponse getSystemInformation() throws ISO15693Exception  {
    if ( mNfcTag == null ) {
        throw new ISO15693Exception("tagService is null. can not execution");
    }
    // get System Information
    GetSystemInformationRequest req = 
        new GetSystemInformationRequest*1;
        return new GetSystemInformationResponse(result); 
    } catch (NfcException e) {
        throw new ISO15693Exception(e);
    }
}

これで取得できたメモリ情報は以下の通りだった。

    • 読み込んだバイト列の12, 13バイト
[12] 0x1b
[13] 0x03

ISO15693の"Get System Information"の戻り値によると、12バイト目がブロック数、13バイト目の5bitがブロックサイズとなっている。なので、ブロック数が27、ブロックサイズが3バイトと戻っているのだ。これはおかしい。それぞれ@touchRLさんの資料と比べても1少ない。

ここで1時間程仕様とにらめっこしたり、自分のコードにバグが無いかと探したのだが、問題は私の英語力だった。

ISO15693の仕様で入手可能なドラフト版は英語版しか無いのだが、その資料のメモリ構造の注釈に以下の一文があるのを見つけた。

Block size is expressed in number of bytes on 5 bits, allowing to specify up to 32 bytes i.e. 256 bits. It is one less than the actual number of bytes. E.g. a value of '1F' indicates 32 bytes, a value of '00' indicates1 byte.
Number of blocks is on 8 bits, allowing to specify up to 256 blocks. It is one less than the actual number of blocks. E.g. a value of 'FF' indicates 256 blocks, a value of '00' indicates 1 block.

「ISO/IEC FCD 15693-3
Identification cards ― Contactless integrated circuit(s) cards - Vicinity cards ― Part 3: Anti-collision and transmission protocol」

簡単に言うと、0オリジンということだ。なので、実際の数としてはそれぞれ1加算して仕様通りの値となる。

英語力が無いとこういう細かい文書をフィルタして読まないことが多く、それがうろ覚えや理解不足の原因となるのだ。情けない。

*1:byte) (( DATA_RATE_HIGH | ADDRESSED_MODE ) & 0xff) , mUID ); try { byte[] result = ISO15693Lib.transceive(mNfcTag, req.getBytes(