Use USB vendor/product IDs instead of bus/dev IDs
This commit is contained in:
parent
8fd8def548
commit
a8f5af7bd0
4 changed files with 23 additions and 15 deletions
12
cmd/ls.go
12
cmd/ls.go
|
|
@ -46,21 +46,21 @@ func getDevicePassthroughConfig(val string) vm.USBDevicePassthroughConfig {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
usbBus, err := strconv.ParseUint(usbValsSplit[0], 10, 8)
|
vendorID, err := strconv.ParseUint(usbValsSplit[0], 16, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Bad USB device bus number", "value", usbValsSplit[0])
|
slog.Error("Bad USB vendor ID", "value", usbValsSplit[0])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
usbPort, err := strconv.ParseUint(usbValsSplit[1], 10, 8)
|
productID, err := strconv.ParseUint(usbValsSplit[1], 16, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Bad USB device port number", "value", usbValsSplit[1])
|
slog.Error("Bad USB product ID", "value", usbValsSplit[1])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return vm.USBDevicePassthroughConfig{
|
return vm.USBDevicePassthroughConfig{
|
||||||
HostBus: uint8(usbBus),
|
VendorID: uint16(vendorID),
|
||||||
HostPort: uint8(usbPort),
|
ProductID: uint16(productID),
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
slog.Error("Unknown device passthrough type", "value", valSplit[0])
|
slog.Error("Unknown device passthrough type", "value", valSplit[0])
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
@ -28,3 +29,9 @@ func ValidateDevName(s string) bool {
|
||||||
|
|
||||||
return devNameRegexp.MatchString(s)
|
return devNameRegexp.MatchString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Uint16ToBytesBE(v uint16) []byte {
|
||||||
|
b := make([]byte, 2)
|
||||||
|
binary.BigEndian.PutUint16(b, v)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type USBDevicePassthroughConfig struct {
|
type USBDevicePassthroughConfig struct {
|
||||||
HostBus uint8
|
VendorID uint16
|
||||||
HostPort uint8
|
ProductID uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
type PortForwardingRule struct {
|
type PortForwardingRule struct {
|
||||||
|
|
|
||||||
11
vm/vm.go
11
vm/vm.go
|
|
@ -4,13 +4,13 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -122,17 +122,18 @@ func NewVM(logger *slog.Logger, cfg VMConfig) (*VM, error) {
|
||||||
|
|
||||||
if !cfg.ShowDisplay {
|
if !cfg.ShowDisplay {
|
||||||
cmdArgs = append(cmdArgs, "-display", "none")
|
cmdArgs = append(cmdArgs, "-display", "none")
|
||||||
if runtime.GOARCH == "arm64" {
|
|
||||||
|
} else if runtime.GOARCH == "arm64" {
|
||||||
// No video is configured by default in ARM. This will enable it.
|
// No video is configured by default in ARM. This will enable it.
|
||||||
|
// TODO: This doesn't really work on arm64. It just shows a blank viewer.
|
||||||
cmdArgs = append(cmdArgs, "-device", "virtio-gpu-device")
|
cmdArgs = append(cmdArgs, "-device", "virtio-gpu-device")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if len(cfg.USBDevices) != 0 {
|
if len(cfg.USBDevices) != 0 {
|
||||||
cmdArgs = append(cmdArgs, "-usb", "-device", "nec-usb-xhci,id=xhci")
|
cmdArgs = append(cmdArgs, "-device", "nec-usb-xhci,id=xhci")
|
||||||
|
|
||||||
for _, dev := range cfg.USBDevices {
|
for _, dev := range cfg.USBDevices {
|
||||||
cmdArgs = append(cmdArgs, "-device", "usb-host,hostbus="+strconv.FormatUint(uint64(dev.HostBus), 10)+",hostport="+strconv.FormatUint(uint64(dev.HostPort), 10))
|
cmdArgs = append(cmdArgs, "-device", "usb-host,vendorid=0x"+hex.EncodeToString(utils.Uint16ToBytesBE(dev.VendorID))+",productid=0x"+hex.EncodeToString(utils.Uint16ToBytesBE(dev.ProductID)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue