When I select an application and create a file like this everything work as expected. Note: I created this app outside the TapLinx Library
evInstance?.selectApplication(withAppID: 0x563412) { _ in
print("app selected")
evInstance?.createStandardFile(withFileID: 0x01, withFileSize: 16, withCommType: CommunicationType.Plain, withReadByte: 0, withWriteByte: 0, withReadWriteByte: 0, withChangeByte: 0) { result in
print("file created", result)
}
}
But when I try to create an application with a similar notation for the appId as the selection I get an error. I tried lots of possibilities, even 0 and 1.
com.nxp.nfclib.exceptions.UsageException: Application ID [appId] must be 3 bytes
I am stuck on creating a new application. Am I doing something in the wrong order? Also tried to manually seleting the root app and with/without authentication.
evInstance?.selectApplicationPICCP1 { _ in
print("main app selected")
evInstance?.authenticate(withCardKeyNo: 0, withAuthenticationType: .native, withAuthKeyType: .THREEDES, withCommandSetForAuth: .Native, withAuthkey: key) { _ in
print("authenticated")
evInstance?.createApplication(withAppID: 0x123456, withNumberOfBytes: 16, withAppSettings: appSettings) { result in
print("Application created successfully", result)
}
}
}
Would appreciate any help. Thanks in advance.
Could you please avoid the use of "?" as shown?
evInstance.selectApplication
and
evInstance.createStandardFile
Instead.
Is possible that the use of "?" symbol may be producing issues. In the case of selecting MIFARE applications, when the reader selects a MIFARE card is a certainty that an Application will be selected. The issue you are having is quite unexpected, I haven't been able to locate any root cause on this.
If you could share any log additional to the error received, I will appreciate it very much.
I don’t see why the optional type should be a problem. If evInstance would have been nil, it would not run the method at all.
The functions “selectApplication” and “createStandardFile” are not the problem. Those functions do work. I mentioned them to indicate that the notation of the “applicationId” is accepted in these methods.
I get this error when executing “createApplication” with every possible “applicationId” I choose. The exception I get is from the method “createApplication”. It would not even return this exception if evInstance was nil.
Removing the optional type did not solve the issue. Below a simplified version of my code.
self.libraryManager = TLLibraryManager.shared()
let evInstance = self.libraryManager.getDESFireEV3Instance()
print("\n=== Step 1: app main selecting... ===")
evInstance.selectApplicationPICCP1() { isSuccess in
print("=== app main selected ===")
print("isSuccess: \(isSuccess)")
}
print("\n=== Step 2: app authenitcating... ===")
evInstance.authenticate(
withCardKeyNo: 0,
withAuthenticationType: .native,
withAuthKeyType: .THREEDES,
withCommandSetForAuth: .Native,
withAuthkey: key)
{ isSuccess in
print("=== app authenticated ===")
print("isSuccess: \(isSuccess)")
}
print("\n=== Step 3: app creating... ===")
let appSettings = CreateAppSettingsModel()
appSettings.appKeySettingChangable = true
appSettings.authRequiredForFileManagement = false
appSettings.authRequiredForFileConfiguration = false
appSettings.numberOfKeySets = 2
appSettings.keyType = .AES128
appSettings.maxKeySize = 32
appSettings.masterKeyInterchangable = true
evInstance.createApplication(withAppID: 0x111111, withNumberOfBytes: 160, withAppSettings: appSettings)
{ isSuccess in
print("\n=== app created ===")
print("isSuccess: \(isSuccess)")
}
This results in the log below, with the exception at the bottom thrown by "createApplication".
initializeTapLinxLibrary
responseString License Verified Successfully, Time to explore Taplinx Library
Tag reader did become active <NFCTagReaderSession: 0x1054c7a20>
isReady: true
didDetect [CoreNFC.NFCTag.miFare(<NFCMiFareTag: 0x10569a0c0>)]
MiFare card found
Connected to tag
=== Step 1: app main selecting... ===
Command sent to card : 5A000000
[general] response.tag.type: (null)
[general] response.responseData: {length = 1, bytes = 0x00}
Response received : 00
=== app main selected ===
isSuccess: true
=== Step 2: app authenitcating... ===
AuthType - Native KeyType - THREEDES KeyInfo.KeyArray - {length = 16, bytes = 0x00000000000000000000000000000000}, cardKeyNo - 0
Command sent to card : 0A00
[general] response.tag.type: (null)
[general] response.responseData: {length = 9, bytes = 0xaf68e6008758263832}
Response received : AF68E6008758263832
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x68e6008758263832}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x85b208b0762265d7}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x8b32a8922dac433b}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
Command sent to card : AFE7109DBEE0E8FD8B7E6B593689DFA4EF
[general] response.tag.type: (null)
[general] response.responseData: {length = 9, bytes = 0x00373c4845f783cf52}
Response received : 00373C4845F783CF52
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x373c4845f783cf52}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
=== app authenticated ===
isSuccess: true
=== Step 3: app creating... ===
Max Size - 32
Key Type - AES128
com.nxp.nfclib.exceptions.UsageException: Application ID [appId] must be 3 bytes
=== app created ===
isSuccess: false
I don’t see why the optional type should be a problem. If evInstance would have been nil, it would not run the method at all.
The functions “selectApplication” and “createStandardFile” are not the problem. Those functions do work. I mentioned them to indicate that the notation of the “applicationId” is accepted in these methods.
I get this error when executing “createApplication” with every possible “applicationId” I choose. The exception I get is from the method “createApplication”. It would not even return this exception if evInstance was nil.
Hello sir,
I am very sorry but is only possible to paste code snippets. Regarding the use of optional type, unfortunatley this is causing some issues with Taplinx.
Have you give it a try? At least for testing purposes.
I'm sorry but I haven't been able to get a reason why is the appId is producing failures.
I finally got something working, don't ask me how. There is this argument "withNumberOfBytes" and this is what the header file say about this argument: "@Param noOfBytes to allocate memory for the application to be created". I tried multiple values and made sure it is multiple of 32. I thought this was the total of amount of bytes that the whole application reserves, just like files.
evInstance.createApplication(withAppID: 0x111111, withNumberOfBytes: 512, withAppSettings: appSettings)
{ isSuccess in
print("\n=== app created ===")
print("isSuccess: \(isSuccess)")
}
Every value gives me this error.
com.nxp.nfclib.exceptions.UsageException: Application ID [appId] must be 3 bytes
I got to this point that I was trying to irrational combinations. Every values of "withNumberOfBytes" gave me the above error. But when I use the value of "3" for "withNumberOfBytes" it does not give me an error, and it did created an application. I was assuming that "noOfBytes" was about the application and not about the application id.
Hello Wilco,
Do you mean the @Param andNumberOfBytes:
This from TL_DESFireEV2.h file?
I will check this internally since the Android JavaDoc function does specify that the applicationID should be a 3-byte number.
Please accept our apologies for the delay this cause to your development timeline. Will let you know as soon as it is updated.
I am trying to post my code and logs as requested, but for some reason it got deleted (twice). I wanted to confirm that removing the optional type does not solve the issue.
To confirm, removing the optional type did not solve the issue. Below a simplified version of my code.
self.libraryManager = TLLibraryManager.shared()
let evInstance = self.libraryManager.getDESFireEV3Instance()
print("\n=== Step 1: app main selecting... ===")
evInstance.selectApplicationPICCP1() { isSuccess in
print("=== app main selected ===")
print("isSuccess: \(isSuccess)")
}
print("\n=== Step 2: app authenitcating... ===")
evInstance.authenticate(
withCardKeyNo: 0,
withAuthenticationType: .native,
withAuthKeyType: .THREEDES,
withCommandSetForAuth: .Native,
withAuthkey: key)
{ isSuccess in
print("=== app authenticated ===")
print("isSuccess: \(isSuccess)")
}
print("\n=== Step 3: app creating... ===")
let appSettings = CreateAppSettingsModel()
appSettings.appKeySettingChangable = true
appSettings.authRequiredForFileManagement = false
appSettings.authRequiredForFileConfiguration = false
appSettings.numberOfKeySets = 2
appSettings.keyType = .AES128
appSettings.maxKeySize = 32
appSettings.masterKeyInterchangable = true
evInstance.createApplication(withAppID: 0x111111, withNumberOfBytes: 160, withAppSettings: appSettings)
{ isSuccess in
print("\n=== app created ===")
print("isSuccess: \(isSuccess)")
}
This results in the log below, with the exception at the bottom thrown by "createApplication".
initializeTapLinxLibrary
responseString License Verified Successfully, Time to explore Taplinx Library
Tag reader did become active <NFCTagReaderSession: 0x1054c7a20>
isReady: true
didDetect [CoreNFC.NFCTag.miFare(<NFCMiFareTag: 0x10569a0c0>)]
MiFare card found
Connected to tag
=== Step 1: app main selecting... ===
Command sent to card : 5A000000
[general] response.tag.type: (null)
[general] response.responseData: {length = 1, bytes = 0x00}
Response received : 00
=== app main selected ===
isSuccess: true
=== Step 2: app authenitcating... ===
AuthType - Native KeyType - THREEDES KeyInfo.KeyArray - {length = 16, bytes = 0x00000000000000000000000000000000}, cardKeyNo - 0
Command sent to card : 0A00
[general] response.tag.type: (null)
[general] response.responseData: {length = 9, bytes = 0xaf68e6008758263832}
Response received : AF68E6008758263832
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x68e6008758263832}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x85b208b0762265d7}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x8b32a8922dac433b}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
Command sent to card : AFE7109DBEE0E8FD8B7E6B593689DFA4EF
[general] response.tag.type: (null)
[general] response.responseData: {length = 9, bytes = 0x00373c4845f783cf52}
Response received : 00373C4845F783CF52
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x373c4845f783cf52}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
=== app authenticated ===
isSuccess: true
=== Step 3: app creating... ===
Max Size - 32
Key Type - AES128
com.nxp.nfclib.exceptions.UsageException: Application ID [appId] must be 3 bytes
=== app created ===
isSuccess: false