diff options
author | Patrick Venture <venture@google.com> | 2018-09-12 08:53:29 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-09-15 13:11:30 -0700 |
commit | ef3aeadc9be37c47d0627e576e81a74a5bb9e94f (patch) | |
tree | 95c183977468b107bdd3faaaa988b5d853be2f00 /crc.hpp | |
parent | baa73da1abaaf05ea1133319405fb2b891825618 (diff) | |
download | phosphor-ipmi-blobs-ef3aeadc9be37c47d0627e576e81a74a5bb9e94f.tar.gz phosphor-ipmi-blobs-ef3aeadc9be37c47d0627e576e81a74a5bb9e94f.zip |
initial drop of phosphor-ipmi-blobs
This implements a majority of the OEM IPMI BLOBS protocol. The only
piece missing from this is the timed expiration of sessions.
Change-Id: I82c9d17b625c94fc3340edcfabbbf1ffeb5ad7ac
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'crc.hpp')
-rw-r--r-- | crc.hpp | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -0,0 +1,60 @@ +#pragma once + +#include <cstdint> + +namespace blobs +{ + +using std::size_t; +using std::uint16_t; +using std::uint32_t; +using std::uint8_t; + +constexpr uint16_t crc16Ccitt = 0x1021; +/* Value from: http://srecord.sourceforge.net/crc16-ccitt.html for + * implementation without explicit bit adding. + */ +constexpr uint16_t crc16Initial = 0xFFFF; + +class CrcInterface +{ + public: + virtual ~CrcInterface() = default; + + /** + * Reset the crc. + */ + virtual void clear() = 0; + + /** + * Provide bytes against which to compute the crc. This method is + * meant to be only called once between clear() and get(). + * + * @param[in] bytes - the data against which to compute. + * @param[in] length - the number of bytes. + */ + virtual void compute(const uint8_t* bytes, uint32_t length) = 0; + + /** + * Read back the current crc value. + * + * @return the crc16 value. + */ + virtual uint16_t get() const = 0; +}; + +class Crc16 : public CrcInterface +{ + public: + Crc16() : poly(crc16Ccitt), value(crc16Initial){}; + ~Crc16() = default; + + void clear() override; + void compute(const uint8_t* bytes, uint32_t length) override; + uint16_t get() const override; + + private: + uint16_t poly; + uint16_t value; +}; +} // namespace blobs |