Skip to content

Commit c5cec99

Browse files
authored
feat: usb dynamic config (#248)
2 parents 5c7acca + d1948ad commit c5cec99

17 files changed

+1224
-502
lines changed

config.go

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package kvm
33
import (
44
"encoding/json"
55
"fmt"
6+
"kvm/internal/usbgadget"
67
"os"
78
"sync"
89
)
@@ -12,32 +13,26 @@ type WakeOnLanDevice struct {
1213
MacAddress string `json:"macAddress"`
1314
}
1415

15-
type UsbConfig struct {
16-
VendorId string `json:"vendor_id"`
17-
ProductId string `json:"product_id"`
18-
SerialNumber string `json:"serial_number"`
19-
Manufacturer string `json:"manufacturer"`
20-
Product string `json:"product"`
21-
}
22-
2316
type Config struct {
24-
CloudURL string `json:"cloud_url"`
25-
CloudAppURL string `json:"cloud_app_url"`
26-
CloudToken string `json:"cloud_token"`
27-
GoogleIdentity string `json:"google_identity"`
28-
JigglerEnabled bool `json:"jiggler_enabled"`
29-
AutoUpdateEnabled bool `json:"auto_update_enabled"`
30-
IncludePreRelease bool `json:"include_pre_release"`
31-
HashedPassword string `json:"hashed_password"`
32-
LocalAuthToken string `json:"local_auth_token"`
33-
LocalAuthMode string `json:"localAuthMode"` //TODO: fix it with migration
34-
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
35-
EdidString string `json:"hdmi_edid_string"`
36-
ActiveExtension string `json:"active_extension"`
37-
DisplayMaxBrightness int `json:"display_max_brightness"`
38-
DisplayDimAfterSec int `json:"display_dim_after_sec"`
39-
DisplayOffAfterSec int `json:"display_off_after_sec"`
40-
UsbConfig *UsbConfig `json:"usb_config"`
17+
CloudURL string `json:"cloud_url"`
18+
CloudAppURL string `json:"cloud_app_url"`
19+
CloudToken string `json:"cloud_token"`
20+
GoogleIdentity string `json:"google_identity"`
21+
JigglerEnabled bool `json:"jiggler_enabled"`
22+
AutoUpdateEnabled bool `json:"auto_update_enabled"`
23+
IncludePreRelease bool `json:"include_pre_release"`
24+
HashedPassword string `json:"hashed_password"`
25+
LocalAuthToken string `json:"local_auth_token"`
26+
LocalAuthMode string `json:"localAuthMode"` //TODO: fix it with migration
27+
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
28+
EdidString string `json:"hdmi_edid_string"`
29+
ActiveExtension string `json:"active_extension"`
30+
DisplayMaxBrightness int `json:"display_max_brightness"`
31+
DisplayDimAfterSec int `json:"display_dim_after_sec"`
32+
DisplayOffAfterSec int `json:"display_off_after_sec"`
33+
TLSMode string `json:"tls_mode"`
34+
UsbConfig *usbgadget.Config `json:"usb_config"`
35+
UsbDevices *usbgadget.Devices `json:"usb_devices"`
4136
}
4237

4338
const configPath = "/userdata/kvm_config.json"
@@ -50,13 +45,20 @@ var defaultConfig = &Config{
5045
DisplayMaxBrightness: 64,
5146
DisplayDimAfterSec: 120, // 2 minutes
5247
DisplayOffAfterSec: 1800, // 30 minutes
53-
UsbConfig: &UsbConfig{
48+
TLSMode: "",
49+
UsbConfig: &usbgadget.Config{
5450
VendorId: "0x1d6b", //The Linux Foundation
5551
ProductId: "0x0104", //Multifunction Composite Gadget
5652
SerialNumber: "",
5753
Manufacturer: "JetKVM",
5854
Product: "USB Emulation Device",
5955
},
56+
UsbDevices: &usbgadget.Devices{
57+
AbsoluteMouse: true,
58+
RelativeMouse: true,
59+
Keyboard: true,
60+
MassStorage: true,
61+
},
6062
}
6163

6264
var (
@@ -95,6 +97,10 @@ func LoadConfig() {
9597
loadedConfig.UsbConfig = defaultConfig.UsbConfig
9698
}
9799

100+
if loadedConfig.UsbDevices == nil {
101+
loadedConfig.UsbDevices = defaultConfig.UsbDevices
102+
}
103+
98104
config = &loadedConfig
99105
}
100106

0 commit comments

Comments
 (0)