Skip to content

Commit

Permalink
Make RANDOM_UID card type aware
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinHub committed Nov 6, 2019
1 parent 7546906 commit 4978115
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Firmware/ChameleonMini/Button.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<ActiveConfiguration.UidSize-1; i++) {
UidBuffer[i] = RandomGetByte();
#ifdef CONFIG_MF_ULTRALIGHT_SUPPORT
// Make RANDOM keep 1st byte safe for Ultralight types
ConfigurationEnum ActiveConfigurationId = GlobalSettings.ActiveSettingPtr->Configuration;
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);
Expand Down

0 comments on commit 4978115

Please sign in to comment.