Announce two new product: SmartCard Reader Rockey200 and USB2.0 Extension Cable

ROCKEY 200 is a handy and portable USB Smart Card reader that can perform read/write operations on any ISO 7816-1/2/3/4 smart cards which are compatible with protocol T=0 and T=1.

USB2.0 Extension Cable With high speed USB 2.0 devices such as USB token ,USB Card Reader and so on.

Come to try it 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