Sync usb.h with NetBSD, apart from usb_device_info.speed, which

requires logic changes.  For now leave it as usb_device_info.lowspeed.
It will get addressed when the usb.c code is sync'd.
This commit is contained in:
joe 2002-01-02 20:16:53 +00:00
parent 59ca9f3607
commit dc37dfab78
6 changed files with 165 additions and 83 deletions

View File

@ -719,10 +719,10 @@ umass_match_proto(struct umass_softc *sc, usbd_interface_handle iface,
sc->proto |= PROTO_CBI; sc->proto |= PROTO_CBI;
#endif #endif
break; break;
case UIPROTO_MASS_BBB: case UIPROTO_MASS_BBB_OLD:
sc->proto |= PROTO_BBB; sc->proto |= PROTO_BBB;
break; break;
case UIPROTO_MASS_BBB_P: case UIPROTO_MASS_BBB:
sc->drive = ZIP_100; sc->drive = ZIP_100;
sc->proto |= PROTO_BBB; sc->proto |= PROTO_BBB;
sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED; sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED;

View File

@ -652,10 +652,10 @@ usbd_add_event(type, dev)
int s; int s;
s = splusb(); s = splusb();
if (type == USB_EVENT_DETACH) { if (type == USB_EVENT_CTRLR_DETACH) {
for (ueq = TAILQ_FIRST(&usb_events); ueq; ueq = ueq_next) { for (ueq = TAILQ_FIRST(&usb_events); ueq; ueq = ueq_next) {
ueq_next = TAILQ_NEXT(ueq, next); ueq_next = TAILQ_NEXT(ueq, next);
if (ueq->ue.ue_cookie.cookie == dev->cookie.cookie) { if (ueq->ue.u.ue_driver.ue_cookie.cookie == dev->cookie.cookie) {
TAILQ_REMOVE(&usb_events, ueq, next); TAILQ_REMOVE(&usb_events, ueq, next);
free(ueq, M_USBDEV); free(ueq, M_USBDEV);
usb_nevents--; usb_nevents--;
@ -676,8 +676,8 @@ usbd_add_event(type, dev)
return; return;
} }
ueq->ue.ue_type = type; ueq->ue.ue_type = type;
ueq->ue.ue_cookie = dev->cookie; ueq->ue.u.ue_driver.ue_cookie = dev->cookie;
usbd_fill_deviceinfo(dev, &ueq->ue.ue_device, 0); usbd_fill_deviceinfo(dev, &ueq->ue.u.ue_device, 0);
microtime(&thetime); microtime(&thetime);
TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time); TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time);
TAILQ_INSERT_TAIL(&usb_events, ueq, next); TAILQ_INSERT_TAIL(&usb_events, ueq, next);

View File

@ -1,5 +1,5 @@
/* $NetBSD: usb.h,v 1.38 1999/10/20 21:02:39 augustss Exp $ */ /* $NetBSD: usb/usb.h,v 1.60 2001/12/29 15:44:11 augustss Exp $ */
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (c) 1998 The NetBSD Foundation, Inc. * Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -79,36 +79,43 @@ MALLOC_DECLARE(M_USBHC);
/* /*
* The USB records contain some unaligned little-endian word * The USB records contain some unaligned little-endian word
* components. The U[SG]ETW macros take care of both the alignment * components. The U[SG]ETW macros take care of both the alignment
* and endian problem and should always be used to access 16 bit * and endian problem and should always be used to access non-byte
* values. * values.
*/ */
typedef u_int8_t uByte; typedef u_int8_t uByte;
typedef u_int8_t uWord[2]; typedef u_int8_t uWord[2];
typedef u_int8_t uDWord[4];
#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
#if 1
#define UGETW(w) ((w)[0] | ((w)[1] << 8)) #define UGETW(w) ((w)[0] | ((w)[1] << 8))
#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8)) #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
typedef u_int8_t uDWord[4];
#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24)) #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \ #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
(w)[1] = (u_int8_t)((v) >> 8), \ (w)[1] = (u_int8_t)((v) >> 8), \
(w)[2] = (u_int8_t)((v) >> 16), \ (w)[2] = (u_int8_t)((v) >> 16), \
(w)[3] = (u_int8_t)((v) >> 24)) (w)[3] = (u_int8_t)((v) >> 24))
#else
/* /*
* On little-endian machines that can handle unanliged accesses * On little-endian machines that can handle unanliged accesses
* (e.g. i386) these macros can be replaced by the following. * (e.g. i386) these macros can be replaced by the following.
*/ */
#if 0
#define UGETW(w) (*(u_int16_t *)(w)) #define UGETW(w) (*(u_int16_t *)(w))
#define USETW(w,v) (*(u_int16_t *)(w) = (v)) #define USETW(w,v) (*(u_int16_t *)(w) = (v))
#define UGETDW(w) (*(u_int32_t *)(w))
#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
#endif #endif
#define UPACKED __attribute__((__packed__))
typedef struct { typedef struct {
uByte bmRequestType; uByte bmRequestType;
uByte bRequest; uByte bRequest;
uWord wValue; uWord wValue;
uWord wIndex; uWord wIndex;
uWord wLength; uWord wLength;
} usb_device_request_t; } UPACKED usb_device_request_t;
#define UT_WRITE 0x00 #define UT_WRITE 0x00
#define UT_READ 0x80 #define UT_READ 0x80
@ -154,6 +161,10 @@ typedef struct {
#define UDESC_STRING 0x03 #define UDESC_STRING 0x03
#define UDESC_INTERFACE 0x04 #define UDESC_INTERFACE 0x04
#define UDESC_ENDPOINT 0x05 #define UDESC_ENDPOINT 0x05
#define UDESC_DEVICE_QUALIFIER 0x06
#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
#define UDESC_INTERFACE_POWER 0x08
#define UDESC_OTG 0x09
#define UDESC_CS_DEVICE 0x21 /* class specific */ #define UDESC_CS_DEVICE 0x21 /* class specific */
#define UDESC_CS_CONFIG 0x22 #define UDESC_CS_CONFIG 0x22
#define UDESC_CS_STRING 0x23 #define UDESC_CS_STRING 0x23
@ -170,19 +181,25 @@ typedef struct {
/* Feature numbers */ /* Feature numbers */
#define UF_ENDPOINT_HALT 0 #define UF_ENDPOINT_HALT 0
#define UF_DEVICE_REMOTE_WAKEUP 1 #define UF_DEVICE_REMOTE_WAKEUP 1
#define UF_TEST_MODE 2
#define USB_MAX_IPACKET 8 /* maximum size of the initial packet */ #define USB_MAX_IPACKET 8 /* maximum size of the initial packet */
#define USB_2_MAX_CTRL_PACKET 64
#define USB_2_MAX_BULK_PACKET 512
typedef struct { typedef struct {
uByte bLength; uByte bLength;
uByte bDescriptorType; uByte bDescriptorType;
uByte bDescriptorSubtype; uByte bDescriptorSubtype;
} usb_descriptor_t; } UPACKED usb_descriptor_t;
typedef struct { typedef struct {
uByte bLength; uByte bLength;
uByte bDescriptorType; uByte bDescriptorType;
uWord bcdUSB; uWord bcdUSB;
#define UD_USB_2_0 0x0200
#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
uByte bDeviceClass; uByte bDeviceClass;
uByte bDeviceSubClass; uByte bDeviceSubClass;
uByte bDeviceProtocol; uByte bDeviceProtocol;
@ -195,7 +212,7 @@ typedef struct {
uByte iProduct; uByte iProduct;
uByte iSerialNumber; uByte iSerialNumber;
uByte bNumConfigurations; uByte bNumConfigurations;
} usb_device_descriptor_t; } UPACKED usb_device_descriptor_t;
#define USB_DEVICE_DESCRIPTOR_SIZE 18 #define USB_DEVICE_DESCRIPTOR_SIZE 18
typedef struct { typedef struct {
@ -211,7 +228,7 @@ typedef struct {
#define UC_REMOTE_WAKEUP 0x20 #define UC_REMOTE_WAKEUP 0x20
uByte bMaxPower; /* max current in 2 mA units */ uByte bMaxPower; /* max current in 2 mA units */
#define UC_POWER_FACTOR 2 #define UC_POWER_FACTOR 2
} usb_config_descriptor_t; } UPACKED usb_config_descriptor_t;
#define USB_CONFIG_DESCRIPTOR_SIZE 9 #define USB_CONFIG_DESCRIPTOR_SIZE 9
typedef struct { typedef struct {
@ -224,7 +241,7 @@ typedef struct {
uByte bInterfaceSubClass; uByte bInterfaceSubClass;
uByte bInterfaceProtocol; uByte bInterfaceProtocol;
uByte iInterface; uByte iInterface;
} usb_interface_descriptor_t; } UPACKED usb_interface_descriptor_t;
#define USB_INTERFACE_DESCRIPTOR_SIZE 9 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
typedef struct { typedef struct {
@ -251,19 +268,23 @@ typedef struct {
#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE) #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
uWord wMaxPacketSize; uWord wMaxPacketSize;
uByte bInterval; uByte bInterval;
} usb_endpoint_descriptor_t; } UPACKED usb_endpoint_descriptor_t;
#define USB_ENDPOINT_DESCRIPTOR_SIZE 7 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
typedef struct { typedef struct {
uByte bLength; uByte bLength;
uByte bDescriptorType; uByte bDescriptorType;
uWord bString[127]; uWord bString[127];
} usb_string_descriptor_t; } UPACKED usb_string_descriptor_t;
#define USB_MAX_STRING_LEN 128 #define USB_MAX_STRING_LEN 128
#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */ #define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
/* Hub specific request */ /* Hub specific request */
#define UR_GET_BUS_STATE 0x02 #define UR_GET_BUS_STATE 0x02
#define UR_CLEAR_TT_BUFFER 0x08
#define UR_RESET_TT 0x09
#define UR_GET_TT_STATE 0x0a
#define UR_STOP_TT 0x0b
/* Hub features */ /* Hub features */
#define UHF_C_HUB_LOCAL_POWER 0 #define UHF_C_HUB_LOCAL_POWER 0
@ -280,30 +301,64 @@ typedef struct {
#define UHF_C_PORT_SUSPEND 18 #define UHF_C_PORT_SUSPEND 18
#define UHF_C_PORT_OVER_CURRENT 19 #define UHF_C_PORT_OVER_CURRENT 19
#define UHF_C_PORT_RESET 20 #define UHF_C_PORT_RESET 20
#define UHF_PORT_TEST 21
#define UHF_PORT_INDICATOR 22
typedef struct { typedef struct {
uByte bDescLength; uByte bDescLength;
uByte bDescriptorType; uByte bDescriptorType;
uByte bNbrPorts; uByte bNbrPorts;
uWord wHubCharacteristics; uWord wHubCharacteristics;
#define UHD_PWR 0x03 #define UHD_PWR 0x0003
#define UHD_PWR_GANGED 0x00 #define UHD_PWR_GANGED 0x0000
#define UHD_PWR_INDIVIDUAL 0x01 #define UHD_PWR_INDIVIDUAL 0x0001
#define UHD_PWR_NO_SWITCH 0x02 #define UHD_PWR_NO_SWITCH 0x0002
#define UHD_COMPOUND 0x04 #define UHD_COMPOUND 0x0004
#define UHD_OC 0x18 #define UHD_OC 0x0018
#define UHD_OC_GLOBAL 0x00 #define UHD_OC_GLOBAL 0x0000
#define UHD_OC_INDIVIDUAL 0x08 #define UHD_OC_INDIVIDUAL 0x0008
#define UHD_OC_NONE 0x10 #define UHD_OC_NONE 0x0010
#define UHD_TT_THINK 0x0060
#define UHD_TT_THINK_8 0x0000
#define UHD_TT_THINK_16 0x0020
#define UHD_TT_THINK_24 0x0040
#define UHD_TT_THINK_32 0x0060
#define UHD_PORT_IND 0x0080
uByte bPwrOn2PwrGood; /* delay in 2 ms units */ uByte bPwrOn2PwrGood; /* delay in 2 ms units */
#define UHD_PWRON_FACTOR 2 #define UHD_PWRON_FACTOR 2
uByte bHubContrCurrent; uByte bHubContrCurrent;
uByte DeviceRemovable[32]; /* max 255 ports */ uByte DeviceRemovable[32]; /* max 255 ports */
#define UHD_NOT_REMOV(desc, i) \ #define UHD_NOT_REMOV(desc, i) \
(((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1) (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
/* deprecated uByte PortPowerCtrlMask[]; */ /* deprecated */ uByte PortPowerCtrlMask[1];
} usb_hub_descriptor_t; } UPACKED usb_hub_descriptor_t;
#define USB_HUB_DESCRIPTOR_SIZE 8 #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
typedef struct {
uByte bLength;
uByte bDescriptorType;
uWord bcdUSB;
uByte bDeviceClass;
uByte bDeviceSubClass;
uByte bDeviceProtocol;
uByte bMaxPacketSize0;
uByte bNumConfigurations;
uByte bReserved;
} UPACKED usb_device_qualifier_t;
#define USB_DEVICE_QUALIFIER_SIZE 10
typedef struct {
uByte bLength;
uByte bDescriptorType;
uByte bmAttributes;
#define UOTG_SRP 0x01
#define UOTG_HNP 0x02
} UPACKED usb_otg_descriptor_t;
/* OTG feature selectors */
#define UOTG_B_HNP_ENABLE 3
#define UOTG_A_HNP_SUPPORT 4
#define UOTG_A_ALT_HNP_SUPPORT 5
typedef struct { typedef struct {
uWord wStatus; uWord wStatus;
@ -312,14 +367,14 @@ typedef struct {
#define UDS_REMOTE_WAKEUP 0x0002 #define UDS_REMOTE_WAKEUP 0x0002
/* Endpoint status flags */ /* Endpoint status flags */
#define UES_HALT 0x0001 #define UES_HALT 0x0001
} usb_status_t; } UPACKED usb_status_t;
typedef struct { typedef struct {
uWord wHubStatus; uWord wHubStatus;
#define UHS_LOCAL_POWER 0x0001 #define UHS_LOCAL_POWER 0x0001
#define UHS_OVER_CURRENT 0x0002 #define UHS_OVER_CURRENT 0x0002
uWord wHubChange; uWord wHubChange;
} usb_hub_status_t; } UPACKED usb_hub_status_t;
typedef struct { typedef struct {
uWord wPortStatus; uWord wPortStatus;
@ -330,13 +385,16 @@ typedef struct {
#define UPS_RESET 0x0010 #define UPS_RESET 0x0010
#define UPS_PORT_POWER 0x0100 #define UPS_PORT_POWER 0x0100
#define UPS_LOW_SPEED 0x0200 #define UPS_LOW_SPEED 0x0200
#define UPS_HIGH_SPEED 0x0400
#define UPS_PORT_TEST 0x0800
#define UPS_PORT_INDICATOR 0x1000
uWord wPortChange; uWord wPortChange;
#define UPS_C_CONNECT_STATUS 0x0001 #define UPS_C_CONNECT_STATUS 0x0001
#define UPS_C_PORT_ENABLED 0x0002 #define UPS_C_PORT_ENABLED 0x0002
#define UPS_C_SUSPEND 0x0004 #define UPS_C_SUSPEND 0x0004
#define UPS_C_OVERCURRENT_INDICATOR 0x0008 #define UPS_C_OVERCURRENT_INDICATOR 0x0008
#define UPS_C_PORT_RESET 0x0010 #define UPS_C_PORT_RESET 0x0010
} usb_port_status_t; } UPACKED usb_port_status_t;
/* Device class codes */ /* Device class codes */
#define UDCLASS_AUDIO 0x00 #define UDCLASS_AUDIO 0x00
@ -344,8 +402,11 @@ typedef struct {
#define UDCLASS_HID 0x00 #define UDCLASS_HID 0x00
#define UDCLASS_HUB 0x09 #define UDCLASS_HUB 0x09
#define UDSUBCLASS_HUB 0 #define UDSUBCLASS_HUB 0
#define UDPROTO_FSHUB 0
#define UDPROTO_HSHUBSTT 1
#define UDPROTO_HSHUBMTT 2
#define UDCLASS_MASS 0x00 #define UDCLASS_MASS 0x00
/* Interface class codes */ /* Interface class codes */
#define UICLASS_UNSPEC 0x00 #define UICLASS_UNSPEC 0x00
@ -374,6 +435,7 @@ typedef struct {
#define UISUBCLASS_PRINTER 1 #define UISUBCLASS_PRINTER 1
#define UIPROTO_PRINTER_UNI 1 #define UIPROTO_PRINTER_UNI 1
#define UIPROTO_PRINTER_BI 2 #define UIPROTO_PRINTER_BI 2
#define UIPROTO_PRINTER_1284 3
#define UICLASS_MASS 0x08 #define UICLASS_MASS 0x08
#define UISUBCLASS_RBC 1 #define UISUBCLASS_RBC 1
@ -384,11 +446,14 @@ typedef struct {
#define UISUBCLASS_SCSI 6 #define UISUBCLASS_SCSI 6
#define UIPROTO_MASS_CBI_I 0 #define UIPROTO_MASS_CBI_I 0
#define UIPROTO_MASS_CBI 1 #define UIPROTO_MASS_CBI 1
#define UIPROTO_MASS_BBB 2 #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
#define UIPROTO_MASS_BBB_P 80 /* 'P' for the Iomega Zip drive */ #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
#define UICLASS_HUB 0x09 #define UICLASS_HUB 0x09
#define UISUBCLASS_HUB 0 #define UISUBCLASS_HUB 0
#define UIPROTO_FSHUB 0
#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
#define UIPROTO_HSHUBMTT 1
#define UICLASS_CDC_DATA 0x0a #define UICLASS_CDC_DATA 0x0a
#define UISUBCLASS_DATA 0 #define UISUBCLASS_DATA 0
@ -409,6 +474,9 @@ typedef struct {
#define UICLASS_FIRM_UPD 0x0c #define UICLASS_FIRM_UPD 0x0c
#define UICLASS_APPL_SPEC 0xfe #define UICLASS_APPL_SPEC 0xfe
#define UISUBCLASS_IRDA 2
#define UIPROTO_IRDA 0
#define UICLASS_VENDOR 0xff #define UICLASS_VENDOR 0xff
@ -424,18 +492,20 @@ typedef struct {
#if 0 #if 0
/* These are the values from the spec. */ /* These are the values from the spec. */
#define USB_PORT_RESET_DELAY 10 /* ms */ #define USB_PORT_RESET_DELAY 10 /* ms */
#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
#define USB_PORT_RESET_SETTLE 10 /* ms */ #define USB_PORT_RESET_SETTLE 10 /* ms */
#define USB_PORT_POWERUP_DELAY 100 /* ms */ #define USB_PORT_POWERUP_DELAY 100 /* ms */
#define USB_SET_ADDRESS_SETTLE 2 /* ms */ #define USB_SET_ADDRESS_SETTLE 2 /* ms */
#define USB_RESUME_TIME (20*5) /* ms */ #define USB_RESUME_DELAY (20*5) /* ms */
#define USB_RESUME_WAIT 10 /* ms */ #define USB_RESUME_WAIT 10 /* ms */
#define USB_RESUME_RECOVERY 10 /* ms */ #define USB_RESUME_RECOVERY 10 /* ms */
#define USB_EXTRA_POWER_UP_TIME 0 /* ms */ #define USB_EXTRA_POWER_UP_TIME 0 /* ms */
#else #else
/* Allow for marginal (i.e. non-conforming) devices. */ /* Allow for marginal (i.e. non-conforming) devices. */
#define USB_PORT_RESET_DELAY 50 /* ms */ #define USB_PORT_RESET_DELAY 50 /* ms */
#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
#define USB_PORT_RESET_RECOVERY 50 /* ms */ #define USB_PORT_RESET_RECOVERY 50 /* ms */
#define USB_PORT_POWERUP_DELAY 200 /* ms */ #define USB_PORT_POWERUP_DELAY 300 /* ms */
#define USB_SET_ADDRESS_SETTLE 10 /* ms */ #define USB_SET_ADDRESS_SETTLE 10 /* ms */
#define USB_RESUME_DELAY (50*5) /* ms */ #define USB_RESUME_DELAY (50*5) /* ms */
#define USB_RESUME_WAIT 50 /* ms */ #define USB_RESUME_WAIT 50 /* ms */
@ -448,8 +518,9 @@ typedef struct {
#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/ #define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
#define USB_UNCONFIG_NO 0
#define USB_UNCONFIG_INDEX (-1) #define USB_UNCONFIG_NO 0
#define USB_UNCONFIG_INDEX (-1)
/*** ioctl() related stuff ***/ /*** ioctl() related stuff ***/
@ -508,26 +579,28 @@ struct usb_ctl_report_desc {
u_char data[1024]; /* filled data size will vary */ u_char data[1024]; /* filled data size will vary */
}; };
typedef struct { u_int32_t cookie; } usb_event_cookie_t;
#define USB_MAX_DEVNAMES 4
#define USB_MAX_DEVNAMELEN 16
struct usb_device_info { struct usb_device_info {
u_int8_t bus; /* bus number */ u_int8_t bus;
u_int8_t addr; /* device address */ u_int8_t addr; /* device address */
# define MAXDEVNAMELEN 10 /* number of drivers */ usb_event_cookie_t cookie;
# define MAXDEVNAMES 4 /* attached drivers */ char product[USB_MAX_STRING_LEN];
char devnames[MAXDEVNAMES][MAXDEVNAMELEN]; char vendor[USB_MAX_STRING_LEN];
/* device names */ char release[8];
char product[USB_MAX_STRING_LEN]; /* iProduct */ u_int16_t productNo;
char vendor[USB_MAX_STRING_LEN]; /* iManufacturer */ u_int16_t vendorNo;
char release[8]; /* string of releaseNo*/ u_int16_t releaseNo;
u_int16_t productNo; /* idProduct */ u_int8_t class;
u_int16_t vendorNo; /* idVendor */ u_int8_t subclass;
u_int16_t releaseNo; /* bcdDevice */ u_int8_t protocol;
u_int8_t class; /* bDeviceClass */ u_int8_t config;
u_int8_t subclass; /* bDeviceSubclass */ u_int8_t lowspeed;
u_int8_t protocol; /* bDeviceProtocol */
u_int8_t config; /* config index */
u_int8_t lowspeed; /* lowsped yes/no */
int power; /* power consumption in mA, 0 if selfpowered */ int power; /* power consumption in mA, 0 if selfpowered */
int nports; /* 0 if not hub */ int nports;
char devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
u_int8_t ports[16];/* hub only: addresses of devices on ports */ u_int8_t ports[16];/* hub only: addresses of devices on ports */
#define USB_PORT_ENABLED 0xff #define USB_PORT_ENABLED 0xff
#define USB_PORT_SUSPENDED 0xfe #define USB_PORT_SUSPENDED 0xfe
@ -544,15 +617,27 @@ struct usb_device_stats {
u_long requests[4]; /* indexed by transfer type UE_* */ u_long requests[4]; /* indexed by transfer type UE_* */
}; };
typedef struct { u_int32_t cookie; } usb_event_cookie_t;
/* Events that can be read from /dev/usb */ /* Events that can be read from /dev/usb */
struct usb_event { struct usb_event {
int ue_type; int ue_type;
#define USB_EVENT_ATTACH 1 #define USB_EVENT_CTRLR_ATTACH 1
#define USB_EVENT_DETACH 2 #define USB_EVENT_CTRLR_DETACH 2
struct usb_device_info ue_device; #define USB_EVENT_DEVICE_ATTACH 3
#define USB_EVENT_DEVICE_DETACH 4
#define USB_EVENT_DRIVER_ATTACH 5
#define USB_EVENT_DRIVER_DETACH 6
#define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH)
struct timespec ue_time; struct timespec ue_time;
usb_event_cookie_t ue_cookie; union {
struct {
int ue_bus;
} ue_ctrlr;
struct usb_device_info ue_device;
struct {
usb_event_cookie_t ue_cookie;
char ue_devname[16];
} ue_driver;
} u;
}; };
/* USB controller */ /* USB controller */
@ -567,6 +652,7 @@ struct usb_event {
#define USB_SET_IMMED _IOW ('U', 22, int) #define USB_SET_IMMED _IOW ('U', 22, int)
#define USB_GET_REPORT _IOWR('U', 23, struct usb_ctl_report) #define USB_GET_REPORT _IOWR('U', 23, struct usb_ctl_report)
#define USB_SET_REPORT _IOW ('U', 24, struct usb_ctl_report) #define USB_SET_REPORT _IOW ('U', 24, struct usb_ctl_report)
#define USB_GET_REPORT_ID _IOR ('U', 25, int)
/* Generic USB device */ /* Generic USB device */
#define USB_GET_CONFIG _IOR ('U', 100, int) #define USB_GET_CONFIG _IOR ('U', 100, int)

View File

@ -1032,7 +1032,7 @@ usbd_new_device(device_ptr_t parent, usbd_bus_handle bus, int depth,
return (err); return (err);
} }
usbd_add_event(USB_EVENT_ATTACH, dev); usbd_add_event(USB_EVENT_CTRLR_ATTACH, dev);
return (USBD_NORMAL_COMPLETION); return (USBD_NORMAL_COMPLETION);
} }
@ -1172,15 +1172,15 @@ usbd_fill_deviceinfo(usbd_device_handle dev, struct usb_device_info *di,
if (dev->subdevs != NULL) { if (dev->subdevs != NULL) {
for (i = 0; dev->subdevs[i] && for (i = 0; dev->subdevs[i] &&
i < MAXDEVNAMES; i++) { i < USB_MAX_DEVNAMES; i++) {
strncpy(di->devnames[i], USBDEVPTRNAME(dev->subdevs[i]), strncpy(di->devnames[i], USBDEVPTRNAME(dev->subdevs[i]),
MAXDEVNAMELEN); USB_MAX_DEVNAMELEN);
di->devnames[i][MAXDEVNAMELEN-1] = '\0'; di->devnames[i][USB_MAX_DEVNAMELEN-1] = '\0';
} }
} else { } else {
i = 0; i = 0;
} }
for (/*i is set */; i < MAXDEVNAMES; i++) for (/*i is set */; i < USB_MAX_DEVNAMES; i++)
di->devnames[i][0] = 0; /* empty */ di->devnames[i][0] = 0; /* empty */
if (dev->hub) { if (dev->hub) {

View File

@ -54,10 +54,6 @@
#define UR_GET_PROTOCOL 0x03 #define UR_GET_PROTOCOL 0x03
#define UR_SET_PROTOCOL 0x0b #define UR_SET_PROTOCOL 0x0b
#if defined(__FreeBSD__)
#define UPACKED __attribute__ ((packed))
#endif
typedef struct usb_hid_descriptor { typedef struct usb_hid_descriptor {
uByte bLength; uByte bLength;
uByte bDescriptorType; uByte bDescriptorType;

View File

@ -109,8 +109,8 @@ typedef struct event_name_s {
} event_name_t; } event_name_t;
event_name_t event_names[] = { event_name_t event_names[] = {
{USB_EVENT_ATTACH, "attach"}, {USB_EVENT_CTRLR_ATTACH, "attach"},
{USB_EVENT_DETACH, "detach"}, {USB_EVENT_CTRLR_DETACH, "detach"},
{0, NULL} /* NULL indicates end of list, not 0 */ {0, NULL} /* NULL indicates end of list, not 0 */
}; };
@ -560,7 +560,7 @@ print_event(struct usb_event *event)
{ {
int i; int i;
struct timespec *timespec = &event->ue_time; struct timespec *timespec = &event->ue_time;
struct usb_device_info *devinfo = &event->ue_device; struct usb_device_info *devinfo = &event->u.ue_device;
printf("%s: ", __progname); printf("%s: ", __progname);
for (i = 0; event_names[i].name != NULL; i++) { for (i = 0; event_names[i].name != NULL; i++) {
@ -585,7 +585,7 @@ print_event(struct usb_event *event)
char c = ' '; char c = ' ';
printf(" device names:"); printf(" device names:");
for (i = 0; i < MAXDEVNAMES; i++) { for (i = 0; i < USB_MAX_DEVNAMES; i++) {
if (devinfo->devnames[i][0] == '\0') if (devinfo->devnames[i][0] == '\0')
break; break;
@ -662,7 +662,7 @@ match_devname(action_t *action, struct usb_device_info *devinfo)
regmatch_t match; regmatch_t match;
int error; int error;
for (i = 0; i < MAXDEVNAMES; i++) { for (i = 0; i < USB_MAX_DEVNAMES; i++) {
if (devinfo->devnames[i][0] == '\0') if (devinfo->devnames[i][0] == '\0')
break; break;
@ -853,9 +853,9 @@ process_event_queue(int fd)
/* handle the event appropriately */ /* handle the event appropriately */
switch (event.ue_type) { switch (event.ue_type) {
case USB_EVENT_ATTACH: case USB_EVENT_CTRLR_ATTACH:
case USB_EVENT_DETACH: case USB_EVENT_CTRLR_DETACH:
if (find_action(&event.ue_device, &action_match) == 0) if (find_action(&event.u.ue_device, &action_match) == 0)
/* nothing found */ /* nothing found */
break; break;
@ -873,9 +873,9 @@ process_event_queue(int fd)
__progname, action_match.devname, strerror(errno)); __progname, action_match.devname, strerror(errno));
} }
if (event.ue_type == USB_EVENT_ATTACH && action_match.action->attach) if (event.ue_type == USB_EVENT_CTRLR_ATTACH && action_match.action->attach)
execute_command(action_match.action->attach); execute_command(action_match.action->attach);
if (event.ue_type == USB_EVENT_DETACH && action_match.action->detach) if (event.ue_type == USB_EVENT_CTRLR_DETACH && action_match.action->detach)
execute_command(action_match.action->detach); execute_command(action_match.action->detach);
break; break;