Chameleon-Mini
DESFireUtils.h
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireUtils.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_UTILS_H__
28 #define __DESFIRE_UTILS_H__
29 
30 #include <stdarg.h>
31 
32 #include "DESFireFirmwareSettings.h"
33 
34 #define UnsignedTypeToUINT(typeValue) \
35  ((UINT) typeValue)
36 #define ExtractLSBLE(ui) \
37  ((BYTE) (((UnsignedTypeToUINT(ui) & 0xff000000) >> 24) & 0x000000ff))
38 #define ExtractLSBBE(ui) \
39  ((BYTE) (UnsignedTypeToUINT(ui) & 0x000000ff))
40 
41 void RotateArrayRight(BYTE *srcBuf, BYTE *destBuf, SIZET bufSize);
42 void RotateArrayLeft(BYTE *srcBuf, BYTE *destBuf, SIZET bufSize);
43 void ConcatByteArrays(BYTE *arrA, SIZET arrASize, BYTE *arrB, SIZET arrBSize, BYTE *destArr);
44 
45 void Int32ToByteBuffer(uint8_t *byteBuffer, int32_t int32Value);
46 void Int24ToByteBuffer(uint8_t *byteBuffer, uint32_t int24Value);
47 int32_t Int32FromByteBuffer(uint8_t *byteBuffer);
48 
49 SIZET RoundBlockSize(SIZET byteSize, SIZET blockSize);
50 
51 /* Copied from the READER configuration sources: */
52 uint16_t DesfireAddParityBits(uint8_t *Buffer, uint16_t bits);
53 uint16_t DesfireRemoveParityBits(uint8_t *Buffer, uint16_t BitCount);
54 bool DesfireCheckParityBits(uint8_t *Buffer, uint16_t BitCount);
55 
56 #endif