Class OneWireContainer33
1-Wire® container for the '1K-Bit protected 1-Wire EEPROM with SHA-1 Engine' family type 33 (hex), Maxim Integrated Products part number: DS1961S,DS2432.
Features
- 1128 bits of 5V EEPROM memory partitioned into four pages of 256 bits, a 64-bit write-only secret and up to 5 general purpose read/write registers.
- On-chip 512-bit SHA-1 engine to compute 160-bit Message Authentication Codes (MAC) and to generate secrets.
- Write access requires knowledge of the secret and the capability of computing and transmitting a 160-bit MAC as authorization.
- Secret and data memory can be write-protected (all or page 0 only) or put in EPROM-emulation mode ("write to 0", page0)
- unique, fatory-lasered and tested 64-bit registration number (8-bit family code + 48-bit serial number + 8-bit CRC tester) assures absolute traceability because no two parts are alike.
- Built-in multidrop controller ensures compatibility with other 1-Wire net products.
- Reduces control, address, data and power to a single data pin.
- Directly connects to a single port pin of a microprocessor and communicates at up to 16.3k bits per second.
- Overdrive mode boosts communication speed to 142k bits per second.
- 8-bit family code specifies DS2432 communication requirements to reader.
- Presence detector acknowledges when reader first applies voltage.
- Low cost 6-lead TSOC surface mount package, or solder-bumped chip scale package.
- Reads and writes over a wide voltage range of 2.8V to 5.25V from -40C to +85C.
The memory can also be accessed through the objects that are returned from
the getMemoryBanks
method.
- Page Zero with write protection
- Implements
MemoryBank
,PagedMemoryBank
- Size 32 starting at physical address 0
- Features Read/Write general-purpose non-volatile
- Page 1 page of length 32 bytes giving 29 bytes Packet data payload
- Page Features page-device-CRC and write protection.
- Implements
- Page One with EPROM mode and write protection
- Implements
MemoryBank
,PagedMemoryBank
- Size 32 starting at physical address 32
- Features Read/Write general-purpose non-volatile
- Page 1 page of length 32 bytes giving 29 bytes Packet data payload
- Page Features page-device-CRC, EPROM mode and write protection.
- Implements
- Page Two and Three with write protection
- Implements
MemoryBank
,PagedMemoryBank
- Size 64 starting at physical address 64
- Features Read/Write general-purpose non-volatile
- Pages 2 pages of length 32 bytes giving 29 bytes Packet data payload
- Page Features page-device-CRC and write protection.
- Implements
- Status Page that contains the secret and the status.
- Implements
MemoryBank
,PagedMemoryBank
- Size 24 starting at physical address 128
- Page Features Contains secret and status for the iButton.
- Implements
Example 1
Display some features of isMACValid where owd is an instanceof OneWireContainer33 and bank is an instanceof PagedMemoryBank:
byte[] read_buf = new byte [bank.getPageLength()];
byte[] extra_buf = new byte [bank.getExtraInfoLength()];
byte[] challenge = new byte [8];
// read a page (use the most verbose and secure method)
if (bank.hasPageAutoCRC())
{
System.out.println("Using device generated CRC");
if (bank.hasExtraInfo())
{
bank.readPageCRC(pg, false, read_buf, 0, extra_buf);
owd.getChallenge(challenge,0);
owd.getContainerSecret(secret, 0);
sernum = owd.getAddress();
macvalid = owd.isMACValid(bank.getStartPhysicalAddress()+pg*bank.getPageLength(),
sernum,read_buf,extra_buf,challenge,secret);
}
else
bank.readPageCRC(pg, false, read_buf, 0);
}
else
{
if (bank.hasExtraInfo())
bank.readPage(pg, false, read_buf, 0, extra_buf);
else
bank.readPage(pg, false, read_buf, 0);
}
DataSheet
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Flag to indicate if the status has been checked.protected static final byte[]
block of 0xFF's used for faster read pre-fill of 1-Wire blocksprotected boolean
Flag to indicate if the secret is write protected.protected boolean
Flag to indicate if the secret has been set.protected boolean
Flag to indicate if the adapter has been specified.protected static final byte[]
block of 0xFF's used for faster erase of blocksFields inherited from class com.dalsemi.onewire.container.OneWireContainer
adapter, address, speed, speedFallBackOK
-
Constructor Summary
ConstructorsConstructorDescriptionDefault Constructor OneWireContainer33.OneWireContainer33
(DSPortAdapter sourceAdapter, byte[] newAddress) Create a container with a provided adapter object and the address of the iButton or 1-Wire device.OneWireContainer33
(DSPortAdapter sourceAdapter, long newAddress) Create a container with a provided adapter object and the address of the iButton or 1-Wire device.OneWireContainer33
(DSPortAdapter sourceAdapter, String newAddress) Create a container with a provided adapter object and the address of the iButton or 1-Wire device. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Tells whether an adapter has been set.boolean
bindSecretToiButton
(int pageNum, byte[] bindData) Binds an installed secret to a DS1961S/DS2432 by using well-known binding data and the DS1961S/DS2432's unique address.protected boolean
To check the status of the part.void
computeNextSecret
(int pageNum) Compute Next Secret using the current contents of data page and scratchpad.void
computeNextSecret
(int pageNum, byte[] partialsecret, int offset) Compute Next Secretboolean
copyScratchpad
(int targetPage, int targetPageOffset) Copy all 8 bytes of the Sratch Pad to a certain page and offset in memory.boolean
copyScratchpad
(int targetPage, int targetPageOffset, byte[] copy_auth, int authStart) Copy all 8 bytes of the Sratch Pad to a certain page and offset in memory.Retrieve the alternate Maxim Integrated Products part numbers or names.void
getChallenge
(byte[] get, int offset) Get the challenge of this device as an array of bytes.void
getContainerSecret
(byte[] secretBuf, int offset) Get the secret of this device as an array of bytes.Retrieve a short description of the function of the iButton type.int
Returns the maximum speed this iButton can communicate at.getMemoryBankForPage
(int page) Returns the instance of the memory bank for a particular pageGet an enumeration of memory bank instances that implement one or more of the following interfaces:MemoryBank
,PagedMemoryBank
, andOTPMemoryBank
.getName()
Retrieve the Maxim Integrated Products part number of the iButton as a string.Returns the instance of the Scratchpad memory bank.Returns the instance of the Status page memory bank.boolean
installMasterSecret
(int page, byte[] newSecret) Installs a secret on a DS1961S/DS2432.boolean
Get the current status of the secret.static boolean
isMACValid
(int addr, byte[] SerNum, byte[] memory, byte[] mac, byte[] challenge, byte[] secret) Authenticates page data given a MAC.boolean
Tells if page one is in EPROM mode.boolean
Get the status of the secret, if it is write protected.boolean
Get the status of all the pages, if they are write protected.boolean
Get the status of page zero, if it is write protected.boolean
loadFirstSecret
(byte[] data, int offset) Load First Secretboolean
readAuthenticatedPage
(int page, byte[] pagedata, int offset, byte[] computed_mac, int macStart) Reads and authenticates a page.boolean
readMemoryPage
(int page, byte[] pageData, int offset) Reads a page of memory..void
readScratchpad
(byte[] scratchpad, int offset, byte[] extraInfo) Read from the Scratch Pad, which is a max of 8 bytes.boolean
refreshPage
(int page) Refreshes all 32 bytes of data on a given page.boolean
refreshPage
(int page, int offset) Refreshes a particular 8-byte set of data on a given page.void
setChallenge
(byte[] challengeset, int offset) Sets the challenge for the Read Authenticate Pagevoid
setContainerSecret
(byte[] newSecret, int offset) Sets the bus master secret for this DS2432.void
Sets the EPROM mode for page 1.void
setupContainer
(DSPortAdapter sourceAdapter, byte[] newAddress) Provide this container the adapter object used to access this device and provide the address of this iButton or 1-Wire device.void
setupContainer
(DSPortAdapter sourceAdapter, long newAddress) Provide this container the adapter object used to access this device and provide the address of this iButton or 1-Wire device.void
setupContainer
(DSPortAdapter sourceAdapter, String newAddress) Provide this container the adapter object used to access this device and provide the address of this iButton or 1-Wire device.boolean
writeDataPage
(int targetPage, byte[] pageData) Writes a data page to the DS1961S/DS2432.boolean
writeDataPage
(int targetPage, byte[] pageData, int offset) Writes a data page to the DS1961S/DS2432.void
Write protect pages 0 to 3void
Write protect page zero only.void
Write protects the secret for the DS2432.boolean
writeScratchpad
(int targetPage, int targetPageOffset, byte[] inputbuffer, int start, int length) Writes data to the scratchpad.Methods inherited from class com.dalsemi.onewire.container.OneWireContainer
doSpeed, equals, getAdapter, getAddress, getAddressAsLong, getAddressAsString, hashCode, isAlarming, isPresent, setSpeed, toString
-
Field Details
-
secretSet
protected boolean secretSetFlag to indicate if the secret has been set. -
secretProtected
protected boolean secretProtectedFlag to indicate if the secret is write protected. -
setAdapter
protected boolean setAdapterFlag to indicate if the adapter has been specified. -
container_check
protected boolean container_checkFlag to indicate if the status has been checked. -
ffBlock
protected static final byte[] ffBlockblock of 0xFF's used for faster read pre-fill of 1-Wire blocks -
zeroBlock
protected static final byte[] zeroBlockblock of 0xFF's used for faster erase of blocks
-
-
Constructor Details
-
OneWireContainer33
public OneWireContainer33()Default Constructor OneWireContainer33. Must call setupContainer before using. -
OneWireContainer33
Create a container with a provided adapter object and the address of the iButton or 1-Wire device.- Parameters:
sourceAdapter
- adapter object required to communicate with this iButton.newAddress
- address of this 1-Wire device
-
OneWireContainer33
Create a container with a provided adapter object and the address of the iButton or 1-Wire device.- Parameters:
sourceAdapter
- adapter object required to communicate with this iButton.newAddress
- address of this 1-Wire device
-
OneWireContainer33
Create a container with a provided adapter object and the address of the iButton or 1-Wire device.- Parameters:
sourceAdapter
- adapter object required to communicate with this iButton.newAddress
- address of this 1-Wire device
-
-
Method Details
-
adapterSet
protected boolean adapterSet()Tells whether an adapter has been set.- Returns:
- boolean telling weather an adapter has been set.
-
setupContainer
Provide this container the adapter object used to access this device and provide the address of this iButton or 1-Wire device.- Overrides:
setupContainer
in classOneWireContainer
- Parameters:
sourceAdapter
- adapter object required to communicate with this iButton.newAddress
- address of this 1-Wire device- See Also:
-
setupContainer
Provide this container the adapter object used to access this device and provide the address of this iButton or 1-Wire device.- Overrides:
setupContainer
in classOneWireContainer
- Parameters:
sourceAdapter
- adapter object required to communicate with this iButton.newAddress
- address of this 1-Wire device- See Also:
-
setupContainer
Provide this container the adapter object used to access this device and provide the address of this iButton or 1-Wire device.- Overrides:
setupContainer
in classOneWireContainer
- Parameters:
sourceAdapter
- adapter object required to communicate with this iButton.newAddress
- address of this 1-Wire device- See Also:
-
getName
Retrieve the Maxim Integrated Products part number of the iButton as a string. For example 'DS1992'.- Overrides:
getName
in classOneWireContainer
- Returns:
- string representation of the iButton name.
-
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.- Overrides:
getAlternateNames
in classOneWireContainer
- Returns:
- the alternate names for this iButton or 1-Wire device
-
getDescription
Retrieve a short description of the function of the iButton type.- Overrides:
getDescription
in classOneWireContainer
- Returns:
- string representation of the function description.
-
getMaxSpeed
public int getMaxSpeed()Returns the maximum speed this iButton can communicate at.- Overrides:
getMaxSpeed
in classOneWireContainer
- Returns:
- max. communication speed.
- See Also:
-
getMemoryBanks
Get an enumeration of memory bank instances that implement one or more of the following interfaces:MemoryBank
,PagedMemoryBank
, andOTPMemoryBank
.- Overrides:
getMemoryBanks
in classOneWireContainer
- Returns:
Enumeration
of memory banks- See Also:
-
getScratchpadMemoryBank
Returns the instance of the Scratchpad memory bank. Contains methods for reading/writing the Scratchpad contents. Also, methods for Load First Secret, Compute Next Secret, and Refresh Scratchpad- Returns:
- the instance of the Scratchpad memory bank
-
getStatusPageMemoryBank
Returns the instance of the Status page memory bank.- Returns:
- the instance of the Status page memory bank
-
getMemoryBankForPage
Returns the instance of the memory bank for a particular page- Parameters:
page
- the page for the requested memory bank;- Returns:
- the instance of the memory bank for the specified page
-
setContainerSecret
public void setContainerSecret(byte[] newSecret, int offset) Sets the bus master secret for this DS2432.- Parameters:
newSecret
- Secret for this DS2432.offset
- index into array to copy the secret from
-
getContainerSecret
public void getContainerSecret(byte[] secretBuf, int offset) Get the secret of this device as an array of bytes.- Parameters:
secretBuf
- array of bytes for holding the container secretoffset
- index into array to copy the secret to
-
isContainerSecretSet
Get the current status of the secret.- Returns:
- boolean telling if the secret is set
- Throws:
OneWireIOException
OneWireException
-
isSecretWriteProtected
Get the status of the secret, if it is write protected.- Returns:
- boolean telling if the secret is write protected.
- Throws:
OneWireIOException
OneWireException
-
setChallenge
public void setChallenge(byte[] challengeset, int offset) Sets the challenge for the Read Authenticate Page- Parameters:
challengeset
- Challenge for all the memory banks.
-
getChallenge
public void getChallenge(byte[] get, int offset) Get the challenge of this device as an array of bytes.- Parameters:
get
- array of bytes containing the iButton challenge
-
isWriteProtectAllSet
Get the status of all the pages, if they are write protected.- Returns:
- boolean telling if all the pages are write protected.
- Throws:
OneWireIOException
OneWireException
-
writeProtectSecret
Write protects the secret for the DS2432.- Throws:
OneWireIOException
OneWireException
-
writeProtectAll
Write protect pages 0 to 3- Throws:
OneWireIOException
OneWireException
-
setEPROMModePageOne
Sets the EPROM mode for page 1. After setting, Page One can only be written to once.- Throws:
OneWireIOException
OneWireException
-
isPageOneEPROMmode
Tells if page one is in EPROM mode.- Returns:
- boolean telling if page one is in EPROM mode.
- Throws:
OneWireIOException
OneWireException
-
writeProtectPageZero
Write protect page zero only.- Throws:
OneWireIOException
OneWireException
-
isWriteProtectPageZeroSet
Get the status of page zero, if it is write protected.- Returns:
- boolean telling if page zero is write protected.
- Throws:
OneWireIOException
OneWireException
-
computeNextSecret
public void computeNextSecret(int pageNum, byte[] partialsecret, int offset) throws OneWireIOException, OneWireException Compute Next Secret- Parameters:
addr
- address of page to use for the next secret computation.parialsecret
- the data to put into the scrathpad in computing next secret.- Throws:
OneWireIOException
OneWireException
-
computeNextSecret
Compute Next Secret using the current contents of data page and scratchpad.- Parameters:
addr
- address of page to use for the next secret computation.- Throws:
OneWireIOException
OneWireException
-
loadFirstSecret
Load First Secret- Returns:
- boolean saying if first secret was loaded
- Throws:
OneWireIOException
OneWireException
-
refreshPage
Refreshes a particular 8-byte set of data on a given page. This will correct any weakly-programmed EEPROM bits. This feature is only available on the DS1961S, but is safely ignored on the DS2432. The refresh consists of a Refresh Scratchpad command followed by a Load First Secret to the same offset.- Parameters:
page
- the page number that contains the 8-bytes to refresh.offset
- the offset into the page for the 8-bytes to refresh.- Returns:
true
if refresh is successful.- Throws:
OneWireException
OneWireIOException
-
refreshPage
Refreshes all 32 bytes of data on a given page. This will correct any weakly-programmed EEPROM bits. This feature is only available on the DS1961S, but is safely ignored on the DS2432. The refresh consists of a Refresh Scratchpad command followed by a Load First Secret to the same offset, for all 8-byte offsets on the page.- Parameters:
page
- the page number that will be refreshed.- Returns:
true
if refresh is successful.- Throws:
OneWireException
OneWireIOException
-
checkStatus
To check the status of the part.- Returns:
- boolean saying the part has been checked or was checked.
- Throws:
OneWireIOException
OneWireException
-
isMACValid
public static boolean isMACValid(int addr, byte[] SerNum, byte[] memory, byte[] mac, byte[] challenge, byte[] secret) Authenticates page data given a MAC.- Parameters:
addr
- address of the data to be readmemory
- the memory read from the pagemac
- the MAC calculated for this function given back as the extra infochallenge
- the 3 bytes written to the scratch pad used in calculating the mac
-
installMasterSecret
public boolean installMasterSecret(int page, byte[] newSecret) throws OneWireIOException, OneWireException Installs a secret on a DS1961S/DS2432. The secret is written in partial phrases of 47 bytes (32 bytes to a memory page, 8 bytes to the scratchpad, 7 bytes are discarded (but included for compatibility with DS193S)) and is cumulative until the entire secret is processed.
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.
- Parameters:
page
- the page number used to write the partial secrets tosecret
- the entire secret, in partial phrases, to be installed- Returns:
true
if successful- Throws:
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- See Also:
-
bindSecretToiButton
public boolean bindSecretToiButton(int pageNum, byte[] bindData) throws OneWireIOException, OneWireException Binds an installed secret to a DS1961S/DS2432 by using well-known binding data and the DS1961S/DS2432's unique address. This makes the secret unique for this iButton.
- Parameters:
page
- the page number that has the master secret already installedbind_data
- 32 bytes of binding data used to bind the iButton to the system- Returns:
true
if successful- Throws:
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- See Also:
-
writeDataPage
public boolean writeDataPage(int targetPage, byte[] pageData) throws OneWireIOException, OneWireException Writes a data page to the DS1961S/DS2432.
- Parameters:
page_number
- page number to writepage_data
- page data to write (must be at least 32 bytes long)- Returns:
true
if successful,false
if the operation failed- Throws:
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
-
writeDataPage
public boolean writeDataPage(int targetPage, byte[] pageData, int offset) throws OneWireIOException, OneWireException Writes a data page to the DS1961S/DS2432.
- Parameters:
page_number
- page number to writepage_data
- page data to write (must be at least 32 bytes long)offset
- the offset to start copying the 32-bytes of page data.- Returns:
true
if successful,false
if the operation failed- Throws:
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
-
writeScratchpad
public 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 thencopyScratchPad()
. Note that the addresses passed to this method will be the addresses the data is copied to if thecopyScratchPad()
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.
- Parameters:
targetPage
- the page number this data will eventually be copied totargetPageOffset
- the offset on the page to copy this data toinputbuffer
- the data that will be copied into the scratchpadstart
- offset into the input buffer for the data to writelength
- number of bytes to write- Returns:
true
if successful,false
on a CRC error- Throws:
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
-
readScratchpad
public void readScratchpad(byte[] scratchpad, int offset, byte[] extraInfo) throws OneWireIOException, OneWireException Read from the Scratch Pad, which is a max of 8 bytes.- Parameters:
scratchpad
- byte array to place read data into length of array is always pageLength.offset
- offset into readBuf to pug dataextraInfo
- byte array to put extra info read into (TA1, TA2, e/s byte) Can be 'null' if extra info is not needed.- Throws:
OneWireIOException
OneWireException
-
copyScratchpad
public boolean copyScratchpad(int targetPage, int targetPageOffset, byte[] copy_auth, int authStart) throws OneWireIOException, OneWireException Copy all 8 bytes of the Sratch Pad to a certain page and offset in memory.- Parameters:
targetPage
- the page to copy the data totargetPageOffset
- the offset into the page to copy tocopy_auth
- byte[] containing write authorizationauthStart
- the offset into the copy_auth array where the authorization begins.- Throws:
OneWireIOException
OneWireException
-
copyScratchpad
public boolean copyScratchpad(int targetPage, int targetPageOffset) throws OneWireIOException, OneWireException Copy all 8 bytes of the Sratch Pad to a certain page and offset in memory. The container secret must be set so that the container can produce the correct MAC.- Parameters:
targetPage
- the page to copy the data totargetPageOffset
- the offset into the page to copy to- Throws:
OneWireIOException
OneWireException
-
readMemoryPage
public boolean readMemoryPage(int page, byte[] pageData, int offset) throws OneWireIOException, OneWireException Reads a page of memory..- Parameters:
page
- page number to read packet frompageData
- byte array to place read data intooffset
- offset into readBuf to place data- Throws:
OneWireIOException
OneWireException
-
readAuthenticatedPage
public boolean readAuthenticatedPage(int page, byte[] pagedata, int offset, byte[] computed_mac, int macStart) 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.- Parameters:
pageNum
- page number to read and authenticatepagedata
- array for the page data.offset
- offset to copy into the arraycomputed_mac
- array for the MAC returned by the device.macStart
- offset to copy into the mac array- Returns:
true
if successful,false
if the operation failed while waiting for the DS1963S's output to alternate- Throws:
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
-