class IsoDep::Tag
Public Class Methods
match?(target)
click to toggle source
# File lib/ruby-nfc/tags/isodep.rb, line 13 def self.match?(target) target[:nti][:nai][:btSak] & IsoDep::ISO_14443_4_COMPATIBLE > 0 end
Public Instance Methods
connect(&block)
click to toggle source
Calls superclass method
NFC::Tag#connect
# File lib/ruby-nfc/tags/isodep.rb, line 17 def connect(&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 # abt + sak + szUidLen offset 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 super(&block) else raise IsoDep::Error, "Can't select tag: #{res}" end end
disconnect()
click to toggle source
# File lib/ruby-nfc/tags/isodep.rb, line 44 def disconnect 0 == LibNFC.nfc_initiator_deselect_target(@reader.ptr) end
select(aid)
click to toggle source
Public: select application with give AID
aid - Identifier of the application that should be selected
Returns APDU::Response
# File lib/ruby-nfc/tags/isodep.rb, line 53 def select(aid) send_apdu("\x00\xA4\x04\x00#{aid.size.chr}#{aid}") end
select!(aid)
click to toggle source
Public: same as select but raises an APDU::Errno
exception if application not present on the card or SW is not equal to 0x9000
aid - Identifier of the application that should be selected
Returns APDU::Response
Raises APDU::Errno
# File lib/ruby-nfc/tags/isodep.rb, line 64 def select!(aid) select(aid).raise_errno! end
send_apdu(apdu)
click to toggle source
Public: Send APDU
command to tag
apdu - APDU
command to send. see ISO/IEC 7816-4 or wiki for details.
APDU is a binary string that should
Returns APDU::Response
object Raises IsoDep::Error
if card didn't respond
# File lib/ruby-nfc/tags/isodep.rb, line 86 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 APDU::Response.new(response_buffer.get_bytes(0, res_len).to_s) end
Also aliased as: '<<'
send_apdu!(apdu)
click to toggle source
Public: Send APDU
command to tag and raises APDU::Errno
exception if SW not equal to 0x9000
apdu - APDU
command to transmit to the tag
Returns APDU::Response
object Raises APDU::Errno
if SW is not equal to 0x9000
# File lib/ruby-nfc/tags/isodep.rb, line 109 def send_apdu!(apdu) send_apdu(apdu).raise_errno! end