Skip to content

Commit

Permalink
Merge pull request #142 from McEloff/ul_otp_locks
Browse files Browse the repository at this point in the history
Ultralight. OTP page and page with locks could not be resets to zero
  • Loading branch information
iceman1001 authored Sep 10, 2019
2 parents 857063e + afc4093 commit 02f85ed
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Firmware/ChameleonMini/Application/MifareUltralight.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@

#define BYTES_PER_WRITE 4
#define PAGE_WRITE_MIN 0x02
#define PAGE_LOCK_BITS 0x02
#define PAGE_OTP 0x03

#define BYTES_PER_COMPAT_WRITE 16

Expand Down Expand Up @@ -195,6 +197,18 @@ static void AuthCounterReset(void)
static uint8_t AppWritePage(uint8_t PageAddress, uint8_t* const Buffer)
{
if (!ActiveConfiguration.ReadOnly) {
if (PageAddress == PAGE_LOCK_BITS || PageAddress == PAGE_OTP) {
// OTP page and page with locks could not be resets to zero
uint8_t PageBytes[MIFARE_ULTRALIGHT_PAGE_SIZE];
MemoryReadBlock(PageBytes, PageAddress * MIFARE_ULTRALIGHT_PAGE_SIZE, MIFARE_ULTRALIGHT_PAGE_SIZE);
// First two bytes of page with locks are not rewritable
if (PageAddress == PAGE_LOCK_BITS) {
Buffer[0] = Buffer[1] = 0;
}
for (uint8_t i = 0; i < MIFARE_ULTRALIGHT_PAGE_SIZE; i++) {
Buffer[i] |= PageBytes[i];
}
}
MemoryWriteBlock(Buffer, PageAddress * MIFARE_ULTRALIGHT_PAGE_SIZE, MIFARE_ULTRALIGHT_PAGE_SIZE);
} else {
/* If the chameleon is in read only mode, it silently
Expand Down

0 comments on commit 02f85ed

Please sign in to comment.