-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
37 lines (33 loc) · 840 Bytes
/
auth.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
package main
import (
"bufio"
"encoding/binary"
"fmt"
"github.com/bettercap/gatt"
"os"
"strconv"
"strings"
)
func auth(p gatt.Peripheral, bytes []byte, c *gatt.Characteristic) error {
reader := bufio.NewReader(os.Stdin)
fmt.Print("PIN: ")
text, _ := reader.ReadString('\n')
text = strings.TrimSpace(text)
pin, err := strconv.ParseInt(text, 10, 16)
if err != nil {
panic(fmt.Errorf("PIN entry err %s", err))
}
pinBase := []byte("\x35\x00\x01\x00")
pinbuf := make([]byte, 2)
binary.LittleEndian.PutUint16(pinbuf, uint16(pin))
pinPkt := append(pinBase, pinbuf...)
bytes = make([]byte, 20)
copy(bytes, pinPkt)
fmt.Printf("Sending PIN: %q\n", bytes)
err = p.WriteCharacteristic(c, bytes, true)
if err != nil {
fmt.Printf("Failed to WriteCharacteristic, err: %s\n", err)
}
fmt.Printf("Wrote PIN\n")
return err
}