1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.

Dependents:   MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more

Superseded by MaximInterface.

Committer:
j3
Date:
Tue Dec 13 13:31:30 2016 -0800
Revision:
139:f0e0a7976846
Parent:
113:13e2865603df
Merge from svn

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 75:8b627804927c 1 /******************************************************************//**
IanBenzMaxim 75:8b627804927c 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 75:8b627804927c 3 *
IanBenzMaxim 75:8b627804927c 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 75:8b627804927c 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 75:8b627804927c 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 75:8b627804927c 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 75:8b627804927c 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 75:8b627804927c 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 75:8b627804927c 10 *
IanBenzMaxim 75:8b627804927c 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 75:8b627804927c 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 75:8b627804927c 13 *
IanBenzMaxim 75:8b627804927c 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 75:8b627804927c 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 75:8b627804927c 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 75:8b627804927c 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 75:8b627804927c 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 75:8b627804927c 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 75:8b627804927c 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 75:8b627804927c 21 *
IanBenzMaxim 75:8b627804927c 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 75:8b627804927c 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 75:8b627804927c 24 * Products, Inc. Branding Policy.
IanBenzMaxim 75:8b627804927c 25 *
IanBenzMaxim 75:8b627804927c 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 75:8b627804927c 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 75:8b627804927c 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 75:8b627804927c 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 75:8b627804927c 30 * ownership rights.
IanBenzMaxim 75:8b627804927c 31 **********************************************************************/
IanBenzMaxim 25:bdb1c5a53b58 32
IanBenzMaxim 73:2cecc1372acc 33 #ifndef OneWire_Authenticators_DS28E15_22_25
IanBenzMaxim 73:2cecc1372acc 34 #define OneWire_Authenticators_DS28E15_22_25
IanBenzMaxim 25:bdb1c5a53b58 35
IanBenzMaxim 86:2ce08ca58b9e 36 #include "Utilities/array.h"
IanBenzMaxim 86:2ce08ca58b9e 37 #include "Slaves/Authenticators/ISha256MacCoproc.h"
IanBenzMaxim 86:2ce08ca58b9e 38 #include "Slaves/OneWireSlave.h"
IanBenzMaxim 73:2cecc1372acc 39
IanBenzMaxim 73:2cecc1372acc 40 namespace OneWire
IanBenzMaxim 73:2cecc1372acc 41 {
IanBenzMaxim 113:13e2865603df 42 /// Interface to the DS28E15/22/25 series of authenticators including low power variants.
IanBenzMaxim 76:84e6c4994e29 43 class DS28E15_22_25 : public OneWireSlave
IanBenzMaxim 74:23be10c32fa3 44 {
IanBenzMaxim 76:84e6c4994e29 45 public:
IanBenzMaxim 76:84e6c4994e29 46 /// Holds the contents of a device memory segment.
IanBenzMaxim 76:84e6c4994e29 47 typedef array<uint8_t, 4> Segment;
IanBenzMaxim 76:84e6c4994e29 48
IanBenzMaxim 76:84e6c4994e29 49 /// Holds the contents of a device memory page.
j3 139:f0e0a7976846 50 typedef array<uint8_t, 32> Page;
IanBenzMaxim 74:23be10c32fa3 51
IanBenzMaxim 76:84e6c4994e29 52 /// Holds the contents of the device scratchpad.
IanBenzMaxim 76:84e6c4994e29 53 typedef array<uint8_t, 32> Scratchpad;
IanBenzMaxim 76:84e6c4994e29 54
IanBenzMaxim 76:84e6c4994e29 55 /// Container for a SHA-256 MAC.
IanBenzMaxim 76:84e6c4994e29 56 typedef array<uint8_t, 32> Mac;
IanBenzMaxim 74:23be10c32fa3 57
IanBenzMaxim 76:84e6c4994e29 58 /// Container for a manufacturer ID.
IanBenzMaxim 76:84e6c4994e29 59 typedef array<uint8_t, 2> ManId;
IanBenzMaxim 74:23be10c32fa3 60
IanBenzMaxim 76:84e6c4994e29 61 /// Container for the device personality.
j3 139:f0e0a7976846 62 class Personality
IanBenzMaxim 76:84e6c4994e29 63 {
j3 139:f0e0a7976846 64 public:
j3 139:f0e0a7976846 65 typedef array<uint8_t, 4> Buffer;
j3 139:f0e0a7976846 66
j3 139:f0e0a7976846 67 private:
j3 139:f0e0a7976846 68 Buffer m_data;
IanBenzMaxim 74:23be10c32fa3 69
j3 139:f0e0a7976846 70 public:
j3 139:f0e0a7976846 71 Personality() { }
j3 139:f0e0a7976846 72 explicit Personality(const Buffer & dataBytes) : m_data(dataBytes) { }
j3 139:f0e0a7976846 73
j3 139:f0e0a7976846 74 uint8_t PB1() const { return m_data[0]; }
j3 139:f0e0a7976846 75 uint8_t PB2() const { return m_data[1]; }
j3 139:f0e0a7976846 76 ManId manId() const { ManId manId = { m_data[2], m_data[3] }; return manId; }
j3 139:f0e0a7976846 77 bool secretLocked() const { return (PB2() & 0x01); }
j3 139:f0e0a7976846 78
j3 139:f0e0a7976846 79 bool operator==(const Personality & rhs) const { return (this->m_data == rhs.m_data); }
j3 139:f0e0a7976846 80 bool operator!=(const Personality & rhs) const { return !operator==(rhs); }
IanBenzMaxim 76:84e6c4994e29 81 };
IanBenzMaxim 74:23be10c32fa3 82
IanBenzMaxim 76:84e6c4994e29 83 /// Represents the status of a memory protection block.
IanBenzMaxim 76:84e6c4994e29 84 class BlockProtection
IanBenzMaxim 76:84e6c4994e29 85 {
IanBenzMaxim 76:84e6c4994e29 86 private:
IanBenzMaxim 76:84e6c4994e29 87 static const uint8_t readProtectionMask = 0x80, writeProtectionMask = 0x40, eepromEmulationMask = 0x20, authProtectionMask = 0x10, blockNumMask = 0x0F;
IanBenzMaxim 76:84e6c4994e29 88 uint8_t m_status;
IanBenzMaxim 74:23be10c32fa3 89
IanBenzMaxim 76:84e6c4994e29 90 public:
j3 139:f0e0a7976846 91 explicit BlockProtection(uint8_t status = 0x00) : m_status(status) { }
j3 139:f0e0a7976846 92 BlockProtection(bool readProtection, bool writeProtection, bool eepromEmulation, bool authProtection, unsigned int blockNum);
IanBenzMaxim 74:23be10c32fa3 93
IanBenzMaxim 76:84e6c4994e29 94 /// Get the byte representation used by the device.
IanBenzMaxim 76:84e6c4994e29 95 uint8_t statusByte() const { return m_status; }
IanBenzMaxim 76:84e6c4994e29 96 /// Set the byte representation used by the device.
IanBenzMaxim 76:84e6c4994e29 97 void setStatusByte(uint8_t status) { m_status = status; }
IanBenzMaxim 74:23be10c32fa3 98
IanBenzMaxim 76:84e6c4994e29 99 /// Get the Block Number which is indexed from zero.
j3 139:f0e0a7976846 100 unsigned int blockNum() const { return (m_status & blockNumMask); }
IanBenzMaxim 76:84e6c4994e29 101 /// Set the Block Number which is indexed from zero.
j3 139:f0e0a7976846 102 void setBlockNum(unsigned int blockNum);
IanBenzMaxim 74:23be10c32fa3 103
IanBenzMaxim 76:84e6c4994e29 104 /// Get the Read Protection status.
IanBenzMaxim 76:84e6c4994e29 105 /// @returns True if Read Protection is enabled.
IanBenzMaxim 76:84e6c4994e29 106 bool readProtection() const { return ((m_status & readProtectionMask) == readProtectionMask); }
IanBenzMaxim 76:84e6c4994e29 107 /// Set the Read Protection status.
IanBenzMaxim 76:84e6c4994e29 108 void setReadProtection(bool readProtection);
IanBenzMaxim 76:84e6c4994e29 109
IanBenzMaxim 76:84e6c4994e29 110 /// Get the Write Protection status.
IanBenzMaxim 76:84e6c4994e29 111 /// @returns True if Write Protection is enabled.
IanBenzMaxim 76:84e6c4994e29 112 bool writeProtection() const { return ((m_status & writeProtectionMask) == writeProtectionMask); }
IanBenzMaxim 76:84e6c4994e29 113 /// Set the Write Protection status.
IanBenzMaxim 76:84e6c4994e29 114 void setWriteProtection(bool writeProtection);
IanBenzMaxim 74:23be10c32fa3 115
IanBenzMaxim 76:84e6c4994e29 116 /// Get the EEPROM Emulation Mode status.
IanBenzMaxim 76:84e6c4994e29 117 /// @returns True if EEPROM Emulation Mode is enabled.
IanBenzMaxim 76:84e6c4994e29 118 bool eepromEmulation() const { return ((m_status & eepromEmulationMask) == eepromEmulationMask); }
IanBenzMaxim 76:84e6c4994e29 119 /// Set the EEPROM Emulation Mode status.
IanBenzMaxim 76:84e6c4994e29 120 void setEepromEmulation(bool eepromEmulation);
IanBenzMaxim 74:23be10c32fa3 121
IanBenzMaxim 76:84e6c4994e29 122 /// Get the Authentication Protection status.
IanBenzMaxim 76:84e6c4994e29 123 /// @returns True if Authentication Protection is enabled.
IanBenzMaxim 76:84e6c4994e29 124 bool authProtection() const { return ((m_status & authProtectionMask) == authProtectionMask); }
IanBenzMaxim 76:84e6c4994e29 125 /// Set the Authentication Protection status.
IanBenzMaxim 76:84e6c4994e29 126 void setAuthProtection(bool authProtection);
IanBenzMaxim 74:23be10c32fa3 127
IanBenzMaxim 76:84e6c4994e29 128 /// Check if no protection options are enabled.
IanBenzMaxim 76:84e6c4994e29 129 /// @returns True if no protection options are enabled.
IanBenzMaxim 76:84e6c4994e29 130 bool noProtection() const;
IanBenzMaxim 74:23be10c32fa3 131
IanBenzMaxim 76:84e6c4994e29 132 bool operator==(const BlockProtection & rhs) const { return (this->m_status == rhs.m_status); }
IanBenzMaxim 76:84e6c4994e29 133 bool operator!=(const BlockProtection & rhs) const { return !operator==(rhs); }
IanBenzMaxim 76:84e6c4994e29 134 };
IanBenzMaxim 74:23be10c32fa3 135
IanBenzMaxim 76:84e6c4994e29 136 /// Compute the MAC for an Authenticated Write to a memory segment.
IanBenzMaxim 76:84e6c4994e29 137 /// @param MacCoproc Coprocessor with Slave Secret to use for the computation.
IanBenzMaxim 76:84e6c4994e29 138 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 139 /// @param segmentNum Segment number within page for write operation.
IanBenzMaxim 76:84e6c4994e29 140 /// @param[in] newData New data to write to the segment.
IanBenzMaxim 76:84e6c4994e29 141 /// @param[in] oldData Existing data contained in the segment.
IanBenzMaxim 76:84e6c4994e29 142 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 143 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 144 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 145 /// @returns The result code indicated by the coprocessor.
IanBenzMaxim 76:84e6c4994e29 146 static ISha256MacCoproc::CmdResult computeSegmentWriteMac(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 147 unsigned int pageNum,
IanBenzMaxim 76:84e6c4994e29 148 unsigned int segmentNum,
IanBenzMaxim 76:84e6c4994e29 149 const Segment & newData,
IanBenzMaxim 76:84e6c4994e29 150 const Segment & oldData,
IanBenzMaxim 76:84e6c4994e29 151 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 152 const ManId & manId,
IanBenzMaxim 76:84e6c4994e29 153 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 154
IanBenzMaxim 76:84e6c4994e29 155 /// Compute the MAC for an Authenticated Write to a memory protection block.
IanBenzMaxim 76:84e6c4994e29 156 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 157 /// @param[in] newProtection New protection status to write.
IanBenzMaxim 76:84e6c4994e29 158 /// @param[in] oldProtection Existing protection status in device.
IanBenzMaxim 76:84e6c4994e29 159 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 160 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 161 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 162 /// @returns The result code indicated by the coprocessor.
IanBenzMaxim 76:84e6c4994e29 163 static ISha256MacCoproc::CmdResult computeProtectionWriteMac(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 164 const BlockProtection & newProtection,
IanBenzMaxim 76:84e6c4994e29 165 const BlockProtection & oldProtection,
IanBenzMaxim 76:84e6c4994e29 166 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 167 const ManId & manId,
IanBenzMaxim 76:84e6c4994e29 168 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 169
IanBenzMaxim 76:84e6c4994e29 170 /// Compute the next secret from the existing secret.
IanBenzMaxim 76:84e6c4994e29 171 /// @param MacCoproc Coprocessor with Master Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 172 /// Slave Secret will be updated with the computation result.
IanBenzMaxim 76:84e6c4994e29 173 /// @param[in] bindingPage Binding data from a device memory page.
IanBenzMaxim 76:84e6c4994e29 174 /// @param bindingPageNum Number of the page where the binding data is from.
IanBenzMaxim 76:84e6c4994e29 175 /// @param[in] partialSecret Partial secret data from the device scratchpad.
IanBenzMaxim 76:84e6c4994e29 176 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 177 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 178 /// @returns The result code indicated by the coprocessor.
IanBenzMaxim 76:84e6c4994e29 179 static ISha256MacCoproc::CmdResult computeNextSecret(ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 180 const Page & bindingPage,
IanBenzMaxim 76:84e6c4994e29 181 unsigned int bindingPageNum,
IanBenzMaxim 76:84e6c4994e29 182 const Scratchpad & partialSecret,
IanBenzMaxim 76:84e6c4994e29 183 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 184 const ManId & manId);
IanBenzMaxim 34:11fffbe98ef9 185
IanBenzMaxim 76:84e6c4994e29 186 /// Compute a Page MAC for authentication.
IanBenzMaxim 76:84e6c4994e29 187 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 188 /// @param[in] pageData Data from a device memory page.
IanBenzMaxim 76:84e6c4994e29 189 /// @param pageNum Number of the page to use data from.
IanBenzMaxim 76:84e6c4994e29 190 /// @param[in] challenge Random challenge to prevent replay attacks.
IanBenzMaxim 76:84e6c4994e29 191 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 192 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 193 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 194 static ISha256MacCoproc::CmdResult computeAuthMac(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 195 const Page & pageData,
IanBenzMaxim 76:84e6c4994e29 196 unsigned int pageNum,
IanBenzMaxim 76:84e6c4994e29 197 const Scratchpad & challenge,
IanBenzMaxim 76:84e6c4994e29 198 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 199 const ManId & manId,
IanBenzMaxim 76:84e6c4994e29 200 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 201
IanBenzMaxim 76:84e6c4994e29 202 /// Compute a Page MAC for authentication using anonymous mode.
IanBenzMaxim 76:84e6c4994e29 203 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 204 /// @param[in] pageData Data from a device memory page.
IanBenzMaxim 76:84e6c4994e29 205 /// @param pageNum Number of the page to use data from.
IanBenzMaxim 76:84e6c4994e29 206 /// @param[in] challenge Random challenge to prevent replay attacks.
IanBenzMaxim 76:84e6c4994e29 207 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 208 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 209 static ISha256MacCoproc::CmdResult computeAuthMacAnon(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 74:23be10c32fa3 210 const Page & pageData,
IanBenzMaxim 74:23be10c32fa3 211 unsigned int pageNum,
IanBenzMaxim 74:23be10c32fa3 212 const Scratchpad & challenge,
IanBenzMaxim 74:23be10c32fa3 213 const ManId & manId,
IanBenzMaxim 74:23be10c32fa3 214 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 215
IanBenzMaxim 76:84e6c4994e29 216 /// Number of segments per page.
j3 139:f0e0a7976846 217 static const unsigned int segmentsPerPage = (Page::csize / Segment::csize);
j3 139:f0e0a7976846 218
j3 139:f0e0a7976846 219 /// Creates a segment representation from a subsection of the page data.
j3 139:f0e0a7976846 220 /// @param segmentNum Segment number within page to copy from.
j3 139:f0e0a7976846 221 /// @returns The copied segment data.
j3 139:f0e0a7976846 222 static Segment segmentFromPage(unsigned int segmentNum, const Page & page);
j3 139:f0e0a7976846 223
j3 139:f0e0a7976846 224 /// Copies segment data to the page.
j3 139:f0e0a7976846 225 /// @param segmentNum Segment number within the page to copy to.
j3 139:f0e0a7976846 226 /// @param[in] segment Segment to copy from.
j3 139:f0e0a7976846 227 static void segmentToPage(unsigned int segmentNum, const Segment & segment, Page & page);
IanBenzMaxim 76:84e6c4994e29 228
IanBenzMaxim 82:c11090a32471 229 /// @{
IanBenzMaxim 76:84e6c4994e29 230 /// Manufacturer ID
IanBenzMaxim 82:c11090a32471 231 ManId manId() const { return m_manId; }
IanBenzMaxim 82:c11090a32471 232 void setManId(const ManId & manId) { m_manId = manId; }
IanBenzMaxim 82:c11090a32471 233 /// @}
IanBenzMaxim 74:23be10c32fa3 234
IanBenzMaxim 82:c11090a32471 235 /// @{
IanBenzMaxim 76:84e6c4994e29 236 /// Enable low voltage timing
IanBenzMaxim 82:c11090a32471 237 bool lowVoltage() const { return m_lowVoltage; }
IanBenzMaxim 82:c11090a32471 238 void setLowVoltage(bool lowVoltage) { m_lowVoltage = lowVoltage; }
IanBenzMaxim 82:c11090a32471 239 /// @}
IanBenzMaxim 74:23be10c32fa3 240
IanBenzMaxim 76:84e6c4994e29 241 // Const member functions should not affect the state of the memory, block protection, or secret on the DS28Exx.
IanBenzMaxim 76:84e6c4994e29 242 // Scratchpad on the DS28Exx is considered mutable.
IanBenzMaxim 74:23be10c32fa3 243
IanBenzMaxim 76:84e6c4994e29 244 /// Perform Load and Lock Secret command on the device.
IanBenzMaxim 76:84e6c4994e29 245 /// @note The secret should already be stored in the scratchpad on the device.
IanBenzMaxim 76:84e6c4994e29 246 /// @param lock Prevent further changes to the secret on the device after loading.
IanBenzMaxim 76:84e6c4994e29 247 CmdResult loadSecret(bool lock);
IanBenzMaxim 74:23be10c32fa3 248
IanBenzMaxim 76:84e6c4994e29 249 /// Read memory segment using the Read Memory command on the device.
IanBenzMaxim 76:84e6c4994e29 250 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 251 /// @param pageNum Page number for read operation.
IanBenzMaxim 76:84e6c4994e29 252 /// @param segmentNum Segment number within page for read operation.
IanBenzMaxim 76:84e6c4994e29 253 /// @param[out] data Buffer to read data from the segment into.
IanBenzMaxim 76:84e6c4994e29 254 /// @param continuing True if continuing a previous Read Memory command.
IanBenzMaxim 76:84e6c4994e29 255 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 256 CmdResult readSegment(unsigned int pageNum, unsigned int segmentNum, Segment & data, bool continuing = false) const;
IanBenzMaxim 74:23be10c32fa3 257
IanBenzMaxim 76:84e6c4994e29 258 /// Write memory segment using the Write Memory command.
IanBenzMaxim 76:84e6c4994e29 259 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 260 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 261 /// @param segmentNum Segment number within page for write operation.
IanBenzMaxim 76:84e6c4994e29 262 /// @param[in] data Data to write to the memory segment.
IanBenzMaxim 76:84e6c4994e29 263 /// @param continuing True to continue writing with the next sequential segment.
IanBenzMaxim 76:84e6c4994e29 264 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 265 CmdResult writeSegment(unsigned int pageNum, unsigned int segmentNum, const Segment & data, bool continuing = false);
IanBenzMaxim 74:23be10c32fa3 266
IanBenzMaxim 76:84e6c4994e29 267 /// Read memory page using the Read Memory command on the device.
IanBenzMaxim 76:84e6c4994e29 268 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 269 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 270 /// @param[out] rdbuf Buffer to read data from the page into.
IanBenzMaxim 76:84e6c4994e29 271 /// @param continuing True if continuing a previous Read Memory command.
IanBenzMaxim 76:84e6c4994e29 272 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 273 CmdResult readPage(unsigned int pageNum, Page & rdbuf, bool continuing = false) const;
IanBenzMaxim 73:2cecc1372acc 274
IanBenzMaxim 76:84e6c4994e29 275 /// Perform a Compute and Lock Secret command on the device.
IanBenzMaxim 76:84e6c4994e29 276 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 277 /// @param pageNum Page number to use as the binding data.
IanBenzMaxim 76:84e6c4994e29 278 /// @param lock Prevent further changes to the secret on the device after computing.
IanBenzMaxim 76:84e6c4994e29 279 CmdResult computeSecret(unsigned int pageNum, bool lock);
IanBenzMaxim 74:23be10c32fa3 280
IanBenzMaxim 76:84e6c4994e29 281 /// Perform a Compute Page MAC command on the device.
IanBenzMaxim 76:84e6c4994e29 282 /// Read back the MAC and verify the CRC16.
IanBenzMaxim 76:84e6c4994e29 283 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 284 /// @param pageNum Page number to use for the computation.
IanBenzMaxim 76:84e6c4994e29 285 /// @param anon True to compute in anonymous mode where ROM ID is not used.
IanBenzMaxim 76:84e6c4994e29 286 /// @param[out] mac The device computed MAC.
IanBenzMaxim 76:84e6c4994e29 287 CmdResult computeReadPageMac(unsigned int pageNum, bool anon, Mac & mac) const;
IanBenzMaxim 74:23be10c32fa3 288
IanBenzMaxim 76:84e6c4994e29 289 /// Update the status of a memory protection block using the Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 290 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 291 /// @param[in] Desired protection status for the block.
IanBenzMaxim 76:84e6c4994e29 292 /// It is not possible to disable existing protections.
IanBenzMaxim 76:84e6c4994e29 293 /// @param continuing True to continue a previous Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 294 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 295 CmdResult writeBlockProtection(const BlockProtection & protection);
IanBenzMaxim 74:23be10c32fa3 296
IanBenzMaxim 76:84e6c4994e29 297 /// Update the status of a memory protection block using the Authenticated Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 298 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 299 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 300 /// @param[in] newProtection New protection status to write.
IanBenzMaxim 76:84e6c4994e29 301 /// @param[in] oldProtection Existing protection status in device.
IanBenzMaxim 76:84e6c4994e29 302 /// @param continuing True to continue a previous Authenticated Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 303 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 304 CmdResult writeAuthBlockProtection(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 305 const BlockProtection & newProtection,
IanBenzMaxim 76:84e6c4994e29 306 const BlockProtection & oldProtection);
IanBenzMaxim 113:13e2865603df 307
j3 139:f0e0a7976846 308 protected:
IanBenzMaxim 113:13e2865603df 309 /// @param owMaster 1-Wire Master to use for communication with DS28E15/22/25.
IanBenzMaxim 113:13e2865603df 310 /// @param lowVoltage Enable low voltage timing.
j3 139:f0e0a7976846 311 DS28E15_22_25(RandomAccessRomIterator & selector, bool lowVoltage);
IanBenzMaxim 113:13e2865603df 312
IanBenzMaxim 113:13e2865603df 313 ~DS28E15_22_25() { }
j3 139:f0e0a7976846 314
j3 139:f0e0a7976846 315 template <class T>
j3 139:f0e0a7976846 316 CmdResult doWriteScratchpad(const Scratchpad & data) const;
j3 139:f0e0a7976846 317
j3 139:f0e0a7976846 318 template <class T>
j3 139:f0e0a7976846 319 CmdResult doReadScratchpad(Scratchpad & data) const;
j3 139:f0e0a7976846 320
j3 139:f0e0a7976846 321 template <class T>
j3 139:f0e0a7976846 322 CmdResult doReadBlockProtection(unsigned int blockNum, BlockProtection & protection) const;
j3 139:f0e0a7976846 323
j3 139:f0e0a7976846 324 template <class T>
j3 139:f0e0a7976846 325 CmdResult doReadPersonality(Personality & personality) const;
j3 139:f0e0a7976846 326
j3 139:f0e0a7976846 327 template <class T>
j3 139:f0e0a7976846 328 CmdResult doWriteAuthSegment(const ISha256MacCoproc & MacCoproc,
j3 139:f0e0a7976846 329 unsigned int pageNum,
j3 139:f0e0a7976846 330 unsigned int segmentNum,
j3 139:f0e0a7976846 331 const Segment & newData,
j3 139:f0e0a7976846 332 const Segment & oldData,
j3 139:f0e0a7976846 333 bool continuing);
j3 139:f0e0a7976846 334
j3 139:f0e0a7976846 335 template <class T>
j3 139:f0e0a7976846 336 CmdResult doWriteAuthSegmentMac(unsigned int pageNum,
j3 139:f0e0a7976846 337 unsigned int segmentNum,
j3 139:f0e0a7976846 338 const Segment & newData,
j3 139:f0e0a7976846 339 const Mac & mac,
j3 139:f0e0a7976846 340 bool continuing);
j3 139:f0e0a7976846 341
j3 139:f0e0a7976846 342 template <class T, size_t N>
j3 139:f0e0a7976846 343 CmdResult doReadAllBlockProtection(array<BlockProtection, N> & protection) const;
IanBenzMaxim 74:23be10c32fa3 344
IanBenzMaxim 76:84e6c4994e29 345 private:
IanBenzMaxim 76:84e6c4994e29 346 /// Read status bytes which are either personality or block protection.
IanBenzMaxim 76:84e6c4994e29 347 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 348 /// @param personality True to read personality or false to read block protection.
IanBenzMaxim 76:84e6c4994e29 349 /// @param allpages True to read all pages or false to read one page.
IanBenzMaxim 76:84e6c4994e29 350 /// @param pageNum Page number if reading block protection.
IanBenzMaxim 76:84e6c4994e29 351 /// @param rdbuf Buffer to receive data read from device.
j3 139:f0e0a7976846 352 template <class T>
IanBenzMaxim 76:84e6c4994e29 353 CmdResult readStatus(bool personality, bool allpages, unsigned int blockNum, uint8_t * rdbuf) const;
j3 139:f0e0a7976846 354
j3 139:f0e0a7976846 355 ManId m_manId;
j3 139:f0e0a7976846 356 bool m_lowVoltage;
j3 139:f0e0a7976846 357
j3 139:f0e0a7976846 358 static const unsigned int shaComputationDelayMs = 3;
j3 139:f0e0a7976846 359 static const unsigned int eepromWriteDelayMs = 10;
j3 139:f0e0a7976846 360 unsigned int secretEepromWriteDelayMs() const { return (m_lowVoltage ? 200 : 100); }
IanBenzMaxim 76:84e6c4994e29 361 };
IanBenzMaxim 73:2cecc1372acc 362 }
IanBenzMaxim 25:bdb1c5a53b58 363
IanBenzMaxim 49:36954b62f503 364 #endif