com.ibutton.jib
Class JibButton

java.lang.Object
  |
  +--com.ibutton.iButton
        |
        +--com.ibutton.jib.JibButton

public class JibButton
extends iButton

Class to provide access to all iButton with Java API commands.


Field Summary
static int SEND_APDU
           
 
Constructor Summary
JibButton(Access access, int[] romID)
          Constructor for the JibButton object.
 
Method Summary
 void appendData(byte[] newData)
          Append a byte[] to the body of the command packet.
 void appendData(char[] newData)
          Append a char[] to the body of the command packet.
 void appendData(int newData)
          Append an integer to the body of the command packet.
 void appendData(int[] newData)
          Append an int[] to the body of the command packet.
 ResponseAPDU getAIDbyNumber(int number)
          Returns the AID of the applet with the given number.
 ResponseAPDU getAppletGCMode()
          Reads the Applet Garbage Collection mode.
 byte[] getATR()
          Reads the Answer to Reset from the iButton as defined in ISO7816-5
 ResponseAPDU getCommandPINMode()
          Returns the mode of the CommandPIN.
 ResponseAPDU getCommitBufferSize()
          Gets the size of the iButton's Commit Buffer.
 ResponseAPDU getEphemeralGCMode()
          Reads the Ephemeral Garbage Collection mode.
 ResponseAPDU getExceptionMode()
          Gets the Exception mode.
 ResponseAPDU getLoadPINMode()
          Returns the mode of the LoadPIN.
protected  ResponseAPDU getPORCount()
          Gets the number of Power On Resets(PORs) the device has experienced since the last master erase.
 ResponseAPDU getRandomBytes(int numBytes)
          Reads random bytes from the iButton.
 ResponseAPDU getRealTimeClock()
          Reads the Real Time Clock of the iButton.
 ResponseAPDU getRestoreMode()
          Get the Restore Mode from the iButton.
 ResponseAPDU masterErase()
          Issues a master erase of the iButton
 ResponseAPDU readFirmwareVersionID()
          returns a ResponseAPDU containing the Firmware Version ID.
 ResponseAPDU readFreeRAM()
          returns a ResponseAPDU that contains the amount of free RAM, the data is returned in little endian format.
 byte[] sendAPDU(byte[] apdu, int ms)
          Sends an APDU to the iButton.
 ResponseAPDU sendAPDU(CommandAPDU apdu, int ms)
          Sends a CommandAPDU, as defined in ISO 7816, to an iButton.
 ResponseAPDU setAppletGCMode(int mode)
          Sets the mode of the applet garbage collector.
 ResponseAPDU setCommandPINMode(int mode)
          Sets the mode of the CommandPIN.
 ResponseAPDU setCommitBufferSize(short size)
          Sets the iButtons CommitBufferSize.
 ResponseAPDU setEphemeralGCMode(int mode)
          Sets the mode of the ephemeral garbage collector.
 ResponseAPDU setExceptionMode(int mode)
          Sets the Exception mode of the iButton.
 ResponseAPDU setLoadPINMode(int mode)
          Sets the mode of the LoadPIN.
 ResponseAPDU setMasterPIN(JibMasterPIN newPIN)
          Sets the common pin of the iButton.
 void setPIN(JibMasterPIN pin)
          This method sets the Common PIN in this class, not on the iButton.
 ResponseAPDU setRestoreMode(int mode)
          Sets the Restore Mode value.
 
Methods inherited from class com.ibutton.iButton
getAccess, getFamilyCode, getRomID, isRomID, select, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SEND_APDU

public static final int SEND_APDU
Constructor Detail

JibButton

public JibButton(Access access,
                 int[] romID)
Constructor for the JibButton object.
Parameters:
access - object representing how this JibButton object will communicate with an iButton.
romID - the romID of the iButton to communicate with.
Method Detail

setPIN

public void setPIN(JibMasterPIN pin)
This method sets the Common PIN in this class, not on the iButton.
Parameters:
pin - the PIN to store internal to this class as the identified Common PIN setCommonPIN

masterErase

