iPXE
Data Structures | Macros | Functions
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. More...
 
#define USB_SUBCLASS_HID_BOOT   1
 Subclass code for boot devices. More...
 
#define USBHID_SET_PROTOCOL
 Set protocol. More...
 
#define USBHID_PROTOCOL_BOOT   0
 Boot protocol. More...
 
#define USBHID_PROTOCOL_REPORT   1
 Report protocol. More...
 
#define USBHID_SET_IDLE
 Set idle time. More...
 
#define USBHID_SET_REPORT
 Set report. More...
 
#define USBHID_REPORT_INPUT   0x01
 Input report type. More...
 
#define USBHID_REPORT_OUTPUT   0x02
 Output report type. More...
 
#define USBHID_REPORT_FEATURE   0x03
 Feature report type. More...
 

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. More...
 
static int usbhid_set_protocol (struct usb_device *usb, unsigned int interface, unsigned int protocol)
 Set protocol. More...
 
static int usbhid_set_idle (struct usb_device *usb, unsigned int interface, unsigned int report, unsigned int duration)
 Set idle time. More...
 
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. More...
 
int usbhid_open (struct usb_hid *hid)
 Open USB human interface device. More...
 
void usbhid_close (struct usb_hid *hid)
 Close USB human interface device. More...
 
int usbhid_refill (struct usb_hid *hid)
 Refill USB human interface device endpoints. More...
 
int usbhid_describe (struct usb_hid *hid, struct usb_configuration_descriptor *config)
 Describe USB human interface device. More...
 

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_RECIP_INTERFACE
Request recipient is an interface.
Definition: usb.h:101
#define USB_DIR_OUT
Data transfer is from host to device.
Definition: usb.h:80
#define USB_TYPE_CLASS
Class-specific request type.
Definition: usb.h:89

Set protocol.

Definition at line 21 of file usbhid.h.

◆ USBHID_PROTOCOL_BOOT

#define USBHID_PROTOCOL_BOOT   0

Boot protocol.

Definition at line 26 of file usbhid.h.

◆ 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 ) )
#define USB_RECIP_INTERFACE
Request recipient is an interface.
Definition: usb.h:101
#define USB_DIR_OUT
Data transfer is from host to device.
Definition: usb.h:80
#define USB_TYPE_CLASS
Class-specific request type.
Definition: usb.h:89

Set idle time.

Definition at line 32 of file usbhid.h.

◆ USBHID_SET_REPORT

#define USBHID_SET_REPORT
Value:
USB_REQUEST_TYPE ( 0x09 ) )
#define USB_RECIP_INTERFACE
Request recipient is an interface.
Definition: usb.h:101
#define USB_DIR_OUT
Data transfer is from host to device.
Definition: usb.h:80
#define USB_TYPE_CLASS
Class-specific request type.
Definition: usb.h:89

Set report.

Definition at line 37 of file usbhid.h.

◆ 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.

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

static 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:35
struct usb_endpoint in
Interrupt IN endpoint.
Definition: usbhid.h:55
struct usb_endpoint out
Interrupt OUT endpoint (optional)
Definition: usbhid.h:57
__be32 out[4]
Definition: CIB_PRM.h:36
A USB device.
Definition: usb.h:706
struct usb_device * usb
USB device.
Definition: usb.h:661
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:525
struct usb_function * func
USB function.
Definition: usbhid.h:53

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

static 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 }
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:753
#define USBHID_SET_PROTOCOL
Set protocol.
Definition: usbhid.h:21
An object interface.
Definition: interface.h:109
uint16_t protocol
Protocol ID.
Definition: stp.h:18
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by usbkbd_probe().

◆ usbhid_set_idle()

static 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 }
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:753
An object interface.
Definition: interface.h:109
u16 duration
Microseconds to reserve link.
Definition: ieee80211.h:15
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#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()

static 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 }
uint8_t type
Type.
Definition: ena.h:16
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:753
An object interface.
Definition: interface.h:109
#define USBHID_SET_REPORT
Set report.
Definition: usbhid.h:37
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

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

Referenced by usbkbd_set_leds().

◆ 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:14
const char * name
Name.
Definition: usb.h:659
struct usb_endpoint in
Interrupt IN endpoint.
Definition: usbhid.h:55
#define DBGC(...)
Definition: compiler.h:505
int usb_endpoint_open(struct usb_endpoint *ep)
Open USB endpoint.
Definition: usb.c:293
struct usb_endpoint out
Interrupt OUT endpoint (optional)
Definition: usbhid.h:57
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:370
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition: usb.c:642
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct usb_device * usb
USB device.
Definition: usb.h:391
struct usb_function * func
USB function.
Definition: usbhid.h:53

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 }
struct usb_endpoint in
Interrupt IN endpoint.
Definition: usbhid.h:55
struct usb_endpoint out
Interrupt OUT endpoint (optional)
Definition: usbhid.h:57
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:370
struct usb_device * usb
USB device.
Definition: usb.h:391

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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_endpoint in
Interrupt IN endpoint.
Definition: usbhid.h:55
struct usb_endpoint out
Interrupt OUT endpoint (optional)
Definition: usbhid.h:57
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition: usb.c:642
struct usb_device * usb
USB device.
Definition: usb.h:391

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  {
122  struct usb_interface_descriptor *desc;
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 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t interface[0]
List of interface numbers.
Definition: usb.h:680
const char * name
Name.
Definition: usb.h:659
struct usb_endpoint in
Interrupt IN endpoint.
Definition: usbhid.h:55
#define DBGC(...)
Definition: compiler.h:505
#define USB_INTERRUPT_IN
Interrupt IN endpoint (internal) type.
Definition: usb.h:287
struct usb_endpoint out
Interrupt OUT endpoint (optional)
Definition: usbhid.h:57
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:241
A USB interface descriptor.
Definition: usb.h:230
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:143
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define USB_INTERRUPT_OUT
Interrupt OUT endpoint (internal) type.
Definition: usb.h:290
struct usb_device * usb
USB device.
Definition: usb.h:391
struct usb_function * func
USB function.
Definition: usbhid.h:53

References DBGC, 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().