Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding an inspect

  • Loading branch information...
commit 6f5c030889681f7add79658f307634102e17b1d6 1 parent ce1d53c
@tenderlove authored
Showing with 74 additions and 3 deletions.
  1. +29 −0 lib/nfc.rb
  2. +36 −3 lib/nfc/lib_nfc.rb
  3. +9 −0 test/test_nfc.rb
View
29 lib/nfc.rb
@@ -28,4 +28,33 @@ def crc= value
def parity= v
LibNFC.nfc_configure @device.pointer, LibNFC::DCO_HANDLE_PARITY, v ? 1 : 0
end
+
+ def infinite_list_passive= v
+ LibNFC.nfc_configure(
+ @device.pointer,
+ LibNFC::DCO_INFINITE_LIST_PASSIVE,
+ v ? 1 : 0
+ )
+ end
+
+ def poll_mifare
+ thing = LibNFC::ISO1443A.new
+ LibNFC.nfc_reader_list_passive(
+ @device.pointer,
+ LibNFC::IM_ISO14443A_106,
+ nil,
+ 0,
+ thing
+ )
+ thing
+ end
+
+ def find
+ deactivate_field
+ self.infinite_list_passive = false
+ self.crc = true
+ self.parity = true
+ activate_field
+ poll_mifare
+ end
end
View
39 lib/nfc/lib_nfc.rb
@@ -9,10 +9,14 @@ class LibNFC # :nodoc
attach_function :nfc_disconnect, [:pointer], :void
attach_function :nfc_reader_init, [:pointer], :int
attach_function :nfc_configure, [:pointer, :int, :int], :int
+ attach_function :nfc_reader_list_passive, [:pointer, :int, :pointer, :int, :pointer], :int
- DCO_HANDLE_CRC = 0x00
- DCO_HANDLE_PARITY = 0x01
- DCO_ACTIVATE_FIELD = 0x10
+ DCO_HANDLE_CRC = 0x00
+ DCO_HANDLE_PARITY = 0x01
+ DCO_ACTIVATE_FIELD = 0x10
+ DCO_INFINITE_LIST_PASSIVE = 0x20
+
+ IM_ISO14443A_106 = 0x00
class Device < FFI::Struct
layout(:name, [:char, 256])
@@ -25,5 +29,34 @@ def self.release ptr
LibNFC.nfc_disconnect ptr
end
end
+
+ class ISO1443A < FFI::Struct
+ layout(
+ :abtAtqa, [:char, 2],
+ :btSak, :char,
+ :uiUidLen, :int,
+ :abtUid, [:uchar, 10],
+ :uiAtsLen, :int,
+ :abtAts, [:char, 36]
+ )
+
+ def inspect
+ uid = sprintf((['%02x'] * self[:uiUidLen]).join(' '), *(self[:abtUid]))
+
+ string_ary =
+ [ "(NFC) ISO14443A Tag",
+ " ATQA (SENS_RES): #{sprintf("%02x %02x", *(self[:abtAtqa]))}",
+ " UID (NFCID1): #{uid}",
+ " SAK (SEL_RES): #{sprintf("%02x", self[:btSak])}"
+ ]
+ if self[:uiAtsLen] > 0
+ ats =
+ sprintf((['%02x'] * self[:uiAtsLen]).join(' '), *(self[:abtAts]))
+ string_ary <<
+ " ATS (ATR): #{ats}"
+ end
+ string_ary.join "\n"
+ end
+ end
end
end
View
9 test/test_nfc.rb
@@ -27,4 +27,13 @@ def test_parity=
@nfc.parity = true
@nfc.parity = false
end
+
+ def test_infinite_list_passive=
+ @nfc.infinite_list_passive = true
+ @nfc.infinite_list_passive = false
+ end
+
+ def test_poll_mifare
+ thing = @nfc.poll_mifare
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.