Documentation
¶
Overview ¶
Package uhid supports creating, handling and destroying devices created via /dev/uhid.
Index ¶
- Constants
- type Device
- func (d *Device) Bus() uint16
- func (d *Device) Close() error
- func (d *Device) Dispatch(ctx context.Context) (ReadStatus, error)
- func (d *Device) EventNodes(ctx context.Context) ([]string, error)
- func (d *Device) HidrawNodes(ctx context.Context) ([]string, error)
- func (d *Device) InjectEvent(data []uint8) error
- func (d *Device) Name() string
- func (d *Device) NewKernelDevice(ctx context.Context) error
- func (d *Device) Phys() string
- func (d *Device) ProductID() uint32
- func (d *Device) Replay(ctx context.Context, file *os.File) error
- func (d *Device) SetUniq(uniq string) error
- func (d *Device) Uniq() string
- func (d *Device) VendorID() uint32
- func (d *Device) WriteEvent(i interface{}) error
- type DeviceData
- type EventType
- type GetReportReplyRequest
- type GetReportRequest
- type Input2Request
- type RNumType
- type ReadStatus
Constants ¶
const ( // Destroy destroys the device freeing up it's resources. Destroy EventType = 1 // Start is written by the kernel to acknowledge the creation of // a device. Start = 2 // Stop is written by the kernel to acknowledge the destruction // of a device. Stop = 3 // Open is written by the kernel to signal that the data being // provided by the device is being read. Open = 4 // Close is written by the kernel to signal that no more processes // are reading this device's data. Close = 5 // Output is written by the kernel to signal that the HID device // driver wants to send raw data to the I/O device on the interrupt // channel. Output = 6 // GetReport is written by the kernel to signal that the kernel // driver wants to perform a GET_REPORT request on the control // channeld as described in the HID specs. GetReport = 9 // GetReportReply must be written by the user as a reply to a // UHIDGetReport request. GetReportReply = 10 // Create2 is written by the user to create a device. Create2 = 11 // Input2 is used to inject events to the device. Input2 = 12 // SetReport is written by the kernel to signal that the kernel // driver wants to perform a SET_REPORT request on the control // channeld as described in the HID specs. SetReport = 13 // SetReportReply must be written by the user as a reply to a // SetReport request. SetReportReply = 14 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct { Data DeviceData // EventHandlers is used on a call to Dispatch to call the // corresponding handling function. If the user wishes to handle a // particular event then they must assign their handler function to // EventHandlers[UHIDEvent] where UHIDEvent is one of the UHID // constants defined above. EventHandlers map[uint32]eventHandler // contains filtered or unexported fields }
Device is the main interface carrying all of the created (or soon to be created) kernel device's information.
func NewDeviceFromRecording ¶
NewDeviceFromRecording receives a file containing a hid recording recorded using hid-tools (https://gitlab.freedesktop.org/libevdev/hid-tools) and creates a device based on the information contained in it.
func (*Device) Close ¶
Close destroys the device specified in d by writing a destroy request to /dev/uhid. The file as well as the hidraw and event nodes are cleared.
func (*Device) Dispatch ¶
func (d *Device) Dispatch(ctx context.Context) (ReadStatus, error)
Dispatch must be called when an event needs to be handled. Be sure to implement some method of checking if the event you wish to handle was indeed the one handled.
func (*Device) EventNodes ¶
EventNodes returns the /dev/input/event* paths associated to this device.
func (*Device) HidrawNodes ¶
HidrawNodes returns the /dev/hidraw* paths associated to this device.
func (*Device) InjectEvent ¶
InjectEvent Injects an event into an existing device. The data array will vary from device to device.
func (*Device) NewKernelDevice ¶
NewKernelDevice creates a device with the attributes specified in d. Only after calling this function will the device be ready for the other operations.
func (*Device) Replay ¶
Replay receives a file containing a hid recording, parses it and injects the events into the given device. An error is returned if the recording file is invalid.
func (*Device) WriteEvent ¶
WriteEvent will write the struct given in i into /dev/uhid and return an error if unsuccessful.
type DeviceData ¶
type DeviceData struct {
// contains filtered or unexported fields
}
DeviceData encapsulates the non-trivial data that will then be copied over to a create request or be used to get information from the device. The fixed size byte arrays are meant to replicate those in struct uhid_create2_req in uhid.h.
type EventType ¶
type EventType uint32
EventType is the type used to encapsulate the different request types that can be written by the kernel or user to /dev/uhid.
type GetReportReplyRequest ¶
type GetReportReplyRequest struct { RequestType uint32 ID uint32 Err uint16 DataSize uint16 Data [hidMaxDescriptorSize]byte }
GetReportReplyRequest replicates struct uhid_get_report_reply_req in uhid.h. It should be written to Device.File in response to a GetReportRequest by the kernel.
type GetReportRequest ¶
GetReportRequest replicates struct uhid_get_report_req in uhid.h. It is used to read GetReport requests written by the kernel and handling them afterwards if necessary.
type Input2Request ¶
Input2Request replicates struct uhid_input2_req in uhid.h. An input request is used to inject events into the created device.
type RNumType ¶
type RNumType uint8
RNumType is the type used for the rnum field in get report requests.
type ReadStatus ¶
type ReadStatus uint8
ReadStatus is returned by Dispatch to signal the multiple results of reading from /dev/uhid
const ( // StatusOK signals that an event was read and no problem was // encountered. StatusOK ReadStatus = iota // StatusNoEvent signals that no event was read. StatusNoEvent )