iPXE
usbhid.h File Reference

USB human interface devices (HID) More...

#include <ipxe/usb.h>

Go to the source code of this file.

Data Structures

struct  usb_hid
 A USB human interface device. More...

Macros

#define USB_CLASS_HID   3
 Class code for human interface devices.
#define USB_SUBCLASS_HID_BOOT   1
 Subclass code for boot devices.
#define USBHID_SET_PROTOCOL
 Set protocol.
#define USBHID_PROTOCOL_BOOT   0
 Boot protocol.
#define USBHID_PROTOCOL_REPORT   1
 Report protocol.
#define USBHID_SET_IDLE
 Set idle time.
#define USBHID_SET_REPORT
 Set report.
#define USBHID_REPORT_INPUT   0x01
 Input report type.
#define USBHID_REPORT_OUTPUT   0x02
 Output report type.
#define USBHID_REPORT_FEATURE   0x03
 Feature report type.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void usbhid_init (struct usb_hid *hid, struct usb_function *func, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
 Initialise USB human interface device.
static int usbhid_set_protocol (struct usb_device *usb, unsigned int interface, unsigned int protocol)
 Set protocol.
static int usbhid_set_idle (struct usb_device *usb, unsigned int interface, unsigned int report, unsigned int duration)
 Set idle time.
static int usbhid_set_report (struct usb_device *usb, unsigned int interface, unsigned int type, unsigned int report, void *data, size_t len)
 Set report.
int usbhid_open (struct usb_hid *hid)
 Open USB human interface device.
void usbhid_close (struct usb_hid *hid)
 Close USB human interface device.
int usbhid_refill (struct usb_hid *hid)
 Refill USB human interface device endpoints.
int usbhid_describe (struct usb_hid *hid, struct usb_configuration_descriptor *config)
 Describe USB human interface device.

Detailed Description

USB human interface devices (HID)

Definition in file usbhid.h.

Macro Definition Documentation

◆ USB_CLASS_HID

#define USB_CLASS_HID   3

Class code for human interface devices.

Definition at line 15 of file usbhid.h.

◆ USB_SUBCLASS_HID_BOOT

#define USB_SUBCLASS_HID_BOOT   1

Subclass code for boot devices.

Definition at line 18 of file usbhid.h.

◆ USBHID_SET_PROTOCOL

#define USBHID_SET_PROTOCOL
Value:
USB_REQUEST_TYPE ( 0x0b ) )
#define USB_DIR_OUT
Data transfer is from host to device.
Definition usb.h:95
#define USB_TYPE_CLASS
Class-specific request type.
Definition usb.h:104
#define USB_RECIP_INTERFACE
Request recipient is an interface.
Definition usb.h:116

Set protocol.

Definition at line 21 of file usbhid.h.

21#define USBHID_SET_PROTOCOL \
22 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
23 USB_REQUEST_TYPE ( 0x0b ) )

Referenced by usbhid_set_protocol().

◆ USBHID_PROTOCOL_BOOT

#define USBHID_PROTOCOL_BOOT   0

Boot protocol.

Definition at line 26 of file usbhid.h.

Referenced by usbkbd_probe().

◆ USBHID_PROTOCOL_REPORT

#define USBHID_PROTOCOL_REPORT   1

Report protocol.

Definition at line 29 of file usbhid.h.

◆ USBHID_SET_IDLE

#define USBHID_SET_IDLE
Value:
USB_REQUEST_TYPE ( 0x0a ) )

Set idle time.

Definition at line 32 of file usbhid.h.

32#define USBHID_SET_IDLE \
33 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
34 USB_REQUEST_TYPE ( 0x0a ) )

Referenced by usbhid_set_idle().

◆ USBHID_SET_REPORT

#define USBHID_SET_REPORT
Value:
USB_REQUEST_TYPE ( 0x09 ) )

Set report.

Definition at line 37 of file usbhid.h.

37#define USBHID_SET_REPORT \
38 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
39 USB_REQUEST_TYPE ( 0x09 ) )

Referenced by usbhid_set_report().

◆ USBHID_REPORT_INPUT

#define USBHID_REPORT_INPUT   0x01

Input report type.

Definition at line 42 of file usbhid.h.

◆ USBHID_REPORT_OUTPUT

#define USBHID_REPORT_OUTPUT   0x02

Output report type.

Definition at line 45 of file usbhid.h.

Referenced by usbkbd_set_leds().

◆ USBHID_REPORT_FEATURE

#define USBHID_REPORT_FEATURE   0x03

Feature report type.

Definition at line 48 of file usbhid.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ usbhid_init()

void usbhid_init ( struct usb_hid * hid,
struct usb_function * func,
struct usb_endpoint_driver_operations * in,
struct usb_endpoint_driver_operations * out )
inlinestatic

