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.
Diff: OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.hpp
- Revision:
- 25:bdb1c5a53b58
- Child:
- 27:d5aaefa252f1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.hpp Tue Mar 22 15:18:00 2016 -0500 @@ -0,0 +1,148 @@ +//------------Copyright (C) 2013 Maxim Integrated Products -------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL MAXIM INTEGRATED PRODCUTS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of Maxim Integrated Products +// shall not be used except as stated in the Maxim Integrated Products +// Branding Policy. +// --------------------------------------------------------------------------- + +#ifndef DS28E15_22_25_H +#define DS28E15_22_25_H + +#include "OneWire_Masters/OneWireMaster.h" +#include "OneWire_Masters/ISha256MacCoprocessor.hpp" +#include "OneWireSlave.hpp" + +class DS28E15_22_25 : public OneWireSlave +{ +public: + enum DeviceFamily + { + DS28E25_FAMILY = 0x47, + DS28E22_FAMILY = 0x48, + DS28E15_FAMILY = 0x17, + UNKNOWN_FAMILY = 0 + }; + + enum DevicePages + { + DS28E25_PAGES = 16, + DS28E22_PAGES = 8, + DS28E15_PAGES = 2, + UNKNOWN_PAGES = 0 + }; + + enum DeviceBlocks + { + DS28E25_BLOCKS = 8, + DS28E22_BLOCKS = 4, + DS28E15_BLOCKS = 4, + UNKNOWN_BLOCKS = 0 + }; + + static const std::size_t pageSize = 32; + static const std::size_t scratchpadSize = 32; + static const std::size_t macLen = 32; + + static const std::size_t segmentSize = 4; + static const std::size_t manIdLen = 2; + + std::uint8_t manId[manIdLen]; + + static ISha256MacCoprocessor::CmdResult CalculateSegmentWriteMAC256(const ISha256MacCoprocessor & MacCoproc, + unsigned int pageNum, + unsigned int segmentNum, + const std::uint8_t (&newData)[segmentSize], + const std::uint8_t (&oldData)[segmentSize], + const RomId & romId, + const std::uint8_t (&manId)[manIdLen], + std::uint8_t (&mac)[macLen]); + static ISha256MacCoprocessor::CmdResult CalculateProtectionWriteMAC256(const ISha256MacCoprocessor & MacCoproc, + std::uint8_t newProtection, + std::uint8_t oldProtection, + const RomId & romId, + const std::uint8_t (&manId)[manIdLen], + std::uint8_t (&mac)[macLen]); + static ISha256MacCoprocessor::CmdResult CalculateNextSecret(ISha256MacCoprocessor & MacCoproc, + const std::uint8_t (&binding)[pageSize], + const std::uint8_t (&partial)[scratchpadSize], + const RomId & romId, + const std::uint8_t (&manId)[manIdLen], + unsigned int pageNum); + static ISha256MacCoprocessor::CmdResult CalculateAuthMAC256(const ISha256MacCoprocessor & MacCoproc, + unsigned int pageNum, + const std::uint8_t (&challenge)[scratchpadSize], + const std::uint8_t (&pageData)[pageSize], + const RomId & romId, + const std::uint8_t (&manId)[manIdLen], + bool anon, + std::uint8_t (&mac)[macLen]); + static ISha256MacCoprocessor::CmdResult AuthVerify(const ISha256MacCoprocessor & MacCoproc, + unsigned int pageNum, + const std::uint8_t (&challenge)[scratchpadSize], + const std::uint8_t (&pageData)[pageSize], + const RomId & romId, + const std::uint8_t (&manId)[manIdLen], + bool anon, + const std::uint8_t (&mac)[macLen]); + + DS28E15_22_25(OneWireMaster & OW_master); + + // Const member functions should not affect the state of the memory, block protection, or secret on the DS28Exx. + // Scratchpad on the DS28Exx is considered mutable. + + DevicePages devicePages(); + DeviceBlocks deviceBlocks(); + + //DS28Exx Specific Functions (DS28E15, DS28E22 & DS28E25) + CmdResult LoadSecret(bool lock); + CmdResult WriteScratchpad(const std::uint8_t (&data)[scratchpadSize]) const; + CmdResult readSegment(unsigned int pageNum, unsigned int segmentNum, std::uint8_t (&data)[segmentSize]) const; + CmdResult writeSegment(unsigned int pageNum, unsigned int segmentNum, const std::uint8_t (&data)[segmentSize], bool continuing); + CmdResult readPage(unsigned int pageNum, std::uint8_t (&rdbuf)[pageSize], bool continuing) const; + CmdResult ComputeSecret(unsigned int pageNum, bool lock); + CmdResult ComputeReadPageMAC(unsigned int pageNum, bool anon, std::uint8_t (&mac)[macLen]) const; + CmdResult WriteBlockProtection(std::uint8_t protection, bool continuing); + CmdResult WriteAuthBlockProtection(const ISha256MacCoprocessor & MacCoproc, + std::uint8_t newProtection, + std::uint8_t oldProtection, + bool continuing); + CmdResult writeAuthSegment(const ISha256MacCoprocessor & MacCoproc, + unsigned int pageNum, + unsigned int segmentNum, + const std::uint8_t (&newData)[segmentSize], + const std::uint8_t (&oldData)[segmentSize], + bool continuing); + CmdResult writeAuthSegmentMAC(unsigned int pageNum, + unsigned int segmentNum, + const std::uint8_t (&newData)[segmentSize], + const std::uint8_t (&mac)[macLen], + bool continuing); + + CmdResult ReadBlockProtectionStatus(unsigned int blockNum, std::uint8_t & status); + // bool ReadAllBlockProtectionStatuses(std::uint8_t (&statuses)[numBlocks]); + +private: + OneWireMaster & m_OW_master; + + CmdResult ReadStatus(bool personality, bool allpages, unsigned int pageNum, unsigned char *rdbuf) const; +}; + +#endif \ No newline at end of file