RFID-Libnfc
    
    
  
  
  
view release on metacpan or search on metacpan
examples/anticol_c.pl view on Meta::CPAN
nfc_configure($pdi, NDO_HANDLE_CRC, 0);
nfc_configure($pdi, NDO_HANDLE_PARITY, 1);
nfc_configure($pdi, NDO_EASY_FRAMING, 0);
nfc_configure($pdi, NDO_AUTO_ISO14443_4, 0);
nfc_configure($pdi, NDO_FORCE_ISO14443_A, 1);
# Enable field so more power consuming cards can power themselves up
nfc_configure($pdi, NDO_ACTIVATE_FIELD, 1);
my $cmd = pack("C", MU_REQA);
if (my $resp = transceive_bits($pdi, $cmd, 7)) {
    $cmd = pack("C2", MU_SELECT1, 0x20); # ANTICOLLISION of cascade level 1
    
    if ($resp = transceive_bytes($pdi, $cmd, 2)) {
        my (@rb) = unpack("C".length($resp), $resp);
        my $cuid = pack("C3", $rb[1], $rb[2], $rb[3]);
        if ($rb[0] == 0x88) { # define a constant for 0x88
            $cmd = pack("C9", MU_SELECT1, 0x70, @rb); # SELECT of cascade level 1  
            iso14443a_crc_append($cmd, 7);
            if ($resp = transceive_bytes($pdi, $cmd, 9)) {
                # we need to do cascade level 2
                # first let's get the missing part of the uid
                $cmd = pack("C2", MU_SELECT2, 0x20); # ANTICOLLISION of cascade level 2
                if ($resp = transceive_bytes($pdi, $cmd, 2)) {
                    @rb = unpack("C".length($resp), $resp);
                    $cuid .= pack("C3", $rb[1], $rb[2], $rb[3]);
                    $cmd = pack("C9", MU_SELECT2, 0x70, @rb); # SELECT of cascade level 2
                    iso14443a_crc_append($cmd, 7);
                    if (transceive_bytes($pdi, $cmd, 9)) {
                         print "2 level cascade anticollision/selection passed for uid : ";
                         print_hex($cuid, 6);
                    } else {
                        warn "Select cascade level 2 failed";
                    }
                } else {
                    warn "Anticollision cascade level 2 failed";
                }
            } else {
                warn "Select cascade level 1 failed";
            }
        }
    } else {
            warn "Anticollision cascade level 1 failed";
    }
} else {
    warn "Device doesn't respond to REQA";
}
exit 0;
examples/tikiread.pl view on Meta::CPAN
    my $tag = $r->connect(IM_ISO14443A_106);
    if ($tag and $DEBUG) {
        $tag->dump_info;
    } else {
        warn "No TAG";
        exit -1;
    }
    die "Token is not a mifare ultralight" unless $tag->type eq "ULTRA";
    # doing the 2-level cascade selection process  is not necessary , 
    # but ensures we will be talking always to the same token 
    # if multiple are within the field
    $tag->select;
    if ($DEBUG) {
        print "ACL - 1 means blocked, 0 means writeable. blbits rule them all\n";
        print Data::Dumper->Dump([$tag->acl], ["ACL"]);
    }
    # Dump the entire token
