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