Class SecureChipHandler

java.lang.Object
  extended by SecureChipHandler
All Implemented Interfaces:
com.nokia.nfc.sc.SecureChipListener, javax.microedition.lcdui.CommandListener

public class SecureChipHandler
extends java.lang.Object
implements com.nokia.nfc.sc.SecureChipListener, javax.microedition.lcdui.CommandListener

SecureChipHandler is responsible for communication with the Nokia NFC payment and ticketing cover.

Since:
1.0
Author:
Magnus Egeberg

Field Summary
private  java.lang.String ALERT_PIN_ERROR_PIN_MISMATCH
           
private  java.lang.String ALERT_PIN_QUERY
           
private  java.lang.String ALERT_PIN_RECEIVED
           
private  java.lang.String ALERT_PIN_TITLE
           
private  javax.microedition.lcdui.Command backCmd
           
private  byte[] buf
           
private  java.lang.String BUSY_CORRECT_PIN
           
private  java.lang.String CMD_BACK
           
private  java.lang.String CMD_OK
           
 boolean connected
           
 com.nokia.nfc.sc.SecureChipConnection coverConnection
           
private  byte[] empty
           
private  java.lang.String ERROR_PIN_MISMATCH
           
private  java.lang.String ERROR_PIN_RESET_TIMEOUT
           
private  java.lang.String ERROR_PIN_TIMEOUT
           
private  java.lang.String ERROR_SC_BUSY
           
private  boolean mifareWrite
           
private  java.lang.String MODE_CHANGE
           
private  java.lang.String MODE_CHANGE_SUCCESS
           
private  javax.microedition.lcdui.Command okCmd
           
private  java.lang.String pin
           
private  javax.microedition.lcdui.Alert pinAlert
           
private  javax.microedition.lcdui.TextBox pinEntry
           
 boolean pinOk
           
private  TicketingSystemMIDlet ts
           
 
Constructor Summary
SecureChipHandler(TicketingSystemMIDlet ts)
          The SecureChipHandler creates the PIN alert and connects to the cover
 
Method Summary
private  void askForPin(java.lang.String text)
          Query the user for PIN to change the communication mode
 void changeMode(com.nokia.nfc.sc.SCCMode mode)
          changes the communication mode of the cover
 void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
          Performs actions based on the commands
 void connectToCover()
          Connects to the cover
 void handleEvent(com.nokia.nfc.sc.SecureChipEvent e)
          Handles events sent from the cover
private  java.lang.String mapResult(int responseCode)
          Maps the given code to a error string.
private  boolean pinEnabled()
          Controls of PIN is enabled
 void readMifare()
          Creates a MifareWriter If PIN is not ok, the user will be queried for the PIN
private  void resetTicket()
          Sets the buffer that the ticket is copied into all (byte) 0x00
 void updateForm(java.lang.String parameter, java.lang.String value)
          Updates the error form with data
 void writeMifare(byte[] data)
          Creats a MifareWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALERT_PIN_TITLE

private final java.lang.String ALERT_PIN_TITLE
See Also:
Constant Field Values

ALERT_PIN_RECEIVED

private final java.lang.String ALERT_PIN_RECEIVED
See Also:
Constant Field Values

ALERT_PIN_QUERY

private final java.lang.String ALERT_PIN_QUERY
See Also:
Constant Field Values

ALERT_PIN_ERROR_PIN_MISMATCH

private final java.lang.String ALERT_PIN_ERROR_PIN_MISMATCH
See Also:
Constant Field Values

BUSY_CORRECT_PIN

private final java.lang.String BUSY_CORRECT_PIN
See Also:
Constant Field Values

CMD_OK

private final java.lang.String CMD_OK
See Also:
Constant Field Values

CMD_BACK

private final java.lang.String CMD_BACK
See Also:
Constant Field Values

MODE_CHANGE

private final java.lang.String MODE_CHANGE
See Also:
Constant Field Values

MODE_CHANGE_SUCCESS

private final java.lang.String MODE_CHANGE_SUCCESS
See Also:
Constant Field Values

ERROR_PIN_MISMATCH

private final java.lang.String ERROR_PIN_MISMATCH
See Also:
Constant Field Values

ERROR_PIN_TIMEOUT

private final java.lang.String ERROR_PIN_TIMEOUT
See Also:
Constant Field Values

ERROR_PIN_RESET_TIMEOUT

private final java.lang.String ERROR_PIN_RESET_TIMEOUT
See Also:
Constant Field Values

ERROR_SC_BUSY

private final java.lang.String ERROR_SC_BUSY
See Also:
Constant Field Values

buf

private byte[] buf

mifareWrite

private boolean mifareWrite

pinAlert

private javax.microedition.lcdui.Alert pinAlert

pinEntry

private javax.microedition.lcdui.TextBox pinEntry

okCmd

private javax.microedition.lcdui.Command okCmd

backCmd

private javax.microedition.lcdui.Command backCmd

coverConnection

public com.nokia.nfc.sc.SecureChipConnection coverConnection

connected

public boolean connected

pinOk

public boolean pinOk

pin

private java.lang.String pin

ts

private TicketingSystemMIDlet ts

empty

private byte[] empty
Constructor Detail

SecureChipHandler

public SecureChipHandler(TicketingSystemMIDlet ts)
The SecureChipHandler creates the PIN alert and connects to the cover

Parameters:
ts - The MIDlet.
Method Detail

handleEvent

public void handleEvent(com.nokia.nfc.sc.SecureChipEvent e)
Handles events sent from the cover

Specified by:
handleEvent in interface com.nokia.nfc.sc.SecureChipListener
Parameters:
e - the SecureChipEvent sent from the cover
See Also:
SecureChipEvent

changeMode

public void changeMode(com.nokia.nfc.sc.SCCMode mode)
changes the communication mode of the cover

Parameters:
mode - The new communication mode
See Also:
SecureChipConnection

askForPin

private void askForPin(java.lang.String text)
Query the user for PIN to change the communication mode

Parameters:
text - The query

updateForm

public void updateForm(java.lang.String parameter,
                       java.lang.String value)
Updates the error form with data

Parameters:
parameter - The parameter to trace
value - The value of the parameter

mapResult

private java.lang.String mapResult(int responseCode)
Maps the given code to a error string.

Parameters:
The - code to be mapped

commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          javax.microedition.lcdui.Displayable d)
Performs actions based on the commands

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener
Parameters:
c - The command
d - The displayable

writeMifare

public void writeMifare(byte[] data)
Creats a MifareWriter. If PIN is not ok, the user will be queried for the PIN

Parameters:
data - The ticket

readMifare

public void readMifare()
Creates a MifareWriter If PIN is not ok, the user will be queried for the PIN


pinEnabled

private boolean pinEnabled()
Controls of PIN is enabled

Returns:
tmp True if PIN is enabled

connectToCover

public void connectToCover()
Connects to the cover


resetTicket

private void resetTicket()
Sets the buffer that the ticket is copied into all (byte) 0x00