public ResponseAPDU masterErase()
Issues a master erase of the iButton
Returns:
returns a ResponseAPDU object containing the response apdu sent by the iButton.

readFreeRAM

public ResponseAPDU readFreeRAM()
returns a ResponseAPDU that contains the amount of free RAM, the data is returned in little endian format.
Returns:
the ResponseAPDU from the iButton.

readFirmwareVersionID

public ResponseAPDU readFirmwareVersionID()
returns a ResponseAPDU containing the Firmware Version ID.
Returns:
ResponseAPDU containing the Firmware Version ID

getEphemeralGCMode

public ResponseAPDU getEphemeralGCMode()
Reads the Ephemeral Garbage Collection mode. If the mode is true the ephemeral collector is on.
Returns:
the ResponseAPDU containing the value of the Ephemeral Garbage Collector. A value of 1 indicates the garbage collector is turned on.

setEphemeralGCMode

public ResponseAPDU setEphemeralGCMode(int mode)
Sets the mode of the ephemeral garbage collector. Setting the mode to true turns the collector on, setting it to false turns the collector off. If the iButton is password protected, setPIN() should be called before invoking this method.
Parameters:
mode - 1 - turn the collector on, 0 - turn the collector off.
Returns:
the ResponseAPDU containing the Status Word of the response.

getAppletGCMode

public ResponseAPDU getAppletGCMode()
Reads the Applet Garbage Collection mode.
Returns:
the ResponseAPDU containing the mode of the Applet Garbage Collector. A value of 1 indicates the garbage collector is turned on.

setAppletGCMode

public ResponseAPDU setAppletGCMode(int mode)
Sets the mode of the applet garbage collector. Setting the mode to true turns the collector on, setting it to false turns the collector off. If the iButton is password protected, setPIN() should be called before invoking this method.
Parameters:
mode - 1 - turn the collector on, 0 - turn the collector off.
Returns:
the ResponseAPDU containing the Status Word of the response.

getCommandPINMode

public ResponseAPDU getCommandPINMode()
Returns the mode of the CommandPIN. If a value of 1 is returned by the iButton, PINs are required to perform all Admistrative commands.
Returns:
the ResponseAPDU containing the mode of the CommandPIN. A value of 1 indicates a PIN is required for all Administrative commands.

setCommandPINMode

public ResponseAPDU setCommandPINMode(int mode)
Sets the mode of the CommandPIN. Setting the mode to 1 indicates the the iButton requires a PIN for all Administrative commands. If the iButton is password protected, setPIN() should be called before invoking this method.
Parameters:
mode - 1 - set the CommandPIN mode to require a PIN for all Administrative commands. 0 - set the CommandPIN mode to not require a PIN for all Administrative commands.
Returns:
the ResponseAPDU containing the Status Word of the response.

getLoadPINMode

public ResponseAPDU getLoadPINMode()
Returns the mode of the LoadPIN. If a value of 1 is returned by the iButton, PINs are required to load applets.
Returns:
the ResponseAPDU containing the mode of the LoadPIN. A value of 1 indicates a PIN is required for loading applets onto the iButton.

setLoadPINMode

public ResponseAPDU setLoadPINMode(int mode)
Sets the mode of the LoadPIN. Setting the mode to 1 indicates the the iButton requires a PIN for all applets loads. If the iButton is password protected, setPIN() should be called before invoking this method.
Parameters:
mode - 1 - set the LoadPIN mode to require a PIN for applet load. 0 - set the CommandPIN mode to not require a PIN for applet load.
Returns:
the ResponseAPDU containing the Status Word of the response.

getRestoreMode

public ResponseAPDU getRestoreMode()
Get the Restore Mode from the iButton. If the mode is 1 then interrupted transactions are restored to their previous values.
Returns:
the ResponseAPDU containing the restore mode.

setRestoreMode

public ResponseAPDU setRestoreMode(int mode)
Sets the Restore Mode value. If the mode is 1, then interrupted transactions are restored to their previous values. If the iButton is password protected, setPIN() should be called before invoking this method.
Returns:
the ResponseAPDU containing the restore mode.

getExceptionMode

