It's our great honour to announce the Industry’s First VHBR CCID reader - VHBR Dual interface smart card reader vR504. It is able to support the world’s fastest ePassports.

To celebrate the new product release, there is Special Discount for New Registered Members in our store.
- Get $20.00 OFF instantly for smart card reader vR504, R502 and bR301

Come to get the readers now!

Sample code to change ATR history bytes

Card Products

Moderator: horse dream

JCaberham
Posts: 24
Joined: Mon Nov 30, 2015 3:02 am
Points: 188
Contact:

Sample code to change ATR history bytes

Postby JCaberham » Wed Oct 26, 2016 10:58 pm

Share a sample code that used to change card ATR history bytes.

Code: Select all

package JC_setATRHistBytes;

import javacard.framework.*;
import org.globalplatform.*;

public class JC_setATRHistBytes_cls extends Applet {
     private static final byte[] newATRHistory  = { 
          (byte)'J', (byte)'C', (byte)'O', (byte)'P', (byte)'4', (byte)'1', (byte)'V', (byte)'2', (byte)'2', (byte)'1'
          } ;
     private static final byte[] newATRHistory1  = { 
          (byte)'J', (byte)'C', (byte)'O', (byte)'P', (byte)'4', (byte)'1', (byte)'V', (byte)'2', (byte)'2', (byte)'3'
          } ;
     public static void install(byte[] bArray, short bOffset, byte bLength) {
   
          new JC_setATRHistBytes_cls().register(bArray,
                    (short) (bOffset + 1), bArray[bOffset]);
     }

     public void process(APDU apdu) {
          if (selectingApplet()) {
               return;
          }

          byte[] buf = apdu.getBuffer();
       
          if (buf[ISO7816.OFFSET_CLA] != 0) ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
          switch (buf[ISO7816.OFFSET_INS]) {
          case (byte) 0x00:
               if (GPSystem.setATRHistBytes(newATRHistory, (short)0, (byte)newATRHistory1.length))
               {
                    return;
               }
               else
               {
                    ISOException.throwIt(ISO7816.SW_WARNING_STATE_UNCHANGED);
               }
          case (byte) 0x01:
               if (GPSystem.setATRHistBytes(newATRHistory1, (short)0, (byte)newATRHistory1.length))
               {
                    return;
               }
               else
               {
                    ISOException.throwIt(ISO7816.SW_WARNING_STATE_UNCHANGED);
               }               
          default:
             
               ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
          }
     }
}

AmigoJack
Posts: 17
Joined: Thu Nov 19, 2015 4:56 am
Points: 85
Contact:

Re: Sample code to change ATR history bytes

Postby AmigoJack » Thu Oct 27, 2016 3:21 am

Thank you for sharing!


Return to “Card Products”

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer