From 45c590f6ee17d54b7e951b209956d886d537155b Mon Sep 17 00:00:00 2001 From: mame82 Date: Fri, 4 May 2018 22:20:44 +0000 Subject: [PATCH] Fixes in USB backend, added gadget autodeploy to CLI --- cli_client/cmd_led.go | 2 +- cli_client/cmd_usb.go | 19 ++++++++++++++++--- service/usb.go | 5 +++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cli_client/cmd_led.go b/cli_client/cmd_led.go index 9da381e..58a882a 100644 --- a/cli_client/cmd_led.go +++ b/cli_client/cmd_led.go @@ -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)") } diff --git a/cli_client/cmd_usb.go b/cli_client/cmd_usb.go index 6c01f87..63b61bb 100644 --- a/cli_client/cmd_usb.go +++ b/cli_client/cmd_usb.go @@ -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)") } diff --git a/service/usb.go b/service/usb.go index e0b866e..0de1001 100644 --- a/service/usb.go +++ b/service/usb.go @@ -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 {