]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include <strings.h> | |
3 | #include <stdint.h> | |
4 | #include <stdarg.h> | |
5 | ||
6 | ||
7 | typedef struct { | |
8 | uint8_t app_limit; | |
9 | uint8_t otp[2]; | |
10 | uint8_t block_writelock; | |
11 | uint8_t chip_config; | |
12 | uint8_t mem_config; | |
13 | uint8_t eas; | |
14 | uint8_t fuses; | |
15 | }picopass_conf_block; | |
16 | ||
17 | ||
18 | typedef struct { | |
19 | uint8_t csn[8]; | |
20 | picopass_conf_block conf; | |
21 | uint8_t epurse[8]; | |
22 | uint8_t key_d[8]; | |
23 | uint8_t key_c[8]; | |
24 | uint8_t app_issuer_area[8]; | |
25 | ||
26 | }picopass_hdr; | |
27 | ||
28 | #define FUSE_FPERS 0x80 | |
29 | #define FUSE_CODING1 0x40 | |
30 | #define FUSE_CODING0 0x20 | |
31 | #define FUSE_CRYPT1 0x10 | |
32 | #define FUSE_CRYPT0 0x08 | |
33 | #define FUSE_FPROD1 0x04 | |
34 | #define FUSE_FPROD0 0x02 | |
35 | #define FUSE_RA 0x01 | |
36 | ||
37 | //#define prnt printf | |
38 | void prnt(char *fmt,...) | |
39 | { | |
40 | va_list argptr; | |
41 | va_start(argptr, fmt); | |
42 | vprintf(fmt, argptr); | |
43 | printf(" "); // cleaning prompt | |
44 | va_end(argptr); | |
45 | printf("\n"); | |
46 | } | |
47 | ||
48 | uint8_t isset(uint8_t val, uint8_t mask) | |
49 | { | |
50 | return (val & mask); | |
51 | } | |
52 | ||
53 | uint8_t notset(uint8_t val, uint8_t mask){ | |
54 | return !(val & mask); | |
55 | } | |
56 | ||
57 | void fuse_config(const picopass_hdr *hdr) | |
58 | { | |
59 | uint8_t fuses = hdr->conf.fuses; | |
60 | ||
61 | if (isset(fuses,FUSE_FPERS))prnt(" Mode: Personalization [Programmable]"); | |
62 | else prnt(" Mode: Application [Locked]"); | |
63 | ||
64 | if (isset(fuses, FUSE_CODING1)) | |
65 | prnt(" Coding: RFU"); | |
66 | else | |
67 | { | |
68 | if( isset( fuses , FUSE_CODING0)) prnt(" Coding: ISO 14443-2 B/ISO 15693"); | |
69 | else prnt(" Coding: ISO 14443B only"); | |
70 | } | |
71 | if( isset (fuses,FUSE_CRYPT1 | FUSE_CRYPT0 )) prnt(" Crypt: Secured page, keys not locked"); | |
72 | if( isset (fuses,FUSE_CRYPT1) && notset( fuses, FUSE_CRYPT0 )) prnt(" Crypt: Secured page, keys not locked"); | |
73 | if( notset (fuses,FUSE_CRYPT1) && isset( fuses, FUSE_CRYPT0 )) prnt(" Crypt: Non secured page"); | |
74 | if( notset (fuses,FUSE_CRYPT1) && notset( fuses, FUSE_CRYPT0 )) prnt(" Crypt: No auth possible. Read only if RA is enabled"); | |
75 | ||
76 | if( isset( fuses, FUSE_RA)) prnt(" RA: Read access enabled"); | |
77 | else prnt(" RA: Read access not enabled"); | |
78 | } | |
79 | void mem_config(const picopass_hdr *hdr) | |
80 | { | |
81 | uint8_t mem = hdr->conf.mem_config; | |
82 | if( isset (mem, 0x80)) prnt(" Mem: 16KBits (255 * 8 bytes)"); | |
83 | else prnt(" Mem: 2 KBits ( 32 * 8 bytes)"); | |
84 | ||
85 | } | |
86 | void applimit_config(const picopass_hdr *hdr) | |
87 | { | |
88 | uint8_t applimit = hdr->conf.app_limit; | |
89 | prnt(" AA1: blocks 6-%d", applimit); | |
90 | prnt(" AA2: blocks %d-", (applimit+1)); | |
91 | } | |
92 | void print_picopass_info(const picopass_hdr *hdr) | |
93 | { | |
94 | fuse_config(hdr); | |
95 | mem_config(hdr); | |
96 | applimit_config(hdr); | |
97 | } | |
98 | void test() | |
99 | { | |
100 | picopass_hdr hdr = {0x27,0xaf,0x48,0x01,0xf9,0xff,0x12,0xe0,0x12,0xff,0xff,0xff,0x7f,0x1f,0xff,0x3c}; | |
101 | prnt("Picopass configuration:"); | |
102 | print_picopass_info(&hdr); | |
103 | } | |
104 | int main(int argc, char *argv[]) | |
105 | { | |
106 | test(); | |
107 | return 0; | |
108 | } |