287 |
return pack('v', $crc); |
return pack('v', $crc); |
288 |
} |
} |
289 |
|
|
290 |
|
sub cpr_psst_wait { |
291 |
|
# Protocol Start Synchronization Time (PSST): 5ms < data timeout 12 ms |
292 |
|
Time::HiRes::sleep 0.005; |
293 |
|
} |
294 |
|
|
295 |
sub cpr { |
sub cpr { |
296 |
my ( $hex, $description ) = @_; |
my ( $hex, $description, $coderef ) = @_; |
297 |
my $bytes = str2bytes($hex); |
my $bytes = str2bytes($hex); |
298 |
my $len = pack( 'c', length( $bytes ) + 3 ); |
my $len = pack( 'c', length( $bytes ) + 3 ); |
299 |
my $send = $len . $bytes; |
my $send = $len . $bytes; |
303 |
warn ">> ", as_hex( $send ), "\t\t[$description]\n"; |
warn ">> ", as_hex( $send ), "\t\t[$description]\n"; |
304 |
$port->write( $send ); |
$port->write( $send ); |
305 |
|
|
306 |
|
cpr_psst_wait; |
307 |
|
|
308 |
my $r_len = $port->read(1); |
my $r_len = $port->read(1); |
309 |
|
|
310 |
while ( ! $r_len ) { |
while ( ! $r_len ) { |
311 |
warn "# wait for response length 0.050\n"; |
warn "# wait for response length 5ms\n"; |
312 |
Time::HiRes::sleep 0.050; |
cpr_psst_wait; |
313 |
$r_len = $port->read(1); |
$r_len = $port->read(1); |
314 |
} |
} |
315 |
|
|
316 |
warn "<< response len: ", as_hex($r_len), "\n"; |
my $data_len = ord($r_len) - 1; |
317 |
$r_len = ord($r_len) - 1; |
my $data = $port->read( $data_len ); |
318 |
my $data = $port->read( $r_len ); |
warn "<< ", as_hex( $r_len . $data ),"\n"; |
319 |
warn "<< ", as_hex( $data ); |
|
320 |
|
cpr_psst_wait; |
321 |
|
|
322 |
|
$coderef->( $data ) if $coderef; |
323 |
|
|
|
Time::HiRes::sleep 0.050; |
|
324 |
} |
} |
325 |
|
|
326 |
# FF = COM-ADDR any |
# FF = COM-ADDR any |
333 |
|
|
334 |
cpr( 'FF 69', 'RF Reset' ); |
cpr( 'FF 69', 'RF Reset' ); |
335 |
|
|
336 |
cpr( 'FF B0 01 00', 'ISO - Inventory' ); |
|
337 |
|
sub cpr_read { |
338 |
|
my $uid = shift; |
339 |
|
my $hex_uid = as_hex($uid); |
340 |
|
|
341 |
|
my $max_block; |
342 |
|
|
343 |
|
cpr( "FF B0 2B 01 $hex_uid", "Get System Information $hex_uid", sub { |
344 |
|
my $data = shift; |
345 |
|
|
346 |
|
warn "# data ",as_hex($data); |
347 |
|
|
348 |
|
my $DSFID = substr($data,5-2,1); |
349 |
|
my $UID = substr($data,6-2,8); |
350 |
|
my $AFI = substr($data,14-2,1); |
351 |
|
my $MEM = substr($data,15-2,1); |
352 |
|
my $SIZE = substr($data,16-2,1); |
353 |
|
my $IC_REF = substr($data,17-2,1); |
354 |
|
|
355 |
|
warn "# split ",as_hex( $DSFID, $UID, $AFI, $MEM, $SIZE, $IC_REF ); |
356 |
|
|
357 |
|
$max_block = ord($SIZE); |
358 |
|
}); |
359 |
|
|
360 |
|
my $transponder_data; |
361 |
|
|
362 |
|
my $block = 0; |
363 |
|
while ( $block < $max_block ) { |
364 |
|
cpr( sprintf("FF B0 23 01 $hex_uid %02x 04", $block), "Read Multiple Blocks $block", sub { |
365 |
|
my $data = shift; |
366 |
|
|
367 |
|
my $DB_N = ord substr($data,5-2,1); |
368 |
|
my $DB_SIZE = ord substr($data,6-2,1); |
369 |
|
|
370 |
|
$data = substr($data,7-2,-2); |
371 |
|
warn "# DB N: $DB_N SIZE: $DB_SIZE ", as_hex( $data ); |
372 |
|
foreach ( 1 .. $DB_N ) { |
373 |
|
my $sec = substr($data,0,1); |
374 |
|
my $db = substr($data,1,$DB_SIZE); |
375 |
|
warn "block $_ ",dump( $sec, $db ); |
376 |
|
$transponder_data .= reverse split(//,$db); |
377 |
|
$data = substr($data, $DB_SIZE + 1); |
378 |
|
} |
379 |
|
}); |
380 |
|
$block += 4; |
381 |
|
} |
382 |
|
|
383 |
|
warn "DATA $hex_uid ", dump($transponder_data); |
384 |
|
exit; |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
my $inventory; |
389 |
|
|
390 |
|
while(1) { |
391 |
|
|
392 |
|
cpr( 'FF B0 01 00', 'ISO - Inventory', sub { |
393 |
|
my $data = shift; |
394 |
|
if (length($data) < 5 + 2 ) { |
395 |
|
warn "# no tags in range\n"; |
396 |
|
return; |
397 |
|
} |
398 |
|
my $data_sets = ord(substr($data,3,1)); |
399 |
|
$data = substr($data,4); |
400 |
|
foreach ( 1 .. $data_sets ) { |
401 |
|
my $tr_type = substr($data,0,1); |
402 |
|
die "FIXME only TR-TYPE=3 ISO 15693 supported" unless $tr_type eq "\x03"; |
403 |
|
my $dsfid = substr($data,1,1); |
404 |
|
my $uid = substr($data,2,8); |
405 |
|
$inventory->{$uid}++; |
406 |
|
$data = substr($data,10); |
407 |
|
warn "# TAG $_ ",as_hex( $tr_type, $dsfid, $uid ),$/; |
408 |
|
|
409 |
|
cpr_read( $uid ); |
410 |
|
} |
411 |
|
warn "inventory: ",dump($inventory); |
412 |
|
}); |
413 |
|
|
414 |
|
} |
415 |
|
|
416 |
#cpr( '', '?' ); |
#cpr( '', '?' ); |
417 |
|
|