From 27f34de6d8e9528cdab3455a19f6e98d30f35fbc Mon Sep 17 00:00:00 2001 From: "@shinhub" Date: Wed, 6 Nov 2019 20:31:26 +0100 Subject: [PATCH 1/4] Fix tabs to spaces --- Firmware/ChameleonMini/Button.c | 300 ++++++++++++++++---------------- Firmware/ChameleonMini/Button.h | 28 +-- 2 files changed, 164 insertions(+), 164 deletions(-) diff --git a/Firmware/ChameleonMini/Button.c b/Firmware/ChameleonMini/Button.c index 5b1f16a..ccad406 100644 --- a/Firmware/ChameleonMini/Button.c +++ b/Firmware/ChameleonMini/Button.c @@ -3,7 +3,7 @@ #include "Common.h" #include "Settings.h" -#define LONG_PRESS_TICK_COUNT 10 +#define LONG_PRESS_TICK_COUNT 10 static const char PROGMEM ButtonActionTable[][32] = { @@ -19,105 +19,105 @@ static const char PROGMEM ButtonActionTable[][32] = void ButtonInit(void) { - BUTTON_PORT.DIRCLR = BUTTON_MASK; - BUTTON_PORT.BUTTON_PINCTRL = PORT_OPC_PULLUP_gc; + BUTTON_PORT.DIRCLR = BUTTON_MASK; + BUTTON_PORT.BUTTON_PINCTRL = PORT_OPC_PULLUP_gc; } static void ExecuteButtonAction(ButtonActionEnum ButtonAction) { - uint8_t UidBuffer[32]; - - if (ButtonAction == BUTTON_ACTION_UID_RANDOM) { - - /* iceman, 2018, this random functionality could be more localized to the current cardtype in use. - ie. for Ultralight based cards with 7byte uid, skip manufacturing byte - */ - - ApplicationGetUid(UidBuffer); - - /* skip manufacturing byte UID0 */ - for (uint8_t i=1; i 0) { - if (Carry) { - if (UidBuffer[i] == 0xFF) { - Carry = 1; - } else { - Carry = 0; - } - - UidBuffer[i] = (UidBuffer[i] + 1) & 0xFF; - } - } - - ApplicationSetUid(UidBuffer); - } else if (ButtonAction == BUTTON_ACTION_UID_LEFT_DECREMENT) { - ApplicationGetUid(UidBuffer); - bool Carry = 1; - uint8_t i; - - for (i=0; i 0) { - if (Carry) { - if (UidBuffer[i] == 0x00) { - Carry = 1; - } else { - Carry = 0; - } - - UidBuffer[i] = (UidBuffer[i] - 1) & 0xFF; - } - } - - ApplicationSetUid(UidBuffer); - } else if (ButtonAction == BUTTON_ACTION_CYCLE_SETTINGS) { - SettingsCycle(); - } else if (ButtonAction == BUTTON_ACTION_TOGGLE_READONLY) { - ActiveConfiguration.ReadOnly = !ActiveConfiguration.ReadOnly; - } + uint8_t UidBuffer[32]; + + if (ButtonAction == BUTTON_ACTION_UID_RANDOM) { + + /* iceman, 2018, this random functionality could be more localized to the current cardtype in use. + ie. for Ultralight based cards with 7byte uid, skip manufacturing byte + */ + + ApplicationGetUid(UidBuffer); + + /* skip manufacturing byte UID0 */ + for (uint8_t i=1; i 0) { + if (Carry) { + if (UidBuffer[i] == 0xFF) { + Carry = 1; + } else { + Carry = 0; + } + + UidBuffer[i] = (UidBuffer[i] + 1) & 0xFF; + } + } + + ApplicationSetUid(UidBuffer); + } else if (ButtonAction == BUTTON_ACTION_UID_LEFT_DECREMENT) { + ApplicationGetUid(UidBuffer); + bool Carry = 1; + uint8_t i; + + for (i=0; i 0) { + if (Carry) { + if (UidBuffer[i] == 0x00) { + Carry = 1; + } else { + Carry = 0; + } + + UidBuffer[i] = (UidBuffer[i] - 1) & 0xFF; + } + } + + ApplicationSetUid(UidBuffer); + } else if (ButtonAction == BUTTON_ACTION_CYCLE_SETTINGS) { + SettingsCycle(); + } else if (ButtonAction == BUTTON_ACTION_TOGGLE_READONLY) { + ActiveConfiguration.ReadOnly = !ActiveConfiguration.ReadOnly; + } } void ButtonTick(void) @@ -130,28 +130,28 @@ void ButtonTick(void) //LastButtonState = ThisButtonState; if (ThisButtonState & BUTTON_MASK) { - /* Button is currently pressed */ - if (PressTickCounter < LONG_PRESS_TICK_COUNT) { - /* Count ticks while button is being pressed */ - PressTickCounter++; - } else if (PressTickCounter == LONG_PRESS_TICK_COUNT) { - /* Long button press detected execute button action and advance PressTickCounter - * to an invalid state. */ - ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonLongAction); - PressTickCounter++; - } else { - /* Button is still pressed, ignore */ - } + /* Button is currently pressed */ + if (PressTickCounter < LONG_PRESS_TICK_COUNT) { + /* Count ticks while button is being pressed */ + PressTickCounter++; + } else if (PressTickCounter == LONG_PRESS_TICK_COUNT) { + /* Long button press detected execute button action and advance PressTickCounter + * to an invalid state. */ + ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonLongAction); + PressTickCounter++; + } else { + /* Button is still pressed, ignore */ + } } else if (!(ThisButtonState & BUTTON_MASK)) { - /* Button is currently not being pressed. Check if PressTickCounter contains - * a recent short button press. */ - if ( (PressTickCounter > 0) && (PressTickCounter <= LONG_PRESS_TICK_COUNT) ) { - /* We have a short button press */ - ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonAction); - } - - PressTickCounter = 0; - } + /* Button is currently not being pressed. Check if PressTickCounter contains + * a recent short button press. */ + if ( (PressTickCounter > 0) && (PressTickCounter <= LONG_PRESS_TICK_COUNT) ) { + /* We have a short button press */ + ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonAction); + } + + PressTickCounter = 0; + } } void ButtonGetActionList(char* ListOut, uint16_t BufferSize) @@ -185,47 +185,47 @@ void ButtonGetActionList(char* ListOut, uint16_t BufferSize) void ButtonSetActionById(ButtonTypeEnum Type, ButtonActionEnum Action) { - #ifndef BUTTON_SETTING_GLOBAL - if (Type == BUTTON_PRESS_SHORT) { - GlobalSettings.ActiveSettingPtr->ButtonAction = Action; - } else if (Type == BUTTON_PRESS_LONG) { - GlobalSettings.ActiveSettingPtr->ButtonLongAction = Action; - } - #else - /* Write button action to all settings when using global settings */ - for (uint8_t i=0; iButtonAction = Action; + } else if (Type == BUTTON_PRESS_LONG) { + GlobalSettings.ActiveSettingPtr->ButtonLongAction = Action; + } + #else + /* Write button action to all settings when using global settings */ + for (uint8_t i=0; iButtonAction], BufferSize); - } else if (Type == BUTTON_PRESS_LONG) { - strncpy_P(ActionOut, ButtonActionTable[GlobalSettings.ActiveSettingPtr->ButtonLongAction], BufferSize); - } else { - /* Should not happen (TM) */ - *ActionOut = '\0'; - } + if (Type == BUTTON_PRESS_SHORT) { + strncpy_P(ActionOut, ButtonActionTable[GlobalSettings.ActiveSettingPtr->ButtonAction], BufferSize); + } else if (Type == BUTTON_PRESS_LONG) { + strncpy_P(ActionOut, ButtonActionTable[GlobalSettings.ActiveSettingPtr->ButtonLongAction], BufferSize); + } else { + /* Should not happen (TM) */ + *ActionOut = '\0'; + } } bool ButtonSetActionByName(ButtonTypeEnum Type, const char* Action) { - uint8_t i; + uint8_t i; - for (i=0; i Date: Wed, 6 Nov 2019 20:36:45 +0100 Subject: [PATCH 2/4] Move constants in header file --- Firmware/ChameleonMini/Button.c | 8 +++----- Firmware/ChameleonMini/Button.h | 8 +++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Firmware/ChameleonMini/Button.c b/Firmware/ChameleonMini/Button.c index ccad406..b35de2e 100644 --- a/Firmware/ChameleonMini/Button.c +++ b/Firmware/ChameleonMini/Button.c @@ -3,8 +3,6 @@ #include "Common.h" #include "Settings.h" -#define LONG_PRESS_TICK_COUNT 10 - static const char PROGMEM ButtonActionTable[][32] = { [BUTTON_ACTION_NONE] = "CLOSED", @@ -131,10 +129,10 @@ void ButtonTick(void) if (ThisButtonState & BUTTON_MASK) { /* Button is currently pressed */ - if (PressTickCounter < LONG_PRESS_TICK_COUNT) { + if (PressTickCounter < BUTTON_LONG_PRESS_TICK_COUNT) { /* Count ticks while button is being pressed */ PressTickCounter++; - } else if (PressTickCounter == LONG_PRESS_TICK_COUNT) { + } else if (PressTickCounter == BUTTON_LONG_PRESS_TICK_COUNT) { /* Long button press detected execute button action and advance PressTickCounter * to an invalid state. */ ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonLongAction); @@ -145,7 +143,7 @@ void ButtonTick(void) } else if (!(ThisButtonState & BUTTON_MASK)) { /* Button is currently not being pressed. Check if PressTickCounter contains * a recent short button press. */ - if ( (PressTickCounter > 0) && (PressTickCounter <= LONG_PRESS_TICK_COUNT) ) { + if ( (PressTickCounter > 0) && (PressTickCounter <= BUTTON_LONG_PRESS_TICK_COUNT) ) { /* We have a short button press */ ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonAction); } diff --git a/Firmware/ChameleonMini/Button.h b/Firmware/ChameleonMini/Button.h index 50fb4d3..b2d0db1 100644 --- a/Firmware/ChameleonMini/Button.h +++ b/Firmware/ChameleonMini/Button.h @@ -12,9 +12,11 @@ #include #include "Application/Application.h" -#define BUTTON_PORT PORTA -#define BUTTON_MASK PIN6_bm -#define BUTTON_PINCTRL PIN6CTRL +#define BUTTON_PORT PORTA +#define BUTTON_MASK PIN6_bm +#define BUTTON_PINCTRL PIN6CTRL + +#define BUTTON_LONG_PRESS_TICK_COUNT 10 typedef enum { BUTTON_ACTION_NONE, From 75469062298188f0065e7625f926eb7bdca8839d Mon Sep 17 00:00:00 2001 From: "@shinhub" Date: Wed, 6 Nov 2019 20:38:04 +0100 Subject: [PATCH 3/4] Free space and sync UID buffer with max UID size in conf --- Firmware/ChameleonMini/Button.c | 5 +++-- Firmware/ChameleonMini/Button.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/ChameleonMini/Button.c b/Firmware/ChameleonMini/Button.c index b35de2e..8b4b09f 100644 --- a/Firmware/ChameleonMini/Button.c +++ b/Firmware/ChameleonMini/Button.c @@ -1,9 +1,10 @@ #include "Button.h" #include "Random.h" +#include "Configuration.h" #include "Common.h" #include "Settings.h" -static const char PROGMEM ButtonActionTable[][32] = +static const char PROGMEM ButtonActionTable[][BUTTON_NAME_MAX_LEN] = { [BUTTON_ACTION_NONE] = "CLOSED", [BUTTON_ACTION_UID_RANDOM] = "RANDOM_UID", @@ -23,7 +24,7 @@ void ButtonInit(void) static void ExecuteButtonAction(ButtonActionEnum ButtonAction) { - uint8_t UidBuffer[32]; + uint8_t UidBuffer[CONFIGURATION_UID_SIZE_MAX]; if (ButtonAction == BUTTON_ACTION_UID_RANDOM) { diff --git a/Firmware/ChameleonMini/Button.h b/Firmware/ChameleonMini/Button.h index b2d0db1..b11d6cc 100644 --- a/Firmware/ChameleonMini/Button.h +++ b/Firmware/ChameleonMini/Button.h @@ -16,6 +16,7 @@ #define BUTTON_MASK PIN6_bm #define BUTTON_PINCTRL PIN6CTRL +#define BUTTON_NAME_MAX_LEN 20 #define BUTTON_LONG_PRESS_TICK_COUNT 10 typedef enum { From 49781153c80c8eb2ddc759acb0d89fd755717323 Mon Sep 17 00:00:00 2001 From: "@shinhub" Date: Wed, 6 Nov 2019 22:02:58 +0100 Subject: [PATCH 4/4] Make RANDOM_UID card type aware --- Firmware/ChameleonMini/Button.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Firmware/ChameleonMini/Button.c b/Firmware/ChameleonMini/Button.c index 8b4b09f..c10b173 100644 --- a/Firmware/ChameleonMini/Button.c +++ b/Firmware/ChameleonMini/Button.c @@ -24,19 +24,23 @@ void ButtonInit(void) static void ExecuteButtonAction(ButtonActionEnum ButtonAction) { - uint8_t UidBuffer[CONFIGURATION_UID_SIZE_MAX]; + ConfigurationUidType UidBuffer; if (ButtonAction == BUTTON_ACTION_UID_RANDOM) { - - /* iceman, 2018, this random functionality could be more localized to the current cardtype in use. - ie. for Ultralight based cards with 7byte uid, skip manufacturing byte - */ - + uint8_t startByte = 0; ApplicationGetUid(UidBuffer); - /* skip manufacturing byte UID0 */ - for (uint8_t i=1; iConfiguration; + if( (ActiveConfigurationId == CONFIG_MF_ULTRALIGHT) + || (ActiveConfigurationId == CONFIG_MF_ULTRALIGHT_EV1_80B) + || (ActiveConfigurationId == CONFIG_MF_ULTRALIGHT_EV1_164B) ) { + startByte = 1; + } +#endif + for( ; startByte < ActiveConfiguration.UidSize; startByte++) { + UidBuffer[startByte] = RandomGetByte(); } ApplicationSetUid(UidBuffer);