Documentation
¶
Overview ¶
Package usbgadget provides a high-level interface to manage USB gadgets THIS PACKAGE IS FOR INTERNAL USE ONLY AND ITS API MAY CHANGE WITHOUT NOTICE
Index ¶
- Constants
- Variables
- type ApplyFunc
- type ChangeSet
- type ChangeSetResolver
- type ChangeState
- type Config
- type Devices
- type FileChange
- type FileChangeResolvedAction
- type FileState
- type KeyboardState
- type RequestedFileChange
- type UsbGadget
- func (u *UsbGadget) AbsMouseReport(x, y int, buttons uint8) error
- func (u *UsbGadget) AbsMouseWheelReport(wheelY int8) error
- func (u *UsbGadget) BindUDC() error
- func (u *UsbGadget) GetConfigPath(itemKey string) (string, error)
- func (u *UsbGadget) GetKeyboardState() KeyboardState
- func (u *UsbGadget) GetLastUserInputTime() time.Time
- func (u *UsbGadget) GetPath(itemKey string) (string, error)
- func (u *UsbGadget) GetUsbState() (state string)
- func (u *UsbGadget) Init() error
- func (u *UsbGadget) IsUDCBound() (bool, error)
- func (u *UsbGadget) KeyboardReport(modifier uint8, keys []uint8) error
- func (u *UsbGadget) OpenKeyboardHidFile() error
- func (u *UsbGadget) OverrideGadgetConfig(itemKey string, itemAttr string, value string) (error, bool)
- func (u *UsbGadget) RebindUsb(ignoreUnbindError bool) error
- func (u *UsbGadget) RelMouseReport(mx, my int8, buttons uint8) error
- func (u *UsbGadget) SetGadgetConfig(config *Config)
- func (u *UsbGadget) SetGadgetDevices(devices *Devices)
- func (u *UsbGadget) SetOnKeyboardStateChange(f func(state KeyboardState))
- func (u *UsbGadget) UnbindUDC() error
- func (u *UsbGadget) UpdateGadgetConfig() error
- func (u *UsbGadget) WithTransaction(fn func() error) error
- type UsbGadgetTransaction
- func (tx *UsbGadgetTransaction) Commit() error
- func (tx *UsbGadgetTransaction) CreateConfigPath()
- func (tx *UsbGadgetTransaction) DisableGadgetItemConfig(item gadgetConfigItem)
- func (tx *UsbGadgetTransaction) MountConfigFS()
- func (tx *UsbGadgetTransaction) RebindUsb(ignoreUnbindError bool)
- func (tx *UsbGadgetTransaction) WriteGadgetConfig()
- func (tx *UsbGadgetTransaction) WriteUDC()
Constants ¶
const ( // https://www.usb.org/sites/default/files/documents/hid1_11.pdf // https://www.usb.org/sites/default/files/hut1_2.pdf KeyboardLedMaskNumLock = 1 << 0 KeyboardLedMaskCapsLock = 1 << 1 KeyboardLedMaskScrollLock = 1 << 2 KeyboardLedMaskCompose = 1 << 3 KeyboardLedMaskKana = 1 << 4 ValidKeyboardLedMasks = KeyboardLedMaskNumLock | KeyboardLedMaskCapsLock | KeyboardLedMaskScrollLock | KeyboardLedMaskCompose | KeyboardLedMaskKana )
Variables ¶
var FileChangeResolvedActionString = map[FileChangeResolvedAction]string{ FileChangeResolvedActionUnknown: "UNKNOWN", FileChangeResolvedActionDoNothing: "DO_NOTHING", FileChangeResolvedActionRemove: "REMOVE", FileChangeResolvedActionCreateFile: "FILE_CREATE", FileChangeResolvedActionWriteFile: "FILE_WRITE", FileChangeResolvedActionUpdateFile: "FILE_UPDATE", FileChangeResolvedActionAppendFile: "FILE_APPEND", FileChangeResolvedActionCreateSymlink: "SYMLINK_CREATE", FileChangeResolvedActionRecreateSymlink: "SYMLINK_RECREATE", FileChangeResolvedActionCreateDirectoryAndSymlinks: "DIR_CREATE_AND_SYMLINKS", FileChangeResolvedActionReorderSymlinks: "SYMLINK_REORDER", FileChangeResolvedActionCreateDirectory: "DIR_CREATE", FileChangeResolvedActionRemoveDirectory: "DIR_REMOVE", FileChangeResolvedActionTouch: "TOUCH", FileChangeResolvedActionMountConfigFS: "CONFIGFS_MOUNT", }
var FileStateString = map[FileState]string{ FileStateUnknown: "UNKNOWN", FileStateAbsent: "ABSENT", FileStateDirectory: "DIRECTORY", FileStateFile: "FILE", FileStateFileContentMatch: "FILE_CONTENT_MATCH", FileStateFileWrite: "FILE_WRITE", FileStateMounted: "MOUNTED", FileStateMountedConfigFS: "CONFIGFS_MOUNTED", FileStateSymlink: "SYMLINK", FileStateSymlinkInOrderConfigFS: "SYMLINK_IN_ORDER_CONFIGFS", FileStateTouch: "TOUCH", }
Functions ¶
This section is empty.
Types ¶
type ApplyFunc ¶
type ApplyFunc func(c *ChangeSet, changes []*FileChange) error
type ChangeSet ¶
type ChangeSet struct {
Changes []FileChange
}
func (*ChangeSet) AddFileChange ¶
func (*ChangeSet) AddFileChangeStruct ¶
func (c *ChangeSet) AddFileChangeStruct(r RequestedFileChange)
func (*ChangeSet) ApplyChanges ¶
type ChangeSetResolver ¶
type ChangeSetResolver struct {
// contains filtered or unexported fields
}
func (*ChangeSetResolver) Apply ¶
func (c *ChangeSetResolver) Apply() error
func (*ChangeSetResolver) GetChanges ¶
func (c *ChangeSetResolver) GetChanges() ([]*FileChange, error)
type ChangeState ¶
type ChangeState uint8
const ( ChangeStateUnknown ChangeState = iota ChangeStateRequired ChangeStateNotChanged ChangeStateChanged ChangeStateError )
type Config ¶
type Config struct { VendorId string `json:"vendor_id"` ProductId string `json:"product_id"` SerialNumber string `json:"serial_number"` Manufacturer string `json:"manufacturer"` Product string `json:"product"` // contains filtered or unexported fields }
Config is a struct that represents the customizations for a USB gadget. TODO: rename to something else that won't confuse with the USB gadget configuration
type Devices ¶
type Devices struct { AbsoluteMouse bool `json:"absolute_mouse"` RelativeMouse bool `json:"relative_mouse"` Keyboard bool `json:"keyboard"` MassStorage bool `json:"mass_storage"` }
Devices is a struct that represents the USB devices that can be enabled on a USB gadget.
type FileChange ¶
type FileChange struct { RequestedFileChange ActualState FileState ActualContent []byte // contains filtered or unexported fields }
func (*FileChange) Action ¶
func (fc *FileChange) Action() FileChangeResolvedAction
func (*FileChange) ResetActionResolution ¶
func (fc *FileChange) ResetActionResolution()
type FileChangeResolvedAction ¶
type FileChangeResolvedAction uint8
const ( FileChangeResolvedActionUnknown FileChangeResolvedAction = iota FileChangeResolvedActionDoNothing FileChangeResolvedActionRemove FileChangeResolvedActionCreateFile FileChangeResolvedActionWriteFile FileChangeResolvedActionUpdateFile FileChangeResolvedActionAppendFile FileChangeResolvedActionCreateSymlink FileChangeResolvedActionRecreateSymlink FileChangeResolvedActionCreateDirectoryAndSymlinks FileChangeResolvedActionReorderSymlinks FileChangeResolvedActionCreateDirectory FileChangeResolvedActionRemoveDirectory FileChangeResolvedActionTouch FileChangeResolvedActionMountConfigFS )
type FileState ¶
type FileState uint8
const ( FileStateUnknown FileState = iota FileStateAbsent FileStateDirectory FileStateFile FileStateFileContentMatch FileStateFileWrite // update file content without checking FileStateMounted FileStateMountedConfigFS FileStateSymlink FileStateSymlinkInOrderConfigFS // configfs is a shithole, so we need to check if the symlinks are created in the correct order FileStateSymlinkNotInOrderConfigFS FileStateTouch )
type KeyboardState ¶
type KeyboardState struct { NumLock bool `json:"num_lock"` CapsLock bool `json:"caps_lock"` ScrollLock bool `json:"scroll_lock"` Compose bool `json:"compose"` Kana bool `json:"kana"` }
Synchronization between LED states and CAPS LOCK, NUM LOCK, SCROLL LOCK, COMPOSE, and KANA events is maintained by the host and NOT the keyboard. If using the keyboard descriptor in Appendix B, LED states are set by sending a 5-bit absolute report to the keyboard via a Set_Report(Output) request.
type RequestedFileChange ¶
type RequestedFileChange struct { Component string Key string Path string // will be used as Key if Key is empty ParamSymlinks []symlink ExpectedState FileState ExpectedContent []byte DependsOn []string BeforeChange []string // if the file is going to be changed, apply the change first Description string IgnoreErrors bool When string // only apply the change if when meets the condition }
func (*RequestedFileChange) IsSame ¶
func (f *RequestedFileChange) IsSame(other *RequestedFileChange) bool
func (*RequestedFileChange) String ¶
func (f *RequestedFileChange) String() string
type UsbGadget ¶
type UsbGadget struct {
// contains filtered or unexported fields
}
UsbGadget is a struct that represents a USB gadget.
func NewUsbGadget ¶
func NewUsbGadget(name string, enabledDevices *Devices, config *Config, logger *zerolog.Logger) *UsbGadget
NewUsbGadget creates a new UsbGadget.
func (*UsbGadget) AbsMouseReport ¶
func (*UsbGadget) AbsMouseWheelReport ¶
func (*UsbGadget) GetConfigPath ¶
GetConfigPath returns the path to the config item.
func (*UsbGadget) GetKeyboardState ¶
func (u *UsbGadget) GetKeyboardState() KeyboardState
func (*UsbGadget) GetLastUserInputTime ¶
func (*UsbGadget) GetUsbState ¶
GetUsbState returns the current state of the USB gadget
func (*UsbGadget) IsUDCBound ¶
IsUDCBound checks if the UDC state is bound.
func (*UsbGadget) KeyboardReport ¶
func (*UsbGadget) OpenKeyboardHidFile ¶
func (*UsbGadget) OverrideGadgetConfig ¶
func (u *UsbGadget) OverrideGadgetConfig(itemKey string, itemAttr string, value string) (error, bool)
OverrideGadgetConfig overrides the gadget config for the given item and attribute. It returns an error if the item is not found or the attribute is not found. It returns true if the attribute is overridden, false otherwise.
func (*UsbGadget) RelMouseReport ¶
func (*UsbGadget) SetGadgetConfig ¶
func (*UsbGadget) SetGadgetDevices ¶
func (*UsbGadget) SetOnKeyboardStateChange ¶
func (u *UsbGadget) SetOnKeyboardStateChange(f func(state KeyboardState))
func (*UsbGadget) UpdateGadgetConfig ¶
func (*UsbGadget) WithTransaction ¶
type UsbGadgetTransaction ¶
type UsbGadgetTransaction struct {
// contains filtered or unexported fields
}
func (*UsbGadgetTransaction) Commit ¶
func (tx *UsbGadgetTransaction) Commit() error
func (*UsbGadgetTransaction) CreateConfigPath ¶
func (tx *UsbGadgetTransaction) CreateConfigPath()
func (*UsbGadgetTransaction) DisableGadgetItemConfig ¶
func (tx *UsbGadgetTransaction) DisableGadgetItemConfig(item gadgetConfigItem)
func (*UsbGadgetTransaction) MountConfigFS ¶
func (tx *UsbGadgetTransaction) MountConfigFS()
func (*UsbGadgetTransaction) RebindUsb ¶
func (tx *UsbGadgetTransaction) RebindUsb(ignoreUnbindError bool)
func (*UsbGadgetTransaction) WriteGadgetConfig ¶
func (tx *UsbGadgetTransaction) WriteGadgetConfig()
func (*UsbGadgetTransaction) WriteUDC ¶
func (tx *UsbGadgetTransaction) WriteUDC()