简体   繁体   English

在Mifare Desfire中创建标准数据文件

[英]Create Standard Data File in Mifare Desfire

Create File in Mifare Desfire. 在Mifare Desfire中创建文件。 Return error response like 0x0E DESFire card related exception has occurred. 返回错误响应,如0x0E DESFire卡相关的异常已发生。 what is the correct command to create files in mifare desfire 在mifare desfire中创建文件的正确命令是什么

CreateStdDataFile(FileNo,Com.Set.,AccessRights,FileSize)
        [8bytes]

public void CreateFile() throws Exception {
    byte[] buffer = new byte[7];
    buffer[0] = (byte) ((0x00)); //file Number
    buffer[1] = (byte) ((0xFF)); //Comm. Sett.
    buffer[2] = (byte) (0x00); // 2 & 3 Access Rights
    buffer[3] = (byte) (0x04);
    buffer[4] = (byte) (0x00);  // 4 & 5 & 6 File Size
    buffer[5] = (byte) (0x00);
    buffer[6] = (byte) (0x0F);

    sendRequest(CREATE_FILE,buffer);
}

try
{
    reader.CreateFile();
}
catch (Exception e) {
    Log.d(TAG, "Problem accessing Desfire tag", e);
} finally {
    try {
        isoDep.close();
    } catch (IOException e) {
        // ignore
    }
}

The problem you are experiencing is endianness . 您遇到的问题是字节序 (See in particular the Illustration section.) (特别请参见插图部分。)

The DESFire instruction requires you to pass the file size in the least significant byte order (little-endian), but your code uses the most significant byte order (big-endian). DESFire指令要求您以最低有效字节顺序(little-endian)传递文件大小,但是您的代码使用最高有效字节顺序(big-endian)。

The way you currently have it in your code ( 0x00, 0x00, 0x0F ) you are not asking for a file of size 0x00000F (15) bytes, but 0x0F0000 (983 040) bytes. 您目前它在你的代码的方式( 0x00, 0x00, 0x0F )你是不是要求的大小的文件0x00000F (15)个字节,但0x0F0000 (983 040)字节。

To request a file of size 15 bytes, your code should be: 要请求15字节大小的文件,您的代码应为:

// ...
buffer[4] = (byte)0x0F;
buffer[5] = (byte)0x00;
buffer[6] = (byte)0x00;
// ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM