-
Notifications
You must be signed in to change notification settings - Fork 2
/
card.go
48 lines (37 loc) · 945 Bytes
/
card.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
package main
import (
"encoding/binary"
"log"
"github.com/ebfe/scard"
)
var (
acsControlCommand = binary.BigEndian.Uint32([]byte{0x00, 0x31, 0x36, 0xB0})
)
func connectToCard(offset uint8, emulator bool) (*scard.Card, error) {
ctx, err := scard.EstablishContext()
if err != nil {
return nil, err
}
readers, err := ctx.ListReaders()
if err != nil {
return nil, err
}
reader := readers[offset]
log.Println("Connecting to reader", reader)
protocol := scard.ProtocolUndefined
if !emulator {
protocol = scard.ProtocolT1
}
// Connect to the reader.
card, err := ctx.Connect(reader, scard.ShareDirect, protocol)
if err != nil {
return nil, err
}
return card, nil
}
func warmResetCard(card *scard.Card) {
check(card.Reconnect(scard.ShareDirect, card.ActiveProtocol(), scard.ResetCard))
}
func coldResetCard(card *scard.Card) {
check(card.Reconnect(scard.ShareDirect, card.ActiveProtocol(), scard.UnpowerCard))
}