|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjavacard.framework.service.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.
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| 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 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
true if output processing is finished,
false otherwise
public byte getP1(APDU apdu)
throws ServiceException
APDU object. When invoked, the APDU
object must be in STATE_INITIAL or
STATE_FULL_INCOMING.
ServiceExceptionpublic byte getINS(APDU apdu)
APDU object. This method can be called regardless
of the APDU processing state of the current command.
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
true if input processing is finished,
false otherwise
public void setStatusWord(APDU apdu,
short sw)
APDU object. This method can be called regardless
of the APDU processing state of the current command.
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.
ServiceException
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.
ServiceExceptionpublic 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
true if the command has been processed,
false otherwise
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.
ServiceExceptionpublic byte getCLA(APDU apdu)
APDU
object. This method can be called regardless of the APDU
processing state of the current command.
public byte getP2(APDU apdu)
throws ServiceException
APDU object. When invoked, the APDU
object must be in STATE_INITIAL or
STATE_FULL_INCOMING.
ServiceExceptionpublic 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:
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).
ServiceException
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.
ServiceException
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
ServiceException
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.
ServiceExceptionpublic boolean selectingApplet()
APDU object is the applet SELECT FILE command which
selected the currently selected applet.
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.
ServiceException
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||