From 656ba2e4ab6586b695efa201a3aa6c1f9d924763 Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Sat, 1 Aug 2015 00:05:09 +0200 Subject: [PATCH] Codebender adoption Had to make some chnages to make the code work on codebender (which seems to run a bit older version of AVR-LIBC. The compiler didn't like array constructor initializations either.. --- libraries/MySensors/MyConfig.h | 3 +- libraries/MySensors/MyHwATMega328.h | 28 ++++++++++++++++++- libraries/MySensors/MySigningAtsha204Soft.cpp | 4 ++- libraries/MySensors/MySigningAtsha204Soft.h | 2 +- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index 11c8af1..098a1f9 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -94,8 +94,7 @@ #define MY_RANDOMSEED_PIN 7 // A7 - Pin used for random generation (do not connect anything to this) // Key to use for HMAC calculation in MySigningAtsha204Soft (32 bytes) -#define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 +#define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /********************************** diff --git a/libraries/MySensors/MyHwATMega328.h b/libraries/MySensors/MyHwATMega328.h index 17a4222..12698d4 100644 --- a/libraries/MySensors/MyHwATMega328.h +++ b/libraries/MySensors/MyHwATMega328.h @@ -37,13 +37,39 @@ #include #endif +#if defined __AVR_ATmega328P__ +#ifndef sleep_bod_disable +#define sleep_bod_disable() \ +do { \ + unsigned char tempreg; \ + __asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \ + "ori %[tempreg], %[bods_bodse]" "\n\t" \ + "out %[mcucr], %[tempreg]" "\n\t" \ + "andi %[tempreg], %[not_bodse]" "\n\t" \ + "out %[mcucr], %[tempreg]" \ + : [tempreg] "=&d" (tempreg) \ + : [mcucr] "I" _SFR_IO_ADDR(MCUCR), \ + [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \ + [not_bodse] "i" (~_BV(BODSE))); \ +} while (0) +#endif +#endif + + // Define these as macros to save valuable space #define hw_init() Serial.begin(BAUD_RATE) #define hw_watchdogReset() wdt_reset() #define hw_reboot() wdt_enable(WDTO_15MS); while (1) #define hw_millis() millis() #define hw_readConfig(__pos) (eeprom_read_byte((uint8_t*)(__pos))) -#define hw_writeConfig(__pos, __value) (eeprom_update_byte((uint8_t*)(__pos), (__value))) + +#ifndef eeprom_update_byte + #define hw_writeConfig(loc, val) if((uint8_t)(val) != eeprom_read_byte((uint8_t*)(loc))) { eeprom_write_byte((uint8_t*)(loc), (val)); } +#else + #define hw_writeConfig(__pos, __value) (eeprom_update_byte((uint8_t*)(__pos), (__value))) +#endif + +// #define hw_readConfigBlock(__buf, __pos, __length) (eeprom_read_block((__buf), (void*)(__pos), (__length))) #define hw_writeConfigBlock(__pos, __buf, __length) (eeprom_write_block((void*)(__pos), (void*)__buf, (__length))) diff --git a/libraries/MySensors/MySigningAtsha204Soft.cpp b/libraries/MySensors/MySigningAtsha204Soft.cpp index d552c17..043d367 100644 --- a/libraries/MySensors/MySigningAtsha204Soft.cpp +++ b/libraries/MySensors/MySigningAtsha204Soft.cpp @@ -61,6 +61,9 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf, #define DEBUG_SIGNING_PRINTBUF(str, buf, sz) #endif +// Initialize hmacKey from MyConfig.h (codebender didn't like static initialization in constructor) +uint8_t MySigningAtsha204Soft::hmacKey[32] = { MY_HMAC_KEY }; + MySigningAtsha204Soft::MySigningAtsha204Soft(bool requestSignatures, #ifdef MY_SECURE_NODE_WHITELISTING uint8_t nof_whitelist_entries, const whitelist_entry_t* the_whitelist, @@ -70,7 +73,6 @@ MySigningAtsha204Soft::MySigningAtsha204Soft(bool requestSignatures, : MySigning(requestSignatures), rndPin(randomseedPin), - hmacKey({MY_HMAC_KEY}), #ifdef MY_SECURE_NODE_WHITELISTING whitlist_sz(nof_whitelist_entries), whitelist(the_whitelist), diff --git a/libraries/MySensors/MySigningAtsha204Soft.h b/libraries/MySensors/MySigningAtsha204Soft.h index e516618..5d8090e 100644 --- a/libraries/MySensors/MySigningAtsha204Soft.h +++ b/libraries/MySensors/MySigningAtsha204Soft.h @@ -73,7 +73,7 @@ private: bool verification_ongoing; uint8_t current_nonce[NONCE_NUMIN_SIZE_PASSTHROUGH]; uint8_t temp_message[32]; - uint8_t hmacKey[32]; + static uint8_t hmacKey[32]; uint8_t rndPin; uint8_t hmac[32]; void calculateSignature(MyMessage &msg);