use modified mifare-tool
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Feb 2014 14:36:08 +0000 (15:36 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Feb 2014 14:36:24 +0000 (15:36 +0100)
lib/Biblio/RFID/Reader/librfid.pm
scripts/mifare_keys.pl.example

index 37dd047..d665d03 100644 (file)
@@ -22,6 +22,10 @@ Due to limitation of L<librfid-tool> only
 L<Biblio::RFID::Reader::API/inventory> and
 L<Biblio::RFID::Reader::API/read_blocks> is supported.
 
+This version uses modidified C<librfid-tool> which supports
+new C<-s> flag which reads sectors 0-3 with C<-k> key and
+sectors 4-7 with key from C<-s> option.
+
 However, this code might provide template for integration
 with any command-line utilities for different RFID readers.
 
@@ -113,6 +117,7 @@ sub read_blocks {
        } else {
                read_mifare_keys unless $mifare_keys;
 
+=for unmodified mifate-tool
                foreach my $sector ( keys %$mifare_keys ) {
                        my $key = lc $mifare_keys->{$sector};
                        _grep_tool 'mifare-tool', "-k $key -r $sector" => sub {
@@ -120,6 +125,11 @@ sub read_blocks {
                                if m/data=\s*(.+)/;
                        };
                }
+=cut
+               _grep_tool 'mifare-tool', "-k " . $mifare_keys->{0} . " -s " . $mifare_keys->{4} => sub {
+                       $blocks->{$sid}->[$1] = hex2bytes($2)
+                       if m/page=(\d+).*data=\s*(.+)/;
+               };
        }
        warn "# read_blocks ",dump($blocks);
        return $blocks;
index d252cba..96a7547 100644 (file)
@@ -1,6 +1,5 @@
 $mifare_keys = {
        0 => 'a0a1a2a3a4a5',
-       1 => 'a0a1a2a3a4a5',
-       2 => 'a0a1a2a3a4a5',
+       4 => 'a0a1a2a3a4a5',
 };
 1;