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.

RMI Usage

Applets Development Guide

Moderator: product

User avatar
JavaCardOS
Posts: 273
Joined: Thu Apr 30, 2015 12:00 pm
Points :2403
Contact:

RMI Usage

Post by JavaCardOS » Thu Feb 25, 2016 2:13 am

1. Declare remote method interface

Code: Select all

package testRMI;

import java.rmi.*;

public interface rmiInterface extends Remote {
   public short getMagic() throws RemoteException;
   public short add(short value1, short value2) throws RemoteException;
}


2. Implement remote method interface

Code: Select all

package testRMI;
public class rmiInterfaceImpl implements rmiInterface {
   public short getMagic() {
      return (short) 0x55AA;
   }

   public short add(short value1, short value2) {
      return (short) (value1 + value2);
   }
}

3. Implement Applet which is used to invoke remote method

Code: Select all

package testRMI;

import java.rmi.*;
import javacard.framework.*;
import javacard.framework.service.Dispatcher;
import javacard.framework.service.RemoteService;
import javacard.framework.service.RMIService;
import javacard.framework.service.CardRemoteObject;

public class testRMI extends Applet
{
   private Remote myRemoteInterface;
   private RemoteService myRemoteService;
   private Dispatcher myDispatcher;
   private CardRemoteObject myCardRemoteObject;
   
   testRMI() {
      myRemoteInterface = new rmiInterfaceImpl();
      myCardRemoteObject = new CardRemoteObject();
      myCardRemoteObject.export(myRemoteInterface);   // Only the exported object can be invoked by card outside;
      
      myDispatcher = new Dispatcher((short) 1);
      myRemoteService = new RMIService(myRemoteInterface);
      myDispatcher.addService(myRemoteService, Dispatcher.PROCESS_COMMAND);
   }
   
   public static void install(byte[] bArray, short bOffset, byte bLength)
   {
      new testRMI().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:
         // break;
      // default:
         // ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      // }
        // Send directly to the service dispatcher;;
      myDispatcher.process(apdu);
   }

}


4. upload and install
(These steps are the same as other applets)

5. SELECT command
>> /select 112233445500
>> 00 A4 04 00 06 11 22 33 44 55 00 00
<< 6F 24 6E 22 5E 20 02 02 38 81 00 B7 00 07 74 65 73 74 52 4D 49 10 72 6D 69 49 6E 74 65 72 66 61 63 65 49 6D 70 6C 90 00

Response to SELECT command

Code: Select all

select_response {
    u1 fci_tag = 0x6F
    u1 fci_length
        u1 application_data_tag = 0x6E
        u1 application_data_length
            u1 jc_rmi_data_tag = 0x5E
            u1 jc_rmi_data_length
            u2 version = 0x0202
            u1 invoke_ins
            union {
                normal_ref_response normal_initial_ref
                normal_null_response null_initial_ref
                error_response initial_ref_error
                } initial_ref
    }


Parsing results:
Version num:0202
invoke ins is 0x38;
remote ref id is 00B7; (Reference value of the remote object)
Package name: 07 74 65 73 74 52 4D 49(testRMI)
Class Name: 10 72 6D 69 49 6E 74 65 72 66 61 63 65 49 6D 70 6C (RMIInterfaceImpl)

6. Invoking method add:
>> /send 803802020800B7A7F611112222
>> 80 38 02 02 08 00 B7 A7 F6 11 11 22 22
<< 81 33 33 90 00

0x81 indicates that it excutes successfully, the result is 3333(1111 + 2222 => 3333);

7. Invoking method getMagic:
>> /send 803802020400B7C741
>> 80 38 02 02 04 00 B7 C7 41
<< 81 55 AA 90 00

0x81 indicates that it excutes successfully, and it returns magic value 55AA.

Note: Please refer to Runtime Environment Specification for the Java Card Platform, Version 2.2.2 - charpter 8 for the response value parsing of SELECT command, commands construction of remote method invoking and response parsing.

Who is online

Users browsing this forum: No registered users and 16 guests

JavaCard OS : Disclaimer