iPXE
Data Structures | Defines | 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...

Defines

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


Define Documentation

#define USB_CLASS_HID   3

Class code for human interface devices.

Definition at line 15 of file usbhid.h.

#define USB_SUBCLASS_HID_BOOT   1

Subclass code for boot devices.

Definition at line 18 of file usbhid.h.

Value:
( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
          USB_REQUEST_TYPE ( 0x0b ) )

Set protocol.

Definition at line 21 of file usbhid.h.

Referenced by usbhid_set_protocol().

#define USBHID_PROTOCOL_BOOT   0

Boot protocol.

Definition at line 26 of file usbhid.h.

Referenced by usbkbd_probe().

#define USBHID_PROTOCOL_REPORT   1

Report protocol.

Definition at line 29 of file usbhid.h.

#define USBHID_SET_IDLE
Value:
( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
          USB_REQUEST_TYPE ( 0x0a ) )

Set idle time.

Definition at line 32 of file usbhid.h.

Referenced by usbhid_set_idle().

Value:
( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
          USB_REQUEST_TYPE ( 0x09 ) )

Set report.

Definition at line 37 of file usbhid.h.

Referenced by usbhid_set_report().

#define USBHID_REPORT_INPUT   0x01

Input report type.

Definition at line 42 of file usbhid.h.

#define USBHID_REPORT_OUTPUT   0x02

Output report type.

Definition at line 45 of file usbhid.h.

Referenced by usbkbd_set_leds().

#define USBHID_REPORT_FEATURE   0x03

Feature report type.

Definition at line 48 of file usbhid.h.


Function Documentation

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 
) [inline, static]

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.

References usb_endpoint_init().

Referenced by usbkbd_probe().

                                                           {
        struct usb_device *usb = func->usb;

        hid->func = func;
        usb_endpoint_init ( &hid->in, usb, in );
        if ( out )
                usb_endpoint_init ( &hid->out, usb, out );
}
static int usbhid_set_protocol ( struct usb_device usb,
unsigned int  interface,
unsigned int  protocol 
) [inline, static]

Set protocol.

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

Definition at line 89 of file usbhid.h.

References NULL, usb_control(), and USBHID_SET_PROTOCOL.

Referenced by usbkbd_probe().

static int usbhid_set_idle ( struct usb_device usb,
unsigned int  interface,
unsigned int  report,
unsigned int  duration 
) [inline, static]

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.

References NULL, usb_control(), and USBHID_SET_IDLE.

Referenced by usbkbd_probe().

                                                               {

        return usb_control ( usb, USBHID_SET_IDLE,
                             ( ( duration << 8 ) | report ),
                             interface, NULL, 0 );
}
static int usbhid_set_report ( struct usb_device usb,
unsigned int  interface,
unsigned int  type,
unsigned int  report,
void *  data,
size_t  len 
) [inline, static]

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.

References usb_control(), and USBHID_SET_REPORT.

Referenced by usbkbd_set_leds().

                                 {

        return usb_control ( usb, USBHID_SET_REPORT, ( ( type << 8 ) | report ),
                             interface, data, len );
}
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.

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

                                        {
        int rc;

        /* Open interrupt IN endpoint */
        if ( ( rc = usb_endpoint_open ( &hid->in ) ) != 0 ) {
                DBGC ( hid, "HID %s could not open interrupt IN: %s\n",
                       hid->func->name, strerror ( rc ) );
                goto err_open_in;
        }

        /* Refill interrupt IN endpoint */
        if ( ( rc = usb_refill ( &hid->in ) ) != 0 ) {
                DBGC ( hid, "HID %s could not refill interrupt IN: %s\n",
                       hid->func->name, strerror ( rc ) );
                goto err_refill_in;
        }

        /* Open interrupt OUT endpoint, if applicable */
        if ( hid->out.usb &&
             ( ( rc = usb_endpoint_open ( &hid->out ) ) != 0 ) ) {
                DBGC ( hid, "HID %s could not open interrupt OUT: %s\n",
                       hid->func->name, strerror ( rc ) );
                goto err_open_out;
        }

        return 0;

        usb_endpoint_close ( &hid->out );
 err_open_out:
 err_refill_in:
        usb_endpoint_close ( &hid->in );
 err_open_in:
        return rc;
}
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.

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

Referenced by usbkbd_probe(), and usbkbd_remove().

                                          {

        /* Close interrupt OUT endpoint, if applicable */
        if ( hid->out.usb )
                usb_endpoint_close ( &hid->out );

        /* Close interrupt IN endpoint */
        usb_endpoint_close ( &hid->in );
}
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.

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

                                          {
        int rc;

        /* Refill interrupt IN endpoint */
        if ( ( rc = usb_refill ( &hid->in ) ) != 0 )
                return rc;

        /* Refill interrupt OUT endpoint, if applicable */
        if ( hid->out.usb && ( ( rc = usb_refill ( &hid->out ) ) != 0 ) )
                return rc;

        return 0;
}
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.

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

                                                                    {
        struct usb_interface_descriptor *desc;
        int rc;

        /* Locate interface descriptor */
        desc = usb_interface_descriptor ( config, hid->func->interface[0], 0 );
        if ( ! desc ) {
                DBGC ( hid, "HID %s has no interface descriptor\n",
                       hid->func->name );
                return -EINVAL;
        }

        /* Describe interrupt IN endpoint */
        if ( ( rc = usb_endpoint_described ( &hid->in, config, desc,
                                             USB_INTERRUPT_IN, 0 ) ) != 0 ) {
                DBGC ( hid, "HID %s could not describe interrupt IN: %s\n",
                       hid->func->name, strerror ( rc ) );
                return rc;
        }

        /* Describe interrupt OUT endpoint, if applicable */
        if ( hid->out.usb &&
             ( ( rc = usb_endpoint_described ( &hid->out, config, desc,
                                               USB_INTERRUPT_OUT, 0 ) ) != 0 )){
                DBGC ( hid, "HID %s could not describe interrupt OUT: %s\n",
                       hid->func->name, strerror ( rc ) );
                return rc;
        }

        return 0;
}