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:
IanBenzMaxim
Date:
Wed Jun 15 15:00:06 2016 -0500
Revision:
86:2ce08ca58b9e
Parent:
Authenticators/DS28E15_22_25/DS28E15_22_25.h@82:c11090a32471
Child:
113:13e2865603df
Updated to match new directory structure.

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 76:84e6c4994e29 42 class OneWireMaster;
IanBenzMaxim 25:bdb1c5a53b58 43
IanBenzMaxim 76:84e6c4994e29 44 /// Interface to the DS28E15/22/25 series of authenticators
IanBenzMaxim 76:84e6c4994e29 45 /// including low power variants.
IanBenzMaxim 76:84e6c4994e29 46 class DS28E15_22_25 : public OneWireSlave
IanBenzMaxim 74:23be10c32fa3 47 {
IanBenzMaxim 76:84e6c4994e29 48 public:
IanBenzMaxim 76:84e6c4994e29 49 /// Family code for each device.
IanBenzMaxim 76:84e6c4994e29 50 enum FamilyCode
IanBenzMaxim 76:84e6c4994e29 51 {
IanBenzMaxim 76:84e6c4994e29 52 DS28E25_Family = 0x47,
IanBenzMaxim 76:84e6c4994e29 53 DS28E22_Family = 0x48,
IanBenzMaxim 76:84e6c4994e29 54 DS28E15_Family = 0x17,
IanBenzMaxim 76:84e6c4994e29 55 Unknown_Family = 0
IanBenzMaxim 76:84e6c4994e29 56 };
IanBenzMaxim 76:84e6c4994e29 57
IanBenzMaxim 76:84e6c4994e29 58 /// Number for memory pages for each device.
IanBenzMaxim 76:84e6c4994e29 59 enum MemoryPages
IanBenzMaxim 76:84e6c4994e29 60 {
IanBenzMaxim 76:84e6c4994e29 61 DS28E25_Pages = 16,
IanBenzMaxim 76:84e6c4994e29 62 DS28E22_Pages = 8,
IanBenzMaxim 76:84e6c4994e29 63 DS28E15_Pages = 2,
IanBenzMaxim 76:84e6c4994e29 64 Unknown_Pages = 0
IanBenzMaxim 76:84e6c4994e29 65 };
IanBenzMaxim 76:84e6c4994e29 66
IanBenzMaxim 76:84e6c4994e29 67 /// Number of protection blocks for each device.
IanBenzMaxim 76:84e6c4994e29 68 enum ProtectionBlocks
IanBenzMaxim 76:84e6c4994e29 69 {
IanBenzMaxim 76:84e6c4994e29 70 DS28E25_Blocks = 8,
IanBenzMaxim 76:84e6c4994e29 71 DS28E22_Blocks = 4,
IanBenzMaxim 76:84e6c4994e29 72 DS28E15_Blocks = 4,
IanBenzMaxim 76:84e6c4994e29 73 Unknown_Blocks = 0
IanBenzMaxim 76:84e6c4994e29 74 };
IanBenzMaxim 76:84e6c4994e29 75
IanBenzMaxim 76:84e6c4994e29 76 /// Holds the contents of a device memory segment.
IanBenzMaxim 76:84e6c4994e29 77 typedef array<uint8_t, 4> Segment;
IanBenzMaxim 76:84e6c4994e29 78
IanBenzMaxim 76:84e6c4994e29 79 /// Holds the contents of a device memory page.
IanBenzMaxim 76:84e6c4994e29 80 class Page
IanBenzMaxim 73:2cecc1372acc 81 {
IanBenzMaxim 74:23be10c32fa3 82 public:
IanBenzMaxim 76:84e6c4994e29 83 /// Length of the buffer in bytes.
IanBenzMaxim 76:84e6c4994e29 84 static const size_t length = 32;
IanBenzMaxim 76:84e6c4994e29 85
IanBenzMaxim 76:84e6c4994e29 86 private:
IanBenzMaxim 76:84e6c4994e29 87 array<uint8_t, length> m_data;
IanBenzMaxim 74:23be10c32fa3 88
IanBenzMaxim 76:84e6c4994e29 89 public:
IanBenzMaxim 76:84e6c4994e29 90 /// Built-in array representation.
IanBenzMaxim 76:84e6c4994e29 91 typedef array<uint8_t, length>::Buffer Buffer;
IanBenzMaxim 76:84e6c4994e29 92
IanBenzMaxim 76:84e6c4994e29 93 Page() { }
IanBenzMaxim 76:84e6c4994e29 94 Page(const Page & page) : m_data(page.m_data) { }
IanBenzMaxim 76:84e6c4994e29 95 Page(const Buffer & dataBytes) : m_data(dataBytes) { }
IanBenzMaxim 76:84e6c4994e29 96
IanBenzMaxim 76:84e6c4994e29 97 const Page & operator=(const Page & rhs)
IanBenzMaxim 74:23be10c32fa3 98 {
IanBenzMaxim 76:84e6c4994e29 99 this->m_data = rhs.m_data;
IanBenzMaxim 76:84e6c4994e29 100 return rhs;
IanBenzMaxim 76:84e6c4994e29 101 }
IanBenzMaxim 74:23be10c32fa3 102
IanBenzMaxim 76:84e6c4994e29 103 bool operator==(const Page & rhs) const
IanBenzMaxim 74:23be10c32fa3 104 {
IanBenzMaxim 76:84e6c4994e29 105 return (this->m_data == rhs.m_data);
IanBenzMaxim 76:84e6c4994e29 106 }
IanBenzMaxim 74:23be10c32fa3 107
IanBenzMaxim 76:84e6c4994e29 108 bool operator!=(const Page & rhs) const
IanBenzMaxim 76:84e6c4994e29 109 {
IanBenzMaxim 76:84e6c4994e29 110 return !operator==(rhs);
IanBenzMaxim 76:84e6c4994e29 111 }
IanBenzMaxim 74:23be10c32fa3 112
IanBenzMaxim 76:84e6c4994e29 113 /// Conversion to array reference.
IanBenzMaxim 76:84e6c4994e29 114 operator Buffer &()
IanBenzMaxim 76:84e6c4994e29 115 {
IanBenzMaxim 76:84e6c4994e29 116 return m_data;
IanBenzMaxim 76:84e6c4994e29 117 }
IanBenzMaxim 74:23be10c32fa3 118
IanBenzMaxim 76:84e6c4994e29 119 /// Conversion to const array reference.
IanBenzMaxim 76:84e6c4994e29 120 operator const Buffer &() const
IanBenzMaxim 76:84e6c4994e29 121 {
IanBenzMaxim 76:84e6c4994e29 122 return m_data;
IanBenzMaxim 76:84e6c4994e29 123 }
IanBenzMaxim 74:23be10c32fa3 124
IanBenzMaxim 76:84e6c4994e29 125 /// Creates a segment representation from a subsection of the page data.
IanBenzMaxim 76:84e6c4994e29 126 /// @param segmentNum Segment number within page to copy from.
IanBenzMaxim 76:84e6c4994e29 127 /// @returns The copied segment data.
IanBenzMaxim 76:84e6c4994e29 128 Segment toSegment(unsigned int segmentNum) const;
IanBenzMaxim 74:23be10c32fa3 129
IanBenzMaxim 76:84e6c4994e29 130 /// Copies segment data to the page.
IanBenzMaxim 76:84e6c4994e29 131 /// @param segmentNum Segment number within the page to copy to.
IanBenzMaxim 76:84e6c4994e29 132 /// @param[in] segment Segment to copy from.
IanBenzMaxim 76:84e6c4994e29 133 void fromSegment(unsigned int segmentNum, const Segment & segment);
IanBenzMaxim 76:84e6c4994e29 134 };
IanBenzMaxim 74:23be10c32fa3 135
IanBenzMaxim 76:84e6c4994e29 136 /// Holds the contents of the device scratchpad.
IanBenzMaxim 76:84e6c4994e29 137 typedef array<uint8_t, 32> Scratchpad;
IanBenzMaxim 76:84e6c4994e29 138
IanBenzMaxim 76:84e6c4994e29 139 /// Container for a SHA-256 MAC.
IanBenzMaxim 76:84e6c4994e29 140 typedef array<uint8_t, 32> Mac;
IanBenzMaxim 74:23be10c32fa3 141
IanBenzMaxim 76:84e6c4994e29 142 /// Container for a manufacturer ID.
IanBenzMaxim 76:84e6c4994e29 143 typedef array<uint8_t, 2> ManId;
IanBenzMaxim 74:23be10c32fa3 144
IanBenzMaxim 76:84e6c4994e29 145 /// Container for the device personality.
IanBenzMaxim 76:84e6c4994e29 146 union Personality
IanBenzMaxim 76:84e6c4994e29 147 {
IanBenzMaxim 76:84e6c4994e29 148 array<uint8_t, 4>::Buffer bytes;
IanBenzMaxim 76:84e6c4994e29 149 struct
IanBenzMaxim 76:84e6c4994e29 150 {
IanBenzMaxim 76:84e6c4994e29 151 uint8_t PB1;
IanBenzMaxim 76:84e6c4994e29 152 uint8_t PB2;
IanBenzMaxim 76:84e6c4994e29 153 ManId::Buffer manIdBytes;
IanBenzMaxim 74:23be10c32fa3 154
IanBenzMaxim 76:84e6c4994e29 155 bool secretLocked() const { return (PB2 & 0x01); }
IanBenzMaxim 76:84e6c4994e29 156 } fields;
IanBenzMaxim 76:84e6c4994e29 157 };
IanBenzMaxim 74:23be10c32fa3 158
IanBenzMaxim 76:84e6c4994e29 159 /// Represents the status of a memory protection block.
IanBenzMaxim 76:84e6c4994e29 160 class BlockProtection
IanBenzMaxim 76:84e6c4994e29 161 {
IanBenzMaxim 76:84e6c4994e29 162 private:
IanBenzMaxim 76:84e6c4994e29 163 static const uint8_t readProtectionMask = 0x80, writeProtectionMask = 0x40, eepromEmulationMask = 0x20, authProtectionMask = 0x10, blockNumMask = 0x0F;
IanBenzMaxim 76:84e6c4994e29 164 uint8_t m_status;
IanBenzMaxim 74:23be10c32fa3 165
IanBenzMaxim 76:84e6c4994e29 166 public:
IanBenzMaxim 76:84e6c4994e29 167 BlockProtection() : m_status(0x00) { }
IanBenzMaxim 76:84e6c4994e29 168 BlockProtection(bool readProtection, bool writeProtection, bool eepromEmulation, bool authProtection, uint8_t blockNum);
IanBenzMaxim 74:23be10c32fa3 169
IanBenzMaxim 76:84e6c4994e29 170 /// Get the byte representation used by the device.
IanBenzMaxim 76:84e6c4994e29 171 uint8_t statusByte() const { return m_status; }
IanBenzMaxim 76:84e6c4994e29 172 /// Set the byte representation used by the device.
IanBenzMaxim 76:84e6c4994e29 173 void setStatusByte(uint8_t status) { m_status = status; }
IanBenzMaxim 74:23be10c32fa3 174
IanBenzMaxim 76:84e6c4994e29 175 /// Get the Block Number which is indexed from zero.
IanBenzMaxim 76:84e6c4994e29 176 uint8_t blockNum() const { return (m_status & blockNumMask); }
IanBenzMaxim 76:84e6c4994e29 177 /// Set the Block Number which is indexed from zero.
IanBenzMaxim 76:84e6c4994e29 178 void setBlockNum(uint8_t blockNum);
IanBenzMaxim 74:23be10c32fa3 179
IanBenzMaxim 76:84e6c4994e29 180 /// Get the Read Protection status.
IanBenzMaxim 76:84e6c4994e29 181 /// @returns True if Read Protection is enabled.
IanBenzMaxim 76:84e6c4994e29 182 bool readProtection() const { return ((m_status & readProtectionMask) == readProtectionMask); }
IanBenzMaxim 76:84e6c4994e29 183 /// Set the Read Protection status.
IanBenzMaxim 76:84e6c4994e29 184 void setReadProtection(bool readProtection);
IanBenzMaxim 76:84e6c4994e29 185
IanBenzMaxim 76:84e6c4994e29 186 /// Get the Write Protection status.
IanBenzMaxim 76:84e6c4994e29 187 /// @returns True if Write Protection is enabled.
IanBenzMaxim 76:84e6c4994e29 188 bool writeProtection() const { return ((m_status & writeProtectionMask) == writeProtectionMask); }
IanBenzMaxim 76:84e6c4994e29 189 /// Set the Write Protection status.
IanBenzMaxim 76:84e6c4994e29 190 void setWriteProtection(bool writeProtection);
IanBenzMaxim 74:23be10c32fa3 191
IanBenzMaxim 76:84e6c4994e29 192 /// Get the EEPROM Emulation Mode status.
IanBenzMaxim 76:84e6c4994e29 193 /// @returns True if EEPROM Emulation Mode is enabled.
IanBenzMaxim 76:84e6c4994e29 194 bool eepromEmulation() const { return ((m_status & eepromEmulationMask) == eepromEmulationMask); }
IanBenzMaxim 76:84e6c4994e29 195 /// Set the EEPROM Emulation Mode status.
IanBenzMaxim 76:84e6c4994e29 196 void setEepromEmulation(bool eepromEmulation);
IanBenzMaxim 74:23be10c32fa3 197
IanBenzMaxim 76:84e6c4994e29 198 /// Get the Authentication Protection status.
IanBenzMaxim 76:84e6c4994e29 199 /// @returns True if Authentication Protection is enabled.
IanBenzMaxim 76:84e6c4994e29 200 bool authProtection() const { return ((m_status & authProtectionMask) == authProtectionMask); }
IanBenzMaxim 76:84e6c4994e29 201 /// Set the Authentication Protection status.
IanBenzMaxim 76:84e6c4994e29 202 void setAuthProtection(bool authProtection);
IanBenzMaxim 74:23be10c32fa3 203
IanBenzMaxim 76:84e6c4994e29 204 /// Check if no protection options are enabled.
IanBenzMaxim 76:84e6c4994e29 205 /// @returns True if no protection options are enabled.
IanBenzMaxim 76:84e6c4994e29 206 bool noProtection() const;
IanBenzMaxim 74:23be10c32fa3 207
IanBenzMaxim 76:84e6c4994e29 208 bool operator==(const BlockProtection & rhs) const { return (this->m_status == rhs.m_status); }
IanBenzMaxim 76:84e6c4994e29 209 bool operator!=(const BlockProtection & rhs) const { return !operator==(rhs); }
IanBenzMaxim 76:84e6c4994e29 210 };
IanBenzMaxim 74:23be10c32fa3 211
IanBenzMaxim 76:84e6c4994e29 212 /// Compute the MAC for an Authenticated Write to a memory segment.
IanBenzMaxim 76:84e6c4994e29 213 /// @param MacCoproc Coprocessor with Slave Secret to use for the computation.
IanBenzMaxim 76:84e6c4994e29 214 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 215 /// @param segmentNum Segment number within page for write operation.
IanBenzMaxim 76:84e6c4994e29 216 /// @param[in] newData New data to write to the segment.
IanBenzMaxim 76:84e6c4994e29 217 /// @param[in] oldData Existing data contained in the segment.
IanBenzMaxim 76:84e6c4994e29 218 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 219 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 220 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 221 /// @returns The result code indicated by the coprocessor.
IanBenzMaxim 76:84e6c4994e29 222 static ISha256MacCoproc::CmdResult computeSegmentWriteMac(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 223 unsigned int pageNum,
IanBenzMaxim 76:84e6c4994e29 224 unsigned int segmentNum,
IanBenzMaxim 76:84e6c4994e29 225 const Segment & newData,
IanBenzMaxim 76:84e6c4994e29 226 const Segment & oldData,
IanBenzMaxim 76:84e6c4994e29 227 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 228 const ManId & manId,
IanBenzMaxim 76:84e6c4994e29 229 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 230
IanBenzMaxim 76:84e6c4994e29 231 /// Compute the MAC for an Authenticated Write to a memory protection block.
IanBenzMaxim 76:84e6c4994e29 232 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 233 /// @param[in] newProtection New protection status to write.
IanBenzMaxim 76:84e6c4994e29 234 /// @param[in] oldProtection Existing protection status in device.
IanBenzMaxim 76:84e6c4994e29 235 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 236 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 237 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 238 /// @returns The result code indicated by the coprocessor.
IanBenzMaxim 76:84e6c4994e29 239 static ISha256MacCoproc::CmdResult computeProtectionWriteMac(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 240 const BlockProtection & newProtection,
IanBenzMaxim 76:84e6c4994e29 241 const BlockProtection & oldProtection,
IanBenzMaxim 76:84e6c4994e29 242 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 243 const ManId & manId,
IanBenzMaxim 76:84e6c4994e29 244 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 245
IanBenzMaxim 76:84e6c4994e29 246 /// Compute the next secret from the existing secret.
IanBenzMaxim 76:84e6c4994e29 247 /// @param MacCoproc Coprocessor with Master Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 248 /// Slave Secret will be updated with the computation result.
IanBenzMaxim 76:84e6c4994e29 249 /// @param[in] bindingPage Binding data from a device memory page.
IanBenzMaxim 76:84e6c4994e29 250 /// @param bindingPageNum Number of the page where the binding data is from.
IanBenzMaxim 76:84e6c4994e29 251 /// @param[in] partialSecret Partial secret data from the device scratchpad.
IanBenzMaxim 76:84e6c4994e29 252 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 253 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 254 /// @returns The result code indicated by the coprocessor.
IanBenzMaxim 76:84e6c4994e29 255 static ISha256MacCoproc::CmdResult computeNextSecret(ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 256 const Page & bindingPage,
IanBenzMaxim 76:84e6c4994e29 257 unsigned int bindingPageNum,
IanBenzMaxim 76:84e6c4994e29 258 const Scratchpad & partialSecret,
IanBenzMaxim 76:84e6c4994e29 259 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 260 const ManId & manId);
IanBenzMaxim 34:11fffbe98ef9 261
IanBenzMaxim 76:84e6c4994e29 262 /// Compute a Page MAC for authentication.
IanBenzMaxim 76:84e6c4994e29 263 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 264 /// @param[in] pageData Data from a device memory page.
IanBenzMaxim 76:84e6c4994e29 265 /// @param pageNum Number of the page to use data from.
IanBenzMaxim 76:84e6c4994e29 266 /// @param[in] challenge Random challenge to prevent replay attacks.
IanBenzMaxim 76:84e6c4994e29 267 /// @param[in] romId 1-Wire ROM ID of the device.
IanBenzMaxim 76:84e6c4994e29 268 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 269 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 270 static ISha256MacCoproc::CmdResult computeAuthMac(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 271 const Page & pageData,
IanBenzMaxim 76:84e6c4994e29 272 unsigned int pageNum,
IanBenzMaxim 76:84e6c4994e29 273 const Scratchpad & challenge,
IanBenzMaxim 76:84e6c4994e29 274 const RomId & romId,
IanBenzMaxim 76:84e6c4994e29 275 const ManId & manId,
IanBenzMaxim 76:84e6c4994e29 276 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 277
IanBenzMaxim 76:84e6c4994e29 278 /// Compute a Page MAC for authentication using anonymous mode.
IanBenzMaxim 76:84e6c4994e29 279 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 280 /// @param[in] pageData Data from a device memory page.
IanBenzMaxim 76:84e6c4994e29 281 /// @param pageNum Number of the page to use data from.
IanBenzMaxim 76:84e6c4994e29 282 /// @param[in] challenge Random challenge to prevent replay attacks.
IanBenzMaxim 76:84e6c4994e29 283 /// @param[in] manId Manufacturer ID of the device.
IanBenzMaxim 76:84e6c4994e29 284 /// @param[out] mac The computed MAC.
IanBenzMaxim 76:84e6c4994e29 285 static ISha256MacCoproc::CmdResult computeAuthMacAnon(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 74:23be10c32fa3 286 const Page & pageData,
IanBenzMaxim 74:23be10c32fa3 287 unsigned int pageNum,
IanBenzMaxim 74:23be10c32fa3 288 const Scratchpad & challenge,
IanBenzMaxim 74:23be10c32fa3 289 const ManId & manId,
IanBenzMaxim 74:23be10c32fa3 290 Mac & mac);
IanBenzMaxim 74:23be10c32fa3 291
IanBenzMaxim 76:84e6c4994e29 292 /// Number of segments per page.
IanBenzMaxim 76:84e6c4994e29 293 static const unsigned int segmentsPerPage = (Page::length / Segment::length);
IanBenzMaxim 76:84e6c4994e29 294
IanBenzMaxim 82:c11090a32471 295 /// @{
IanBenzMaxim 76:84e6c4994e29 296 /// Manufacturer ID
IanBenzMaxim 82:c11090a32471 297 ManId manId() const { return m_manId; }
IanBenzMaxim 82:c11090a32471 298 void setManId(const ManId & manId) { m_manId = manId; }
IanBenzMaxim 82:c11090a32471 299 /// @}
IanBenzMaxim 74:23be10c32fa3 300
IanBenzMaxim 82:c11090a32471 301 /// @{
IanBenzMaxim 76:84e6c4994e29 302 /// Enable low voltage timing
IanBenzMaxim 82:c11090a32471 303 bool lowVoltage() const { return m_lowVoltage; }
IanBenzMaxim 82:c11090a32471 304 void setLowVoltage(bool lowVoltage) { m_lowVoltage = lowVoltage; }
IanBenzMaxim 82:c11090a32471 305 /// @}
IanBenzMaxim 74:23be10c32fa3 306
IanBenzMaxim 76:84e6c4994e29 307 /// @param owMaster 1-Wire Master to use for communication with DS28E15/22/25.
IanBenzMaxim 76:84e6c4994e29 308 /// @param lowVoltage Enable low voltage timing.
IanBenzMaxim 77:529edb329ee0 309 DS28E15_22_25(RandomAccessRomIterator & selector, bool lowVoltage = false);
IanBenzMaxim 76:84e6c4994e29 310
IanBenzMaxim 76:84e6c4994e29 311 // Const member functions should not affect the state of the memory, block protection, or secret on the DS28Exx.
IanBenzMaxim 76:84e6c4994e29 312 // Scratchpad on the DS28Exx is considered mutable.
IanBenzMaxim 74:23be10c32fa3 313
IanBenzMaxim 76:84e6c4994e29 314 /// Get the number of memory pages from the ROM ID of this device.
IanBenzMaxim 76:84e6c4994e29 315 MemoryPages memoryPages();
IanBenzMaxim 74:23be10c32fa3 316
IanBenzMaxim 76:84e6c4994e29 317 /// Get the number of protection blocks from the ROM ID of this device.
IanBenzMaxim 76:84e6c4994e29 318 ProtectionBlocks protectionBlocks();
IanBenzMaxim 74:23be10c32fa3 319
IanBenzMaxim 76:84e6c4994e29 320 /// Perform Load and Lock Secret command on the device.
IanBenzMaxim 76:84e6c4994e29 321 /// @note The secret should already be stored in the scratchpad on the device.
IanBenzMaxim 76:84e6c4994e29 322 /// @param lock Prevent further changes to the secret on the device after loading.
IanBenzMaxim 76:84e6c4994e29 323 CmdResult loadSecret(bool lock);
IanBenzMaxim 74:23be10c32fa3 324
IanBenzMaxim 76:84e6c4994e29 325 /// Perform Write Scratchpad operation on the device.
IanBenzMaxim 76:84e6c4994e29 326 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 327 /// @param[in] data Data to write to the scratchpad.
IanBenzMaxim 76:84e6c4994e29 328 CmdResult writeScratchpad(const Scratchpad & data) const;
IanBenzMaxim 74:23be10c32fa3 329
IanBenzMaxim 76:84e6c4994e29 330 /// Perform a Read Scratchpad operation on the device.
IanBenzMaxim 76:84e6c4994e29 331 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 332 /// @param[out] data Buffer to read data from the scratchpad into.
IanBenzMaxim 76:84e6c4994e29 333 CmdResult readScratchpad(Scratchpad & data) const;
IanBenzMaxim 74:23be10c32fa3 334
IanBenzMaxim 76:84e6c4994e29 335 /// Read memory segment using the Read Memory command on the device.
IanBenzMaxim 76:84e6c4994e29 336 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 337 /// @param pageNum Page number for read operation.
IanBenzMaxim 76:84e6c4994e29 338 /// @param segmentNum Segment number within page for read operation.
IanBenzMaxim 76:84e6c4994e29 339 /// @param[out] data Buffer to read data from the segment into.
IanBenzMaxim 76:84e6c4994e29 340 /// @param continuing True if continuing a previous Read Memory command.
IanBenzMaxim 76:84e6c4994e29 341 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 342 CmdResult readSegment(unsigned int pageNum, unsigned int segmentNum, Segment & data, bool continuing = false) const;
IanBenzMaxim 74:23be10c32fa3 343
IanBenzMaxim 76:84e6c4994e29 344 /// Write memory segment using the Write Memory command.
IanBenzMaxim 76:84e6c4994e29 345 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 346 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 347 /// @param segmentNum Segment number within page for write operation.
IanBenzMaxim 76:84e6c4994e29 348 /// @param[in] data Data to write to the memory segment.
IanBenzMaxim 76:84e6c4994e29 349 /// @param continuing True to continue writing with the next sequential segment.
IanBenzMaxim 76:84e6c4994e29 350 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 351 CmdResult writeSegment(unsigned int pageNum, unsigned int segmentNum, const Segment & data, bool continuing = false);
IanBenzMaxim 74:23be10c32fa3 352
IanBenzMaxim 76:84e6c4994e29 353 /// Read memory page using the Read Memory command on the device.
IanBenzMaxim 76:84e6c4994e29 354 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 355 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 356 /// @param[out] rdbuf Buffer to read data from the page into.
IanBenzMaxim 76:84e6c4994e29 357 /// @param continuing True if continuing a previous Read Memory command.
IanBenzMaxim 76:84e6c4994e29 358 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 359 CmdResult readPage(unsigned int pageNum, Page & rdbuf, bool continuing = false) const;
IanBenzMaxim 73:2cecc1372acc 360
IanBenzMaxim 76:84e6c4994e29 361 /// Perform a Compute and Lock Secret command on the device.
IanBenzMaxim 76:84e6c4994e29 362 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 363 /// @param pageNum Page number to use as the binding data.
IanBenzMaxim 76:84e6c4994e29 364 /// @param lock Prevent further changes to the secret on the device after computing.
IanBenzMaxim 76:84e6c4994e29 365 CmdResult computeSecret(unsigned int pageNum, bool lock);
IanBenzMaxim 74:23be10c32fa3 366
IanBenzMaxim 76:84e6c4994e29 367 /// Perform a Compute Page MAC command on the device.
IanBenzMaxim 76:84e6c4994e29 368 /// Read back the MAC and verify the CRC16.
IanBenzMaxim 76:84e6c4994e29 369 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 370 /// @param pageNum Page number to use for the computation.
IanBenzMaxim 76:84e6c4994e29 371 /// @param anon True to compute in anonymous mode where ROM ID is not used.
IanBenzMaxim 76:84e6c4994e29 372 /// @param[out] mac The device computed MAC.
IanBenzMaxim 76:84e6c4994e29 373 CmdResult computeReadPageMac(unsigned int pageNum, bool anon, Mac & mac) const;
IanBenzMaxim 74:23be10c32fa3 374
IanBenzMaxim 76:84e6c4994e29 375 /// Read the status of a memory protection block using the Read Status command.
IanBenzMaxim 76:84e6c4994e29 376 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 377 /// @param blockNum Block number to to read status of.
IanBenzMaxim 76:84e6c4994e29 378 /// @param[out] protection Receives protection status read from device.
IanBenzMaxim 76:84e6c4994e29 379 CmdResult readBlockProtection(unsigned int blockNum, BlockProtection & protection);
IanBenzMaxim 74:23be10c32fa3 380
IanBenzMaxim 76:84e6c4994e29 381 /// @{
IanBenzMaxim 76:84e6c4994e29 382 /// Read the status of all memory protection blocks using the Read Status command.
IanBenzMaxim 76:84e6c4994e29 383 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 384 /// @param[out] protection Receives protection statuses read from device.
IanBenzMaxim 76:84e6c4994e29 385 CmdResult readAllBlockProtection(BlockProtection(&protection)[DS28E15_Blocks]) const;
IanBenzMaxim 76:84e6c4994e29 386 CmdResult readAllBlockProtection(BlockProtection(&protection)[DS28E25_Blocks]) const;
IanBenzMaxim 76:84e6c4994e29 387 /// @}
IanBenzMaxim 74:23be10c32fa3 388
IanBenzMaxim 76:84e6c4994e29 389 /// Read the personality bytes using the Read Status command.
IanBenzMaxim 76:84e6c4994e29 390 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 391 /// @param[out] personality Receives personality read from device.
IanBenzMaxim 76:84e6c4994e29 392 CmdResult readPersonality(Personality & personality) const;
IanBenzMaxim 74:23be10c32fa3 393
IanBenzMaxim 76:84e6c4994e29 394 /// Update the status of a memory protection block using the Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 395 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 396 /// @param[in] Desired protection status for the block.
IanBenzMaxim 76:84e6c4994e29 397 /// It is not possible to disable existing protections.
IanBenzMaxim 76:84e6c4994e29 398 /// @param continuing True to continue a previous Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 399 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 400 CmdResult writeBlockProtection(const BlockProtection & protection);
IanBenzMaxim 74:23be10c32fa3 401
IanBenzMaxim 76:84e6c4994e29 402 /// Update the status of a memory protection block using the Authenticated Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 403 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 404 /// @param MacCoproc Coprocessor with Slave Secret to use for the operation.
IanBenzMaxim 76:84e6c4994e29 405 /// @param[in] newProtection New protection status to write.
IanBenzMaxim 76:84e6c4994e29 406 /// @param[in] oldProtection Existing protection status in device.
IanBenzMaxim 76:84e6c4994e29 407 /// @param continuing True to continue a previous Authenticated Write Page Protection command.
IanBenzMaxim 76:84e6c4994e29 408 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 409 CmdResult writeAuthBlockProtection(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 410 const BlockProtection & newProtection,
IanBenzMaxim 76:84e6c4994e29 411 const BlockProtection & oldProtection);
IanBenzMaxim 74:23be10c32fa3 412
IanBenzMaxim 76:84e6c4994e29 413 /// Write memory segment with authentication using the Authenticated Write Memory command.
IanBenzMaxim 76:84e6c4994e29 414 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 415 /// @param MacCoproc Coprocessor to use for Write MAC computation.
IanBenzMaxim 76:84e6c4994e29 416 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 417 /// @param segmentNum Segment number within page for write operation.
IanBenzMaxim 76:84e6c4994e29 418 /// @param[in] newData New data to write to the segment.
IanBenzMaxim 76:84e6c4994e29 419 /// @param[in] oldData Existing data contained in the segment.
IanBenzMaxim 76:84e6c4994e29 420 /// @param continuing True to continue writing with the next sequential segment.
IanBenzMaxim 76:84e6c4994e29 421 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 422 CmdResult writeAuthSegment(const ISha256MacCoproc & MacCoproc,
IanBenzMaxim 76:84e6c4994e29 423 unsigned int pageNum,
IanBenzMaxim 76:84e6c4994e29 424 unsigned int segmentNum,
IanBenzMaxim 76:84e6c4994e29 425 const Segment & newData,
IanBenzMaxim 76:84e6c4994e29 426 const Segment & oldData,
IanBenzMaxim 76:84e6c4994e29 427 bool continuing = false);
IanBenzMaxim 74:23be10c32fa3 428
IanBenzMaxim 76:84e6c4994e29 429 /// Write memory segment with authentication using the Authenticated Write Memory command.
IanBenzMaxim 76:84e6c4994e29 430 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 431 /// @param pageNum Page number for write operation.
IanBenzMaxim 76:84e6c4994e29 432 /// @param segmentNum Segment number within page for write operation.
IanBenzMaxim 76:84e6c4994e29 433 /// @param[in] newData New data to write to the segment.
IanBenzMaxim 76:84e6c4994e29 434 /// @param[in] mac Write MAC computed for this operation.
IanBenzMaxim 76:84e6c4994e29 435 /// @param continuing True to continue writing with the next sequential segment.
IanBenzMaxim 76:84e6c4994e29 436 /// False to begin a new command.
IanBenzMaxim 76:84e6c4994e29 437 CmdResult writeAuthSegmentMac(unsigned int pageNum,
IanBenzMaxim 76:84e6c4994e29 438 unsigned int segmentNum,
IanBenzMaxim 76:84e6c4994e29 439 const Segment & newData,
IanBenzMaxim 76:84e6c4994e29 440 const Mac & mac,
IanBenzMaxim 76:84e6c4994e29 441 bool continuing = false);
IanBenzMaxim 74:23be10c32fa3 442
IanBenzMaxim 76:84e6c4994e29 443 private:
IanBenzMaxim 82:c11090a32471 444 ManId m_manId;
IanBenzMaxim 82:c11090a32471 445 bool m_lowVoltage;
IanBenzMaxim 82:c11090a32471 446
IanBenzMaxim 76:84e6c4994e29 447 static const unsigned int shaComputationDelayMs = 3;
IanBenzMaxim 76:84e6c4994e29 448 static const unsigned int eepromWriteDelayMs = 10;
IanBenzMaxim 82:c11090a32471 449 unsigned int secretEepromWriteDelayMs() const { return (m_lowVoltage ? 200 : 100); }
IanBenzMaxim 74:23be10c32fa3 450
IanBenzMaxim 76:84e6c4994e29 451 /// Read status bytes which are either personality or block protection.
IanBenzMaxim 76:84e6c4994e29 452 /// @note 1-Wire ROM selection should have already occurred.
IanBenzMaxim 76:84e6c4994e29 453 /// @param personality True to read personality or false to read block protection.
IanBenzMaxim 76:84e6c4994e29 454 /// @param allpages True to read all pages or false to read one page.
IanBenzMaxim 76:84e6c4994e29 455 /// @param pageNum Page number if reading block protection.
IanBenzMaxim 76:84e6c4994e29 456 /// @param rdbuf Buffer to receive data read from device.
IanBenzMaxim 76:84e6c4994e29 457 CmdResult readStatus(bool personality, bool allpages, unsigned int blockNum, uint8_t * rdbuf) const;
IanBenzMaxim 74:23be10c32fa3 458
IanBenzMaxim 76:84e6c4994e29 459 /// Extends readStatus() to use the BlockProtection wrapper.
IanBenzMaxim 76:84e6c4994e29 460 /// @see readAllBlockProtection(BlockProtection (&)[DS28E15_BLOCKS])
IanBenzMaxim 76:84e6c4994e29 461 template <ProtectionBlocks blocks> CmdResult readAllBlockProtection(BlockProtection(&protection)[blocks]) const;
IanBenzMaxim 76:84e6c4994e29 462 };
IanBenzMaxim 73:2cecc1372acc 463 }
IanBenzMaxim 25:bdb1c5a53b58 464
IanBenzMaxim 49:36954b62f503 465 #endif