Initialise USB human interface device.

Parameters
hidUSB human interface device
funcUSB function
inInterrupt IN endpoint operations
outInterrupt OUT endpoint operations (or NULL)

Definition at line 69 of file usbhid.h.

71 {
72 struct usb_device *usb = func->usb;
73
74 hid->func = func;
75 usb_endpoint_init ( &hid->in, usb, in );
76 if ( out )
77 usb_endpoint_init ( &hid->out, usb, out );
78}
__be32 in[4]
Definition CIB_PRM.h:7
__be32 out[4]
Definition CIB_PRM.h:8
static void usb_endpoint_init(struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
Initialise USB endpoint.
Definition usb.h:540
A USB device.
Definition usb.h:723
struct usb_device * usb
USB device.
Definition usb.h:678
struct usb_endpoint in
Interrupt IN endpoint.
Definition usbhid.h:55
struct usb_function * func
USB function.
Definition usbhid.h:53
struct usb_endpoint out
Interrupt OUT endpoint (optional)
Definition usbhid.h:57

References usb_hid::func, in, usb_hid::in, out, usb_hid::out, usb_function::usb, and usb_endpoint_init().

Referenced by usbkbd_probe().

◆ usbhid_set_protocol()

int usbhid_set_protocol ( struct usb_device * usb,
unsigned int interface,
unsigned int protocol )
inlinestatic

Set protocol.

Parameters
usbUSB device
interfaceInterface number
protocolHID protocol
Return values
rcReturn status code

Definition at line 89 of file usbhid.h.

90 {
91
93 NULL, 0 );
94}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint16_t protocol
Protocol ID.
Definition stp.h:7
An object interface.
Definition interface.h:125
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition usb.c:784
#define USBHID_SET_PROTOCOL
Set protocol.
Definition usbhid.h:21

References NULL, protocol, usb_control(), and USBHID_SET_PROTOCOL.

Referenced by usbkbd_probe().

◆ usbhid_set_idle()

int usbhid_set_idle ( struct usb_device * usb,
unsigned int interface,
unsigned int report,
unsigned int duration )
inlinestatic

Set idle time.

Parameters
usbUSB device
interfaceInterface number
reportReport ID
durationDuration (in 4ms units)
Return values
rcReturn status code

Definition at line 106 of file usbhid.h.

107 {
108
109 return usb_control ( usb, USBHID_SET_IDLE,
110 ( ( duration << 8 ) | report ),
111 interface, NULL, 0 );
112}
u16 duration
Microseconds to reserve link.
Definition ieee80211.h:1
#define USBHID_SET_IDLE
Set idle time.
Definition usbhid.h:32

References duration, NULL, usb_control(), and USBHID_SET_IDLE.

Referenced by usbkbd_probe().

◆ usbhid_set_report()

int usbhid_set_report ( struct usb_device * usb,
unsigned int interface,
unsigned int type,
unsigned int report,
void * data,
size_t len )
inlinestatic

Set report.

Parameters
usbUSB device
interfaceInterface number
typeReport type
reportReport ID
dataReport data
lenLength of report data
Return values
rcReturn status code

Definition at line 126 of file usbhid.h.

128 {
129
130 return usb_control ( usb, USBHID_SET_REPORT, ( ( type << 8 ) | report ),
131 interface, data, len );
132}
ring len
Length.
Definition dwmac.h:226
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define USBHID_SET_REPORT
Set report.
Definition usbhid.h:37

References data, len, type, usb_control(), and USBHID_SET_REPORT.

Referenced by usbkbd_set_leds().

◆ usbhid_open()

int usbhid_open ( struct usb_hid * hid)
extern

Open USB human interface device.

Parameters
hidUSB human interface device
Return values
rcReturn status code

Definition at line 43 of file usbhid.c.

43 {
44 int rc;
45
46 /* Open interrupt IN endpoint */
47 if ( ( rc = usb_endpoint_open ( &hid->in ) ) != 0 ) {
48 DBGC ( hid, "HID %s could not open interrupt IN: %s\n",
49 hid->func->name, strerror ( rc ) );
50 goto err_open_in;
51 }
52
53 /* Refill interrupt IN endpoint */
54 if ( ( rc = usb_refill ( &hid->in ) ) != 0 ) {
55 DBGC ( hid, "HID %s could not refill interrupt IN: %s\n",
56 hid->func->name, strerror ( rc ) );
57 goto err_refill_in;
58 }
59
60 /* Open interrupt OUT endpoint, if applicable */
61 if ( hid->out.usb &&
62 ( ( rc = usb_endpoint_open ( &hid->out ) ) != 0 ) ) {
63 DBGC ( hid, "HID %s could not open interrupt OUT: %s\n",
64 hid->func->name, strerror ( rc ) );
65 goto err_open_out;
66 }
67
68 return 0;
69
70 usb_endpoint_close ( &hid->out );
71 err_open_out:
72 err_refill_in:
73 usb_endpoint_close ( &hid->in );
74 err_open_in:
75 return rc;
76}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DBGC(...)
Definition compiler.h:505
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
struct usb_device * usb
USB device.
Definition usb.h:406
const char * name
Name.
Definition usb.h:676
int usb_endpoint_open(struct usb_endpoint *ep)
Open USB endpoint.
Definition usb.c:294
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition usb.c:400
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition usb.c:711

