--- 3m-810.pl 2010/02/11 20:57:51 71 +++ 3m-810.pl 2010/07/23 13:16:51 92 @@ -31,7 +31,7 @@ Reuse => 1 ); - die "can't setup server" unless $server; + die "can't setup server: $!" unless $server; print "Server $0 ready at $server_url\n"; @@ -168,7 +168,8 @@ my $http_server = 1; # 3M defaults: 8,4 -my $max_rfid_block = 16; +# cards 16, stickers: 8 +my $max_rfid_block = 8; my $read_blocks = 8; my $response = { @@ -392,7 +393,11 @@ sub decode_tag { my $tag = shift; - my $data = $tags_data->{$tag} || die "no data for $tag"; + my $data = $tags_data->{$tag}; + if ( ! $data ) { + warn "no data for $tag\n"; + return; + } my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data); my $hash = { @@ -446,6 +451,12 @@ "D6 00 0F FE 00 00 05 01 $tag BEEF", sub { print "FIXME: tag $tag ready? (expected block read instead)\n"; }, + "D6 00 0D 02 06 $tag", sub { + my $rest = shift; + print "ERROR reading $tag ", as_hex($rest), $/; + forget_tag $tag; + $start_block = $max_rfid_block; # XXX break out of while + }, ); } @@ -462,7 +473,12 @@ $security = as_hex( $security ); $tags_security->{$tag} = $security; warn "# SECURITY $tag = $security\n"; - } + }, + "D6 00 0C 0A 06", sub { + my $rest = shift; + warn "ERROR reading security from $rest\n"; + forget_tag $tag; + }, ); print "TAG $tag ", dump(decode_tag( $tag )); @@ -502,16 +518,26 @@ print "write_tag $tag = ",dump( $data ), " [$len/$blocks] == $hex_data\n"; + my $ok = 0; + cmd( "d6 00 ff 04 $tag 00 $blocks 00 $hex_data BEEF", "write $tag", - "d6 00 0d 04 00 $tag $blocks BEEF", sub { assert() }, + "d6 00 0d 06 00 $tag $blocks BEEF", sub { assert(); $ok++ }, + "d6 00 0d 04 06 ", sub { + my $data = shift; + warn "no tag ",as_hex( substr($data,0,8) ), " in range for write\n"; + }, ); # foreach ( 1 .. 3 ); # XXX 3m software does this three times! - my $to = $path; - $to .= '.' . time(); + if ( $ok ) { - rename $path, $to; - print ">> $to\n"; + my $to = $path; + $to .= '.' . time(); + + rename $path, $to; + print ">> $to\n"; + + } forget_tag $tag; } @@ -522,6 +548,10 @@ cmd( "d6 00 0c 09 $tag $data BEEF", "secure $tag -> $data", "d6 00 0c 09 00 $tag BEEF", sub { assert() }, + "d6 00 0c 09 06 ", sub { + my $data = shift; + warn "no tag ",as_hex( substr($data,0,8) ), " in range for secure\n"; + }, ); forget_tag $tag; @@ -582,7 +612,7 @@ sub as_hex { my @out; foreach my $str ( @_ ) { - my $hex = unpack( 'H*', $str ); + my $hex = uc unpack( 'H*', $str ); $hex =~ s/(..)/$1 /g if length( $str ) > 2; $hex =~ s/\s+$//; push @out, $hex; @@ -696,7 +726,7 @@ warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug; $dispatch->{ $to }->( $rest ); } else { - die "NO DISPATCH for ",as_hex( $full ),"\n"; + die "NO DISPATCH for ",as_hex( $full ), " in ", dump( $dispatch ); } return $data;