mirror of
https://github.com/RoganDawes/P4wnP1_aloa.git
synced 2025-03-17 21:31:56 +01:00
Fixes in USB backend, added gadget autodeploy to CLI
This commit is contained in:
parent
b7092ebf6b
commit
45c590f6ee
@ -51,5 +51,5 @@ func init() {
|
||||
ledCmd.AddCommand(ledGetCmd)
|
||||
ledCmd.AddCommand(ledSetCmd)
|
||||
|
||||
ledSetCmd.Flags().Uint32Var(&blink_count,"blink", 0,"Set blink count (0: Off, 1..254: blink n times, >254: On)")
|
||||
ledSetCmd.Flags().Uint32VarP(&blink_count,"blink", "b", 0,"Set blink count (0: Off, 1..254: blink n times, >254: On)")
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
//Empty settings used to store cobra flags
|
||||
var (
|
||||
//tmpGadgetSettings = pb.GadgetSettings{CdcEcmSettings:&pb.GadgetSettingsEthernet{},RndisSettings:&pb.GadgetSettingsEthernet{}}
|
||||
tmpNoAutoDeploy = false
|
||||
tmpDisableGadget bool = false
|
||||
tmpUseHIDKeyboard uint8 = 0
|
||||
tmpUseHIDMouse uint8 = 0
|
||||
@ -165,6 +166,17 @@ func cobraUsbSet(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
fmt.Printf("New USB Gadget Settings:\n%s", spew.Sdump(gs))
|
||||
|
||||
//if "auto deploy" isn't disabled, we deploy the gadget immediately to ConfigFS
|
||||
if !tmpNoAutoDeploy {
|
||||
fmt.Println("Auto-deploy the new settings...")
|
||||
if gs, err := ClientDeployGadgetSettings(StrRemoteHost, StrRemotePort); err != nil {
|
||||
fmt.Printf("Error deploying Gadget Settings: %v\nReverted to:\n%s", err, spew.Sdump(gs))
|
||||
} else {
|
||||
fmt.Printf("Successfully deployed:\n%s", spew.Sdump(gs))
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -202,14 +214,15 @@ func init() {
|
||||
usbGetCmd.AddCommand(usbGetDeployedCmd)
|
||||
usbSetCmd.AddCommand(usbSetDeployeCmd)
|
||||
|
||||
usbSetCmd.Flags().BoolVarP(&tmpDisableGadget, "disabled","d", false, "If this option is set, the gadget stays inactive after deployment (not bound to UDC)")
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseRNDIS, "rndis", "n",0,"Use the RNDIS gadget function (0: disable, 1..n: enable)")
|
||||
usbSetCmd.Flags().BoolVarP(&tmpNoAutoDeploy, "no-deploy","n", false, "If this flag is set, the gadget isn't deployed automatically (allows further changes before deployment)")
|
||||
usbSetCmd.Flags().BoolVarP(&tmpDisableGadget, "disabled","d", false, "If this flag is set, the gadget stays inactive after deployment (not bound to UDC)")
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseRNDIS, "rndis", "r",0,"Use the RNDIS gadget function (0: disable, 1..n: enable)")
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseECM, "cdc-ecm", "e",0,"Use the CDC ECM gadget function (0: disable, 1..n: enable)")
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseSerial, "serial", "s",0,"Use the SERIAL gadget function (0: disable, 1..n: enable)")
|
||||
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseHIDKeyboard, "hid-keyboard", "k",0,"Use the HID KEYBOARD gadget function (0: disable, 1..n: enable)")
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseHIDMouse, "hid-mouse", "m",0,"Use the HID MOUSE gadget function (0: disable, 1..n: enable)")
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseHIDRaw, "hid-raw", "r",0,"Use the HID RAW gadget function (0: disable, 1..n: enable)")
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseHIDRaw, "hid-raw", "g",0,"Use the HID RAW gadget function (0: disable, 1..n: enable)")
|
||||
|
||||
usbSetCmd.Flags().Uint8VarP(&tmpUseUMS, "ums", "u",0,"Use the USB MAss Storage gadget function (0: disable, 1..n: enable)")
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ func ValidateGadgetSetting(gs pb.GadgetSettings) error {
|
||||
- check EP consumption to be not more than 7 (ECM 2 EP, RNDIS 2 EP, HID Mouse 1 EP, HID Keyboard 1 EP, HID Raw 1 EP, Serial 2 EP ??, UMS ??)
|
||||
- check serial, product, Manufacturer to not be empty
|
||||
- check Pid, Vid with regex (Note: we don't check if Vid+Pid have been used for another composite function setup, yet)
|
||||
- If the gadget is enabled, at least one function has to be enabled
|
||||
*/
|
||||
|
||||
return nil
|
||||
@ -305,7 +306,7 @@ func ParseGadgetState(gadgetName string) (result *pb.GadgetSettings, err error)
|
||||
|
||||
//USB HID Mouse
|
||||
if _, err1 := os.Stat(gadget_dir+"/configs/c.1/"+USB_FUNCTION_HID_MOUSE_name); !os.IsNotExist(err1) {
|
||||
result.Use_HID_KEYBOARD = true
|
||||
result.Use_HID_MOUSE = true
|
||||
}
|
||||
|
||||
//USB HID RAW
|
||||
@ -507,7 +508,7 @@ func DeployGadgetSettings(settings pb.GadgetSettings) error {
|
||||
|
||||
deleteUSBEthernetBridge() //delete former used bridge, if there's any
|
||||
//In case USB ethernet is uesd (RNDIS or CDC ECM), we add a bridge interface
|
||||
if usesUSBEthernet {
|
||||
if usesUSBEthernet && settings.Enabled {
|
||||
//wait till "usb0" or "usb1" comes up
|
||||
err := pollForUSBEthernet(10*time.Second)
|
||||
if err == nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user