Skip to content

Commit

Permalink
Several fixes to responsiveness and frozen behavior noted in PR #319
Browse files Browse the repository at this point in the history
  • Loading branch information
maxieds committed Jul 1, 2022
1 parent 93e77a2 commit bc8057b
Show file tree
Hide file tree
Showing 31 changed files with 323 additions and 383 deletions.
9 changes: 2 additions & 7 deletions Doc/DESFireSupportReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

## Quick configuration of cloned DESFire tags

### Chameleon Mini terminal addons to support ``CONFIG=MF_DESFIRE`` modes

Note that these commands are only compiled into the firmware when the compiler
option ``-DALLOW_DESFIRE_TERMINAL_COMMANDS`` and ``-DCONFIG_MF_DESFIRE_SUPPORT`` are
specified. If you do not at miniumum have a configuration, ``CONFIG=MF_DESFIRE``, then
these commands will not work. Note that LIVE logging should be disabled before attempting to
run these commands.
### Chameleon Mini terminal addons to support DESFire tag configurations

#### Selecting a DESFire configuration

Expand Down Expand Up @@ -47,6 +41,7 @@ DF_SETHDR=ATS 0675f7b102
```
To reset the ATQA value returned in the anticollision loop handshaking:
```
DF_SETHDR=ATQA 0344
DF_SETHDR=ATQA 2838
```

Expand Down
2 changes: 1 addition & 1 deletion Firmware/Chameleon-Mini/AntennaLevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void AntennaLevelTick(void) {
if (rssi < FIELD_MIN_RSSI) {
LEDHook(LED_FIELD_DETECTED, LED_OFF);
if (ActiveConfiguration.UidSize != 0) // this implies that we are emulating right now
ApplicationReset(); // reset the application just like a real card gets reset when there is no field
ApplicationReset(); // reset the application just like a real card gets reset when there is no field
} else {
LEDHook(LED_FIELD_DETECTED, LED_ON);
AntennaLevelLogReaderDetectCount = (++AntennaLevelLogReaderDetectCount) % ANTENNA_LEVEL_LOG_RDRDETECT_INTERVAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ uint16_t DeleteApp(const DESFireAidType Aid) {
AppDir.FirstFreeSlot = MIN(Slot, AppDir.FirstFreeSlot);
SynchronizeAppDir();
if (!IsPiccAppSelected()) {
InvalidateAuthState(0x00);
InvalidateAuthState(0);
}
SelectAppBySlot(DESFIRE_PICC_APP_SLOT);
return STATUS_OPERATION_OK;
Expand All @@ -720,11 +720,11 @@ TransferStatus GetApplicationIdsTransfer(uint8_t *Buffer) {
Status.BytesProcessed = 0;
for (EntryIndex = TransferState.GetApplicationIds.NextIndex;
EntryIndex < DESFIRE_MAX_SLOTS; ++EntryIndex) {
if ((AppDir.AppIds[EntryIndex][0] | AppDir.AppIds[EntryIndex][1] |
AppDir.AppIds[EntryIndex][2]) == 0)
if ((AppDir.AppIds[EntryIndex][0] | AppDir.AppIds[EntryIndex][1] | AppDir.AppIds[EntryIndex][2]) == 0) {
continue;
}
/* If it won't fit -- remember and return */
if (Status.BytesProcessed >= TERMINAL_BUFFER_SIZE) { // TODO ??? 19 / Magic Number ???
if (Status.BytesProcessed >= TERMINAL_BUFFER_SIZE) {
TransferState.GetApplicationIds.NextIndex = EntryIndex;
Status.IsComplete = false;
return Status;
Expand Down
4 changes: 2 additions & 2 deletions Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ uint8_t CryptoAESTransferEncryptSend(uint8_t *Buffer, uint8_t Count, const uint8
}

uint8_t CryptoAESTransferEncryptReceive(uint8_t *Buffer, uint8_t Count, const uint8_t *Key) {
LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count);
DesfireLogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count);
return STATUS_OPERATION_OK;
}
#endif
Expand Down Expand Up @@ -322,7 +322,7 @@ uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count) {
}

uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count) {
LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count);
DesfireLogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count);
return 0;
}

Expand Down
27 changes: 0 additions & 27 deletions Firmware/Chameleon-Mini/Application/DESFire/DESFireFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,31 +370,4 @@ uint8_t ValidateAuthentication(uint16_t AccessRights, uint16_t CheckMask) {
return VALIDATED_ACCESS_DENIED;
}

const char *GetFileAccessPermissionsDesc(uint16_t fileAccessRights) {
__InternalStringBuffer[0] = '\0';
BYTE removeTrailingText = 0x00;
if (GetReadPermissions(fileAccessRights) != DESFIRE_ACCESS_DENY) {
strcat_P(__InternalStringBuffer, PSTR("R/"));
removeTrailingText = 0x01;
}
if (GetWritePermissions(fileAccessRights) != DESFIRE_ACCESS_DENY) {
strcat_P(__InternalStringBuffer, PSTR("W/"));
removeTrailingText = 0x01;

}
if (GetReadWritePermissions(fileAccessRights) != DESFIRE_ACCESS_DENY) {
strcat_P(__InternalStringBuffer, PSTR("RW/"));
removeTrailingText = 0x01;
}
if (GetChangePermissions(fileAccessRights) != DESFIRE_ACCESS_DENY) {
strcat_P(__InternalStringBuffer, PSTR("CHG"));
removeTrailingText = 0x00;
}
if (removeTrailingText) {
BYTE bufSize = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE);
__InternalStringBuffer[bufSize - 1] = '\0';
}
return __InternalStringBuffer;
}

#endif /* CONFIG_MF_DESFIRE_SUPPORT */
6 changes: 2 additions & 4 deletions Firmware/Chameleon-Mini/Application/DESFire/DESFireFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ This notice must be retained at the top of all source files where indicated.
/* Data about an application's file is currently kept in this structure.
* The location of these structures is defined by the file index.
*/
typedef struct DESFIRE_FIRMWARE_PACKING {
typedef struct DESFIRE_FIRMWARE_PACKING DESFIRE_FIRMWARE_ALIGNAT {
uint8_t FileType;
uint8_t FileNumber;
uint16_t FileSize;
Expand Down Expand Up @@ -86,7 +86,7 @@ typedef struct DESFIRE_FIRMWARE_PACKING {

uint16_t GetFileSizeFromFileType(DESFireFileTypeSettings *File);

typedef struct DESFIRE_FIRMWARE_PACKING {
typedef struct DESFIRE_FIRMWARE_PACKING DESFIRE_FIRMWARE_ALIGNAT {
BYTE Num;
DESFireFileTypeSettings File;
} SelectedFileCacheType;
Expand Down Expand Up @@ -149,8 +149,6 @@ uint16_t WriteDataFileIterator(uint8_t *Buffer, uint16_t ByteCount);
#define GetChangePermissions(AccessRights) \
(BYTE) (((0xf000 & AccessRights) >> 12) & 0x000f)

const char *GetFileAccessPermissionsDesc(uint16_t fileAccessRights);

/*
* There are also command/instruction-wise
* citations given from file's access permissions. This data is taken
Expand Down
Loading

0 comments on commit bc8057b

Please sign in to comment.