Reduce the need to accesss struct usb_device by providing functions to access
the product, manufacturer and serial strings. Submitted by: Hans Petter Selasky
This commit is contained in:
parent
d2d71ce7a8
commit
ae538d8533
@ -62,13 +62,11 @@ __FBSDID("$FreeBSD$");
|
||||
#define USB_DEBUG_VAR uhso_debug
|
||||
#include <dev/usb/usb_debug.h>
|
||||
#include <dev/usb/usb_process.h>
|
||||
#include <dev/usb/usb_device.h>
|
||||
#include <dev/usb/usb_busdma.h>
|
||||
#include <dev/usb/usb_controller.h>
|
||||
#include <dev/usb/usb_bus.h>
|
||||
#include <dev/usb/serial/usb_serial.h>
|
||||
#include <dev/usb/usb_msctest.h>
|
||||
|
||||
#include <dev/usb/serial/usb_serial.h>
|
||||
|
||||
struct uhso_tty {
|
||||
struct uhso_softc *ht_sc;
|
||||
struct usb_xfer *ht_xfer[3];
|
||||
@ -513,7 +511,7 @@ uhso_probe(device_t self)
|
||||
return (ENXIO);
|
||||
if (uaa->info.bConfigIndex != 0)
|
||||
return (ENXIO);
|
||||
if (uaa->device->ddesc.bDeviceClass != 0xff)
|
||||
if (uaa->info.bDeviceClass != 0xff)
|
||||
return (ENXIO);
|
||||
|
||||
error = usbd_lookup_id_by_uaa(uhso_devs, sizeof(uhso_devs), uaa);
|
||||
@ -603,8 +601,9 @@ uhso_attach(device_t self)
|
||||
/* Announce device */
|
||||
device_printf(self, "<%s port> at <%s %s> on %s\n",
|
||||
uhso_port_type[UHSO_IFACE_PORT_TYPE(sc->sc_type)],
|
||||
uaa->device->manufacturer, uaa->device->product,
|
||||
device_get_nameunit(uaa->device->bus->bdev));
|
||||
usb_get_manufacturer(uaa->device),
|
||||
usb_get_product(uaa->device),
|
||||
device_get_nameunit(device_get_parent(self)));
|
||||
|
||||
if (sc->sc_ttys > 0) {
|
||||
SYSCTL_ADD_INT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "ports",
|
||||
|
@ -104,7 +104,6 @@ __FBSDID("$FreeBSD$");
|
||||
#define USB_DEBUG_VAR ubser_debug
|
||||
#include <dev/usb/usb_debug.h>
|
||||
#include <dev/usb/usb_process.h>
|
||||
#include <dev/usb/usb_device.h>
|
||||
|
||||
#include <dev/usb/serial/usb_serial.h>
|
||||
|
||||
@ -226,7 +225,7 @@ ubser_probe(device_t dev)
|
||||
return (ENXIO);
|
||||
}
|
||||
/* check if this is a BWCT vendor specific ubser interface */
|
||||
if ((strcmp(uaa->device->manufacturer, "BWCT") == 0) &&
|
||||
if ((strcmp(usb_get_manufacturer(uaa->device), "BWCT") == 0) &&
|
||||
(uaa->info.bInterfaceClass == 0xff) &&
|
||||
(uaa->info.bInterfaceSubClass == 0x00))
|
||||
return (0);
|
||||
|
@ -124,7 +124,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usb_device.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
#include "usbdevs.h"
|
||||
|
||||
#include <dev/usb/quirk/usb_quirk.h>
|
||||
@ -2304,23 +2304,24 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
|
||||
if (umass_std_transform(sc, ccb, cmd, ccb->csio.cdb_len)) {
|
||||
|
||||
if (sc->sc_transfer.cmd_data[0] == INQUIRY) {
|
||||
const char *pserial;
|
||||
|
||||
pserial = usb_get_serial(sc->sc_udev);
|
||||
|
||||
/*
|
||||
* Umass devices don't generally report their serial numbers
|
||||
* in the usual SCSI way. Emulate it here.
|
||||
*/
|
||||
if ((sc->sc_transfer.cmd_data[1] & SI_EVPD) &&
|
||||
sc->sc_transfer.cmd_data[2] == SVPD_UNIT_SERIAL_NUMBER &&
|
||||
sc->sc_udev != NULL &&
|
||||
sc->sc_udev->serial != NULL &&
|
||||
sc->sc_udev->serial[0] != '\0') {
|
||||
(sc->sc_transfer.cmd_data[2] == SVPD_UNIT_SERIAL_NUMBER) &&
|
||||
(pserial[0] != '\0')) {
|
||||
struct scsi_vpd_unit_serial_number *vpd_serial;
|
||||
|
||||
vpd_serial = (struct scsi_vpd_unit_serial_number *)ccb->csio.data_ptr;
|
||||
vpd_serial->length = strlen(sc->sc_udev->serial);
|
||||
vpd_serial->length = strlen(pserial);
|
||||
if (vpd_serial->length > sizeof(vpd_serial->serial_num))
|
||||
vpd_serial->length = sizeof(vpd_serial->serial_num);
|
||||
memcpy(vpd_serial->serial_num, sc->sc_udev->serial, vpd_serial->length);
|
||||
memcpy(vpd_serial->serial_num, pserial, vpd_serial->length);
|
||||
ccb->csio.scsi_status = SCSI_STATUS_OK;
|
||||
ccb->ccb_h.status = CAM_REQ_CMP;
|
||||
xpt_done(ccb);
|
||||
@ -2553,9 +2554,7 @@ umass_cam_cb(struct umass_softc *sc, union ccb *ccb, uint32_t residue,
|
||||
sc->sc_transfer.cmd_data[0] == INQUIRY &&
|
||||
(sc->sc_transfer.cmd_data[1] & SI_EVPD) &&
|
||||
sc->sc_transfer.cmd_data[2] == SVPD_SUPPORTED_PAGE_LIST &&
|
||||
sc->sc_udev != NULL &&
|
||||
sc->sc_udev->serial != NULL &&
|
||||
sc->sc_udev->serial[0] != '\0') {
|
||||
(usb_get_serial(sc->sc_udev)[0] != '\0')) {
|
||||
struct ccb_scsiio *csio;
|
||||
struct scsi_vpd_supported_page_list *page_list;
|
||||
|
||||
|
@ -136,6 +136,24 @@ usb_statestr(enum usb_dev_state state)
|
||||
return ((state < USB_STATE_MAX) ? statestr[state] : "UNKNOWN");
|
||||
}
|
||||
|
||||
const char *
|
||||
usb_get_manufacturer(struct usb_device *udev)
|
||||
{
|
||||
return (udev->manufacturer ? udev->manufacturer : "Unknown");
|
||||
}
|
||||
|
||||
const char *
|
||||
usb_get_product(struct usb_device *udev)
|
||||
{
|
||||
return (udev->product ? udev->product : "");
|
||||
}
|
||||
|
||||
const char *
|
||||
usb_get_serial(struct usb_device *udev)
|
||||
{
|
||||
return (udev->serial ? udev->serial : "");
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*
|
||||
* usbd_get_ep_by_addr
|
||||
*
|
||||
@ -1833,7 +1851,8 @@ usb_alloc_device(device_t parent_dev, struct usb_bus *bus,
|
||||
udev->ugen_symlink = usb_alloc_symlink(udev->ugen_name);
|
||||
|
||||
/* Announce device */
|
||||
printf("%s: <%s> at %s\n", udev->ugen_name, udev->manufacturer,
|
||||
printf("%s: <%s> at %s\n", udev->ugen_name,
|
||||
usb_get_manufacturer(udev),
|
||||
device_get_nameunit(udev->bus->bdev));
|
||||
|
||||
usb_notify_addq("ATTACH", udev);
|
||||
@ -1985,7 +2004,7 @@ usb_free_device(struct usb_device *udev, uint8_t flag)
|
||||
usb_notify_addq("DETACH", udev);
|
||||
|
||||
printf("%s: <%s> at %s (disconnected)\n", udev->ugen_name,
|
||||
udev->manufacturer, device_get_nameunit(bus->bdev));
|
||||
usb_get_manufacturer(udev), device_get_nameunit(bus->bdev));
|
||||
|
||||
/* Destroy UGEN symlink, if any */
|
||||
if (udev->ugen_symlink) {
|
||||
@ -2150,7 +2169,8 @@ usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len)
|
||||
if (udd->bDeviceClass != 0xFF) {
|
||||
snprintf(dst_ptr, dst_len, "%s %s, class %d/%d, rev %x.%02x/"
|
||||
"%x.%02x, addr %d",
|
||||
udev->manufacturer, udev->product,
|
||||
usb_get_manufacturer(udev),
|
||||
usb_get_product(udev),
|
||||
udd->bDeviceClass, udd->bDeviceSubClass,
|
||||
(bcdUSB >> 8), bcdUSB & 0xFF,
|
||||
(bcdDevice >> 8), bcdDevice & 0xFF,
|
||||
@ -2158,7 +2178,8 @@ usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len)
|
||||
} else {
|
||||
snprintf(dst_ptr, dst_len, "%s %s, rev %x.%02x/"
|
||||
"%x.%02x, addr %d",
|
||||
udev->manufacturer, udev->product,
|
||||
usb_get_manufacturer(udev),
|
||||
usb_get_product(udev),
|
||||
(bcdUSB >> 8), bcdUSB & 0xFF,
|
||||
(bcdDevice >> 8), bcdDevice & 0xFF,
|
||||
udev->address);
|
||||
@ -2397,7 +2418,7 @@ usb_notify_addq_compat(const char *type, struct usb_device *udev)
|
||||
UGETW(udev->ddesc.idProduct),
|
||||
udev->ddesc.bDeviceClass,
|
||||
udev->ddesc.bDeviceSubClass,
|
||||
udev->serial,
|
||||
usb_get_serial(udev),
|
||||
UGETW(udev->ddesc.bcdDevice),
|
||||
udev->port_no,
|
||||
udev->parent_hub != NULL ?
|
||||
@ -2437,7 +2458,7 @@ usb_notify_addq(const char *type, struct usb_device *udev)
|
||||
UGETW(udev->ddesc.idProduct),
|
||||
udev->ddesc.bDeviceClass,
|
||||
udev->ddesc.bDeviceSubClass,
|
||||
udev->serial,
|
||||
usb_get_serial(udev),
|
||||
UGETW(udev->ddesc.bcdDevice),
|
||||
(udev->flags.usb_mode == USB_MODE_HOST) ? "host" : "device",
|
||||
udev->port_no,
|
||||
@ -2476,7 +2497,7 @@ usb_notify_addq(const char *type, struct usb_device *udev)
|
||||
UGETW(udev->ddesc.idProduct),
|
||||
udev->ddesc.bDeviceClass,
|
||||
udev->ddesc.bDeviceSubClass,
|
||||
udev->serial,
|
||||
usb_get_serial(udev),
|
||||
UGETW(udev->ddesc.bcdDevice),
|
||||
(udev->flags.usb_mode == USB_MODE_HOST) ? "host" : "device",
|
||||
iface->idesc->bInterfaceNumber,
|
||||
|
@ -825,9 +825,9 @@ usb_gen_fill_deviceinfo(struct usb_fifo *f, struct usb_device_info *di)
|
||||
di->udi_bus = device_get_unit(udev->bus->bdev);
|
||||
di->udi_addr = udev->address;
|
||||
di->udi_index = udev->device_index;
|
||||
strlcpy(di->udi_serial, udev->serial, sizeof(di->udi_serial));
|
||||
strlcpy(di->udi_vendor, udev->manufacturer, sizeof(di->udi_vendor));
|
||||
strlcpy(di->udi_product, udev->product, sizeof(di->udi_product));
|
||||
strlcpy(di->udi_serial, usb_get_serial(udev), sizeof(di->udi_serial));
|
||||
strlcpy(di->udi_vendor, usb_get_manufacturer(udev), sizeof(di->udi_vendor));
|
||||
strlcpy(di->udi_product, usb_get_product(udev), sizeof(di->udi_product));
|
||||
usb_printbcd(di->udi_release, sizeof(di->udi_release),
|
||||
UGETW(udev->ddesc.bcdDevice));
|
||||
di->udi_vendorNo = UGETW(udev->ddesc.idVendor);
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usb_ioctl.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
|
||||
#define USB_DEBUG_VAR uhub_debug
|
||||
|
||||
@ -1059,7 +1060,7 @@ uhub_child_pnpinfo_string(device_t parent, device_t child,
|
||||
UGETW(res.udev->ddesc.idProduct),
|
||||
res.udev->ddesc.bDeviceClass,
|
||||
res.udev->ddesc.bDeviceSubClass,
|
||||
res.udev->serial,
|
||||
usb_get_serial(res.udev),
|
||||
UGETW(res.udev->ddesc.bcdDevice),
|
||||
iface->idesc->bInterfaceClass,
|
||||
iface->idesc->bInterfaceSubClass);
|
||||
|
@ -78,4 +78,11 @@ usb_error_t usbd_req_set_protocol(struct usb_device *udev, struct mtx *mtx,
|
||||
usb_error_t usbd_req_set_report(struct usb_device *udev, struct mtx *mtx,
|
||||
void *data, uint16_t len, uint8_t iface_index,
|
||||
uint8_t type, uint8_t id);
|
||||
|
||||
/* The following functions will not return NULL strings. */
|
||||
|
||||
const char *usb_get_manufacturer(struct usb_device *);
|
||||
const char *usb_get_product(struct usb_device *);
|
||||
const char *usb_get_serial(struct usb_device *);
|
||||
|
||||
#endif /* _USB_USBDI_UTIL_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user