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@34:11fffbe98ef9, 2016-04-01 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Fri Apr 01 09:29:55 2016 -0500
- Revision:
- 34:11fffbe98ef9
- Parent:
- 33:a4c015046956
- Child:
- 49:36954b62f503
Continue code cleanup of DS2465 and DS28E15_22_25.
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 | 25:bdb1c5a53b58 | 35 | class DS28E15_22_25 : public OneWireSlave |
IanBenzMaxim | 25:bdb1c5a53b58 | 36 | { |
IanBenzMaxim | 25:bdb1c5a53b58 | 37 | public: |
IanBenzMaxim | 34:11fffbe98ef9 | 38 | enum FamilyCode |
IanBenzMaxim | 25:bdb1c5a53b58 | 39 | { |
IanBenzMaxim | 25:bdb1c5a53b58 | 40 | DS28E25_FAMILY = 0x47, |
IanBenzMaxim | 25:bdb1c5a53b58 | 41 | DS28E22_FAMILY = 0x48, |
IanBenzMaxim | 25:bdb1c5a53b58 | 42 | DS28E15_FAMILY = 0x17, |
IanBenzMaxim | 25:bdb1c5a53b58 | 43 | UNKNOWN_FAMILY = 0 |
IanBenzMaxim | 25:bdb1c5a53b58 | 44 | }; |
IanBenzMaxim | 25:bdb1c5a53b58 | 45 | |
IanBenzMaxim | 34:11fffbe98ef9 | 46 | enum MemoryPages |
IanBenzMaxim | 25:bdb1c5a53b58 | 47 | { |
IanBenzMaxim | 25:bdb1c5a53b58 | 48 | DS28E25_PAGES = 16, |
IanBenzMaxim | 25:bdb1c5a53b58 | 49 | DS28E22_PAGES = 8, |
IanBenzMaxim | 25:bdb1c5a53b58 | 50 | DS28E15_PAGES = 2, |
IanBenzMaxim | 25:bdb1c5a53b58 | 51 | UNKNOWN_PAGES = 0 |
IanBenzMaxim | 25:bdb1c5a53b58 | 52 | }; |
IanBenzMaxim | 25:bdb1c5a53b58 | 53 | |
IanBenzMaxim | 34:11fffbe98ef9 | 54 | enum ProtectionBlocks |
IanBenzMaxim | 25:bdb1c5a53b58 | 55 | { |
IanBenzMaxim | 25:bdb1c5a53b58 | 56 | DS28E25_BLOCKS = 8, |
IanBenzMaxim | 25:bdb1c5a53b58 | 57 | DS28E22_BLOCKS = 4, |
IanBenzMaxim | 25:bdb1c5a53b58 | 58 | DS28E15_BLOCKS = 4, |
IanBenzMaxim | 25:bdb1c5a53b58 | 59 | UNKNOWN_BLOCKS = 0 |
IanBenzMaxim | 25:bdb1c5a53b58 | 60 | }; |
IanBenzMaxim | 25:bdb1c5a53b58 | 61 | |
IanBenzMaxim | 33:a4c015046956 | 62 | typedef array<std::uint8_t, 32> Page; |
IanBenzMaxim | 33:a4c015046956 | 63 | typedef array<std::uint8_t, 32> Scratchpad; |
IanBenzMaxim | 33:a4c015046956 | 64 | typedef array<std::uint8_t, 32> Mac; |
IanBenzMaxim | 33:a4c015046956 | 65 | typedef array<std::uint8_t, 4> Segment; |
IanBenzMaxim | 33:a4c015046956 | 66 | typedef array<std::uint8_t, 2> ManId; |
IanBenzMaxim | 25:bdb1c5a53b58 | 67 | |
IanBenzMaxim | 34:11fffbe98ef9 | 68 | class BlockProtection |
IanBenzMaxim | 34:11fffbe98ef9 | 69 | { |
IanBenzMaxim | 34:11fffbe98ef9 | 70 | private: |
IanBenzMaxim | 34:11fffbe98ef9 | 71 | static const std::uint8_t readProtectionMask = 0x80, writeProtectionMask = 0x40, eepromEmulationMask = 0x20, authProtectionMask = 0x10, blockNumMask = 0x03; |
IanBenzMaxim | 34:11fffbe98ef9 | 72 | std::uint8_t m_status; |
IanBenzMaxim | 34:11fffbe98ef9 | 73 | |
IanBenzMaxim | 34:11fffbe98ef9 | 74 | public: |
IanBenzMaxim | 34:11fffbe98ef9 | 75 | BlockProtection() : m_status(0x00) { } |
IanBenzMaxim | 34:11fffbe98ef9 | 76 | BlockProtection(bool readProtection, bool writeProtection, bool eepromEmulation, bool authProtection, std::uint8_t blockNum); |
IanBenzMaxim | 34:11fffbe98ef9 | 77 | |
IanBenzMaxim | 34:11fffbe98ef9 | 78 | std::uint8_t status() const { return m_status; } |
IanBenzMaxim | 34:11fffbe98ef9 | 79 | void setStatus(std::uint8_t status) { m_status = status; } |
IanBenzMaxim | 34:11fffbe98ef9 | 80 | |
IanBenzMaxim | 34:11fffbe98ef9 | 81 | std::uint8_t blockNum() const { return (m_status & blockNumMask); } |
IanBenzMaxim | 34:11fffbe98ef9 | 82 | void setBlockNum(std::uint8_t blockNum); |
IanBenzMaxim | 34:11fffbe98ef9 | 83 | |
IanBenzMaxim | 34:11fffbe98ef9 | 84 | bool readProtection() const { return ((m_status & readProtectionMask) == readProtectionMask); } |
IanBenzMaxim | 34:11fffbe98ef9 | 85 | void setReadProtection(bool readProtection); |
IanBenzMaxim | 34:11fffbe98ef9 | 86 | |
IanBenzMaxim | 34:11fffbe98ef9 | 87 | bool writeProtection() const { return ((m_status & writeProtectionMask) == writeProtectionMask); } |
IanBenzMaxim | 34:11fffbe98ef9 | 88 | void setWriteProtection(bool writeProtection); |
IanBenzMaxim | 34:11fffbe98ef9 | 89 | |
IanBenzMaxim | 34:11fffbe98ef9 | 90 | bool eepromEmulation() const { return ((m_status & eepromEmulationMask) == eepromEmulationMask); } |
IanBenzMaxim | 34:11fffbe98ef9 | 91 | void setEepromEmulation(bool eepromEmulation); |
IanBenzMaxim | 34:11fffbe98ef9 | 92 | |
IanBenzMaxim | 34:11fffbe98ef9 | 93 | bool authProtection() const { return ((m_status & authProtectionMask) == authProtectionMask); } |
IanBenzMaxim | 34:11fffbe98ef9 | 94 | void setAuthProtection(bool authProtection); |
IanBenzMaxim | 34:11fffbe98ef9 | 95 | |
IanBenzMaxim | 34:11fffbe98ef9 | 96 | bool noProtection() const; |
IanBenzMaxim | 34:11fffbe98ef9 | 97 | |
IanBenzMaxim | 34:11fffbe98ef9 | 98 | bool operator==(const BlockProtection & rhs) const { return (this->m_status == rhs.m_status); } |
IanBenzMaxim | 34:11fffbe98ef9 | 99 | bool operator!=(const BlockProtection & rhs) const { return !operator==(rhs); } |
IanBenzMaxim | 34:11fffbe98ef9 | 100 | }; |
IanBenzMaxim | 34:11fffbe98ef9 | 101 | |
IanBenzMaxim | 34:11fffbe98ef9 | 102 | static ISha256MacCoprocessor::CmdResult calculateSegmentWriteMac(const ISha256MacCoprocessor & MacCoproc, |
IanBenzMaxim | 34:11fffbe98ef9 | 103 | unsigned int pageNum, |
IanBenzMaxim | 34:11fffbe98ef9 | 104 | unsigned int segmentNum, |
IanBenzMaxim | 34:11fffbe98ef9 | 105 | const Segment & newData, |
IanBenzMaxim | 34:11fffbe98ef9 | 106 | const Segment & oldData, |
IanBenzMaxim | 34:11fffbe98ef9 | 107 | const RomId & romId, |
IanBenzMaxim | 34:11fffbe98ef9 | 108 | const ManId & manId, |
IanBenzMaxim | 34:11fffbe98ef9 | 109 | Mac & mac); |
IanBenzMaxim | 34:11fffbe98ef9 | 110 | static ISha256MacCoprocessor::CmdResult calculateProtectionWriteMac(const ISha256MacCoprocessor & MacCoproc, |
IanBenzMaxim | 34:11fffbe98ef9 | 111 | const BlockProtection & newProtection, |
IanBenzMaxim | 34:11fffbe98ef9 | 112 | const BlockProtection & oldProtection, |
IanBenzMaxim | 34:11fffbe98ef9 | 113 | const RomId & romId, |
IanBenzMaxim | 34:11fffbe98ef9 | 114 | const ManId & manId, |
IanBenzMaxim | 34:11fffbe98ef9 | 115 | Mac & mac); |
IanBenzMaxim | 34:11fffbe98ef9 | 116 | static ISha256MacCoprocessor::CmdResult calculateNextSecret(ISha256MacCoprocessor & MacCoproc, |
IanBenzMaxim | 34:11fffbe98ef9 | 117 | const Page & binding, |
IanBenzMaxim | 34:11fffbe98ef9 | 118 | const Scratchpad & partial, |
IanBenzMaxim | 34:11fffbe98ef9 | 119 | const RomId & romId, |
IanBenzMaxim | 34:11fffbe98ef9 | 120 | const ManId & manId, |
IanBenzMaxim | 34:11fffbe98ef9 | 121 | unsigned int pageNum); |
IanBenzMaxim | 34:11fffbe98ef9 | 122 | static ISha256MacCoprocessor::CmdResult calculateAuthMac(const ISha256MacCoprocessor & MacCoproc, |
IanBenzMaxim | 34:11fffbe98ef9 | 123 | unsigned int pageNum, |
IanBenzMaxim | 34:11fffbe98ef9 | 124 | const Scratchpad & challenge, |
IanBenzMaxim | 34:11fffbe98ef9 | 125 | const Page & pageData, |
IanBenzMaxim | 34:11fffbe98ef9 | 126 | const RomId & romId, |
IanBenzMaxim | 34:11fffbe98ef9 | 127 | const ManId & manId, |
IanBenzMaxim | 34:11fffbe98ef9 | 128 | bool anon, |
IanBenzMaxim | 34:11fffbe98ef9 | 129 | Mac & mac); |
IanBenzMaxim | 34:11fffbe98ef9 | 130 | |
IanBenzMaxim | 33:a4c015046956 | 131 | // Manufacturer ID |
IanBenzMaxim | 33:a4c015046956 | 132 | ManId manId; |
IanBenzMaxim | 25:bdb1c5a53b58 | 133 | |
IanBenzMaxim | 34:11fffbe98ef9 | 134 | // Low voltage |
IanBenzMaxim | 34:11fffbe98ef9 | 135 | bool lowVoltage; |
IanBenzMaxim | 25:bdb1c5a53b58 | 136 | |
IanBenzMaxim | 34:11fffbe98ef9 | 137 | DS28E15_22_25(OneWireMaster & OW_master, bool lowVoltage = false); |
IanBenzMaxim | 25:bdb1c5a53b58 | 138 | |
IanBenzMaxim | 25:bdb1c5a53b58 | 139 | // Const member functions should not affect the state of the memory, block protection, or secret on the DS28Exx. |
IanBenzMaxim | 25:bdb1c5a53b58 | 140 | // Scratchpad on the DS28Exx is considered mutable. |
IanBenzMaxim | 25:bdb1c5a53b58 | 141 | |
IanBenzMaxim | 34:11fffbe98ef9 | 142 | MemoryPages memoryPages(); |
IanBenzMaxim | 34:11fffbe98ef9 | 143 | ProtectionBlocks protectionBlocks(); |
IanBenzMaxim | 25:bdb1c5a53b58 | 144 | |
IanBenzMaxim | 25:bdb1c5a53b58 | 145 | //DS28Exx Specific Functions (DS28E15, DS28E22 & DS28E25) |
IanBenzMaxim | 34:11fffbe98ef9 | 146 | CmdResult loadSecret(bool lock); |
IanBenzMaxim | 34:11fffbe98ef9 | 147 | CmdResult writeScratchpad(const Scratchpad & data) const; |
IanBenzMaxim | 33:a4c015046956 | 148 | CmdResult readSegment(unsigned int pageNum, unsigned int segmentNum, Segment & data) const; |
IanBenzMaxim | 34:11fffbe98ef9 | 149 | CmdResult writeSegment(unsigned int pageNum, unsigned int segmentNum, const Segment & data, bool continuing = false); |
IanBenzMaxim | 34:11fffbe98ef9 | 150 | CmdResult readPage(unsigned int pageNum, Page & rdbuf, bool continuing = false) const; |
IanBenzMaxim | 34:11fffbe98ef9 | 151 | CmdResult computeSecret(unsigned int pageNum, bool lock); |
IanBenzMaxim | 34:11fffbe98ef9 | 152 | CmdResult computeReadPageMAC(unsigned int pageNum, bool anon, Mac & mac) const; |
IanBenzMaxim | 34:11fffbe98ef9 | 153 | CmdResult readBlockProtection(unsigned int blockNum, BlockProtection & protection); |
IanBenzMaxim | 34:11fffbe98ef9 | 154 | CmdResult writeBlockProtection(const BlockProtection & protection, bool continuing = false); |
IanBenzMaxim | 34:11fffbe98ef9 | 155 | CmdResult writeAuthBlockProtection(const ISha256MacCoprocessor & MacCoproc, |
IanBenzMaxim | 34:11fffbe98ef9 | 156 | const BlockProtection & newProtection, |
IanBenzMaxim | 34:11fffbe98ef9 | 157 | const BlockProtection & oldProtection, |
IanBenzMaxim | 34:11fffbe98ef9 | 158 | bool continuing = false); |
IanBenzMaxim | 25:bdb1c5a53b58 | 159 | CmdResult writeAuthSegment(const ISha256MacCoprocessor & MacCoproc, |
IanBenzMaxim | 34:11fffbe98ef9 | 160 | unsigned int pageNum, |
IanBenzMaxim | 34:11fffbe98ef9 | 161 | unsigned int segmentNum, |
IanBenzMaxim | 34:11fffbe98ef9 | 162 | const Segment & newData, |
IanBenzMaxim | 34:11fffbe98ef9 | 163 | const Segment & oldData, |
IanBenzMaxim | 34:11fffbe98ef9 | 164 | bool continuing = false); |
IanBenzMaxim | 34:11fffbe98ef9 | 165 | CmdResult writeAuthSegmentMac(unsigned int pageNum, |
IanBenzMaxim | 25:bdb1c5a53b58 | 166 | unsigned int segmentNum, |
IanBenzMaxim | 33:a4c015046956 | 167 | const Segment & newData, |
IanBenzMaxim | 33:a4c015046956 | 168 | const Mac & mac, |
IanBenzMaxim | 34:11fffbe98ef9 | 169 | bool continuing = false); |
IanBenzMaxim | 25:bdb1c5a53b58 | 170 | |
IanBenzMaxim | 25:bdb1c5a53b58 | 171 | private: |
IanBenzMaxim | 34:11fffbe98ef9 | 172 | static const unsigned int shaComputationDelayMs = 3; |
IanBenzMaxim | 34:11fffbe98ef9 | 173 | static const unsigned int eepromWriteDelayMs = 10; |
IanBenzMaxim | 34:11fffbe98ef9 | 174 | unsigned int secretEepromWriteDelayMs() const { return (lowVoltage ? 200 : 100); } |
IanBenzMaxim | 34:11fffbe98ef9 | 175 | |
IanBenzMaxim | 25:bdb1c5a53b58 | 176 | OneWireMaster & m_OW_master; |
IanBenzMaxim | 34:11fffbe98ef9 | 177 | CmdResult readStatus(bool personality, bool allpages, unsigned int pageNum, std::uint8_t * rdbuf) const; |
IanBenzMaxim | 25:bdb1c5a53b58 | 178 | }; |
IanBenzMaxim | 25:bdb1c5a53b58 | 179 | |
IanBenzMaxim | 25:bdb1c5a53b58 | 180 | #endif |