ruby-nfc 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/ruby-nfc/nfc.rb +1 -0
- data/lib/ruby-nfc/reader.rb +30 -42
- data/lib/ruby-nfc/tags/isodep.rb +10 -0
- data/lib/ruby-nfc/tags/mifare/tag.rb +2 -2
- data/lib/ruby-nfc/tags/tag.rb +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGMyYWNlNjRjNWRlOTQ4YzQxMzg3MjUxZTMyNjljNjdiZWQxMDMxNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmFlNmYxNzNhNDQyZmY3NmI2N2NjMjRlZjA4NGViMjdhYmQ3ODA2OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODRiMTJmZmEyYjQ1ZDg0NmMzNmI0YmQ0ZGZlMDMwOTM1NGI2ZDg3OWRmMDZm
|
10
|
+
OWUzYjYwZmFiNzk4ZTRiMmIwNTUyMzcwNWRiZWQyM2IzMTNmMzZhYjdkMTc5
|
11
|
+
ZjI0NDhiZTdkMmNjMWIwNjFkYzFiYjNjZDA5MjQ5MTU2ZjYzMTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGQxZDYxMTBiY2I1MGQxMjlkYmIzYmZiZGVlMDQ4YjJkMGQ3NzM4MzE4ZDlh
|
14
|
+
ZjdkMGM2MDgyMGMwY2VhODM5ZDU3NjIyYTExMTM1ZTRiZmYxZDFlNWY2YjBm
|
15
|
+
NTkwZGEzZjhkMTViN2VmYjM3NDJiN2M4NDM3YjY5MDI0NzJhODI=
|
data/lib/ruby-nfc/nfc.rb
CHANGED
data/lib/ruby-nfc/reader.rb
CHANGED
@@ -7,66 +7,58 @@ module NFC
|
|
7
7
|
@ptr = nil
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
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
|
10
|
+
def set_flag(name, value)
|
11
|
+
LibNFC.nfc_device_set_property_bool(@ptr, name, value)
|
12
|
+
end
|
27
13
|
|
14
|
+
def connect
|
15
|
+
@ptr ||= LibNFC.nfc_open(NFC.context, @name)
|
16
|
+
raise NFC::Error.new('Cant connect to ' << @name) if @ptr.null?
|
28
17
|
self
|
29
18
|
end
|
30
19
|
|
31
20
|
# Returns list of tags applied to reader
|
32
|
-
def discover(*
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
21
|
+
def discover(*card_types)
|
22
|
+
# TODO: по правильному здесь надо делать низкоуровневый
|
23
|
+
card_types.inject([]) do |tags, card_type|
|
24
|
+
raise NFC::Error.new('Wrong card type') unless card_type.respond_to? :discover
|
25
|
+
tags += card_type.discover(connect)
|
44
26
|
end
|
45
27
|
end
|
46
28
|
|
47
|
-
def poll(*
|
29
|
+
def poll(*card_types, &block)
|
48
30
|
connect
|
49
31
|
|
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
|
+
|
50
44
|
targets = FFI::MemoryPointer.new(:uchar, LibNFC::Target.size * 10)
|
51
45
|
|
52
46
|
loop do
|
53
|
-
res = LibNFC.nfc_initiator_list_passive_targets(@ptr,
|
47
|
+
res = LibNFC.nfc_initiator_list_passive_targets(@ptr, modulation,
|
54
48
|
targets, 10)
|
55
49
|
|
56
|
-
# iterate over all applied targets
|
50
|
+
# iterate over all applied targets and iterate
|
57
51
|
0.upto(res - 1) do |i|
|
58
52
|
target = LibNFC::Target.new(targets + i * LibNFC::Target.size)
|
59
53
|
# iterate over requested card types for each target
|
60
54
|
# notice that some targets can match several types i.e.
|
61
55
|
# contactless credit cards (PayPass/payWave) with mifare chip
|
62
56
|
# on board
|
63
|
-
|
64
|
-
if
|
65
|
-
tag =
|
57
|
+
card_types.each do |card_type|
|
58
|
+
if card_type.match?(target)
|
59
|
+
tag = card_type.new(target, self)
|
66
60
|
tag.connect(&block)
|
67
|
-
|
68
|
-
# if this tag was marked as processed within the bloc -
|
69
|
-
# continue with the next tag
|
61
|
+
# if this tag was marked as processed - continue with next tag
|
70
62
|
break if target.processed?
|
71
63
|
end
|
72
64
|
end
|
@@ -89,9 +81,5 @@ module NFC
|
|
89
81
|
names.map {|name| Reader.new(name)}
|
90
82
|
end
|
91
83
|
end
|
92
|
-
|
93
|
-
def set_flag(name, value)
|
94
|
-
LibNFC.nfc_device_set_property_bool(@ptr, name, value)
|
95
|
-
end
|
96
84
|
end
|
97
85
|
end
|
data/lib/ruby-nfc/tags/isodep.rb
CHANGED
@@ -65,6 +65,16 @@ 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
|
+
|
68
78
|
# Public: Send APDU command to tag
|
69
79
|
#
|
70
80
|
# apdu - APDU command to send. see ISO/IEC 7816-4 or wiki for details.
|
@@ -21,7 +21,7 @@ module Mifare
|
|
21
21
|
}
|
22
22
|
|
23
23
|
# common freefare functions prototypes
|
24
|
-
attach_function :freefare_tag_new, [:pointer, LibNFC::
|
24
|
+
attach_function :freefare_tag_new, [:pointer, LibNFC::Target.by_value], :pointer
|
25
25
|
attach_function :freefare_free_tag, [:pointer], :void
|
26
26
|
|
27
27
|
# tag
|
@@ -37,7 +37,7 @@ module Mifare
|
|
37
37
|
def initialize(target, reader)
|
38
38
|
super(target, reader)
|
39
39
|
|
40
|
-
@pointer = Mifare.freefare_tag_new(reader.ptr, target
|
40
|
+
@pointer = Mifare.freefare_tag_new(reader.ptr, target)
|
41
41
|
|
42
42
|
raise Mifare::Error, "Unknown mifare tag" if @pointer.null?
|
43
43
|
end
|
data/lib/ruby-nfc/tags/tag.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nfc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.4'
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: ! " \tThis gem is built on top of libnfc and libfreefare using ffi and
|