Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp
- Revision:
- 62:43039aeca2ab
- Parent:
- 61:268612a10614
--- a/OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp Thu Apr 14 14:38:42 2016 -0500 +++ b/OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp Tue Apr 19 10:05:06 2016 -0500 @@ -42,6 +42,20 @@ CMD_WRITE_AUTH_PROTECT = 0xCC, }; +DS28E15_22_25::Segment DS28E15_22_25::Page::toSegment(unsigned int segmentNum) const +{ + if (segmentNum > (segmentsPerPage - 1)) + segmentNum = (segmentsPerPage - 1); + return Segment(*reinterpret_cast<const Segment::Buffer *>(&m_data[segmentNum * sizeof(Segment::Buffer)])); +} + +void DS28E15_22_25::Page::fromSegment(unsigned int segmentNum, const Segment & segment) +{ + if (segmentNum > (segmentsPerPage - 1)) + segmentNum = (segmentsPerPage - 1); + std::memcpy(&m_data[segmentNum * sizeof(Segment::Buffer)], &static_cast<const Segment::Buffer &>(segment), Segment::length); +} + DS28E15_22_25::BlockProtection::BlockProtection(bool readProtection, bool writeProtection, bool eepromEmulation, bool authProtection, std::uint8_t blockNum) { setReadProtection(readProtection); @@ -382,7 +396,7 @@ authMacData[11] = 0x00; - return MacCoproc.computeAuthMac(pageData, challenge, authMacData, mac); + return MacCoproc.computeAuthMac(ISha256MacCoprocessor::DevicePage(pageData), challenge, authMacData, mac); } ISha256MacCoprocessor::CmdResult DS28E15_22_25::computeAuthMacAnon(const ISha256MacCoprocessor & MacCoproc, const Page & pageData, unsigned int pageNum, const Scratchpad & challenge, const ManId & manId, Mac & mac) @@ -1008,5 +1022,5 @@ slaveSecretData[9] = manId[0]; slaveSecretData[8] = manId[1]; - return MacCoproc.computeSlaveSecret(bindingPage, partialSecret, slaveSecretData); + return MacCoproc.computeSlaveSecret(ISha256MacCoprocessor::DevicePage(bindingPage), partialSecret, slaveSecretData); }