com.ibm.opencard.isofs
Class MFC35FileAccessImpl
java.lang.Object
|
+--com.ibm.opencard.isofs.MFC35FileAccessImpl
- public class MFC35FileAccessImpl
- extends java.lang.Object
- implements MFCFileAccessImpl
Implementation of a file access card service for MFC 3.5 and some others.
File access refers to read and update operations. It does not include
create, invalidate or other creational operations.
- Version:
- $Id: MFC35FileAccessImpl.java,v 1.1 1999/12/02 16:06:04 damke Exp $
|
Field Summary |
protected byte |
iso_class
The CLAss byte for ISO commands gets cached here. |
protected MFCCodes |
mfc_codes
The CLAss and INStruction bytes for commands. |
|
Method Summary |
void |
appendRecord(MFCCardChannel channel,
byte[] data)
Appends data to a structured file.
|
byte[] |
decreaseValue(MFCCardChannel channel,
int delta)
Decreases the value of a record in a structured file.
|
byte[] |
increaseValue(MFCCardChannel channel,
int delta)
Increases the value of a record in a structured file.
|
byte[] |
readBinary(MFCCardChannel channel,
int offset,
int length)
Reads data from a transparent file.
|
protected byte[] |
readBinaryBytes(MFCCardChannel channel,
int accgroup,
byte[] target,
int toffset,
int foffset,
int length)
Reads bytes from a transparent file using a single command.
|
protected byte[][] |
readCyclicRecords(MFCCardChannel channel,
MFCCommandAPDU command,
int accgroup,
int number)
Reads the first records from a cyclic file with MFC 3.5 or 4.0.
|
byte[] |
readRecord(MFCCardChannel channel,
int record)
Reads a record from a structured file.
|
byte[][] |
readRecords(MFCCardChannel channel,
int number)
Reads the first records from a structured file.
|
void |
writeBinary(MFCCardChannel channel,
int foffset,
byte[] source,
int soffset,
int length)
Writes data to a transparent file.
|
protected void |
writeBinaryBytes(MFCCardChannel channel,
int accgroup,
int foffset,
byte[] source,
int soffset,
int length)
Writes bytes to a transparent file using a single command.
|
protected void |
writeCyclicRecord(MFCCardChannel channel,
byte[] source)
Writes a record in a cyclic file with MFC 3.5 or 4.0 smartcards.
|
void |
writeRecord(MFCCardChannel channel,
int record,
byte[] source)
Writes data to a structured file.
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
mfc_codes
protected MFCCodes mfc_codes
- The CLAss and INStruction bytes for commands.
iso_class
protected byte iso_class
- The CLAss byte for ISO commands gets cached here.
MFC35FileAccessImpl
public MFC35FileAccessImpl(MFCCodes codes)
- Instantiates a new file access card service implementation.
- Parameters:
codes - the command codes for the MFC card to support
readBinaryBytes
protected byte[] readBinaryBytes(MFCCardChannel channel,
int accgroup,
byte[] target,
int toffset,
int foffset,
int length)
throws CardServiceException,
CardTerminalException
- Reads bytes from a transparent file using a single command.
The file has to be selected. The length of the data to read
must be small enough to fit into a single response APDU.
- Parameters:
channel - where to contact the smartcardaccgroup - access group for READ commandstarget - array to fill in the bytes, or nulltoffset - array index to start filling. If target
is null, this value is ignored.foffset - file index to start readinglength - number of bytes to read and fill in- Returns:
- array holding the data read.
If target is not null, it's value is returned.
Otherwise, a new array will be allocated and returned.
- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
writeBinaryBytes
protected void writeBinaryBytes(MFCCardChannel channel,
int accgroup,
int foffset,
byte[] source,
int soffset,
int length)
throws CardServiceException,
CardTerminalException
- Writes bytes to a transparent file using a single command.
The file has to be selected. The length of the data to write
must be small enough to fit into a single command APDU.
- Parameters:
channel - where to contact the smartcardaccgroup - access group for UPDATE commandsfoffset - file index to start writing atsource - array holding the bytes to writesoffset - first byte to writelength - number of bytes to write- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
readCyclicRecords
protected byte[][] readCyclicRecords(MFCCardChannel channel,
MFCCommandAPDU command,
int accgroup,
int number)
throws CardServiceException,
CardTerminalException
- Reads the first records from a cyclic file with MFC 3.5 or 4.0.
MFC cards up to and including 4.0 implement an obscure scheme for
addressing cyclic files. The most recently written record has to
be selected using absolute addressing and the magic number for the
current record. The following records have to be read using
relative addressing and the previous mode.
This method is invoked only for MFC cards up to and including MFC 4.0,
and for cyclic files. Since MFC 4.1, reading cyclic files can be done
using absolute addresses, so there is no need for a special method.
- Parameters:
channel - how to contact the smartcardcommand - the APDU to send, pre-initializedaccgroup - the access group for readingnumber - number of records to read- Returns:
- an array of arrays holding the data read
- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
writeCyclicRecord
protected void writeCyclicRecord(MFCCardChannel channel,
byte[] source)
throws CardServiceException,
CardTerminalException
- Writes a record in a cyclic file with MFC 3.5 or 4.0 smartcards.
MFC cards prior to 4.1 do not support the APPEND RECORD command.
Since they do not support linear variable files either, this does
not matter except for cyclic files, in which case a similiar
effect can be achieved using the UPDATE BINARY command.
This method is invoked only for MFC cards up to and including MFC 4.0,
and for cyclic files. Since MFC 4.1, APPEND RECORD is suppported, so
there is no need for a special method. The difference lies with the
access conditions: APPEND RECORD has command class Create,
while UPDATE RECORD has command class Update.
- Parameters:
channel - how to contact the smartcardsource - the data to write to the file- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
readBinary
public byte[] readBinary(MFCCardChannel channel,
int offset,
int length)
throws CardServiceException,
CardTerminalException
- Reads data from a transparent file.
The file has to be selected.
- Specified by:
- readBinary in interface MFCFileAccessImpl
- Parameters:
channel - how to contact the smartcardoffset - index of first byte to readlength - number of bytes to read- Returns:
- byte array holding the data read
- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
readRecord
public byte[] readRecord(MFCCardChannel channel,
int record)
throws CardServiceException,
CardTerminalException
- Reads a record from a structured file.
The file has to be selected, and the file info
must have been set in the channel state.
- Specified by:
- readRecord in interface MFCFileAccessImpl
- Parameters:
channel - how to contact the smartcardrecord - number of the record to read (0 for first record)- Returns:
- byte array holding the data read
- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
readRecords
public byte[][] readRecords(MFCCardChannel channel,
int number)
throws CardServiceException,
CardTerminalException
- Reads the first records from a structured file.
The structured file has to be selected.
- Specified by:
- readRecords in interface MFCFileAccessImpl
- Parameters:
channel - how to contact the smartcardnumber - number of records to read, 0 for all- Returns:
- an array of arrays holding the data read
- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
writeBinary
public void writeBinary(MFCCardChannel channel,
int foffset,
byte[] source,
int soffset,
int length)
throws CardServiceException,
CardTerminalException
- Writes data to a transparent file.
The file has to be selected.
- Specified by:
- writeBinary in interface MFCFileAccessImpl
- Parameters:
channel - how to contact the smartcardfoffset - file index of first byte to write tosource - the data to writesoffset - array index of first byte to writelength - number of bytes to write- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
writeRecord
public void writeRecord(MFCCardChannel channel,
int record,
byte[] source)
throws CardServiceException,
CardTerminalException
- Writes data to a structured file.
The file has to be selected.
- Specified by:
- writeRecord in interface MFCFileAccessImpl
- Parameters:
channel - how to contact the smartcardsource - the data to write in the recordrecord - number of the record to write (0 for first record)- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
appendRecord
public void appendRecord(MFCCardChannel channel,
byte[] data)
throws CardServiceException,
CardTerminalException
- Appends data to a structured file.
The structured file has to be selected.
Appending is supported for cyclic and linear variable files.
MFC smartcards prior to 4.1 do not support the APPEND RECORD command.
Invocations of this method are mapped onto the UPDATE RECORD command
in this case. When designing a card layout, it has to be taken into
account that the access condition is taken from the Update group,
not the Create group. Additionally, the UPDATE RECORD command
is mutually exclusive with the INCREASE command. Implementing a purse
that supports appending records as well as increasing the value is
just not possible with MFC smartcards prior to 4.1.
See also writeCyclicRecord, which is invoked in this case.
- Specified by:
- appendRecord in interface MFCFileAccessImpl
- Parameters:
channel - how to contact the smartcarddata - the data to append- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
- See Also:
writeCyclicRecord(com.ibm.opencard.service.MFCCardChannel, byte[])
increaseValue
public byte[] increaseValue(MFCCardChannel channel,
int delta)
throws CardServiceException,
CardTerminalException
- Increases the value of a record in a structured file.
The file has to be selected. The first record within
the selected file will be modified. Typically, this
operation is used with cyclic files.
- Specified by:
- increaseValue in interface MFCFileAccessImpl
- Parameters:
channel - the contact to the smartcarddelta - the 3-byte unsigned amount by which to increase- Returns:
- the record after the operation.
- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
decreaseValue
public byte[] decreaseValue(MFCCardChannel channel,
int delta)
throws CardServiceException,
CardTerminalException
- Decreases the value of a record in a structured file.
The file has to be selected. The first record within
the selected file will be modified. Typically, this
operation is used with cyclic files.
- Specified by:
- decreaseValue in interface MFCFileAccessImpl
- Parameters:
channel - the contact to the smartcarddelta - the 3-byte unsigned amount by which to decrease- Returns:
- the record after the operation
- Throws:
- CardServiceException - if the service encountered an error
- CardTerminalException - if the terminal encountered an error
|