References DBGC, usb_hid::func, usb_hid::in, usb_function::name, usb_hid::out, rc, strerror(), usb_endpoint::usb, usb_endpoint_close(), usb_endpoint_open(), and usb_refill().

Referenced by usbkbd_probe().

◆ usbhid_close()

void usbhid_close ( struct usb_hid * hid)
extern

Close USB human interface device.

Parameters
hidUSB human interface device

Definition at line 83 of file usbhid.c.

83 {
84
85 /* Close interrupt OUT endpoint, if applicable */
86 if ( hid->out.usb )
87 usb_endpoint_close ( &hid->out );
88
89 /* Close interrupt IN endpoint */
90 usb_endpoint_close ( &hid->in );
91}

References usb_hid::in, usb_hid::out, usb_endpoint::usb, and usb_endpoint_close().

Referenced by usbkbd_probe(), and usbkbd_remove().

◆ usbhid_refill()

int usbhid_refill ( struct usb_hid * hid)
extern

Refill USB human interface device endpoints.

Parameters
hidUSB human interface device
Return values
rcReturn status code

Definition at line 99 of file usbhid.c.

99 {
100 int rc;
101
102 /* Refill interrupt IN endpoint */
103 if ( ( rc = usb_refill ( &hid->in ) ) != 0 )
104 return rc;
105
106 /* Refill interrupt OUT endpoint, if applicable */
107 if ( hid->out.usb && ( ( rc = usb_refill ( &hid->out ) ) != 0 ) )
108 return rc;
109
110 return 0;
111}

References usb_hid::in, usb_hid::out, rc, usb_endpoint::usb, and usb_refill().

◆ usbhid_describe()

int usbhid_describe ( struct usb_hid * hid,
struct usb_configuration_descriptor * config )
extern

Describe USB human interface device.

Parameters
hidUSB human interface device
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 120 of file usbhid.c.

121 {
123 int rc;
124
125 /* Locate interface descriptor */
126 desc = usb_interface_descriptor ( config, hid->func->interface[0], 0 );
127 if ( ! desc ) {
128 DBGC ( hid, "HID %s has no interface descriptor\n",
129 hid->func->name );
130 return -EINVAL;
131 }
132
133 /* Describe interrupt IN endpoint */
134 if ( ( rc = usb_endpoint_described ( &hid->in, config, desc,
135 USB_INTERRUPT_IN, 0 ) ) != 0 ) {
136 DBGC ( hid, "HID %s could not describe interrupt IN: %s\n",
137 hid->func->name, strerror ( rc ) );
138 return rc;
139 }
140
141 /* Describe interrupt OUT endpoint, if applicable */
142 if ( hid->out.usb &&
143 ( ( rc = usb_endpoint_described ( &hid->out, config, desc,
144 USB_INTERRUPT_OUT, 0 ) ) != 0 )){
145 DBGC ( hid, "HID %s could not describe interrupt OUT: %s\n",
146 hid->func->name, strerror ( rc ) );
147 return rc;
148 }
149
150 return 0;
151}
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define EINVAL
Invalid argument.
Definition errno.h:429
#define USB_INTERRUPT_OUT
Interrupt OUT endpoint (internal) type.
Definition usb.h:305
#define USB_INTERRUPT_IN
Interrupt IN endpoint (internal) type.
Definition usb.h:302
uint8_t interface[0]
List of interface numbers.
Definition usb.h:697
A USB interface descriptor.
Definition usb.h:245
int usb_endpoint_described(struct usb_endpoint *ep, struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface, unsigned int type, unsigned int index)
Describe USB endpoint from device configuration.
Definition usb.c:242
struct usb_interface_descriptor * usb_interface_descriptor(struct usb_configuration_descriptor *config, unsigned int interface, unsigned int alternate)
Locate USB interface descriptor.
Definition usb.c:144

References DBGC, desc, EINVAL, usb_hid::func, usb_hid::in, usb_function::interface, usb_function::name, usb_hid::out, rc, strerror(), usb_endpoint::usb, usb_endpoint_described(), usb_interface_descriptor(), USB_INTERRUPT_IN, and USB_INTERRUPT_OUT.

Referenced by usbkbd_probe().