]> git.zerfleddert.de Git - proxmark3-svn/blob - common/protocols.c
removed some duplicates.
[proxmark3-svn] / common / protocols.c
1 #include "protocols.h"
2
3 // ATA55xx shared presets & routines
4 uint32_t GetT55xxClockBit(uint32_t clock) {
5 switch (clock) {
6 case 128: return T55x7_BITRATE_RF_128;
7 case 100: return T55x7_BITRATE_RF_100;
8 case 64: return T55x7_BITRATE_RF_64;
9 case 50: return T55x7_BITRATE_RF_50;
10 case 40: return T55x7_BITRATE_RF_40;
11 case 32: return T55x7_BITRATE_RF_32;
12 case 16: return T55x7_BITRATE_RF_16;
13 case 8: return T55x7_BITRATE_RF_8;
14 default : return 0;
15 }
16 }
17
18 #ifndef ON_DEVICE
19 #include "ui.h"
20 #define prnt PrintAndLog
21
22 uint8_t isset(uint8_t val, uint8_t mask) {
23 return (val & mask);
24 }
25
26 uint8_t notset(uint8_t val, uint8_t mask){
27 return !(val & mask);
28 }
29
30 void fuse_config(const picopass_hdr *hdr) {
31 uint8_t fuses = hdr->conf.fuses;
32
33 if (isset(fuses,FUSE_FPERS))
34 prnt(" Mode: Personalization [Programmable]");
35 else
36 prnt(" Mode: Application [Locked]");
37
38 if (isset(fuses, FUSE_CODING1)) {
39 prnt(" Coding: RFU");
40 } else {
41 if( isset( fuses , FUSE_CODING0))
42 prnt(" Coding: ISO 14443-2 B/ISO 15693");
43 else
44 prnt(" Coding: ISO 14443B only");
45 }
46 if( isset (fuses,FUSE_CRYPT1 | FUSE_CRYPT0 )) prnt(" Crypt: Secured page, keys not locked");
47 if( isset (fuses,FUSE_CRYPT1) && notset( fuses, FUSE_CRYPT0 )) prnt(" Crypt: Secured page, keys not locked");
48 if( notset (fuses,FUSE_CRYPT1) && isset( fuses, FUSE_CRYPT0 )) prnt(" Crypt: Non secured page");
49 if( notset (fuses,FUSE_CRYPT1) && notset( fuses, FUSE_CRYPT0 )) prnt(" Crypt: No auth possible. Read only if RA is enabled");
50
51 if( isset( fuses, FUSE_RA))
52 prnt(" RA: Read access enabled");
53 else
54 prnt(" RA: Read access not enabled");
55 }
56
57 void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t *app_areas, uint8_t *kb) {
58 // mem-bit 5, mem-bit 7, chip-bit 4: defines chip type
59 uint8_t k16 = isset(mem_cfg, 0x80);
60 //uint8_t k2 = isset(mem_cfg, 0x08);
61 uint8_t book = isset(mem_cfg, 0x20);
62
63 if(isset(chip_cfg, 0x10) && !k16 && !book) {
64 *kb = 2;
65 *app_areas = 2;
66 *max_blk = 31;
67 } else if(isset(chip_cfg, 0x10) && k16 && !book) {
68 *kb = 16;
69 *app_areas = 2;
70 *max_blk = 255; //16kb
71 } else if(notset(chip_cfg, 0x10) && !k16 && !book) {
72 *kb = 16;
73 *app_areas = 16;
74 *max_blk = 255; //16kb
75 } else if(isset(chip_cfg, 0x10) && k16 && book) {
76 *kb = 32;
77 *app_areas = 3;
78 *max_blk = 255; //16kb
79 } else if(notset(chip_cfg, 0x10) && !k16 && book) {
80 *kb = 32;
81 *app_areas = 17;
82 *max_blk = 255; //16kb
83 } else {
84 *kb = 32;
85 *app_areas = 2;
86 *max_blk = 255;
87 }
88 }
89
90 void mem_app_config(const picopass_hdr *hdr) {
91 uint8_t mem = hdr->conf.mem_config;
92 uint8_t chip = hdr->conf.chip_config;
93 uint8_t applimit = hdr->conf.app_limit;
94 if (applimit < 6) applimit = 26;
95 uint8_t kb = 2;
96 uint8_t app_areas = 2;
97 uint8_t max_blk = 31;
98 getMemConfig(mem, chip, &max_blk, &app_areas, &kb);
99 prnt(" Mem: %u KBits/%u App Areas (%u * 8 bytes) [%02X]", kb, app_areas, max_blk, mem);
100 prnt(" AA1: blocks 06-%02X", applimit);
101 prnt(" AA2: blocks %02X-%02X", applimit+1, max_blk);
102
103 prnt("");
104 uint8_t book = isset(mem, 0x20);
105 if (book) {
106 prnt("KeyAccess:");
107 prnt("\tRead A - Kd");
108 prnt("\tRead B - Kc");
109 prnt("\tWrite A - Kd");
110 prnt("\tWrite B - Kc");
111 prnt("\tDebit - Kd or Kc");
112 prnt("\tCredit - Kc");
113 } else{
114 prnt("KeyAccess:");
115 prnt("\tRead A - Kd or Kc");
116 prnt("\tRead B - Kd or Kc");
117 prnt("\tWrite A - Kc");
118 prnt("\tWrite B - Kc");
119 prnt("\tDebit - Kd or Kc");
120 prnt("\tCredit - Kc");
121 }
122 }
123 void print_picopass_info(const picopass_hdr *hdr) {
124 fuse_config(hdr);
125 mem_app_config(hdr);
126 }
127 void printIclassDumpInfo(uint8_t* iclass_dump) {
128 print_picopass_info((picopass_hdr *) iclass_dump);
129 }
130
131 /*
132 void test() {
133 picopass_hdr hdr = {0x27,0xaf,0x48,0x01,0xf9,0xff,0x12,0xe0,0x12,0xff,0xff,0xff,0x7f,0x1f,0xff,0x3c};
134 prnt("Picopass configuration:");
135 print_picopass_info(&hdr);
136 }
137 int main(int argc, char *argv[]) {
138 test();
139 return 0;
140 }
141 */
142
143 #endif
144 //ON_DEVICE
Impressum, Datenschutz