ruby-nfc 1.2 → 1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/ruby-nfc/reader.rb +42 -30
- data/lib/ruby-nfc/tags/isodep.rb +0 -10
- data/lib/ruby-nfc/tags/tag.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDg5NmM4MjM1Zjg5NGQxMzI4OGZjYTUwYjVhNGYzMDQ4NzQ0NjU0Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGNkNTBkMmE5YThiY2M0YWI3NDZiODRkOTQ5YjU2Y2MxYjcxZjA3NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGQwOGQzYmJjOTAxYmVkYjcwYzk4NTBhNzZkMWZjYzE0YTUyMjAxYmM0MzBk
|
10
|
+
NjZmMDkwYzkyZWQ2NzUzNjQyZTQyM2M0ZWJlYmIxODUxYjM0Y2ZiNjMwZWYw
|
11
|
+
MWQwMmI0NzAyM2FiMDdhODVlMzk4YjE0ZTYzM2M3ZTczMTRjOTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MThlODVkNjcyYjAxYzg2YTU1MGYwYTdlOTMyZmY3ZWEzYzhhODJlODM0NzQy
|
14
|
+
YjRlZTc0Mjg2ZmYyY2RlZWNkMzk5NWUyNWEyYzE4OTc4YjUxZDFkYjBhOGMz
|
15
|
+
ZDQ2MDc2MTA2YjBmZjdiODdlOWFmYmUxMTc1YzZlN2M2NWRiZjc=
|
data/lib/ruby-nfc/reader.rb
CHANGED
@@ -7,58 +7,66 @@ module NFC
|
|
7
7
|
@ptr = nil
|
8
8
|
end
|
9
9
|
|
10
|
-
def set_flag(name, value)
|
11
|
-
LibNFC.nfc_device_set_property_bool(@ptr, name, value)
|
12
|
-
end
|
13
|
-
|
14
10
|
def connect
|
15
|
-
@ptr
|
16
|
-
|
11
|
+
unless @ptr
|
12
|
+
@ptr = LibNFC.nfc_open(NFC.context, @name)
|
13
|
+
raise NFC::Error.new("Cant connect to #{@name}") if @ptr.null?
|
14
|
+
|
15
|
+
LibNFC.nfc_initiator_init(@ptr)
|
16
|
+
|
17
|
+
set_flag(:NP_ACTIVATE_FIELD, false)
|
18
|
+
set_flag(:NP_HANDLE_CRC, true)
|
19
|
+
set_flag(:NP_HANDLE_PARITY, true)
|
20
|
+
set_flag(:NP_AUTO_ISO14443_4, true)
|
21
|
+
set_flag(:NP_ACTIVATE_FIELD, true)
|
22
|
+
|
23
|
+
@modulation = LibNFC::Modulation.new
|
24
|
+
@modulation[:nmt] = :NMT_ISO14443A
|
25
|
+
@modulation[:nbr] = :NBR_106
|
26
|
+
end
|
27
|
+
|
17
28
|
self
|
18
29
|
end
|
19
30
|
|
20
31
|
# Returns list of tags applied to reader
|
21
|
-
def discover(*
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
32
|
+
def discover(*tag_types)
|
33
|
+
connect
|
34
|
+
|
35
|
+
targets = FFI::MemoryPointer.new(:uchar, LibNFC::Target.size * 10)
|
36
|
+
res = LibNFC.nfc_initiator_list_passive_targets(@ptr, @modulation,
|
37
|
+
targets, 10)
|
38
|
+
0.upto(res - 1).inject([]) do |tags, i|
|
39
|
+
target = LibNFC::Target.new(targets + i * LibNFC::Target.size)
|
40
|
+
|
41
|
+
tag_types.select{|type| type.match?(target)}.inject(tags) do |r, type|
|
42
|
+
r << type.new(target, self)
|
43
|
+
end
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
29
|
-
def poll(*
|
47
|
+
def poll(*tag_types, &block)
|
30
48
|
connect
|
31
49
|
|
32
|
-
LibNFC.nfc_initiator_init(@ptr) # we'll be initiator not a target
|
33
|
-
|
34
|
-
set_flag(:NP_ACTIVATE_FIELD, false)
|
35
|
-
set_flag(:NP_HANDLE_CRC, true)
|
36
|
-
set_flag(:NP_HANDLE_PARITY, true)
|
37
|
-
set_flag(:NP_AUTO_ISO14443_4, true)
|
38
|
-
set_flag(:NP_ACTIVATE_FIELD, true)
|
39
|
-
|
40
|
-
modulation = LibNFC::Modulation.new
|
41
|
-
modulation[:nmt] = :NMT_ISO14443A
|
42
|
-
modulation[:nbr] = :NBR_106
|
43
|
-
|
44
50
|
targets = FFI::MemoryPointer.new(:uchar, LibNFC::Target.size * 10)
|
45
51
|
|
46
52
|
loop do
|
47
|
-
res = LibNFC.nfc_initiator_list_passive_targets(@ptr, modulation,
|
53
|
+
res = LibNFC.nfc_initiator_list_passive_targets(@ptr, @modulation,
|
48
54
|
targets, 10)
|
49
55
|
|
50
|
-
# iterate over all applied targets
|
56
|
+
# iterate over all applied targets
|
51
57
|
0.upto(res - 1) do |i|
|
52
58
|
target = LibNFC::Target.new(targets + i * LibNFC::Target.size)
|
53
59
|
# iterate over requested card types for each target
|
54
60
|
# notice that some targets can match several types i.e.
|
55
61
|
# contactless credit cards (PayPass/payWave) with mifare chip
|
56
62
|
# on board
|
57
|
-
|
58
|
-
if
|
59
|
-
tag =
|
63
|
+
tag_types.each do |tag_type|
|
64
|
+
if tag_type.match?(target)
|
65
|
+
tag = tag_type.new(target, self)
|
60
66
|
tag.connect(&block)
|
61
|
-
|
67
|
+
|
68
|
+
# if this tag was marked as processed within the bloc -
|
69
|
+
# continue with the next tag
|
62
70
|
break if target.processed?
|
63
71
|
end
|
64
72
|
end
|
@@ -81,5 +89,9 @@ module NFC
|
|
81
89
|
names.map {|name| Reader.new(name)}
|
82
90
|
end
|
83
91
|
end
|
92
|
+
|
93
|
+
def set_flag(name, value)
|
94
|
+
LibNFC.nfc_device_set_property_bool(@ptr, name, value)
|
95
|
+
end
|
84
96
|
end
|
85
97
|
end
|
data/lib/ruby-nfc/tags/isodep.rb
CHANGED
@@ -65,16 +65,6 @@ module IsoDep
|
|
65
65
|
select(aid).raise_errno!
|
66
66
|
end
|
67
67
|
|
68
|
-
# Public: Select application with given AID (Application Identifier)
|
69
|
-
#
|
70
|
-
# aid - Application Identifier of an applet located on a card
|
71
|
-
#
|
72
|
-
# Returns nothing.
|
73
|
-
# Raises APDU::Errno if application with such AID doesn't exists on a card
|
74
|
-
def select(aid)
|
75
|
-
send_apdu!("\x00\xA4\x04\x00#{aid.size.chr}#{aid}")
|
76
|
-
end
|
77
|
-
|
78
68
|
# Public: Send APDU command to tag
|
79
69
|
#
|
80
70
|
# apdu - APDU command to send. see ISO/IEC 7816-4 or wiki for details.
|
data/lib/ruby-nfc/tags/tag.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nfc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxim Chechel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|