forked from usbarmory/tamago-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusbarmory.go
More file actions
115 lines (85 loc) · 2.12 KB
/
Copy pathusbarmory.go
File metadata and controls
115 lines (85 loc) · 2.12 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// https://github.com/usbarmory/tamago-example
//
// Copyright (c) WithSecure Corporation
// https://foundry.withsecure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
//go:build usbarmory
// +build usbarmory
package main
import (
"fmt"
"io"
"log"
"runtime"
"time"
"golang.org/x/crypto/ssh/terminal"
usbarmory "github.com/usbarmory/tamago/board/f-secure/usbarmory/mark-two"
"github.com/usbarmory/tamago/soc/imx6"
)
const CR = 0x0d
var boardName = "USB armory Mk II"
func init() {
i2c = append(i2c, imx6.I2C1)
cards = append(cards, usbarmory.SD)
cards = append(cards, usbarmory.MMC)
LED = usbarmory.LED
if imx6.Native && (imx6.Family == imx6.IMX6UL || imx6.Family == imx6.IMX6ULL) {
boardName = usbarmory.Model()
// On the USB armory Mk II the standard serial console (UART2) is
// exposed through the debug accessory, which needs to be enabled.
debugConsole, _ := usbarmory.DetectDebugAccessory(250 * time.Millisecond)
<-debugConsole
log.Println("-- i.mx6 ble ---------------------------------------------------------")
usbarmory.BLE.Init()
log.Println("ANNA-B112 BLE module initialized")
}
}
func reset() {
usbarmory.Reset()
}
func bleConsole(term *terminal.Terminal) (err error) {
log.Printf("switching to BLE console, type `quit` to exit")
if usbarmory.BLE.UART == nil {
log.Printf("BLE module is not initialized")
return io.EOF
}
defer func() {
log.Printf("resetting BLE module")
usbarmory.BLE.Reset()
}()
term.SetPrompt(string(term.Escape.Blue) + "BLE> " + string(term.Escape.Reset))
defer term.SetPrompt(string(term.Escape.Red) + "> " + string(term.Escape.Reset))
exit := make(chan bool)
go func() {
for {
select {
case <-exit:
return
default:
}
c, valid := imx6.UART1.Rx()
if !valid || c == CR {
runtime.Gosched()
continue
}
fmt.Fprintf(term, "%s", string(c))
}
}()
for {
var tx string
tx, err = term.ReadLine()
if err == io.EOF {
continue
} else if err != nil {
break
}
if tx == "quit" {
break
}
usbarmory.BLE.UART.Write([]byte(tx + "\r"))
}
exit <- true
return
}