Merge pull request #2654 from Antiklesys/master
[RRG-proxmark3.git] / include / pmflash.h
blobbbed4b12e9f107cf41a364ee1efb9b0e2d6d8448
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // RDV4 flash constants
17 //-----------------------------------------------------------------------------
19 #ifndef __PMFLASH_H
20 #define __PMFLASH_H
22 #include "common.h"
24 // RDV40 Section
25 // 256kb divided into 4k sectors.
27 // 0x3F000 - 1 4kb sector = signature
28 // 0x3E000 - 1 4kb sector = settings
29 // 0x3D000 - 1 4kb sector = default T55XX keys dictionary
30 // 0x3B000 - 1 4kb sector = default ICLASS keys dictionary
31 // 0x38000 - 3 4kb sectors = default MFC keys dictionary
33 #ifndef FLASH_MEM_BLOCK_SIZE
34 # define FLASH_MEM_BLOCK_SIZE 256
35 #endif
37 #ifndef FLASH_MEM_MAX_SIZE
38 # define FLASH_MEM_MAX_SIZE 0x40000 // (262144)
39 #endif
40 #ifndef FLASH_MEM_MAX_SIZE_P
41 # define FLASH_MEM_MAX_SIZE_P(p64k) (1024 * 64 * (p64k))
42 #endif
44 #ifndef FLASH_MEM_MAX_4K_SECTOR
45 # define FLASH_MEM_MAX_4K_SECTOR 0x3F000
46 #endif
47 #ifndef FLASH_MEM_MAX_4K_SECTOR_P
48 # define FLASH_MEM_MAX_4K_SECTOR_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - 4096)
49 #endif
51 #ifndef FLASH_MEM_ID_LEN
52 # define FLASH_MEM_ID_LEN 8
53 #endif
55 #ifndef FLASH_MEM_SIGNATURE_LEN
56 # define FLASH_MEM_SIGNATURE_LEN 128
57 #endif
59 #ifndef FLASH_MEM_SIGNATURE_OFFSET
60 // -1 for historical compatibility with already released Proxmark3 RDV4.0 devices
61 # define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN - 1)
62 #endif
63 #ifndef FLASH_MEM_SIGNATURE_OFFSET_P
64 # define FLASH_MEM_SIGNATURE_OFFSET_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - FLASH_MEM_SIGNATURE_LEN - 1)
65 #endif
67 #ifndef T55XX_CONFIG_LEN
68 # define T55XX_CONFIG_LEN sizeof( t55xx_configurations_t )
69 #endif
71 #ifndef T55XX_CONFIG_OFFSET
72 # define T55XX_CONFIG_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x2000)
73 #endif
74 #ifndef T55XX_CONFIG_OFFSET_P
75 # define T55XX_CONFIG_OFFSET_P(p64k) (FLASH_MEM_MAX_4K_SECTOR_P(p64k) - 0x2000)
76 #endif
78 // Reserved space for T55XX PWD = 4 kb
79 #ifndef DEFAULT_T55XX_KEYS_OFFSET
80 # define DEFAULT_T55XX_KEYS_LEN (0x1000)
81 # define DEFAULT_T55XX_KEYS_OFFSET (T55XX_CONFIG_OFFSET - DEFAULT_T55XX_KEYS_LEN)
82 # define DEFAULT_T55XX_KEYS_MAX ((DEFAULT_T55XX_KEYS_LEN - 2) / 4)
83 #endif
84 #ifndef DEFAULT_T55XX_KEYS_OFFSET_P
85 # define DEFAULT_T55XX_KEYS_OFFSET_P(p64k) (T55XX_CONFIG_OFFSET_P(p64k) - DEFAULT_T55XX_KEYS_LEN)
86 #endif
88 // Reserved space for iClass keys = 4 kb
89 #ifndef DEFAULT_ICLASS_KEYS_OFFSET
90 # define DEFAULT_ICLASS_KEYS_LEN (0x1000)
91 # define DEFAULT_ICLASS_KEYS_OFFSET (DEFAULT_T55XX_KEYS_OFFSET - DEFAULT_ICLASS_KEYS_LEN)
92 # define DEFAULT_ICLASS_KEYS_MAX ((DEFAULT_ICLASS_KEYS_LEN - 2) / 8)
93 #endif
94 #ifndef DEFAULT_ICLASS_KEYS_OFFSET_P
95 # define DEFAULT_ICLASS_KEYS_OFFSET_P(p64k) (DEFAULT_T55XX_KEYS_OFFSET_P(p64k) - DEFAULT_ICLASS_KEYS_LEN)
96 #endif
98 // Reserved space for MIFARE Keys = 12 kb
99 #ifndef DEFAULT_MF_KEYS_OFFSET
100 # define DEFAULT_MF_KEYS_LEN (0x3000)
101 # define DEFAULT_MF_KEYS_OFFSET (DEFAULT_ICLASS_KEYS_OFFSET - DEFAULT_MF_KEYS_LEN)
102 # define DEFAULT_MF_KEYS_MAX ((DEFAULT_MF_KEYS_LEN - 2) / 6)
103 #endif
104 #ifndef DEFAULT_MF_KEYS_OFFSET_P
105 # define DEFAULT_MF_KEYS_OFFSET_P(p64k) (DEFAULT_ICLASS_KEYS_OFFSET_P(p64k) - DEFAULT_MF_KEYS_LEN)
106 #endif
108 // RDV40, validation structure to help identifying that client/firmware is talking with RDV40
109 typedef struct {
110 uint8_t magic[4];
111 uint8_t flashid[FLASH_MEM_ID_LEN];
112 uint8_t signature[FLASH_MEM_SIGNATURE_LEN];
113 } PACKED rdv40_validation_t;
116 #endif // __PMFLASH_H