public ResponseAPDU getExceptionMode()
Gets the Exception mode. If the mode is 1, then VM exceptions are thrown. If the mode is 0, then VM exceptions are not thrown.
Returns:
the ResponseAPDU containing the Exception mode.

setExceptionMode

public ResponseAPDU setExceptionMode(int mode)
Sets the Exception mode of the iButton. If the mode is 1, then VM exceptions are thrown. If the iButton is password protected, setPIN() should be called before invoking this method.
Parameters:
mode - 1 - set the Exception mode to allow VM thrown exceptions. 0 - set the Exception mode to not allow the VM to throw exceptions.
Returns:
the ResponseAPDU containing the Status Word of the response.

getCommitBufferSize

public ResponseAPDU getCommitBufferSize()
Gets the size of the iButton's Commit Buffer.
Returns:
the ResponseAPDU containing the size of the iButton's commit buffer.

setCommitBufferSize

public ResponseAPDU setCommitBufferSize(short size)
Sets the iButtons CommitBufferSize. The value passed in is rounded up by the iButton to the nearest multiple of 9. If the iButton is password protected, setPIN() should be called before invoking this method.
Parameters:
size - the new size of the commit buffer.
Returns:
the ResponseAPDU containing the Status Word of the response.

getATR

public byte[] getATR()
Reads the Answer to Reset from the iButton as defined in ISO7816-5
Returns:
byte array that contains the iButton's ATR.

getRealTimeClock

public ResponseAPDU getRealTimeClock()
Reads the Real Time Clock of the iButton.
Returns:
the ResponseAPDU containing the value of the Real Time Clock.

getRandomBytes

public ResponseAPDU getRandomBytes(int numBytes)
Reads random bytes from the iButton. The maximum number of bytes that can be read is 128.
Parameters:
numBytes - the number of random bytes to read from the iButton.
Returns:
Response APDU that contains the requested number of random bytes.

getAIDbyNumber

public ResponseAPDU getAIDbyNumber(int number)
Returns the AID of the applet with the given number. Each applet stored on the iButton is assigned a number(0 - 15). A directory structure of applets on an iButton can be built by calling this method iteratively with parameter values from 0 to 15.
Parameters:
number - the number of the applet to retrieve the AID.
Returns:
Response APDU containing the AID of the applet requested.

getPORCount

protected ResponseAPDU getPORCount()
Gets the number of Power On Resets(PORs) the device has experienced since the last master erase.
Returns:
Response APDU containing the number of PORs since the last master erase.

setMasterPIN

public ResponseAPDU setMasterPIN(JibMasterPIN newPIN)
Sets the common pin of the iButton. A call to setPIN with the old PIN is required before this method can be called. The PIN to be set is passed in.
Parameters:
newPIN - the new PIN for the iButton
Returns:
Response APDU indicating success or failure. setPIN

sendAPDU

public ResponseAPDU sendAPDU(CommandAPDU apdu,
                             int ms)
Sends a CommandAPDU, as defined in ISO 7816, to an iButton. This is a generic method to communicate with an iButton.
Parameters:
apdu - - the command apdu object to be sent to the iButton.
ms - - the number of milliseconds to run the iButton.
Returns:
Response APDU from the iButton. The data is command specific.

sendAPDU

public byte[] sendAPDU(byte[] apdu,
                       int ms)
Sends an APDU to the iButton.
Parameters:
apdu - the byte array (APDU) to be sent to the iButton.
ms - the run time in milliseconds for the iButton.
Returns:
the data returned by the iButton.

appendData

public void appendData(int[] newData)
Append an int[] to the body of the command packet.
Parameters:
newData - the array to be appended to the body of the command packet.

appendData

public void appendData(char[] newData)
Append a char[] to the body of the command packet.
Parameters:
newData - the char[] to be appended to the body of the command packet.

appendData

public void appendData(int newData)
Append an integer to the body of the command packet.
Parameters:
newData - the integer to be appended.

appendData

public void appendData(byte[] newData)
Append a byte[] to the body of the command packet.
Parameters:
newData - the byte[] to be appended.