iPXE
Functions
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 ( GPL2_OR_LATER_OR_UBDL  )
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;
}