Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

a way to send and receive messages between applets?

JavaCard Applet Development Related Questions and Answers.
sla1023
Posts: 7
Joined: Mon Feb 13, 2017 12:00 am
Points :78
Contact:

a way to send and receive messages between applets?

Post by sla1023 » Sun Feb 26, 2017 9:52 pm

Is there a way to send and receive messages between applets?

For example, is it possible to run the functions defined in the process function in A applet with the B applet?

For example code
A applet

Code: Select all

package Test
import javacard.framework.*;

public class A extends Applet
{
   private A() {
   }
   
   public static void install(byte[] bArray, short bOffset, byte bLength)
   {
      new A().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
   }

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

      byte[] buf = apdu.getBuffer();
      switch (buf[ISO7816.OFFSET_INS])
      {
      case (byte)0x00:
      // Send message to B applet(apdu or ....)
         break;
      default:
         ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      }
   }

}


B applet

Code: Select all

package Test
import javacard.framework.*;

public class B extends Applet
{
   private B() {
   }
   
   public static void install(byte[] bArray, short bOffset, byte bLength)
   {
      new B().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
   }

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

      // Receive message from A applet(apdu or ...)
      
      byte[] buf = apdu.getBuffer();
      switch (buf[ISO7816.OFFSET_INS])
      {
      // Execute A applet message
      case (byte)0x00:
         break;
      default:
         ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      }
   }

}

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: a way to send and receive messages between applets?

Post by UNKNwYSHSA » Mon Feb 27, 2017 12:00 am

You want to process commands in different applet with one code block?
You can use the BasicService class.

AppletA:

Code: Select all

package testService;

import javacard.framework.*;
import javacard.framework.service.*;

public class AppletA extends Applet
{

   public static void install(byte[] bArray, short bOffset, byte bLength)
   {
      new AppletA().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
   }

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

      byte[] buf = apdu.getBuffer();
      switch (buf[ISO7816.OFFSET_INS])
      {
      case (byte)0x00:
         BasicService bs = theService.getInstance();
         bs.processCommand(apdu);
         break;
      default:
         ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      }
   }

}


AppletB:

Code: Select all

package testService;

import javacard.framework.*;
import javacard.framework.service.*;

public class AppletB extends Applet
{

   public static void install(byte[] bArray, short bOffset, byte bLength)
   {
      new AppletB().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
   }

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

      byte[] buf = apdu.getBuffer();
      switch (buf[ISO7816.OFFSET_INS])
      {
      case (byte)0x00:
         BasicService bs = theService.getInstance();
         bs.processCommand(apdu);
         break;
      default:
         ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      }
   }

}


The service:

Code: Select all

package testService;

import javacard.framework.service.BasicService;
import javacard.framework.APDU;

public class theService extends BasicService {
   public static BasicService the_service;
   public static BasicService getInstance() {
      if (the_service == null) {
         the_service = new theService();
      }
      
      return the_service;
   }
   
   public boolean processCommand(APDU apdu) {
      fail(apdu, (short) 0x6600);
      return true;
   }
}
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 39 guests

JavaCard OS : Disclaimer