forked from sipeed/NanoKVM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbios.go
More file actions
59 lines (47 loc) · 1.05 KB
/
bios.go
File metadata and controls
59 lines (47 loc) · 1.05 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
package hid
import (
"NanoKVM-Server/proto"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
func (s *Service) GetBiosMode(c *gin.Context) {
var rsp proto.Response
mode, err := getBiosMode()
if err != nil {
rsp.ErrRsp(c, -1, "get HID BIOS mode failed")
return
}
rsp.OkRspWithData(c, &proto.GetBiosModeRsp{
Mode: mode,
})
log.Debugf("get hid bios mode: %s", mode)
}
func (s *Service) SetBiosMode(c *gin.Context) {
var req proto.SetBiosModeReq
var rsp proto.Response
if err := proto.ParseFormRequest(c, &req); err != nil {
rsp.ErrRsp(c, -1, "invalid arguments")
return
}
if req.Mode != ModeNonBios && req.Mode != ModeHidBios {
rsp.ErrRsp(c, -2, "invalid arguments")
return
}
if mode, _ := getBiosMode(); req.Mode == mode {
rsp.OkRsp(c)
return
}
hidmode, _ := getHidMode()
wowmode, _ := getWoWMode();
msg, err := setHidMode(hidmode, req.Mode, wowmode)
if err != nil {
rsp.ErrRsp(c, -2, msg)
return
}
msg, err = setBootBios(req.Mode)
if err != nil {
rsp.ErrRsp(c, -4, msg)
return
}
rsp.OkRsp(c)
}