Christmas is coming!

To celebrate the new year and thank for the support from all our dear customers, Christmas promotional activity is being held in JavaCardOS online store.

During the event, you can enjoy many promotional activities - High Discount on JavaCardOS products,Lucky Draw,Double forum Points.

Come to choose your own Christmas gift and try your luck now!

Sample code to change ATR history bytes

Card Products

Moderator: horse dream

JCaberham
Posts: 23
Joined: Mon Nov 30, 2015 3:02 am
Points: 170
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