7 # MIFARE Application Directory (MAD)
8 # http://www.nxp.com/acrobat_download2/other/identification/MAD_overview.pdf
10 use Data::Dump qw(dump);
12 my $debug = $ENV{DEBUG} || 0;
14 my $function_clusters;
20 my ( $code, $function ) = split(/\s+/,$_,2);
22 if ( $code =~ m/^($h{2})-($h{2})$/ ) {
23 foreach my $c ( hex($1) .. hex($2) ) {
24 $function_clusters->{ unpack('HH',$c) } = $function;
26 } elsif ( $code =~ m/^($h{2})$/ ) {
27 $function_clusters->{ lc $code } = $function;
28 } elsif ( $code =~ m/^($h{4})$/ ) {
29 $mad_id->{ lc $1 } = $function;
31 die "can't parse __DATA__ line $.\n$_\n";
36 warn "# function_clusters ",dump($function_clusters);
37 warn "# mad_id ", dump($mad_id);
43 die "expected 4096 bytes, got ",length($card), " bytes\n"
44 unless length $card == 4096;
46 foreach my $i ( 0 .. 15 ) {
47 my $v = unpack('v',(substr($card, 0x10 + ( $i * 2 ), 2)));
48 my $cluster_id = unpack('HH', (( $v & 0xff00 ) >> 8) );
49 my $full_id = sprintf "%04x",$v;
50 printf "MAD sector %-2d %04x [%s]\n%s\n", $i, $v
51 , $function_clusters->{ $cluster_id }
52 , $mad_id->{$full_id} || "FIXME: add $full_id from MAD_overview.pdf to __DATA__ at end of $0"
56 foreach my $j ( 0 .. 3 ) {
57 my $offset = $pos + $j * 0x10;
58 my $block = substr($card, $offset, 0x10);
59 printf "%04x %s\n", $offset, unpack('H*',$block);
63 # RLE encoded card holder information
64 my $data = substr( $card, $pos, 0x30);
72 while ( substr($data,$o,1) ne "\x00" ) {
73 my $len = ord(substr($data,$o,1));
74 my $type = ( $len & 0b11000000 ) >> 6;
75 $len = $len & 0b00111111;
76 my $dump = substr($data,$o+1,$len-1);
77 $dump = '0x' . unpack('H*', $dump) if $type == 0b11; # any
78 printf "%-10s %2d %s\n", $types->{$type}, $len, $dump;
81 } elsif ( $v == 0x0015 ) {
82 printf "Card number: %s\n", unpack('h*',substr($card,$pos + 0x04,6));
90 00 card administration
91 01-07 miscellaneous applications
99 21 multi modal transit
103 40 city card services
104 47-48 access control & security
106 4A Ministry of Defence, Netherlands
107 4B Bosch Telecom, Germany
108 4A Ministry of Defence, Netherlands
109 4C European Union Institutions
111 51-54 access control & security
119 80 administration services
130 C0 entertainment & sports
139 F8-FF miscellaneous applications
142 0001 sector defective
147 0015 - card administration MIKROELEKTRONIKA spol.s.v.MIKROELEKTRONIKA spol.s.v.o. worldwide 1 01.02.2007 Card publisher info
148 0016 - card administration Mikroelektronika spol.s.r.o., Kpt.Mikroelektronika spol.s.r.o., Kpt. PoEurope 1 10.10.2007 Issuer information
150 071C - miscellaneous applications MIKROELEKTRONIKA spol.s.r. MIKROELEKTRONIKA spol.s.r.o., Europe 1 01.12.2008 Customer profile
151 071D - miscellaneous applications ZAGREBACKI Holding d.o.o. MIKROELEKTRONIKA spol.s.r.o. EUROPE,Croatia 1 01.04.2009 Customer profile
152 071E - miscellaneous applications ZAGREBACKI Holding d.o.o. MIKROELEKTRONIKA spol.s.r.o. EUROPE,Croatia 1 01.04.2009 Bonus counter
154 1835 - city traffic KORID LK, spol.s.r.o. KORID LK, spol.s.r.o. Europe 2 08.09.2008 Eticket
155 1836 - city traffic MIKROELEKTRONIKA spol.s.r. MIKROELEKTRONIKA spol.s.r.o., Europe 1 01.12.2008 Prepaid coupon 1S
156 1837 - city traffic ZAGREBACKI Holding d.o.o. MIKROELEKTRONIKA spol.s.r.o. EUROPE,Croatia 1 01.04.2009 Prepaid coupon
157 1838 - city traffic MIKROELEKTRONIKA spol.s.r. MIKROELEKTRONIKA spol.s.r.o. Europe 1 01.05.2009 Prepaid coupon
158 1839 - city traffic Mikroelektronika spol.s r.o Mikroelektronika spol.s r.o EUROPE,Czech R 1 01.08.2009 Prepaid coupon
159 183B - city traffic UNICARD S.A. UNICARD S.A. Poland 15 01.01.2010 city traffic services
161 2061 - bus services Mikroelektronika spol.s r.o. Mikroelektronika spol.s r.o. Europe 1 01.08.2008 Electronic ticket
162 2062 - bus services ZAGREBACKI Holding d.o.o. MIKROELEKTRONIKA spol.s.r.o EUROPE,Croatia 1 01.04.2009 Electronic tiicket
163 2063 - bus services MIKROELEKTRONIKA spol.s.r. MIKROELEKTRONIKA spol.s.r.o. Europe 3 01.05.2009 electronic ticket
165 887B - electronic purse ZAGREBACKI Holding d.o.o. MIKROELEKTRONIKA spol.s.r.o. EUROPE,Croatia 4 01.04.2009 Electronic purse
166 887C - electronic purse MIKROELEKTRONIKA spol.s.r. MIKROELEKTRONIKA spol.s.r.o. Europe 4 01.05.2009 electronic purse
167 887D - electronic purse Mikroelektronika spol.s r.o Mikroelektronika spol.s r.o EUROPE,Czech R 4 01.08.2009 Electronic purse