|
Java Card v2.2.2 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavacard.framework.service.BasicService
public class BasicService
This class should be used as the base class for implementing services. It
provides a default implementation for the methods defined in the Service
interface, and defines a set
of helper methods that manage the APDU buffer to enable co-operation
among different Services.
The BasicService class uses the state of APDU processing to enforce the
validity of the various helper operations. It expects and maintains the
following Common Service Format (CSF) of data in the APDU Buffer corresponding
to the various APDU processing states (See APDU ):
Init State format of APDU Buffer. This format corresponds to the APDU processing state -STATE_INITIAL: 0 1 2 3 4 5 <- offset +------------------------------------------------------------+ | CLA | INS | P1 | P2 | P3 | ... Implementation dependent ...| +------------------------------------------------------------+ Input Ready format of APDU Buffer. This format corresponds to the APDU processing state -STATE_FULL_INCOMING. 0 1 2 3 4 5 <- offset +------------------------------------------------------------+ | CLA | INS | P1 | P2 | Lc | Incoming Data( Lc bytes ) | +------------------------------------------------------------+ Output Ready format of APDU Buffer. This format corresponds to the APDU processing status -STATE_OUTGOING..STATE_FULL_OUTGOING0 1 2 3 4 5 <- offset +------------------------------------------------------------+ | CLA | INS | SW1 | SW2 | La | Outgoing Data( La bytes ) | +------------------------------------------------------------+
When the APDU buffer is in the Init and Input Ready formats, the helper methods allow input access methods but flag errors if output access is attempted. Conversely, when the APDU buffer is in the Output format, input access methods result in exceptions.
The Common Service Format (CSF) of the APDU Buffer is only defined for APDUs using
the short length (normal semantics) of the ISO7816 protocol. When an implementation
supports extended length APDU format
(see ExtendedLength) and an APDU with more than 255 input or output
data bytes is being processed, the behavior of BasicService class
is undefined.
If the header areas maintained by the BasicService helper methods are
modified directly in the APDU buffer and the format of the APDU buffer
described above is not maintained, unexpected behavior might result.
In addition, both La=0 and La=256 are represented in the CSF format
as La=0. The distinction is implementation dependent. The
getOutputLength method must be used to avoid ambiguity.
Many of the helper methods also throw exceptions if the APDU object is in an error state ( processing status code < 0 ).
APDU,
javacardx.apdu.ExtendedLength| Constructor Summary | |
|---|---|
BasicService()
Creates new BasicService. |
|
| Method Summary | |
|---|---|
boolean |
fail(APDU apdu,
short sw)
Sets the processing state for the command in the APDU object
to processed, and indicates that the
processing has failed. |
byte |
getCLA(APDU apdu)
Returns the class byte for the command in the APDU object. |
byte |
getINS(APDU apdu)
Returns the instruction byte for the command in the APDU object. |
short |
getOutputLength(APDU apdu)
Returns the output length for the command in the APDU object. |
byte |
getP1(APDU apdu)
Returns the first parameter byte for the command in the APDU object. |
byte |
getP2(APDU apdu)
Returns the second parameter byte for the command in the APDU object. |
short |
getStatusWord(APDU apdu)
Returns the response status word for the command in the APDU object. |
boolean |
isProcessed(APDU apdu)
Checks if the command in the APDU object has already been
processed. |
boolean |
processCommand(APDU apdu)
This BasicService method is a default implementation and
simply returns false without performing any processing. |
boolean |
processDataIn(APDU apdu)
This BasicService method is a default implementation and
simply returns false without performing any processing. |
boolean |
processDataOut(APDU apdu)
This BasicService method is a default implementation and
simply returns false without performing any processing. |
short |
receiveInData(APDU apdu)
Receives the input data for the command in the APDU object if the input
has not already been
received. |
boolean |
selectingApplet()
This method is used to determine if the command in the APDU object
is the applet SELECT FILE command which selected the currently selected applet. |
void |
setOutputLength(APDU apdu,
short length)
Sets the output length of the outgoing response for the command in the APDU object. |
void |
setProcessed(APDU apdu)
Sets the processing state of the command in the APDU object to
processed. |
void |
setStatusWord(APDU apdu,
short sw)
Sets the response status word for the command in the APDU object. |
boolean |
succeed(APDU apdu)
Sets the processing state for the command in the APDU object
to processed, and indicates that the
processing has succeeded. |
boolean |
succeedWithStatusWord(APDU apdu,
short sw)
Sets the processing state for the command in the APDU object
to processed, and indicates that the
processing has partially succeeded. |
| Methods inherited from class java.lang.Object |
|---|
equals |
| Constructor Detail |
|---|
public BasicService()
BasicService.
| Method Detail |
|---|
public boolean processDataIn(APDU apdu)
BasicService method is a default implementation and
simply returns false without performing any processing.
processDataIn in interface Serviceapdu - the APDU object containing the command being processed
falsepublic boolean processCommand(APDU apdu)
BasicService method is a default implementation and
simply returns false without performing any processing.
processCommand in interface Serviceapdu - the APDU object containing the command being processed
falsepublic boolean processDataOut(APDU apdu)
BasicService method is a default implementation and
simply returns false without performing any processing.
processDataOut in interface Serviceapdu - the APDU object containing the command being processed
false
public short receiveInData(APDU apdu)
throws ServiceException
APDU object if the input
has not already been
received. The entire input data must fit in the APDU buffer starting at
offset 5. When invoked, the APDU object must either be in STATE_INITIAL
with the APDU buffer in the Init format
or in STATE_FULL_INCOMING with the APDU buffer in the Input Ready format
apdu - the APDU object containing the apdu being processed
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_IN_COMMAND if the APDU
object is not in STATE_INITIAL or in STATE_FULL_INCOMING or,
ServiceException.COMMAND_DATA_TOO_LONG if the input data
does not fit in the APDU buffer starting at offset 5.
public void setProcessed(APDU apdu)
throws ServiceException
APDU object to
processed. This is done by setting the APDU object in
outgoing mode by invoking
the APDU.setOutgoing method. If the APDU is already in outgoing
mode, this method does nothing (allowing the method to be called several
times).
apdu - the APDU object containing the command being processed
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_OUT_COMMAND if the APDU
object is not accessible (APDU object in STATE_ERROR_.. )
javacard.framework.APDU.getCurrentState()public boolean isProcessed(APDU apdu)
APDU object has already been
processed. This is done
by checking whether or not the APDU object has been set in
outgoing mode via a previous invocation of the APDU.setOutgoing method.
Note:
apdu - the APDU object containing the command being processed
true if the command has been processed, false otherwise
public void setOutputLength(APDU apdu,
short length)
throws ServiceException
APDU object. This method can be
called regardless of the current state of the APDU processing.
apdu - the APDU object containing the command being processedlength - the number of bytes in the response to the command
ServiceException - with the following reason code:ServiceException.ILLEGAL_PARAM if the length
parameter is greater than 256 or if the outgoing response will not fit
within the APDU Buffer.
public short getOutputLength(APDU apdu)
throws ServiceException
APDU object.
This method can only
be called if the APDU processing state indicates that the command has
been processed.
apdu - the APDU object containing the command being processed
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_OUT_COMMAND if the command
is not processed or if the APDU
object is not accessible (APDU object in STATE_ERROR_.. )
javacard.framework.APDU.getCurrentState()
public void setStatusWord(APDU apdu,
short sw)
APDU object.
This method can be called
regardless of the APDU processing state of the current command.
apdu - the APDU object containing the command being processedsw - the status word response for this command
public short getStatusWord(APDU apdu)
throws ServiceException
APDU object.
This method can only
be called if the APDU processing state indicates that the command has
been processed.
apdu - the APDU object containing the command being processed
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_OUT_COMMAND if the command
is not processed or if the APDU
object is not accessible (APDU object in STATE_ERROR_.. )
javacard.framework.APDU.getCurrentState()
public boolean fail(APDU apdu,
short sw)
throws ServiceException
APDU object
to processed, and indicates that the
processing has failed. Sets the output length to 0 and the status word
of the response to the specified value.
apdu - the APDU object containing the command being processedsw - the status word response for this command
true
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_OUT_COMMAND if the APDU
object is not accessible (APDU object in STATE_ERROR_.. )
javacard.framework.APDU.getCurrentState()
public boolean succeed(APDU apdu)
throws ServiceException
APDU object
to processed, and indicates that the
processing has succeeded. Sets the status word of the response to 0x9000.
The output length of the response must be set separately.
apdu - the APDU object containing the command being processed.
true
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_OUT_COMMAND if the APDU
object is not accessible (APDU object in STATE_ERROR_.. )
javacard.framework.APDU.getCurrentState()
public boolean succeedWithStatusWord(APDU apdu,
short sw)
throws ServiceException
APDU object
to processed, and indicates that the
processing has partially succeeded. Sets the the status word of the
response to the specified value. The output length of the response must be
set separately.
apdu - the APDU object containing the command being processedsw - the status word to be returned for this command
true
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_OUT_COMMAND if the APDU
object is not accessible (APDU object in STATE_ERROR_.. )
javacard.framework.APDU.getCurrentState()public byte getCLA(APDU apdu)
APDU object.
This method can be called
regardless of the APDU processing state of the current command.
apdu - the APDU object containing the command being processed
public byte getINS(APDU apdu)
APDU object.
This method can be
called regardless of the APDU processing state of the current command.
apdu - the APDU object containing the command being processed
public byte getP1(APDU apdu)
throws ServiceException
APDU object.
When invoked, the APDU object must be in STATE_INITIAL
or STATE_FULL_INCOMING.
apdu - the APDU object containing the command being processed
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_IN_COMMAND if the APDU
object is not in STATE_INITIAL or in STATE_FULL_INCOMING.
public byte getP2(APDU apdu)
throws ServiceException
APDU object.
When invoked, the APDU object must be in STATE_INITIAL
or STATE_FULL_INCOMING.
apdu - the APDU object containing the command being processed
ServiceException - with the following reason code:ServiceException.CANNOT_ACCESS_IN_COMMAND if the APDU
object is not in STATE_INITIAL or in STATE_FULL_INCOMING.
public boolean selectingApplet()
APDU object
is the applet SELECT FILE command which selected the currently selected applet.
true if applet SELECT FILE command is being processed
|
Java Card v2.2.2 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||