| 1 | package Biblio::RFID::Reader::librfid; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | ▶ | use base 'Biblio::RFID::Reader::API'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use Biblio::RFID; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use Data::Dump qw(dump); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | Biblio::RFID::Reader::librfid - execute librfid-tool | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | This is wrapper around C<librfid-tool> from | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | L<http://openmrtd.org/projects/librfid/> | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | Due to limitation of L<librfid-tool> only | ||||||||||||||||||||
| 22 | L<Biblio::RFID::Reader::API/inventory> and | ||||||||||||||||||||
| 23 | L<Biblio::RFID::Reader::API/read_blocks> is supported. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | However, this code might provide template for integration | ||||||||||||||||||||
| 26 | with any command-line utilities for different RFID readers. | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | Currently tested with only with Omnikey CardMan 5321 which | ||||||||||||||||||||
| 29 | has problems. After a while it stops responding to commands | ||||||||||||||||||||
| 30 | by C<librfid-tool> so I provided small C program to reset it: | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | C<examples/usbreset.c> | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | ▶ | sub serial_settings {} # don't open serial | |||||||||||||||||||
|
Subroutine
serial_settings: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 3 | our $bin = '/rest/cvs/librfid/utils/librfid-tool'; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub init { | ||||||||||||||||||||
| 41 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||||||||
| 42 | 1 | ▶ | if ( -e $bin ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | warn "# using $bin"; | |||||||||||||||||||
| 44 | 0 | return 1; | |||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||
| 46 | 1 | warn "# no $bin found\n"; | |||||||||||||||||||
| 47 | 1 | return 0; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | sub _grep_tool { | ||||||||||||||||||||
| 52 | 0 | ▶ | my ( $param, $coderef ) = @_; | ||||||||||||||||||
|
Subroutine
_grep_tool: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | warn "# _grep_tool $bin $param\n"; | |||||||||||||||||||
| 55 | 0 | ▶ | open(my $s, '-|', "$bin $param") || die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | ▶ | while(<$s>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | chomp; | |||||||||||||||||||
| 58 | 0 | warn "## $_\n"; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | my $sid; | |||||||||||||||||||
| 61 | 0 | ▶ | if ( m/success.+:\s+(.+)/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | $sid = $1; | |||||||||||||||||||
| 63 | 0 | $sid =~ s/\s*'\s*//g; | |||||||||||||||||||
| 64 | 0 | $sid = uc join('', reverse split(/\s+/, $sid)); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | $coderef->( $sid ); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | sub inventory { | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | ▶ | my @tags; | ||||||||||||||||||
|
Subroutine
inventory: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 76 | _grep_tool '--scan' => sub { | ||||||||||||||||||||
| 77 | 0 | ▶ | my $sid = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 78 | 0 | ▶ | push @tags, $sid if $sid; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 0 | }; | |||||||||||||||||||
| 80 | 0 | warn "# invetory ",dump(@tags); | |||||||||||||||||||
| 81 | 0 | return @tags; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | sub read_blocks { | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | my $sid; | ||||||||||||||||||
|
Subroutine
read_blocks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 87 | my $blocks; | ||||||||||||||||||||
| 88 | _grep_tool '--read -1' => sub { | ||||||||||||||||||||
| 89 | 0 | ▶ | $sid ||= shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Condition0%0/3
$sid ||= shift()
MC/DC0%0/2
$sid ||= shift()
$sid
shift()
Truth table0%0/3
A ||= B
A= $sidB= shift()
| |||||||||||||||||||||
| 90 | 0 | ▶ | $blocks->{$sid}->[$1] = hex2bytes($2) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | if m/block\[\s*(\d+):.+data.+:\s*(.+)/; | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | }; | |||||||||||||||||||
| 94 | 0 | warn "# read_blocks ",dump($blocks); | |||||||||||||||||||
| 95 | 0 | return $blocks; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | ▶ | sub write_blocks {} | |||||||||||||||||||
|
Subroutine
write_blocks: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 99 | 0 | ▶ | sub read_afi { -1 } | ||||||||||||||||||
|
Subroutine
read_afi: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 100 | ▶ | sub write_afi {} | |||||||||||||||||||
|
Subroutine
write_afi: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 3 | 1 | |||||||||||||||||||