iOS SDK: Creating an application fails because of appId not being 3 bytes

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iOS SDK: Creating an application fails because of appId not being 3 bytes

391 Views
Wilco_G
Contributor I

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.

Labels (2)
Tags (1)
0 Kudos
Reply
11 Replies

344 Views
Fabian_R
NXP TechSupport
NXP TechSupport

Hello sir,

This is NXP customer support. Could you please clarify if you have checked our User Guide (UG10045)?

I would like to start from the top on this, to understand what could be happening.

Have you registered you application in our site and, followed the guide mentioned?

Best Regards,
Fabian
0 Kudos
Reply

328 Views
Wilco_G
Contributor I
Hello Fabian,

I did indeed use that guide. The app is also registered, and I successfully verified a license, also the offline version.

I have to say, though, that the guide has quite a few gaps. A sample app would have been helpful. But with the help of this forum, I’ve been able to execute basic commands. However, I’m stuck on creating an app. No matter what I use as the app ID, I keep getting this error.
0 Kudos
Reply

235 Views
Fabian_R
NXP TechSupport
NXP TechSupport

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.

Best Regards,
Fabian
0 Kudos
Reply

60 Views
Wilco_G
Contributor I

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

 

0 Kudos
Reply

202 Views
Wilco_G
Contributor I

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.

0 Kudos
Reply

152 Views
Fabian_R
NXP TechSupport
NXP TechSupport

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.

Best Regards,
Fabian
0 Kudos
Reply

140 Views
Wilco_G
Contributor I

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.

0 Kudos
Reply

48 Views
Fabian_R
NXP TechSupport
NXP TechSupport

Hello Wilco,

Do you mean the @Param andNumberOfBytes:

This from TL_DESFireEV2.h file?

Fabian_R_1-1747176422804.png

 

I will check this internally since the Android JavaDoc function does specify that the applicationID should be a 3-byte number.

Fabian_R_2-1747176576192.png

 

Please accept our apologies for the delay this cause to your development timeline. Will let you know as soon as it is updated.

 

Best Regards,
Fabian
0 Kudos
Reply

148 Views
Wilco_G
Contributor I
I did remove the optional type and it did not solve the issue.

Not being able to post more than two lines of code makes it hard to get real support on these kind of issues. The provided iOS guides has lots of gaps in my opinion and does not provide a complete solution.

I managed to get the basics up and running by scraping pieces from code from this forum. Some of the methods I tested do works. I just can’t get this “createApplication” to work. While it does work, when I create an application by creating my own APDU commands outside the TapLinx library. I have this feeling that this function is bugged some how.

Do you actually have a sample application that uses “createApplication” with the iOS SDK?
0 Kudos
Reply

188 Views
Wilco_G
Contributor I

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.

0 Kudos
Reply

62 Views
Wilco_G
Contributor I

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
0 Kudos
Reply