Class: IsoDep::Tag
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from NFC::Tag
#initialize, #processed!, #processed?, #to_s, #uid, #uid_hex
Constructor Details
This class inherits a constructor from NFC::Tag
Class Method Details
.match?(target) ⇒ Boolean
11
12
13
|
# File 'lib/ruby-nfc/tags/isodep.rb', line 11
def self.match?(target)
target[:nti][:nai][:btSak] & IsoDep::ISO_14443_4_COMPATIBLE > 0
end
|
Instance Method Details
#deselect ⇒ Object
48
49
50
|
# File 'lib/ruby-nfc/tags/isodep.rb', line 48
def deselect
0 == LibNFC.nfc_initiator_deselect_target(@reader.ptr)
end
|
#select(aid = nil, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ruby-nfc/tags/isodep.rb', line 15
def select(aid = nil, &block)
@reader.set_flag(:NP_AUTO_ISO14443_4, true)
modulation = LibNFC::Modulation.new
modulation[:nmt] = :NMT_ISO14443A
modulation[:nbr] = :NBR_106
nai_ptr = @target[:nti][:nai].pointer
uid_ptr = nai_ptr + FFI.type_size(:uint8) * 3 + FFI.type_size(:size_t)
res = LibNFC.nfc_initiator_select_passive_target(
@reader.ptr,
modulation,
uid_ptr,
uid.length,
@target.pointer
)
if res > 0
if aid
sw = send_apdu("\x00\xA4\x04\x00#{aid.size.chr}#{aid}")
raise IsoDep::Error, "Application not found: #{aid.unpack('H*').pop}" unless "\x90\x00" == sw
end
super(&block)
else
raise IsoDep::Error, "Can't select tag: #{res}"
end
end
|
#send_apdu(apdu) ⇒ Object
Also known as:
<<
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ruby-nfc/tags/isodep.rb', line 52
def send_apdu(apdu)
cmd = apdu
cmd.force_encoding('ASCII-8BIT')
command_buffer = FFI::MemoryPointer.new(:uint8, cmd.length)
command_buffer.write_string_length(cmd, cmd.length)
response_buffer = FFI::MemoryPointer.new(:uint8, 254)
res_len = LibNFC.nfc_initiator_transceive_bytes(@reader.ptr,
command_buffer, cmd.length, response_buffer, 254, 0)
raise IsoDep::Error, "APDU sending failed: #{res_len}" if res_len < 0
response_buffer.get_bytes(0, res_len).to_s
end
|