Home > NFC > NFC applet development > Use of STK for Contactless

Use of STK for Contactless   

pdf Mail Impression

In an NFC contactless applet, only the process() method is used to deal with contactless data. In order to use the SIM Toolkit interface to interact with the user, the processTooolkit() method must be called because proactive commands can only be sent from this method.


The following method describes a way to achieve this:

  1. Register to the EVENT_PROACTIVE_HANDLER_AVAILABLE event at the end of the process() method.
  2. Catch the EVENT_PROACTIVE_HANDLER_AVAILABLE event in the processTooolkit() method and perform the proactive action there.

Example:

/*
 * Package name
 */
package contactless.example;

/*
 * Imported packages
 */
// specific import for Javacard API access
import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;
import uicc.toolkit.*;        

public final class exampleSTK extends javacard.framework.Applet implements ToolkitInterface, ToolkitConstants
{
 
     private ToolkitRegistry reg;


     //Constructor
     public exampleSTK(byte[] bArray, short bOffset, byte bLength)
     {    
           // Any process

           // Register ToolKit in handset
                reg = ToolkitRegistrySystem.getEntry();
     }



     public final void process(APDU apdu) throws ISOException
     {
        // get the APDU buffer
        byte[] apduBuffer = apdu.getBuffer();
       
        // Mask Channel number  
        apduBuffer[ISO7816.OFFSET_CLA] &= 0xFC;
             
        byte cla = apduBuffer[ISO7816.OFFSET_CLA];
        byte ins = apduBuffer[ISO7816.OFFSET_INS];
        
        // APDU instruction parser
        switch (ins)
        {
            case 0x01:
                // do any processing here

                // Register to EVENT_PROACTIVE_HANDLER_AVAILABLE
                reg.setEvent(EVENT_PROACTIVE_HANDLER_AVAILABLE);

        }

     }

     


     /**
     * Method called by the Toolkit Framework
     */
     public void processToolkit(short event)
     {          
         // get the handler references
            ProactiveResponseHandler rspHdlr ;
         ProactiveHandler proHdlr;
                  
         // treat each event
         switch(event)
         {
                // Event launch in process() method
                case EVENT_PROACTIVE_HANDLER_AVAILABLE:
              
                // TOOLKIT Process here
                break;

            
         }
     }

}

 

 

 Next: Instructions and advices (Proximera)