Skip to content

Commit 656ba2e

Browse files
committed
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..
1 parent abd9e48 commit 656ba2e

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

libraries/MySensors/MyConfig.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@
9494
#define MY_RANDOMSEED_PIN 7 // A7 - Pin used for random generation (do not connect anything to this)
9595

9696
// Key to use for HMAC calculation in MySigningAtsha204Soft (32 bytes)
97-
#define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
98-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
97+
#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
9998

10099

101100
/**********************************

libraries/MySensors/MyHwATMega328.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,39 @@
3737
#include <SPI.h>
3838
#endif
3939

40+
#if defined __AVR_ATmega328P__
41+
#ifndef sleep_bod_disable
42+
#define sleep_bod_disable() \
43+
do { \
44+
unsigned char tempreg; \
45+
__asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \
46+
"ori %[tempreg], %[bods_bodse]" "\n\t" \
47+
"out %[mcucr], %[tempreg]" "\n\t" \
48+
"andi %[tempreg], %[not_bodse]" "\n\t" \
49+
"out %[mcucr], %[tempreg]" \
50+
: [tempreg] "=&d" (tempreg) \
51+
: [mcucr] "I" _SFR_IO_ADDR(MCUCR), \
52+
[bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \
53+
[not_bodse] "i" (~_BV(BODSE))); \
54+
} while (0)
55+
#endif
56+
#endif
57+
58+
4059
// Define these as macros to save valuable space
4160
#define hw_init() Serial.begin(BAUD_RATE)
4261
#define hw_watchdogReset() wdt_reset()
4362
#define hw_reboot() wdt_enable(WDTO_15MS); while (1)
4463
#define hw_millis() millis()
4564
#define hw_readConfig(__pos) (eeprom_read_byte((uint8_t*)(__pos)))
46-
#define hw_writeConfig(__pos, __value) (eeprom_update_byte((uint8_t*)(__pos), (__value)))
65+
66+
#ifndef eeprom_update_byte
67+
#define hw_writeConfig(loc, val) if((uint8_t)(val) != eeprom_read_byte((uint8_t*)(loc))) { eeprom_write_byte((uint8_t*)(loc), (val)); }
68+
#else
69+
#define hw_writeConfig(__pos, __value) (eeprom_update_byte((uint8_t*)(__pos), (__value)))
70+
#endif
71+
72+
//
4773
#define hw_readConfigBlock(__buf, __pos, __length) (eeprom_read_block((__buf), (void*)(__pos), (__length)))
4874
#define hw_writeConfigBlock(__pos, __buf, __length) (eeprom_write_block((void*)(__pos), (void*)__buf, (__length)))
4975

libraries/MySensors/MySigningAtsha204Soft.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
6161
#define DEBUG_SIGNING_PRINTBUF(str, buf, sz)
6262
#endif
6363

64+
// Initialize hmacKey from MyConfig.h (codebender didn't like static initialization in constructor)
65+
uint8_t MySigningAtsha204Soft::hmacKey[32] = { MY_HMAC_KEY };
66+
6467
MySigningAtsha204Soft::MySigningAtsha204Soft(bool requestSignatures,
6568
#ifdef MY_SECURE_NODE_WHITELISTING
6669
uint8_t nof_whitelist_entries, const whitelist_entry_t* the_whitelist,
@@ -70,7 +73,6 @@ MySigningAtsha204Soft::MySigningAtsha204Soft(bool requestSignatures,
7073
:
7174
MySigning(requestSignatures),
7275
rndPin(randomseedPin),
73-
hmacKey({MY_HMAC_KEY}),
7476
#ifdef MY_SECURE_NODE_WHITELISTING
7577
whitlist_sz(nof_whitelist_entries),
7678
whitelist(the_whitelist),

libraries/MySensors/MySigningAtsha204Soft.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class MySigningAtsha204Soft : public MySigning
7373
bool verification_ongoing;
7474
uint8_t current_nonce[NONCE_NUMIN_SIZE_PASSTHROUGH];
7575
uint8_t temp_message[32];
76-
uint8_t hmacKey[32];
76+
static uint8_t hmacKey[32];
7777
uint8_t rndPin;
7878
uint8_t hmac[32];
7979
void calculateSignature(MyMessage &msg);

0 commit comments

Comments
 (0)