iPXE
usbhid.c File Reference

USB human interface devices (HID) More...

#include <string.h>
#include <errno.h>
#include <ipxe/usb.h>
#include <ipxe/usbhid.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
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.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ usbhid_open()

int usbhid_open ( struct usb_hid * hid)

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
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
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)

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)

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 )

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().