mirror of https://github.com/jetkvm/kvm.git
Compare commits
6 Commits
382c07b87a
...
58c5875aa7
Author | SHA1 | Date |
---|---|---|
|
58c5875aa7 | |
|
682b5911e8 | |
|
621c333041 | |
|
313f78000e | |
|
6a6ab143a8 | |
|
bffac9a6b5 |
20
config.go
20
config.go
|
@ -12,11 +12,11 @@ type WakeOnLanDevice struct {
|
|||
}
|
||||
|
||||
type UsbConfig struct {
|
||||
UsbVendorId string `json:"usb_vendor_id"`
|
||||
UsbProductId string `json:"usb_product_id"`
|
||||
UsbSerialNumber string `json:"usb_serial_number"`
|
||||
UsbManufacturer string `json:"usb_manufacturer"`
|
||||
UsbProduct string `json:"usb_product"`
|
||||
VendorId string `json:"vendor_id"`
|
||||
ProductId string `json:"product_id"`
|
||||
SerialNumber string `json:"serial_number"`
|
||||
Manufacturer string `json:"manufacturer"`
|
||||
Product string `json:"product"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
@ -39,11 +39,11 @@ var defaultConfig = &Config{
|
|||
CloudURL: "https://api.jetkvm.com",
|
||||
AutoUpdateEnabled: true, // Set a default value
|
||||
UsbConfig: UsbConfig{
|
||||
UsbVendorId: "0x1d6b", //The Linux Foundation
|
||||
UsbProductId: "0x0104", //Multifunction Composite Gadget¬
|
||||
UsbSerialNumber: "",
|
||||
UsbManufacturer: "JetKVM",
|
||||
UsbProduct: "JetKVM USB Emulation Device",
|
||||
VendorId: "0x1d6b", //The Linux Foundation
|
||||
ProductId: "0x0104", //Multifunction Composite Gadget¬
|
||||
SerialNumber: "",
|
||||
Manufacturer: "JetKVM",
|
||||
Product: "JetKVM USB Emulation Device",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export interface UsbConfigState {
|
|||
product_id: string;
|
||||
serial_number: string;
|
||||
manufacturer: string;
|
||||
product_name: string;
|
||||
product: string;
|
||||
}
|
||||
|
||||
export default function USBConfigDialog({
|
||||
|
@ -79,11 +79,11 @@ function UpdateUsbConfigModal({
|
|||
error: string | null;
|
||||
}) {
|
||||
const [usbConfig, setUsbConfig] = useState({
|
||||
usb_vendor_id: '',
|
||||
usb_product_id: '',
|
||||
usb_serial_number: '',
|
||||
usb_manufacturer: '',
|
||||
usb_product: '',
|
||||
vendor_id: '',
|
||||
product_id: '',
|
||||
serial_number: '',
|
||||
manufacturer: '',
|
||||
product: '',
|
||||
})
|
||||
|
||||
const [usbConfigState, setUsbConfigState] = useState<UsbConfigState>();
|
||||
|
@ -91,11 +91,10 @@ function UpdateUsbConfigModal({
|
|||
|
||||
const syncUsbConfig = useCallback(() => {
|
||||
send("getUsbConfig", {}, resp => {
|
||||
if ("result" in resp) {
|
||||
console.info("Successfully synced USB Config: ", resp.result);
|
||||
setUsbConfigState(resp.result as UsbConfigState);
|
||||
} else {
|
||||
if ("error" in resp) {
|
||||
console.error("Failed to load USB Config:", resp.error);
|
||||
} else {
|
||||
setUsbConfigState(resp.result as UsbConfigState);
|
||||
}
|
||||
});
|
||||
}, [send, setUsbConfigState]);
|
||||
|
@ -105,24 +104,24 @@ function UpdateUsbConfigModal({
|
|||
syncUsbConfig();
|
||||
}, [syncUsbConfig]);
|
||||
|
||||
const handleUsbVendorIdChange = (vendorId: string) => {
|
||||
setUsbConfig({... usbConfig, usb_vendor_id: vendorId})
|
||||
const handleUsbVendorIdChange = (value: string) => {
|
||||
setUsbConfig({... usbConfig, vendor_id: value})
|
||||
};
|
||||
|
||||
const handleUsbProductIdChange = (productId: string) => {
|
||||
setUsbConfig({... usbConfig, usb_product_id: productId})
|
||||
const handleUsbProductIdChange = (value: string) => {
|
||||
setUsbConfig({... usbConfig, product_id: value})
|
||||
};
|
||||
|
||||
const handleUsbSerialChange = (serialNumber: string) => {
|
||||
setUsbConfig({... usbConfig, usb_serial_number: serialNumber})
|
||||
const handleUsbSerialChange = (value: string) => {
|
||||
setUsbConfig({... usbConfig, serial_number: value})
|
||||
};
|
||||
|
||||
const handleUsbManufacturer = (manufacturer: string) => {
|
||||
setUsbConfig({... usbConfig, usb_manufacturer: manufacturer})
|
||||
const handleUsbManufacturer = (value: string) => {
|
||||
setUsbConfig({... usbConfig, manufacturer: value})
|
||||
};
|
||||
|
||||
const handleUsbProduct = (name: string) => {
|
||||
setUsbConfig({... usbConfig, usb_product: name})
|
||||
const handleUsbProduct = (value: string) => {
|
||||
setUsbConfig({... usbConfig, product: value})
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -143,35 +142,37 @@ function UpdateUsbConfigModal({
|
|||
required
|
||||
label="Vendor ID"
|
||||
placeholder="Enter Vendor ID"
|
||||
value={usbConfigState?.vendor_id}
|
||||
pattern="^0[xX][\da-fA-F]{4}$"
|
||||
defaultValue={usbConfigState?.vendor_id}
|
||||
onChange={e => handleUsbVendorIdChange(e.target.value)}
|
||||
/>
|
||||
<InputFieldWithLabel
|
||||
required
|
||||
label="Product ID"
|
||||
placeholder="Enter Product ID"
|
||||
value={usbConfigState?.product_id}
|
||||
pattern="^0[xX][\da-fA-F]{4}$"
|
||||
defaultValue={usbConfigState?.product_id}
|
||||
onChange={e => handleUsbProductIdChange(e.target.value)}
|
||||
/>
|
||||
<InputFieldWithLabel
|
||||
required
|
||||
label="Serial Number"
|
||||
placeholder="Enter Serial Number"
|
||||
value={usbConfigState?.serial_number}
|
||||
defaultValue={usbConfigState?.serial_number}
|
||||
onChange={e => handleUsbSerialChange(e.target.value)}
|
||||
/>
|
||||
<InputFieldWithLabel
|
||||
required
|
||||
label="Manufacturer"
|
||||
placeholder="Enter Manufacturer"
|
||||
value={usbConfigState?.manufacturer}
|
||||
defaultValue={usbConfigState?.manufacturer}
|
||||
onChange={e => handleUsbManufacturer(e.target.value)}
|
||||
/>
|
||||
<InputFieldWithLabel
|
||||
required
|
||||
label="Product Name"
|
||||
placeholder="Enter Product Name"
|
||||
value={usbConfigState?.product_name}
|
||||
defaultValue={usbConfigState?.product}
|
||||
onChange={e => handleUsbProduct(e.target.value)}
|
||||
/>
|
||||
<div className="flex gap-x-2">
|
||||
|
|
18
usb.go
18
usb.go
|
@ -61,8 +61,8 @@ func init() {
|
|||
func UpdateGadgetConfig() error {
|
||||
LoadConfig()
|
||||
gadgetAttrs := [][]string{
|
||||
{"idVendor", config.UsbConfig.UsbVendorId},
|
||||
{"idProduct", config.UsbConfig.UsbProductId},
|
||||
{"idVendor", config.UsbConfig.VendorId},
|
||||
{"idProduct", config.UsbConfig.ProductId},
|
||||
}
|
||||
err := writeGadgetAttrs(kvmGadgetPath, gadgetAttrs)
|
||||
if err != nil {
|
||||
|
@ -72,9 +72,9 @@ func UpdateGadgetConfig() error {
|
|||
log.Printf("Successfully updated usb gadget attributes: %v", gadgetAttrs)
|
||||
|
||||
strAttrs := [][]string{
|
||||
{"serialnumber", config.UsbConfig.UsbSerialNumber},
|
||||
{"manufacturer", config.UsbConfig.UsbManufacturer},
|
||||
{"product", config.UsbConfig.UsbProduct},
|
||||
{"serialnumber", config.UsbConfig.SerialNumber},
|
||||
{"manufacturer", config.UsbConfig.Manufacturer},
|
||||
{"product", config.UsbConfig.Product},
|
||||
}
|
||||
gadgetStringsPath := filepath.Join(kvmGadgetPath, "strings", "0x409")
|
||||
err = os.MkdirAll(gadgetStringsPath, 0755)
|
||||
|
@ -120,8 +120,8 @@ func writeGadgetConfig() error {
|
|||
LoadConfig()
|
||||
err = writeGadgetAttrs(kvmGadgetPath, [][]string{
|
||||
{"bcdUSB", "0x0200"}, //USB 2.0
|
||||
{"idVendor", config.UsbConfig.UsbVendorId},
|
||||
{"idProduct", config.UsbConfig.UsbProductId},
|
||||
{"idVendor", config.UsbConfig.VendorId},
|
||||
{"idProduct", config.UsbConfig.ProductId},
|
||||
{"bcdDevice", "0100"},
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -136,8 +136,8 @@ func writeGadgetConfig() error {
|
|||
|
||||
err = writeGadgetAttrs(gadgetStringsPath, [][]string{
|
||||
{"serialnumber", GetDeviceID()},
|
||||
{"manufacturer", config.UsbConfig.UsbManufacturer},
|
||||
{"product", config.UsbConfig.UsbProduct},
|
||||
{"manufacturer", config.UsbConfig.Manufacturer},
|
||||
{"product", config.UsbConfig.Product},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue