ds.ov2.util
Class Protocol_applet

java.lang.Object
  extended by javacard.framework.Applet
      extended by ds.ov2.util.Protocol_applet
Direct Known Subclasses:
RSA_applet, Test_applet

public class Protocol_applet
extends Applet

General functionality for the main applet instance for applets using the OV-Chip protocol layer. In the applet specific code there must be one class extending this class and overriding the install method. In addition to the usual tasks (creation of one instance and calling register at the end) this install method must do the following things (in conjunction with the constructor of the extending class):

  1. allocate and populate the array of registered protocols (which has type Protocol[]).
  2. Create one instance of Registered_protocols, initialize the registered protocols there (via Registered_protocols.set_protocols)
  3. register the instance of Registered_protocols in the main applet instance (i.e., the only instance of the class that extends this class). This can be done with with set_registered_protocols.
Note that the registered protocols are also needed in the host driver. It is therefore recommended that points 1 and 2 in the above list are factored out in a separate class, say XXX_protocols while point 3 is done in the constructor of the class extending this class. This way the class XXX_protocols remains independent of Applet and can be compiled directly into the host driver without too much hassle.

CPP Preprocessing
This class uses the following cpp defines: PACKAGE, PUBLIC, ASSERT
Execution Environment:
host, card
Author:
Hendrik Tews
Version:
$Revision: 1.3 $
Last Commit:
$Date: 2009-06-19 20:37:36 $ by $Author: tews $

Field Summary
private  Card_protocol card_protocol
          Card protocol instance.
private  Registered_protocols registered_protocols
          Registered protocols instance.
 
Constructor Summary
protected Protocol_applet()
          Constructor.
 
Method Summary
 void process(APDU apdu)
          Process an incoming APDU.
 boolean select()
          Applet selection.
 void set_registered_protocols(Registered_protocols registered_protocols)
          Initialize the registered_protocols field.
 
Methods inherited from class javacard.framework.Applet
deselect, getShareableInterfaceObject, install, register, register, selectingApplet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

card_protocol

private Card_protocol card_protocol
Card protocol instance. Responsible for running arbitrary protocols. Initialized in constructor. If a protocol is active then card_protocol.protocol != null and Card_protocol.protocol_running() returns true.


registered_protocols

private Registered_protocols registered_protocols
Registered protocols instance. This instance maintains the registered protocols. New protocols are selected via this instance. The main applet instance that extends this class must manually initialize this field via set_registered_protocols. This must happen at initialization time before the applet is selected the first time.

Constructor Detail

Protocol_applet

protected Protocol_applet()
Constructor. Initializes card_protocol.

Method Detail

set_registered_protocols

public void set_registered_protocols(Registered_protocols registered_protocols)
Initialize the registered_protocols field. This must happen at initialization time before the applet is selected the first time.

Parameters:
registered_protocols - Registered_protocols instance

select

public boolean select()
Applet selection. Called from Java Card runtime when the applet is selected. Resets the protocol layer.

Overrides:
select in class Applet
Returns:
true because the applet is always ready to be selected

process

public void process(APDU apdu)
Process an incoming APDU. If no protocol is running select a new protocol according to the INS byte of the incoming APDU. Otherwise continue the currently selected protocol. In any case the APDU is delegated to Card_protocol.process for processing.

Specified by:
process in class Applet
Parameters:
apdu - application protocol data unit