Forum Replies Created
-
Re: Reply To: getting Incomplete response when select application – Desfire EV1 card
9. August 2017 at 20:42 in reply to: getting Incomplete response when select application – Desfire EV1 cardHi Team,
Now, I am able to erase all applications from card(using PCSC commands with other windows app). However, when i try to create a application, I am getting the same message.
I have attached the source file here.
Could you please provide some sample code to select/create application.
Thanks,
Shiva
package com.nxp.taplinxtest;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.MifareClassic;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.nxp.nfclib.CardType;
import com.nxp.nfclib.KeyType;
import com.nxp.nfclib.NxpNfcLib;
import com.nxp.nfclib.classic.ClassicFactory;
import com.nxp.nfclib.classic.IMFClassicEV1;
import com.nxp.nfclib.defaultimpl.KeyData;
import com.nxp.nfclib.desfire.DESFireFactory;
import com.nxp.nfclib.desfire.EV1ApplicationKeySettings;
import com.nxp.nfclib.desfire.EV1KeySettings;
import com.nxp.nfclib.desfire.IDESFireEV1;
import com.nxp.nfclib.ultralight.IUltralightEV1;
import com.nxp.nfclib.desfire.IDESFireEV2;
import com.nxp.nfclib.ultralight.UltralightFactory;
import com.nxp.nfclib.utils.Utilities;
import java.security.Key;
import javax.crypto.spec.SecretKeySpec;
public class MainActivity extends AppCompatActivity
{
private String TAG = MainActivity.class.getSimpleName();
private NxpNfcLib m_libInstance = null; // The TapLinX library instance
private TextView m_textView = null;
private IDESFireEV1 m_objDESFireEV1 = null;
private IDESFireEV2 m_objDESFireEV2 = null;
private CardType m_cardType = CardType.UnknownCard;
private byte[] app_id={(byte)0x11,(byte)0x22,(byte)0x33};
public static final byte[] DEFAULT_KEY_AES =
{ // Default AES128 key
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00
};
public static final byte[] DEFAULT_DES_KEY =
{ // Default AES128 key
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
};
public static final byte[] DEFAULT_KEY_MIFARE =
{ // The MIFARE default key
(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff
};
private void initializeLibrary()
{ // Initialize the TapLinx library
m_libInstance = NxpNfcLib.getInstance();
m_libInstance.registerActivity( this, "00112233445566778899aabbccddeeff" );
}
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
m_textView = (TextView)findViewById( R.id.mainTextView );
initializeLibrary(); // Initialize library
}
@Override
protected void onResume()
{ // Called if app becomes active
m_libInstance.startForeGroundDispatch();
super.onResume();
}
@Override
protected void onPause()
{ // Called if app becomes inactive
m_libInstance.stopForeGroundDispatch();
super.onPause();
}
@Override
public void onNewIntent( final Intent intent )
{
Log.d( TAG, "onNewIntent" );
cardLogic( intent );
super.onNewIntent( intent );
}
private void cardLogic( final Intent intent )
{
try
{
Key keyDefault;
KeyData keyDataDefault;
byte[] data;
m_cardType = m_libInstance.getCardType( intent );
Log.d( TAG, "Card type: " + m_cardType.getTagName() );
m_textView.setText( "Card type found: " + m_cardType.getTagName() );
switch( m_cardType )
{
case DESFireEV1:
Log.d( TAG, "DESFire EV1 found" );
m_objDESFireEV1 = DESFireFactory.getInstance()
.getDESFire( m_libInstance.getCustomModules() );
m_objDESFireEV1.getReader().connect();
// Timeout to prevent exceptions in authenticate
m_objDESFireEV1.getReader().setTimeout( 2000 );
//m_objDESFireEV1.selectApplication( 0x000000 );
EV1ApplicationKeySettings.Builder appsetbuilder = new EV1ApplicationKeySettings.Builder();
EV1ApplicationKeySettings appsettings = appsetbuilder.setAppKeySettingsChangeable(true)
.setAppMasterKeyChangeable(true)
.setAuthenticationRequiredForDirectoryConfigurationData(false)
.setKeyTypeOfApplicationKeys(KeyType.TWO_KEY_THREEDES).build();
m_objDESFireEV1.createApplication(app_id, appsettings);
keyDefault = new SecretKeySpec( DEFAULT_KEY_AES, "AES" );
keyDataDefault = new KeyData();
keyDataDefault.setKey( keyDefault );
// Authenticate to application Master Key
m_objDESFireEV1.authenticate( 0, IDESFireEV1.AuthType.AES,
KeyType.AES128, keyDataDefault );
// Select root app
// EV1KeySettings ev1= m_objDESFireEV1.getKeySettings();
m_objDESFireEV1.selectApplication( 0x000000 );
// DEFAULT_KEY_AES is a byte array of 16 bytes
keyDefault = new SecretKeySpec( DEFAULT_KEY_AES, "AES" );
keyDataDefault = new KeyData();
keyDataDefault.setKey( keyDefault );
// Authenticate to application Master Key
Log.d( TAG, "AID 0 authenticated" );
break;
case DESFireEV2:
Log.d( TAG, "DESFire EV2 found" );
m_objDESFireEV2 = DESFireFactory.getInstance()
.getDESFireEV2( m_libInstance.getCustomModules() );
m_objDESFireEV2.getReader().connect();
// Timeout to prevent exceptions in authenticate
m_objDESFireEV2.getReader().setTimeout( 2000 );
// Select root app
m_objDESFireEV2.selectApplication(0);
// DEFAULT_KEY_AES is a byte array of 16 bytes
keyDefault = new SecretKeySpec( DEFAULT_KEY_AES, "AES" );
keyDataDefault = new KeyData();
keyDataDefault.setKey( keyDefault );
// Authenticate to application Master Key
m_objDESFireEV2.authenticate( 0, IDESFireEV1.AuthType.AES,
KeyType.AES128, keyDataDefault );
Log.d( TAG, "AID 0 authenticated" );
break;
case UltralightEV1_11:
case UltralightEV1_21:
Log.d( TAG, "UltraLightEV1 found" ); // Retrieve card type form NFC adapter
IUltralightEV1 objUltra = UltralightFactory.getInstance()
.getUltralightEV1( m_libInstance.getCustomModules());
if( ! objUltra.getReader().isConnected() )
{
objUltra.getReader().connect();
}
data = objUltra.read(1);
Log.d( TAG, "Read page 0: " + data );
break;
case MIFAREClassicEV1:
Tag tag = intent.getParcelableExtra( NfcAdapter.EXTRA_TAG );
IMFClassicEV1 objClassic = ClassicFactory.getInstance()
.getClassicEV1( MifareClassic.get( tag ) );
if( ! objClassic.getReader().isConnected() )
{
objClassic.getReader().connect();
}
// Authenticate with the default key
objClassic.authenticateSectorWithKeyA( 0, DEFAULT_KEY_MIFARE );
Log.d( TAG, "To block 0 authenticated" );
data = objClassic.readBlock( 0 );
String str = Utilities.dumpBytes( data );
Log.d( TAG, "Read block 1: " + str );
break;
default:
Log.d( TAG, "Card type found: " + m_cardType.getTagName() );
m_textView.setText( "Card type found: " + m_cardType.getTagName() );
break;
}
}
catch( Throwable t )
{
t.printStackTrace();
}
}
}
+ 0 | - 0
Re: Reply To: getting Incomplete response when select application – Desfire EV1 card
9. August 2017 at 17:04 in reply to: getting Incomplete response when select application – Desfire EV1 cardHi Team,
Could you please let me know, where can i find this method formatPICC().
Thanks,
Shiva
+ 0 | - 0
Re: Reply To: getting Incomplete response when select application – Desfire EV1 card
8. August 2017 at 17:00 in reply to: getting Incomplete response when select application – Desfire EV1 cardAttached file.
+ 0 | - 0
Re: Reply To: getting Incomplete response when select application – Desfire EV1 card
8. August 2017 at 16:58 in reply to: getting Incomplete response when select application – Desfire EV1 cardHi Team,
I just tried to get all application from card even it throws the same error. Also, i tried to get the exists application id from card and still getting the error message.
Attached the screenshot for your reference.
int[] appids=m_objDESFireEV1.getApplicationIDs();
Thanks,
Shiva
+ 0 | - 0
-
AuthorPosts