Forum / MIFARE SDK / DesFire EV2 read linear record
Tagged: desfire ev2, linear record
-
Hi
I have created an application with AES Application Key.
EV2ApplicationKeySettings appsettings = appsetbuilder
.setAppKeySettingsChangeable(true)
.setAppMasterKeyChangeable(true)
.setAuthenticationRequiredForFileManagement(true)
.setAuthenticationRequiredForDirectoryConfigurationData(false)
.setKeyTypeOfApplicationKeys(KeyType.AES128)
.setMaxNumberOfApplicationKeys(1)
.setApplicationKeySets(true)
.setNumberOfKeySets(2)
.build();
I then changed the key from default to custom. Created a Linear Record File. I can write data to the file but cannot read the file content.
desFireEV2.createFile(objectFileNo, new DESFireFile.LinearRecordFileSettings(
IDESFireEV1.CommunicationType.Plain, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
fileSize, 1, 0));
byte[] data = userJson.getBytes(encode);
desFireEV2.writeRecord(objectFileNo, 0, data);
desFireEV2.commitTransaction();
byte[] userData = desFireEV2.readRecords(objectFileNo, 0, 1);
In the above last line with readRecords, I get om.nxp.nfclib.exceptions.InvalidResponseLengthException: Boundary Error
Please help
+ 0 | - 0
Hi Jagesh,
“InvalidResponseLengthException” indicates that the expected bytes to read differ from what was sent.
You should exactly specify how many bytes you want to read. For the MIFARE DESFire you usually use the offset and the length parameters. Please keep in mind, reading from the card is a more costly operation as reading from a file on a PC.
The TapLinx team
+ 0 | - 0
Hi Support,
After much debugging I found out that after
desFireEV2.createFile(1, new DESFireFile.LinearRecordFileSettings(
IDESFireEV1.CommunicationType.Enciphered, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
fileSize, 1, 1));
desFireEV2.writeRecord(1, 0, data, IDESFireEV1.CommunicationType.Enciphered);
desFireEV2.commitTransaction();
When I read the file settings with
DESFireFile.LinearRecordFileSettings fileSettings = (DESFireFile.LinearRecordFileSettings) desFireEV2.getFileSettings(1);
And log the result with
Log.i(TAG, "fileSettings: => MaxNumberOfRecords: " + fileSettings.getMaxNumberOfRecords()
+ " CurrentNumberOfRecords: " + fileSettings.getCurrentNumberOfRecords() +
" RecordSize: " + fileSettings.getRecordSize() + " fileType: " + fileSettings.getType());
I am getting the 0 as currentNumberOfRecords
I/DemoActivity: fileSettings: => MaxNumberOfRecords: 3, CurrentNumberOfRecords: 0, RecordSize: 500, fileType: RecordLinear
Why is the currentNumberOfRecords = 0?
I am banging my head to understand.
Thanks in advance.
+ 0 | - 0
Hi Support,
Thanks for the reply.
According to the documentation readRecords description is following:
byte[] readRecords(int fileNo,
int offsetRecords,
int noOfRecords)
Parameters:
fileNo - Record file number.
offsetRecords - Offset from which records is read.
noOfRecords - Number of records to read.
Returns:
read records as byte[]
In my code i have
byte[] userData = desFireEV2.readRecords(objectFileNo, 0, 1);
where
objectFileNo is 0,
offsetRecords is 0,
noOfRecords is 1
since i have only written the record once.
I am still receiving the same error.
com.nxp.nfclib.exceptions.InvalidResponseLengthException: Boundary Error
To try your answer i even used readRecords with more parameters which is below.
byte[] readRecords(int fileNumber,
int offsetRecords,
int numberOfRecords,
int recordSize,
IDESFireEV1.CommunicationType communicationSettings,
int filesize)
But still receiving the same error message.
What am I missing?
Please help.
+ 0 | - 0
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.