grub/commands/usbtest.c
robertmh d64399b562 2009-02-08 Marco Gerards <marco@gnu.org>
* Makefile.in (enable_grub_emu_usb): New variable.
        * conf/i386-pc.rmk (grub_emu_SOURCES): Add `disk/scsi.c'.
        (grub_emu_SOURCES) [grub_emu_SOURCES]: Add `disk/usbms.c',
        `util/usb.c', `bus/usb/usb.c' and `commands/usbtest.c'.
        (grub_emu_LDFLAGS): Add `$(LIBUSB)'.
        (pkglib_MODULES): Add `usb.mod', `uhci.mod', `ohci.mod',
        `usbtest.mod' and `usbms.mod'.
        (usb_mod_SOURCES, usb_mod_CFLAGS, usb_mod_LDFLAGS)
        (usbtest_mod_SOURCES, usbtest_mod_CFLAGS, usbtest_mod_LDFLAGS)
        (uhci_mod_SOURCES, uhci_mod_CFLAGS, uhci_mod_LDFLAGS,
        (ohci_mod_SOURCES, ohci_mod_CFLAGS, ohci_mod_LDFLAGS)
        (usbms_mod_SOURCES, usbms_mod_CFLAGS, usbms_mod_LDFLAGS): New
        variables.

        * disk/usbms.c: New file.

        * include/grub/usb.h: Likewise.

        * include/grub/usbtrans.h: Likewise.

        * include/grub/usbdesc.h: Likewise.

        * bus/usb/usbtrans.c: Likewise.

        * bus/usb/ohci.c: Likewise.

        * bus/usb/uhci.c: Likewise.

        * bus/usb/usbhub.c: Likewise.

        * bus/usb/usb.c: Likewise.

        * commands/usbtest.c: Likewise.

        * util/usb.c: Likewise.

        * include/grub/err.h (grub_err_t): Add `GRUB_ERR_IO'.

        * configure.ac: Test for libusb presence.

        * util/grub-emu.c (main) [HAVE_LIBUSB_H]: Call `grub_libusb_init'.
2009-02-08 17:58:32 +00:00

160 lines
4 KiB
C

/* usbtest.c - test module for USB */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/normal.h>
#include <grub/usb.h>
static const char *usb_classes[] =
{
"",
"Audio",
"Communication Interface",
"HID",
"",
"Physical",
"Image",
"Printer",
"Mass Storage",
"Hub",
"Data Interface",
"Smart Card",
"Content Security",
"Video"
};
static const char *usb_endp_type[] =
{
"Control",
"Isochronous",
"Bulk",
"Interrupt"
};
static const char *usb_devspeed[] =
{
"",
"Low",
"Full",
"High"
};
static void
usb_print_str (const char *description, grub_usb_device_t dev, int idx)
{
char *name;
/* XXX: LANGID */
if (! idx)
return;
grub_usb_get_string (dev, idx, 0x0409, &name);
grub_printf ("%s: `%s'\n", description, name);
grub_free (name);
}
static int
usb_iterate (grub_usb_device_t dev)
{
struct grub_usb_desc_device *descdev;
int i;
descdev = &dev->descdev;
usb_print_str ("Product", dev, descdev->strprod);
usb_print_str ("Vendor", dev, descdev->strvendor);
usb_print_str ("Serial", dev, descdev->strserial);
if (descdev->class > 0 && descdev->class <= 0x0E)
grub_printf ("Class: (0x%02x) %s, Subclass: 0x%02x, Protocol: 0x%02x\n",
descdev->class, usb_classes[descdev->class],
descdev->subclass, descdev->protocol);
grub_printf ("USB version %d.%d, VendorID: 0x%02x, ProductID: 0x%02x, #conf: %d\n",
descdev->usbrel >> 8, (descdev->usbrel >> 4) & 0x0F,
descdev->vendorid, descdev->prodid, descdev->configcnt);
grub_printf ("%s speed device\n", usb_devspeed[dev->speed]);
for (i = 0; i < descdev->configcnt; i++)
{
struct grub_usb_desc_config *config;
config = dev->config[i].descconf;
usb_print_str ("Configuration:", dev, config->strconfig);
}
for (i = 0; i < dev->config[0].descconf->numif; i++)
{
int j;
struct grub_usb_desc_if *interf;
interf = dev->config[0].interf[i].descif;
grub_printf ("Interface #%d: #Endpoints: %d ",
i, interf->endpointcnt);
if (interf->class > 0 && interf->class <= 0x0E)
grub_printf ("Class: (0x%02x) %s, Subclass: 0x%02x, Protocol: 0x%02x\n",
interf->class, usb_classes[interf->class],
interf->subclass, interf->protocol);
usb_print_str ("Interface", dev, interf->strif);
for (j = 0; j < interf->endpointcnt; j++)
{
struct grub_usb_desc_endp *endp;
endp = &dev->config[0].interf[i].descendp[j];
grub_printf ("Endpoint #%d: %s, max packed size: %d, transfer type: %s, latency: %d\n",
endp->endp_addr & 15,
(endp->endp_addr & 128) ? "IN" : "OUT",
endp->maxpacket, usb_endp_type[endp->attrib & 3],
endp->interval);
}
}
grub_printf("\n");
return 0;
}
static grub_err_t
grub_cmd_usbtest (struct grub_arg_list *state __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
grub_printf ("USB devices:\n\n");
grub_usb_iterate (usb_iterate);
return 0;
}
GRUB_MOD_INIT(usbtest)
{
(void)mod; /* To stop warning. */
grub_register_command ("usb", grub_cmd_usbtest, GRUB_COMMAND_FLAG_BOTH,
"usb", "Test USB support", 0);
}
GRUB_MOD_FINI(usbtest)
{
grub_unregister_command ("usb");
}