lib/RFID/Libnfc/Tag/ISO14443A_106/ULTRA.pm view on Meta::CPAN
    nfc_configure($self->reader->pdi, NDO_EASY_FRAMING, 0); 
    nfc_configure($self->reader->pdi, NDO_AUTO_ISO14443_4, 0); 
    nfc_configure($self->reader->pdi, NDO_FORCE_ISO14443_A, 1); 
    # Enable field so more power consuming cards can power themselves up
    nfc_configure($self->reader->pdi, ,NDO_ACTIVATE_FIELD, 1);
    my $retry = 0;
    my $retrycnt = 0;
    do {
        if (my $resp = nfc_initiator_transceive_bits($self->reader->pdi, pack("C", MU_REQA), 7)) {
            my $cmd = pack("C2", MU_SELECT1, 0x20); # ANTICOLLISION of cascade level 1
            if ($resp = nfc_initiator_transceive_bytes($self->reader->pdi, $cmd, 2)) {
                my (@rb) = split(//, $resp);
                my $cuid = pack("C3", $rb[1], $rb[2], $rb[3]);
                if ($rb[0] == 0x88) { # define a constant for 0x88
                    $cmd = pack("C9", MU_SELECT1, 0x70, @rb); # SELECT of cascade level 1  
                    #my $crc = $self->crc($cmd);
                    iso14443a_crc_append($cmd, 7);
                    if ($resp = nfc_initiator_transceive_bytes($self->reader->pdi, $cmd, 9)) {
                        # we need to do cascade level 2
                        # first let's get the missing part of the uid
                        $cmd = pack("C2", MU_SELECT2, 0x20); # ANTICOLLISION of cascade level 2
                        if ($resp = nfc_initiator_transceive_bytes($self->reader->pdi, $cmd, 2)) {
                            @rb = split(//, $resp);
                            $cuid .= pack("C3", $rb[1], $rb[2], $rb[3]);
                            $cmd = pack("C9", MU_SELECT2, 0x70, @rb); # SELECT of cascade level 2
                            #my $crc = $self->crc($cmd);
                            iso14443a_crc_append($cmd, 7);
                            if ($resp = nfc_initiator_transceive_bytes($self->reader->pdi, $cmd, 9)) {
                                if ($uid == $cuid) {
                                    return 1;
                                } else {
                                    # HALT the unwanted tag
                                    $cmd = pack("C2", MU_HALT, 0x00);
                                    nfc_initiator_transceive_bytes($self->reader->pdi, $cmd, 2);
                                    $retry = 1;
                                    $retrycnt++;
                                }
                            } else {
                                $self->{_last_error} = "Select cascade level 2 failed";
                            }
                        } else {
                            $self->{_last_error} = "Anticollision cascade level 2 failed";
                        }
                    } else {
                        $self->{_last_error} = "Select cascade level 1 failed";
                    }
                }
            } else {
                    $self->{_last_error} = "Anticollision cascade level 1 failed";
            }
        } else {
            $self->{_last_error} = "Device doesn't respond to REQA";
        }
    } while ($retry-- and $retrycnt < 10); # fail if we are redoing the selection process for the tenth time
    $self->{_last_error} = "Max retrycount reached" if ($retrycnt >= 10);
    return 0;
}
1;
lib/RFID/Libnfc/Tag/ISO14443A_106/ULTRA.pm view on Meta::CPAN
RFID::Libnfc::Tag::ISO14443A_106::ULTRA 
Specific implementation for mifare ultralight tags
=head1 SYNOPSIS
  use RFID::Libnfc;
  $tag = $r->connectTag(IM_ISO14443A_106);
  # so the 2-level cascade selection process as specified in M028634_MF0ICU1_Functional_Spec_V3.4.pdf 
  $tag->select()  
=head1 DESCRIPTION
  Base class for ISO14443A_106 compliant tags
=head2 EXPORT
None by default.
lib/RFID/Libnfc/Tag/ISO14443A_106/ULTRA.pm view on Meta::CPAN
Returns the number of sectors present on the card
=item acl ( )
Returns a representation of the aclbits.
(boths page-locking bits and block-locking bits)
=item select ( )
implements the 2-level cascade selection process
=back
=head1 SEE ALSO
RFID::Libnfc::Tag::ISO14443A_106::ULTRA RFID::Libnfc::Tag::ISO14443A_106::4K
RFID::Libnfc::Tag::ISO14443A_106 RFID::Libnfc::Constants RFID::Libnfc 
**
( run in 0.275 second using v1.01-cache-2.11-cpan-5dc5da66d9d )