Skip to content

Commit 4978115

Browse files
committed
Make RANDOM_UID card type aware
1 parent 7546906 commit 4978115

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Diff for: Firmware/ChameleonMini/Button.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,23 @@ void ButtonInit(void)
2424

2525
static void ExecuteButtonAction(ButtonActionEnum ButtonAction)
2626
{
27-
uint8_t UidBuffer[CONFIGURATION_UID_SIZE_MAX];
27+
ConfigurationUidType UidBuffer;
2828

2929
if (ButtonAction == BUTTON_ACTION_UID_RANDOM) {
30-
31-
/* iceman, 2018, this random functionality could be more localized to the current cardtype in use.
32-
ie. for Ultralight based cards with 7byte uid, skip manufacturing byte
33-
*/
34-
30+
uint8_t startByte = 0;
3531
ApplicationGetUid(UidBuffer);
3632

37-
/* skip manufacturing byte UID0 */
38-
for (uint8_t i=1; i<ActiveConfiguration.UidSize-1; i++) {
39-
UidBuffer[i] = RandomGetByte();
33+
#ifdef CONFIG_MF_ULTRALIGHT_SUPPORT
34+
// Make RANDOM keep 1st byte safe for Ultralight types
35+
ConfigurationEnum ActiveConfigurationId = GlobalSettings.ActiveSettingPtr->Configuration;
36+
if( (ActiveConfigurationId == CONFIG_MF_ULTRALIGHT)
37+
|| (ActiveConfigurationId == CONFIG_MF_ULTRALIGHT_EV1_80B)
38+
|| (ActiveConfigurationId == CONFIG_MF_ULTRALIGHT_EV1_164B) ) {
39+
startByte = 1;
40+
}
41+
#endif
42+
for( ; startByte < ActiveConfiguration.UidSize; startByte++) {
43+
UidBuffer[startByte] = RandomGetByte();
4044
}
4145

4246
ApplicationSetUid(UidBuffer);

0 commit comments

Comments
 (0)