-
Notifications
You must be signed in to change notification settings - Fork 0
/
initiator.listpassivetargets.go
87 lines (76 loc) · 2.2 KB
/
initiator.listpassivetargets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package gonfc
// InitiatorListPassiveTargets List passive or emulated tags
// nfc.c nfc_initiator_list_passive_targets
func InitiatorListPassiveTargets(pnd Device, nm Modulation) ([]*NfcTarget, error) {
ant := make([]*NfcTarget, 0)
pnd.SetLastError(nil)
// Let the reader only try once to find a tag
bInfiniteSelect := pnd.GetInfiniteSelect()
if err := pnd.SetPropertyBool(InfiniteSelect, false); err != nil {
return ant, err
}
pbtInitData := PrepateInitiatorData(nm)
var nt *NfcTarget
var err error
for {
nt, err = InitiatorSelectPassiveTarget(pnd, nm, pbtInitData)
if err != nil {
pnd.Logger().Warnf("TODO : handle error InitiatorSelectPassiveTarget: %v", err)
break
}
var seen bool
for _, t := range ant {
if nt == t {
seen = true
break
}
}
if seen {
break
}
ant = append(ant, nt)
if err := pnd.InitiatorDeselectTarget(); err != nil {
pnd.Logger().Warnf("TODO : handle error InitiatorDeselectTarget: %v", err)
}
// deselect has no effect on FeliCa, Jewel and Thinfilm cards so we'll stop after one...
// ISO/IEC 14443 B' cards are polled at 100% probability so it's not possible to detect correctly two cards at the same time
if (nm.Type == NMT_FELICA) || (nm.Type == NMT_JEWEL) || (nm.Type == NMT_BARCODE) ||
(nm.Type == NMT_ISO14443BI) || (nm.Type == NMT_ISO14443B2SR) || (nm.Type == NMT_ISO14443B2CT) {
break
}
}
if bInfiniteSelect {
if err := pnd.SetPropertyBool(InfiniteSelect, true); err != nil {
return ant, err
}
}
return ant, nil
}
func PrepateInitiatorData(nm Modulation) []byte {
switch nm.Type {
case NMT_ISO14443B:
// Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3)
return []byte{0}
case NMT_ISO14443BI:
// APGEN
return []byte{0x01, 0x0b, 0x3f, 0x80}
case NMT_FELICA:
// polling payload must be present (see ISO/IEC 18092 11.2.2.5)
return []byte{0x00, 0xff, 0xff, 0x01, 0x00}
case NMT_ISO14443A:
fallthrough
case NMT_ISO14443B2CT:
fallthrough
case NMT_ISO14443B2SR:
fallthrough
case NMT_ISO14443BICLASS:
fallthrough
case NMT_JEWEL:
fallthrough
case NMT_BARCODE:
fallthrough
case NMT_DEP:
return nil
}
panic("unknown modulation")
}