com.ibm.jc.terminal
Class RemoteJCTerminal

java.lang.Object
  extended bycom.ibm.jc.JCTerminal
      extended bycom.ibm.jc.terminal.RemoteJCTerminal

public class RemoteJCTerminal
extends JCTerminal

Establish a socket connection to a remove terminal/card. The server part can be either a terminal server enabling remote access to a terminal device or it can be the JCOP simulation that simulates a real card and terminal.

Each message has the following format:

Byte # Abbr. Meaning
0 MTY Message type
1 NAD Node addess
2 LNH High byte of payload length
3 LNL Low byte of payload length
4... PY0 First byte of payload (interpretation depends on message type)
...3+(LNH*256)+LNL PYn Last byte of payload

The client sends a message and the terminal server responds with a message. Request and response message must have the same MTY and NAD field. Length and payload of the messages may differ. A value of 0 for NAD means client to card communication.

The following types of messages are defined:

Wait for card (MTY=0x00)
The payload contains four bytes denoting the time in milliseconds the remote part will wait for card insertion. The bytes are sent in big endian format. The reply message contains the full ATR as payload. A reply message with 0 bytes length means that the terminal could not trigger an ATR (reason might be retrieved using MTY=3 or MTY=2.
APDU data (MTY=0x01)
This message transports APDU data. The payload contains the byte of the APDU and the reply the response APDU.
Status (MTY=0x02)
The request message contains no payload (LNH==LNL==0) and the reply has length 4 bytes and denotes big endian integer. It contains values as described in the abstract class JCTerminal as legal return values the getStatus method. If status is not supported return value 0.
Error message (MTY=0x03)
Request the remote error message. Request payload has length 0 and return payload contains the last error message in ASCII encoding. If this message is not supported then an empty string is returned.
Terminal info (MTY=0x04)
The request message has payload length 0 and the reply contains an ASCII string specifiying terminal details like device type, port, etc. If this message is not supported then an empty string is returned.
Initialization data (MTY=0x05)
The request message contains a terminal specification. The interpretation of this data depends on the server. The reply has length 0 if initialization parameter have been accepted by server. Otherwise an ASCII string is sent describing the rejection reason.
Information text (MTY=0x06)
The data is a string in encoding ISO8859_1 to be displayed at remote terminal server for informational purposes to its operator.
Debug information (MTY=0x07)
The command and response data is a JCOP-simulator debug message. This message sets or retrieves information in the simulator.
The socket connection is established when the open method is called and it is terminated when close is called.


Field Summary
 
Fields inherited from class com.ibm.jc.JCTerminal
CARD_PRESENT, ERROR, NOT_CONNECTED, PROTOCOL_T0, PROTOCOL_T1, PROTOCOL_TCL, SLOT_EMPTY
 
Constructor Summary
RemoteJCTerminal()
           
 
Method Summary
 void close()
          Close socket connection.
 byte[] debug(byte[] data, int offset, int len)
          Exchange debug message with terminal/card simulator.
 java.lang.String getErrorMessage()
           
 int getState()
           
 JCTerminal init(java.lang.Object param)
          Initialize terminal.
 void open()
          Open the card terminal.
 byte[] send(int nad, byte[] toSend, int offset, int len)
          Send data to the card terminal.
 int send(int mty, int nad, byte[] toSend, int offset, int len)
           
 java.lang.String toString()
           
 byte[] waitForCard(int time)
          Try to get an ATR from socket peer.
 
Methods inherited from class com.ibm.jc.JCTerminal
filterFor, filterFor, generateParityError, getInstance, ioctl, pps, send, sendraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RemoteJCTerminal

public RemoteJCTerminal()
Method Detail

init

public JCTerminal init(java.lang.Object param)
Initialize terminal.

Overrides:
init in class JCTerminal
Parameters:
param - param has the form "[HOST:]PORT[/REMOTE]]" with REMOTE and HOST being optional. HOST specifies the remote host (default localhost) and PORT the port to contact. REMOTE is a string used to initialize remote terminal server. If omitted no remote initializtion message will be sent. If param is null it defaults to "localhost:8050".
Returns:
this

toString

public java.lang.String toString()
Overrides:
toString in class JCTerminal
Returns:
a string of the form "Remote(SOCK/TERM)" where SOCK describes the socket setup and TERM information about the remote terminal.

getErrorMessage

public java.lang.String getErrorMessage()
Overrides:
getErrorMessage in class JCTerminal
Returns:
last error message

open

public void open()
Open the card terminal. The socket connection is established.

Specified by:
open in class JCTerminal

close

public void close()
Close socket connection.

Specified by:
close in class JCTerminal
See Also:
JCTerminal.open()

waitForCard

public byte[] waitForCard(int time)
Try to get an ATR from socket peer.

Specified by:
waitForCard in class JCTerminal
Parameters:
time - the calls blocks for specified milliseconds.
Returns:
ATR (answer to reset) or null if no ATR could be retrieved. The reason might be that no card is inserted or because of communication problems.

getState

public int getState()
Specified by:
getState in class JCTerminal
Returns:
the status of the terminal.

send

public byte[] send(int nad,
                   byte[] toSend,
                   int offset,
                   int len)
Send data to the card terminal.

Specified by:
send in class JCTerminal
Parameters:
toSend - byte array containing data to be send
offset - offset starting at which data sending is to begin
len - number of bytes to be transmitted
nad - node address to which data is being sent
Returns:
response APDU as a byte array
Throws:
JCException - if communication failed or if some parameters are wrong
See Also:
com.ibm.jc.JCard.send

debug

public byte[] debug(byte[] data,
                    int offset,
                    int len)
Exchange debug message with terminal/card simulator.


send

public int send(int mty,
                int nad,
                byte[] toSend,
                int offset,
                int len)