1-Wire API for .NET Version 4.00
|
Inherits com::dalsemi::onewire::container::OneWireContainer.
Public Member Functions | |
OneWireContainer18 () | |
Creates a new OneWireContainer for communication with a DS1963S SHA iButton. | |
OneWireContainer18 (DSPortAdapter sourceAdapter, byte[] newAddress) | |
Creates a new OneWireContainer for communication with a DS1963S SHA iButton. | |
OneWireContainer18 (DSPortAdapter sourceAdapter, long newAddress) | |
Creates a new OneWireContainer for communication with a DS1963S SHA iButton. | |
OneWireContainer18 (DSPortAdapter sourceAdapter, String newAddress) | |
Creates a new OneWireContainer for communication with a DS1963S SHA iButton. | |
void | setupContainer (DSPortAdapter sourceAdapter, byte[] newAddress) |
String | getName () |
Get the Maxim Integrated Products part number of the iButton or 1-Wire Device as a java.lang.String . | |
String | getAlternateNames () |
Retrieve the alternate Maxim Integrated Products part numbers or names. | |
String | getDescription () |
Get a short description of the function of this iButton or 1-Wire Device type. | |
int | getMaxSpeed () |
Returns the maximum speed this iButton device can communicate at. | |
Enumeration | getMemoryBanks () |
Gets an enumeration of memory bank instances that implement one or more of the following interfaces: MemoryBank, PagedMemoryBank, and OTPMemoryBank. | |
synchronized void | setSpeedCheck (boolean doSpeedCheck) |
Directs the container to avoid the calls to doSpeed() in methods that communicate with the SHA iButton. | |
synchronized void | useResume (boolean set) |
synchronized boolean | eraseScratchPad (int page) throws OneWireIOException, OneWireException |
synchronized boolean | waitForSuccessfulFinish () throws OneWireIOException, OneWireException |
void | readMemoryPage (int pageNum, byte[] data, int start) throws OneWireIOException, OneWireException |
boolean | readAuthenticatedPage (int pageNum, byte[] data, int start) throws OneWireIOException, OneWireException |
synchronized boolean | writeScratchPad (int targetPage, int targetPageOffset, byte[] inputbuffer, int start, int length) throws OneWireIOException, OneWireException |
synchronized boolean | matchScratchPad (byte[] mac) throws OneWireIOException, OneWireException |
synchronized int | readScratchPad (byte[] data, int start) throws OneWireIOException, OneWireException |
synchronized boolean | copyScratchPad () throws OneWireIOException, OneWireException |
Copies the contents of the scratchpad to the target destination that was specified in a call to writeScratchPad() or eraseScratchPad() . | |
synchronized boolean | installMasterSecret (int page, byte[] secret, int secret_number) throws OneWireIOException, OneWireException |
synchronized boolean | bindSecretToiButton (int page, byte[] bind_data, byte[] bind_code, int secret_number) throws OneWireIOException, OneWireException |
synchronized boolean | writeDataPage (int page_number, byte[] page_data) throws OneWireIOException, OneWireException |
boolean | SHAFunction (byte function) throws OneWireIOException, OneWireException |
synchronized boolean | SHAFunction (byte function, int T) throws OneWireIOException, OneWireException |
1-Wire® container for a SHA Transaction iButton, DS1963S. This container encapsulates the functionality of the 1-Wire family type 18 (hex).
This container provides the functionality to use the raw power of the DS1963S. It does not immediately implement transactions and authentication. The class SHAiButton does these. The SHAiButton
class exists on top of this class, making higher level calls to implement transactions.
This container makes use of several optimizations to help it run fast on TINI. These optimizations do little for the PC, but they do not slow down the PC. Most methods are synchronized
because they access an instance byte array. This is less expensive than creating new byte arrays for every method, because there should not be contention for the resources in this container between threads. Threads should use the com.dalsemi.onewire.adapter.DSPortAdapter
methods beginExclusive(boolean)
and endExclusive()
to synchronize on the 1-Wire port.
Notice that for maximum performance, programs should call the method setSpeedCheck(boolean)
with an argument false
before any other methods that access the 1-Wire. A program that calls this function is assumed to understand and control the speed of communication on the 1-Wire bus. If the speed check is not disabled, a call to the method OneWireContainer.doSpeed()
will occur in almost every function. While this should guarantee that the 1-Wire bus is never at an unknown speed, it will slow down throughput considerably.
In the interest of speed, this container has several methods to quickly access the memory of a DS9163S. These methods include:
The memory can also be accessed through the objects that are returned from the getMemoryBanks method.
The following is a list of the MemoryBank instances that are returned:
For examples on using the SHA iButton for transactions and authentications, see the examples in the SHAiButton usage section.
For examples regarding memory operations,
http://pdfserv.maxim-ic.com/arpdf/DS1963S.pdf
Note that the protocol for transactions using SHA iButtons calls for 2 iButtons. One belongs to the system that grants authentication and is authorized to validate money. This iButton is usually called the Coprocessor. The other iButton is the device that contains digital money that must be authenticated and verified to perform transactions. This iButton is usually called a User iButton, Roaming iButton, or Roving iButton.
Creates a new OneWireContainer
for communication with a DS1963S SHA iButton.
Note that the method setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[])
must be called to set the correct DSPortAdapter
device address.
OneWireContainer18 | ( | DSPortAdapter | sourceAdapter, |
byte[] | newAddress | ||
) |
Creates a new OneWireContainer
for communication with a DS1963S SHA iButton.
sourceAdapter | adapter object required to communicate with this iButton |
newAddress | address of this DS1963S SHA iButton |
OneWireContainer18 | ( | DSPortAdapter | sourceAdapter, |
long | newAddress | ||
) |
Creates a new OneWireContainer
for communication with a DS1963S SHA iButton.
sourceAdapter | adapter object required to communicate with this iButton |
newAddress | address of this DS1963S SHA iButton |
OneWireContainer18 | ( | DSPortAdapter | sourceAdapter, |
String | newAddress | ||
) |
Creates a new OneWireContainer
for communication with a DS1963S SHA iButton.
sourceAdapter | adapter object required to communicate with this iButton |
newAddress | address of this DS1963S SHA iButton |
synchronized boolean bindSecretToiButton | ( | int | page, |
byte[] | bind_data, | ||
byte[] | bind_code, | ||
int | secret_number | ||
) | throws OneWireIOException, OneWireException |
Binds an installed secret to a DS1963S by using well-known binding data and the DS1963S's unique address. This makes the secret unique for this iButton. Coprocessor iButtons use this method to recreate the iButton's secret to verify authentication. Roving iButtons use this method to finalize their secret keys.
Note that unlike in the installMasterSecret()
method, the page number does not need to be equivalent to the secret_number
modulo 8. The new secret (installed secret + binding code) is generated from this page but can be copied into another secret. User iButtons should bind to the same page the secret was installed on. Coprocessor iButtons must copy to a new secret to preserve the general system authentication secret.
The binding should be either 7 bytes long or 15 bytes long. A 15-length byte
array is unaltered and placed in the scratchpad for the binding. A 7-length byte
array is combined with the page number and DS1963S unique address and then placed in the scratchpad. Coprocessors should use a pre-formatted 15-length byte
array. User iButtons should let the method format for them (i.e. use the 7-length byte
array option).
page | the page number that has the master secret already installed |
bind_data | 32 bytes of binding data used to bind the iButton to the system |
bind_code | the 7-byte or 15-byte binding code |
secret_number | secret number to copy the resulting secret to |
true
if successfulOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized boolean copyScratchPad | ( | ) | throws OneWireIOException, OneWireException |
Copies the contents of the scratchpad to the target destination that was specified in a call to writeScratchPad()
or eraseScratchPad()
.
This method will not success unless a call to readScratchPad()
is made first to verify the target address registers in the DS1963S.
true
if successful, false
if the operation failed while waiting for the DS1963S's output to alternateOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized boolean eraseScratchPad | ( | int | page | ) | throws OneWireIOException, OneWireException |
Erases the scratchpad of the DS1963S. The cryptographic features of the DS1963S leave the device in 'hidden mode', which makes most memory functions inaccessible. A call to eraseScratchPad(int)
brings the device out of 'hidden mode', filling the scratchpad with 0x0FF bytes
.
The argument page
is usually unimportant, except in cases where a memory page needs to be erased. Erase a memory page by calling eraseScratchPad(page_number)
, followed by readScratchPad()
and then copyScratchPad()
.
page | the target page number |
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
String getAlternateNames | ( | ) |
Retrieve the alternate Maxim Integrated Products part numbers or names.
A 'family' of MicroLAN devices may have more than one part number depending on packaging. There can also be nicknames such as "Crypto iButton".
Reimplemented from OneWireContainer.
String getDescription | ( | ) |
Get a short description of the function of this iButton or 1-Wire Device type.
Reimplemented from OneWireContainer.
int getMaxSpeed | ( | ) |
Returns the maximum speed this iButton device can communicate at.
Reimplemented from OneWireContainer.
Enumeration getMemoryBanks | ( | ) |
Gets an enumeration of memory bank instances that implement one or more of the following interfaces: MemoryBank, PagedMemoryBank, and OTPMemoryBank.
Enumeration
of memory banks Reimplemented from OneWireContainer.
String getName | ( | ) |
Get the Maxim Integrated Products part number of the iButton or 1-Wire Device as a java.lang.String
.
For example "DS1992".
Reimplemented from OneWireContainer.
synchronized boolean installMasterSecret | ( | int | page, |
byte[] | secret, | ||
int | secret_number | ||
) | throws OneWireIOException, OneWireException |
Installs a secret on a DS1963S. The secret is written in partial phrases of 47 bytes (32 bytes to a memory page, 15 bytes to the scratchpad) and is cumulative until the entire secret is processed. Secrets are associated with a page number. See the datasheet for more information on this association.
In most cases, page
should be equal to secret_number
or secret_number+8
, based on the association of secrets and page numbers. Secrets are stored across pages 16 and 17 of the DS1963S memory. A secret is 8 bytes, so there are 8 secrets. These 8 secrets are associated with the first 16 pages of memory.
On TINI, this method will be slightly faster if the secret's length is divisible by 47. However, since secret key generation is a part of initialization, it is probably not necessary.
page | the page number used to write the partial secrets to |
secret | the entire secret, in partial phrases, to be installed |
secret_number | the secret 'page' to use (0 - 7) |
true
if successfulOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized boolean matchScratchPad | ( | byte[] | mac | ) | throws OneWireIOException, OneWireException |
Verifies the hidden signature in the scratchpad of the DS1963S. After a VALIDATE_DATA_PAGE
command, the scratchpad contains a signature that cannot be read, but must be verified. This method gives the DS1963S a signature. The iButton then checks to see if it equals the hidden signature in its scratchpad.
The signature must be 20 bytes long, and it must start at offset 0 of the input array.
mac | the signature starting at offset 0 |
true
if the signature matchesOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
boolean readAuthenticatedPage | ( | int | pageNum, |
byte[] | data, | ||
int | start | ||
) | throws OneWireIOException, OneWireException |
Reads and authenticates a page. See readMemoryPage()
for a description of page numbers and their contents. This method will also generate a signature for the selected page, used in the authentication of roving (User) iButtons. Extra data is returned with the page as well--such as the write cycle counter for the page and the write cycle counter of the selected secret page.
Note that the CRC will be verified by this method, though it is returned with the data.
pageNum | page number to read and authenticate |
data | array for the page data plus extra information (2 write cycle counters of 4 bytes each, one 2 byte CRC, appended after 32 bytes of the data page). This byte array must be at least 42 bytes long. |
start | offset to copy into the array |
true
if successful, false
if the operation failed while waiting for the DS1963S's output to alternateOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
void readMemoryPage | ( | int | pageNum, |
byte[] | data, | ||
int | start | ||
) | throws OneWireIOException, OneWireException |
Reads a memory page from the DS1963S. Pages 0-15 are normal memory pages. Pages 16 and 17 contain the secrets--the DS1963S will return all 1's (0x0ff bytes). Page 18 is the physical location of the scratchpad, and will only return valid data if the part is not in hidden mode (0x0ff bytes are returned otherwise). Pages 19 and 20 contain the write cycle counters. Page 21 contains the counter for the pseudo random number generator (PRNG). Consult the datasheet for the memory maps of these special pages.
Note that the same data can be returned through the MemoryBank
s returned by getMemoryBanks()
. However, this method contains several enhancements for faster reading.
pageNum | page number to read |
data | array for the return of the data (must be at least 32 bytes long) |
start | offset into the byte array to start copying page data |
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized int readScratchPad | ( | byte[] | data, |
int | start | ||
) | throws OneWireIOException, OneWireException |
Reads the contents of the DS1963S scratchpad. If the device is in hidden mode, all 1's (0x0ff bytes) will be returned.
This method will return up to 32 bytes. It may return less if the target address stored internally on the DS1963S is not a multiple of 32.
data | array to hold the contents of the scratchpad |
start | offset to copy the scratchpad data into the byte array |
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized void setSpeedCheck | ( | boolean | doSpeedCheck | ) |
Directs the container to avoid the calls to doSpeed() in methods that communicate with the SHA iButton.
To ensure that all parts can talk to the 1-Wire bus at their desired speed, each method contains a call to doSpeed()
. However, this is an expensive operation. If a user manages the bus speed in an application, call this method with doSpeedCheck
as false
. The default behavior is to call doSpeed()
.
doSpeedCheck | true for doSpeed() to be called before every 1-Wire bus access, false to skip this expensive call |
void setupContainer | ( | DSPortAdapter | sourceAdapter, |
byte[] | newAddress | ||
) |
Provides this container with the adapter object used to access this device and the address of the iButton or 1-Wire device. Overrides the OneWireContainer
method for speed, as the OneWireContainer
version has a byte array allocation. Since there is a call to setupContainer()
in the critical path of a transaction (when a roving SHA iButton is introduced to the 1-Wire Bus), this must occur quickly. This improves performance on TINI.
sourceAdapter | adapter object required to communicate with this iButton |
newAddress | address of this 1-Wire device |
Reimplemented from OneWireContainer.
boolean SHAFunction | ( | byte | function | ) | throws OneWireIOException, OneWireException |
Performs one of the DS1963S's cryptographic functions. See the datasheet for more information on these functions.
Valid parameters for the function
argument are:
This method uses the last target address used by this OneWireContainer
. These are read in the copyScratchPad()
and readScratchPad()
methods.
function | the SHA function code |
true
if the function successfully completed, false
if the operation failed on a CRC error or while waiting for the DS1963S's output to alternateOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized boolean SHAFunction | ( | byte | function, |
int | T | ||
) | throws OneWireIOException, OneWireException |
Performs one of the DS1963S's cryptographic functions. See the datasheet for more information on these functions.
Valid parameters for the function
argument are:
This method uses the last target address used by this OneWireContainer
. These are read in the copyScratchPad()
and readScratchPad()
methods.
function | the SHA function code |
T | the raw target address for the operation |
true
if the function successfully completed, false
if the operation failed on a CRC error or while waiting for the DS1963S's output to alternateOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized void useResume | ( | boolean | set | ) |
Tells this OneWireContainer18
whether it can use the RESUME
command. The RESUME
command allows the DS1963S to be re-selected for communication quickly by using a one byte
RESUME
command rather than a nine byte
selection sequence. If another 1-Wire device is accessed, useResume(false)
must be called, a normal selection of the part must be performed, and then useResume(true)
can be called.
set | true to use the one byte RESUME command instead of the nine byte select command |
synchronized boolean waitForSuccessfulFinish | ( | ) | throws OneWireIOException, OneWireException |
Waits for the DS1963S's output to alternate. Several operations must wait for the DS1963S to stop sending 0x0ff's and begin alternating its output bits. This method reads until it finds a non-0x0ff byte
or until it reaches a specified number of tries, indicating failure.
This method can often be optimized away. A normal 1-Wire transaction involves writing and reading a known number of bytes. If a few more bytes are read, a program can check to see if the DS1963S has started alternating its output much quicker than calling this method will. For instance, to copy the scratchpad, the source code might look like this:
buffer [0] = COPY_SCRATCHPAD; buffer [1] = TA1; buffer [2] = TA2; buffer [3] = ES;
adapter.dataBlock(buffer,0,4); return waitForSuccessfulFinish();
To optimize the code, read more bytes than required:
buffer [0] = COPY_SCRATCHPAD; buffer [1] = TA1; buffer [2] = TA2; buffer [3] = ES;
//copy 0x0FF into the buffer, this effectively reads System.arraycopy(FF, 0, buffer, 4, 5);
//read 5 extra bytes adapter.dataBlock(buffer, 0, 9);
//if the last byte has not shown alternating output, //still call waitForSuccessfulFinish(), else //we are already done if (buffer [8] == ( byte ) 0x0ff) return waitForSuccessfulFinish(); else return true;
The second method is faster because it is more expensive to invoke another method that goes down to the native access layer than it is to just read a few more bytes while the program is already at the native access layer.
See the datasheet for which operations function in this manner. Only call this method after another method which has successfully communicated with the DS1963S.
true
if the DS1963S completed its operation successfullyOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized boolean writeDataPage | ( | int | page_number, |
byte[] | page_data | ||
) | throws OneWireIOException, OneWireException |
Writes a data page to the DS1963S. This method is the equivalent of calling:
eraseScratchPad(0);
writeScratchPad(page_number,0,page_data_array,0,32);
readScratchPad(buffer,0);
copyScratchPad();
However, this method makes several optimizations to help it run faster. Because of the optimizations, this is the preferred way of writing data to a normal memory page on the DS1963S.
page_number | page number to write |
page_data | page data to write (must be at least 32 bytes long) |
true
if successful, false
if the operation failed on a CRC error or while waiting for the DS1963S's output to alternateOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |
synchronized boolean writeScratchPad | ( | int | targetPage, |
int | targetPageOffset, | ||
byte[] | inputbuffer, | ||
int | start, | ||
int | length | ||
) | throws OneWireIOException, OneWireException |
Writes data to the scratchpad. In order to write to a data page using this method, next call readScratchPad()
, and then copyScratchPad()
. Note that the addresses passed to this method will be the addresses the data is copied to if the copyScratchPad()
method is called afterward.
Also note that if too many bytes are written, this method will truncate the data so that only a valid number of bytes will be sent.
targetPage | the page number this data will eventually be copied to |
targetPageOffset | the offset on the page to copy this data to |
inputbuffer | the data that will be copied into the scratchpad |
start | offset into the input buffer for the data to write |
length | number of bytes to write |
true
if successful, false
on a CRC errorOneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. |
OneWireException | on a communication or setup error with the 1-Wire adapter |