3.0 KiB
3.0 KiB
USB gadget RPC mechanincs
- RPC server is in
service.go - RPC client with CLI is in
cli_client.go
RPC server
- holds state of desired USB setting with name
settingsStateand typeproto.GadgetSettings settingsStateis initialized to the hard-coded default settings when the RPC server is started (init) and deployed to the kernel via config FS- the active USB gadget has not the same setting as the state stored in
settingsState, this is only the case on init, when the default settings are deployed settingsStateis meant to store the desired settings, which are customized by the user via RPC calls, in order to deploy the settings, an additional RPC call is needed (deploySettings)- the user can change a single or multiple USB gadget settings with a single RPC call from the cli_client
- for this purpose, the RPC call
SetGadgetSettingsis used, which has to provide a fullproto.GadgetSettingsstruct - the settings provided with
SetGadgetSettingsoverwrite the settings stored insettingsState(RPC doesn't keep track of changed and unchanged settings) - thus, in order to change only a part of the settings, the client has to retrieve current
settingsStatevia the RPC callGetGadgetSettingsmodify the result to its needs and send it back withSetGadgetSettings - once the client is done with changing settings (could be done with a single or multiple calls to
SetGadgetSettings) he issues the RPC calldeploySettingsto deploy the settings (real active seetings andsettingsStateare the same again, if no error occures)
GetDeployedGadgetSettingRPC call could be used to retrieve the real settings in use from the running gadget
Error handling
- the RPC server checks the settings to be valid after every call of
SetGadgetSettings, if an error occures it is reported back and thesettingsStateisn't updated - if
deploySettingsis called, the server stores the old settings of the gadgets, in case of an error it is reported back and the active gadget configuration, as well as thesettingsState, are reverted to the stored configuration - before Deploying new gadget settings, they are compared to the active ones, to avoid re-building of the composite gadget if it isn't needed
- the most likely reason to end up with invalid gadget settings is that too many USB gadgets functions are enabled simultaneously, as each function consumes one or more USB endpoints (there're only 7 EPs available)
Additional notes
- the reason for not directly applying changed gadget settings, is that the whole composite gadget is destroyed and brought up again for every change
- there're likely parameters which could be changed without destroying the gadget (like the image backing an USB Mass Storage), these parameters are handled differently
- Re-deployment of the USB gagdget with changed settings interrupts the workflow, for example USB-based network interfaces are shut down during re-deployment (even if they aren't affected by the changed settings) - this would interrupt running connections or listening server sockets