-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
93 lines (78 loc) · 1.92 KB
/
main.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
88
89
90
91
92
93
package main
import (
"github.com/clausecker/nfc/v2"
log "github.com/sirupsen/logrus"
"github.com/skythen/apdu"
"time"
)
func main() {
device, err := nfc.Open("")
if err != nil {
log.Fatal("error opening nfc device", err)
}
err = device.InitiatorInit()
if err != nil {
log.Fatal("error initializing initiator", err)
}
modulation := nfc.Modulation{Type: nfc.ISO14443a, BaudRate: nfc.Nbr106}
targets, err := device.InitiatorListPassiveTargets(modulation)
if err != nil {
log.Fatal("Error listing Passive Targets: ", err)
}
if len(targets) <= 0 {
log.Fatal("No targets found")
}
target := targets[0].(*nfc.ISO14443aTarget)
log.Print("found UID: ", target.UID[:target.UIDLen])
_, err = device.InitiatorSelectPassiveTarget(
modulation,
target.UID[:target.UIDLen],
)
if err != nil {
log.Fatal("Error Selecting Target: ", err)
}
selectApplication := apdu.Capdu{
Cla: 0x00,
Ins: 0xA4,
P1: 04,
P2: 00,
// Data: []byte{0xF0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07},
Data: []byte{0xA0, 0x00, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA},
}
tx, err := selectApplication.Bytes()
if err != nil {
log.Fatal("Error assembling SelectApplication APDU", err)
}
rx := make([]byte, 256)
n, err := device.InitiatorTransceiveBytes(
tx, rx, 0,
)
if err != nil {
log.Fatal("Error sending bytes: ", err)
}
log.Infof("Received %d bytes: %x", n, rx[0:n])
for true {
log.Info("Loooop")
getAccessToken := apdu.Capdu{
Cla: 0xD0,
Ins: 0x0F,
P1: 0x00,
P2: 0x00,
// Data: []byte{0xF0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07},
Data: []byte{0x00, 0x08},
}
tx, err = getAccessToken.Bytes()
if err != nil {
log.Fatal("Error assembling getAccessToken APDU", err)
}
rx = make([]byte, 256)
n, err = device.InitiatorTransceiveBytes(
tx, rx, 0,
)
if err != nil {
log.Fatal("Error sending bytes: ", err)
}
log.Infof("Received %d bytes: %x", n, rx[0:n])
time.Sleep(10 * time.Millisecond)
}
}