diff --git a/src/ECCX08.cpp b/src/ECCX08.cpp index 0164343..3b7383e 100644 --- a/src/ECCX08.cpp +++ b/src/ECCX08.cpp @@ -548,6 +548,54 @@ int ECCX08Class::nonce(const byte data[]) return challenge(data); } +long ECCX08Class::incrementCounter(int keyId) +{ + uint32_t counter; // the counter can go up to 2,097,151 + + if (!wakeup()) { + return -1; + } + + if (!sendCommand(0x24, 1, keyId)) { + return -1; + } + + delay(20); + + if (!receiveResponse(&counter, sizeof(counter))) { + return -1; + } + + delay(1); + idle(); + + return counter; +} + +long ECCX08Class::readCounter(int keyId) +{ + uint32_t counter; // the counter can go up to 2,097,151 + + if (!wakeup()) { + return -1; + } + + if (!sendCommand(0x24, 0, keyId)) { + return -1; + } + + delay(20); + + if (!receiveResponse(&counter, sizeof(counter))) { + return -1; + } + + delay(1); + idle(); + + return counter; +} + int ECCX08Class::wakeup() { _wire->setClock(_wakeupFrequency); @@ -892,4 +940,4 @@ uint16_t ECCX08Class::crc16(const byte data[], size_t length) ECCX08Class ECCX08(CRYPTO_WIRE, 0x60); #else ECCX08Class ECCX08(Wire, 0x60); -#endif \ No newline at end of file +#endif diff --git a/src/ECCX08.h b/src/ECCX08.h index 54fdc3a..ead8468 100644 --- a/src/ECCX08.h +++ b/src/ECCX08.h @@ -66,6 +66,9 @@ class ECCX08Class int nonce(const byte data[]); + long incrementCounter(int keyId); + long readCounter(int keyId); + private: int wakeup(); int sleep();