本文整理汇总了C++中UGETW函数的典型用法代码示例。如果您正苦于以下问题:C++ UGETW函数的具体用法?C++ UGETW怎么用?C++ UGETW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UGETW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ugen_do_ioctl
//.........这里部分代码省略.........
int error;
cdesc = usbd_get_cdesc(sc->sc_udev, fd->ufd_config_index, &len);
if (cdesc == NULL)
return (EINVAL);
if (len > fd->ufd_size)
len = fd->ufd_size;
iov.iov_base = (caddr_t)fd->ufd_data;
iov.iov_len = len;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
uio.uio_resid = len;
uio.uio_offset = 0;
uio.uio_segflg = UIO_USERSPACE;
uio.uio_rw = UIO_READ;
uio.uio_procp = p;
error = uiomove((void *)cdesc, len, &uio);
free(cdesc, M_TEMP, 0);
return (error);
}
case USB_GET_STRING_DESC:
{
int len;
si = (struct usb_string_desc *)addr;
err = usbd_get_string_desc(sc->sc_udev, si->usd_string_index,
si->usd_language_id, &si->usd_desc, &len);
if (err)
return (EINVAL);
break;
}
case USB_DO_REQUEST:
{
struct usb_ctl_request *ur = (void *)addr;
int len = UGETW(ur->ucr_request.wLength);
struct iovec iov;
struct uio uio;
void *ptr = 0;
int error = 0;
if (!(flag & FWRITE))
return (EPERM);
/* Avoid requests that would damage the bus integrity. */
if ((ur->ucr_request.bmRequestType == UT_WRITE_DEVICE &&
ur->ucr_request.bRequest == UR_SET_ADDRESS) ||
(ur->ucr_request.bmRequestType == UT_WRITE_DEVICE &&
ur->ucr_request.bRequest == UR_SET_CONFIG) ||
(ur->ucr_request.bmRequestType == UT_WRITE_INTERFACE &&
ur->ucr_request.bRequest == UR_SET_INTERFACE))
return (EINVAL);
if (len < 0 || len > 32767)
return (EINVAL);
if (len != 0) {
iov.iov_base = (caddr_t)ur->ucr_data;
iov.iov_len = len;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
uio.uio_resid = len;
uio.uio_offset = 0;
uio.uio_segflg = UIO_USERSPACE;
uio.uio_rw =
ur->ucr_request.bmRequestType & UT_READ ?
UIO_READ : UIO_WRITE;
uio.uio_procp = p;
ptr = malloc(len, M_TEMP, M_WAITOK);
if (uio.uio_rw == UIO_WRITE) {
示例2: uhub_explore
int
uhub_explore(struct usbd_device *dev)
{
struct uhub_softc *sc = dev->hub->hubsoftc;
struct usbd_port *up;
int status, change;
int port;
if (usbd_is_dying(sc->sc_hub))
return (EIO);
if (!sc->sc_running)
return (ENXIO);
/* Ignore hubs that are too deep. */
if (sc->sc_hub->depth > USB_HUB_MAX_DEPTH)
return (EOPNOTSUPP);
for (port = 1; port <= sc->sc_hub->hub->nports; port++) {
up = &sc->sc_hub->hub->ports[port-1];
change = 0;
status = 0;
if ((sc->sc_status & (1 << port)) || up->reattach) {
sc->sc_status &= ~(1 << port);
if (usbd_get_port_status(dev, port, &up->status))
continue;
status = UGETW(up->status.wPortStatus);
change = UGETW(up->status.wPortChange);
DPRINTF("%s: port %d status=0x%04x change=0x%04x\n",
sc->sc_dev.dv_xname, port, status, change);
}
if (up->reattach) {
change |= UPS_C_CONNECT_STATUS;
up->reattach = 0;
}
if (change & UPS_C_PORT_ENABLED) {
usbd_clear_port_feature(sc->sc_hub, port,
UHF_C_PORT_ENABLE);
if (change & UPS_C_CONNECT_STATUS) {
/* Ignore the port error if the device
vanished. */
} else if (status & UPS_PORT_ENABLED) {
printf("%s: illegal enable change, port %d\n",
sc->sc_dev.dv_xname, port);
} else {
/* Port error condition. */
if (up->restartcnt) /* no message first time */
printf("%s: port error, restarting "
"port %d\n",
sc->sc_dev.dv_xname, port);
if (up->restartcnt++ < USBD_RESTART_MAX)
change |= UPS_C_CONNECT_STATUS;
else
printf("%s: port error, giving up "
"port %d\n",
sc->sc_dev.dv_xname, port);
}
}
if (change & UPS_C_CONNECT_STATUS) {
if (uhub_port_connect(sc, port, status, change))
continue;
/* The port set up succeeded, reset error count. */
up->restartcnt = 0;
}
if (change & UPS_C_PORT_LINK_STATE) {
usbd_clear_port_feature(sc->sc_hub, port,
UHF_C_PORT_LINK_STATE);
}
/* Recursive explore. */
if (up->device != NULL && up->device->hub != NULL)
up->device->hub->explore(up->device);
}
return (0);
}
示例3: url_rxeof
Static void
url_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
{
struct url_chain *c = priv;
struct url_softc *sc = c->url_sc;
struct ifnet *ifp = GET_IFP(sc);
struct mbuf *m;
u_int32_t total_len;
url_rxhdr_t rxhdr;
int s;
DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
if (sc->sc_dying)
return;
if (status != USBD_NORMAL_COMPLETION) {
if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
return;
sc->sc_rx_errs++;
if (usbd_ratecheck(&sc->sc_rx_notice)) {
printf("%s: %u usb errors on rx: %s\n",
USBDEVNAME(sc->sc_dev), sc->sc_rx_errs,
usbd_errstr(status));
sc->sc_rx_errs = 0;
}
if (status == USBD_STALLED) {
sc->sc_refcnt++;
usbd_clear_endpoint_stall(sc->sc_pipe_rx);
if (--sc->sc_refcnt < 0)
usb_detach_wakeup(USBDEV(sc->sc_dev));
}
goto done;
}
usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
memcpy(mtod(c->url_mbuf, char *), c->url_buf, total_len);
if (total_len <= ETHER_CRC_LEN) {
ifp->if_ierrors++;
goto done;
}
memcpy(&rxhdr, c->url_buf + total_len - ETHER_CRC_LEN, sizeof(rxhdr));
DPRINTF(("%s: RX Status: %dbytes%s%s%s%s packets\n",
USBDEVNAME(sc->sc_dev),
UGETW(rxhdr) & URL_RXHDR_BYTEC_MASK,
UGETW(rxhdr) & URL_RXHDR_VALID_MASK ? ", Valid" : "",
UGETW(rxhdr) & URL_RXHDR_RUNTPKT_MASK ? ", Runt" : "",
UGETW(rxhdr) & URL_RXHDR_PHYPKT_MASK ? ", Physical match" : "",
UGETW(rxhdr) & URL_RXHDR_MCASTPKT_MASK ? ", Multicast" : ""));
if ((UGETW(rxhdr) & URL_RXHDR_VALID_MASK) == 0) {
ifp->if_ierrors++;
goto done;
}
ifp->if_ipackets++;
total_len -= ETHER_CRC_LEN;
m = c->url_mbuf;
m->m_pkthdr.len = m->m_len = total_len;
m->m_pkthdr.rcvif = ifp;
s = splnet();
if (url_newbuf(sc, c, NULL) == ENOBUFS) {
ifp->if_ierrors++;
goto done1;
}
#if NBPFILTER > 0
if (ifp->if_bpf)
BPF_MTAP(ifp, m);
#endif
DPRINTF(("%s: %s: deliver %d\n", USBDEVNAME(sc->sc_dev),
__func__, m->m_len));
IF_INPUT(ifp, m);
done1:
splx(s);
done:
/* Setup new transfer */
usbd_setup_xfer(xfer, sc->sc_pipe_rx, c, c->url_buf, URL_BUFSZ,
USBD_SHORT_XFER_OK | USBD_NO_COPY,
USBD_NO_TIMEOUT, url_rxeof);
sc->sc_refcnt++;
usbd_transfer(xfer);
if (--sc->sc_refcnt < 0)
usb_detach_wakeup(USBDEV(sc->sc_dev));
DPRINTF(("%s: %s: start rx\n", USBDEVNAME(sc->sc_dev), __func__));
}
示例4: uftdi_attach
void
uftdi_attach(device_t parent, device_t self, void *aux)
{
struct uftdi_softc *sc = device_private(self);
struct usb_attach_arg *uaa = aux;
usbd_device_handle dev = uaa->device;
usbd_interface_handle iface;
usb_device_descriptor_t *ddesc;
usb_interface_descriptor_t *id;
usb_endpoint_descriptor_t *ed;
char *devinfop;
const char *devname = device_xname(self);
int i,idx;
usbd_status err;
struct ucom_attach_args uca;
DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
aprint_naive("\n");
aprint_normal("\n");
devinfop = usbd_devinfo_alloc(dev, 0);
aprint_normal_dev(self, "%s\n", devinfop);
usbd_devinfo_free(devinfop);
/* Move the device into the configured state. */
err = usbd_set_config_index(dev, UFTDI_CONFIG_INDEX, 1);
if (err) {
aprint_error("\n%s: failed to set configuration, err=%s\n",
devname, usbd_errstr(err));
goto bad;
}
sc->sc_dev = self;
sc->sc_udev = dev;
sc->sc_numports = 1;
sc->sc_type = UFTDI_TYPE_8U232AM; /* most devices are post-8U232AM */
sc->sc_hdrlen = 0;
if (uaa->vendor == USB_VENDOR_FTDI
&& uaa->product == USB_PRODUCT_FTDI_SERIAL_8U100AX) {
sc->sc_type = UFTDI_TYPE_SIO;
sc->sc_hdrlen = 1;
}
ddesc = usbd_get_device_descriptor(dev);
sc->sc_chiptype = UGETW(ddesc->bcdDevice);
switch (sc->sc_chiptype) {
case 0x500: /* 2232D */
case 0x700: /* 2232H */
sc->sc_numports = 2;
break;
case 0x800: /* 4232H */
sc->sc_numports = 4;
break;
case 0x200: /* 232/245AM */
case 0x400: /* 232/245BL */
case 0x600: /* 232/245R */
default:
break;
}
for (idx = UFTDI_IFACE_INDEX; idx < sc->sc_numports; idx++) {
err = usbd_device2interface_handle(dev, idx, &iface);
if (err) {
aprint_error(
"\n%s: failed to get interface idx=%d, err=%s\n",
devname, idx, usbd_errstr(err));
goto bad;
}
id = usbd_get_interface_descriptor(iface);
sc->sc_iface[idx] = iface;
uca.bulkin = uca.bulkout = -1;
uca.ibufsize = uca.obufsize = 0;
for (i = 0; i < id->bNumEndpoints; i++) {
int addr, dir, attr;
ed = usbd_interface2endpoint_descriptor(iface, i);
if (ed == NULL) {
aprint_error_dev(self,
"could not read endpoint descriptor: %s\n",
usbd_errstr(err));
goto bad;
}
addr = ed->bEndpointAddress;
dir = UE_GET_DIR(ed->bEndpointAddress);
attr = ed->bmAttributes & UE_XFERTYPE;
if (dir == UE_DIR_IN && attr == UE_BULK) {
uca.bulkin = addr;
uca.ibufsize = UGETW(ed->wMaxPacketSize);
if (uca.ibufsize >= UFTDI_MAX_IBUFSIZE)
uca.ibufsize = UFTDI_MAX_IBUFSIZE;
} else if (dir == UE_DIR_OUT && attr == UE_BULK) {
uca.bulkout = addr;
uca.obufsize = UGETW(ed->wMaxPacketSize)
- sc->sc_hdrlen;
if (uca.obufsize >= UFTDI_MAX_OBUFSIZE)
uca.obufsize = UFTDI_MAX_OBUFSIZE;
//.........这里部分代码省略.........
示例5: ugensa_attach
static int
ugensa_attach(device_t self)
{
struct ugensa_softc *sc = device_get_softc(self);
struct usb_attach_arg *uaa = device_get_ivars(self);
struct ucom_softc *ucom;
usb_interface_descriptor_t *id;
usb_endpoint_descriptor_t *ed;
int i;
ucom = &sc->sc_ucom;
bzero(sc, sizeof (struct ugensa_softc));
ucom->sc_dev = self;
ucom->sc_udev = uaa->device;
ucom->sc_iface = uaa->iface;
id = usbd_get_interface_descriptor(ucom->sc_iface);
sc->sc_iface_no = id->bInterfaceNumber;
ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
for (i = 0; i < id->bNumEndpoints; i++) {
ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
if (ed == NULL) {
device_printf(ucom->sc_dev, "no endpoint descriptor "
"found for %d\n", i);
goto error;
}
if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
sc->sc_intr_number = ed->bEndpointAddress;
sc->sc_isize = UGETW(ed->wMaxPacketSize);
} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
ucom->sc_bulkin_no = ed->bEndpointAddress;
else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
ucom->sc_bulkout_no = ed->bEndpointAddress;
}
if (ucom->sc_bulkin_no == -1 || ucom->sc_bulkout_no == -1) {
device_printf(ucom->sc_dev, "missing endpoint\n");
goto error;
}
sc->sc_dtr = sc->sc_rts = -1;
ucom->sc_parent = sc;
ucom->sc_portno = UCOM_UNK_PORTNO;
ucom->sc_ibufsize = UGENSABUFSZ;
ucom->sc_obufsize = UGENSABUFSZ;
ucom->sc_ibufsizepad = UGENSABUFSZ;
ucom->sc_opkthdrlen = 0;
ucom->sc_callback = &ugensa_callback;
usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
ucom->sc_dev);
DPRINTF(("%s: in = 0x%x, out = 0x%x\n",
device_get_nameunit(ucom->sc_dev), ucom->sc_bulkin_no,
ucom->sc_bulkout_no));
ucom_attach(&sc->sc_ucom);
return 0;
error:
ucom->sc_dying = 1;
return ENXIO;
}
示例6: usb_hw_ep_get_needs
/*------------------------------------------------------------------------*
* usb_hw_ep_get_needs
*
* This function will figure out the type and number of endpoints
* which are needed for an USB configuration.
*
* Return values:
* 0: Success.
* Else: Failure.
*------------------------------------------------------------------------*/
static uint8_t
usb_hw_ep_get_needs(struct usb_hw_ep_scratch *ues,
uint8_t ep_type, uint8_t is_complete)
{
const struct usb_hw_ep_profile *pf;
struct usb_hw_ep_scratch_sub *ep_iface;
struct usb_hw_ep_scratch_sub *ep_curr;
struct usb_hw_ep_scratch_sub *ep_max;
struct usb_hw_ep_scratch_sub *ep_end;
struct usb_descriptor *desc;
struct usb_interface_descriptor *id;
struct usb_endpoint_descriptor *ed;
enum usb_dev_speed speed;
uint16_t wMaxPacketSize;
uint16_t temp;
uint8_t ep_no;
ep_iface = ues->ep_max;
ep_curr = ues->ep_max;
ep_end = ues->ep + USB_EP_MAX;
ep_max = ues->ep_max;
desc = NULL;
speed = usbd_get_speed(ues->udev);
repeat:
while ((desc = usb_desc_foreach(ues->cd, desc))) {
if ((desc->bDescriptorType == UDESC_INTERFACE) &&
(desc->bLength >= sizeof(*id))) {
id = (void *)desc;
if (id->bAlternateSetting == 0) {
/* going forward */
ep_iface = ep_max;
} else {
/* reset */
ep_curr = ep_iface;
}
}
if ((desc->bDescriptorType == UDESC_ENDPOINT) &&
(desc->bLength >= sizeof(*ed))) {
ed = (void *)desc;
goto handle_endpoint_desc;
}
}
ues->ep_max = ep_max;
return (0);
handle_endpoint_desc:
temp = (ed->bmAttributes & UE_XFERTYPE);
if (temp == ep_type) {
if (ep_curr == ep_end) {
/* too many endpoints */
return (1); /* failure */
}
wMaxPacketSize = UGETW(ed->wMaxPacketSize);
if ((wMaxPacketSize & 0xF800) &&
(speed == USB_SPEED_HIGH)) {
/* handle packet multiplier */
temp = (wMaxPacketSize >> 11) & 3;
wMaxPacketSize &= 0x7FF;
if (temp == 1) {
wMaxPacketSize *= 2;
} else {
wMaxPacketSize *= 3;
}
}
/*
* Check if we have a fixed endpoint number, else the
* endpoint number is allocated dynamically:
*/
ep_no = (ed->bEndpointAddress & UE_ADDR);
if (ep_no != 0) {
/* get HW endpoint profile */
(ues->methods->get_hw_ep_profile)
(ues->udev, &pf, ep_no);
if (pf == NULL) {
/* HW profile does not exist - failure */
DPRINTFN(0, "Endpoint profile %u "
"does not exist\n", ep_no);
return (1);
}
/* reserve fixed endpoint number */
//.........这里部分代码省略.........
示例7: usbd_fill_iface_data
usbd_status
usbd_fill_iface_data(struct usbd_device *dev, int ifaceidx, int altidx)
{
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
struct usbd_interface *ifc = &dev->ud_ifaces[ifaceidx];
usb_interface_descriptor_t *idesc;
char *p, *end;
int endpt, nendpt;
DPRINTFN(4, "ifaceidx=%d altidx=%d", ifaceidx, altidx, 0, 0);
idesc = usbd_find_idesc(dev->ud_cdesc, ifaceidx, altidx);
if (idesc == NULL)
return USBD_INVAL;
ifc->ui_dev = dev;
ifc->ui_idesc = idesc;
ifc->ui_index = ifaceidx;
ifc->ui_altindex = altidx;
nendpt = ifc->ui_idesc->bNumEndpoints;
DPRINTFN(4, "found idesc nendpt=%d", nendpt, 0, 0, 0);
if (nendpt != 0) {
ifc->ui_endpoints = kmem_alloc(nendpt * sizeof(struct usbd_endpoint),
KM_SLEEP);
if (ifc->ui_endpoints == NULL)
return USBD_NOMEM;
} else
ifc->ui_endpoints = NULL;
ifc->ui_priv = NULL;
p = (char *)ifc->ui_idesc + ifc->ui_idesc->bLength;
end = (char *)dev->ud_cdesc + UGETW(dev->ud_cdesc->wTotalLength);
#define ed ((usb_endpoint_descriptor_t *)p)
for (endpt = 0; endpt < nendpt; endpt++) {
DPRINTFN(10, "endpt=%d", endpt, 0, 0, 0);
for (; p < end; p += ed->bLength) {
DPRINTFN(10, "p=%p end=%p len=%d type=%d",
p, end, ed->bLength, ed->bDescriptorType);
if (p + ed->bLength <= end && ed->bLength != 0 &&
ed->bDescriptorType == UDESC_ENDPOINT)
goto found;
if (ed->bLength == 0 ||
ed->bDescriptorType == UDESC_INTERFACE)
break;
}
/* passed end, or bad desc */
printf("usbd_fill_iface_data: bad descriptor(s): %s\n",
ed->bLength == 0 ? "0 length" :
ed->bDescriptorType == UDESC_INTERFACE ? "iface desc":
"out of data");
goto bad;
found:
ifc->ui_endpoints[endpt].ue_edesc = ed;
if (dev->ud_speed == USB_SPEED_HIGH) {
u_int mps;
/* Control and bulk endpoints have max packet limits. */
switch (UE_GET_XFERTYPE(ed->bmAttributes)) {
case UE_CONTROL:
mps = USB_2_MAX_CTRL_PACKET;
goto check;
case UE_BULK:
mps = USB_2_MAX_BULK_PACKET;
check:
if (UGETW(ed->wMaxPacketSize) != mps) {
USETW(ed->wMaxPacketSize, mps);
#ifdef DIAGNOSTIC
printf("usbd_fill_iface_data: bad max "
"packet size\n");
#endif
}
break;
default:
break;
}
}
ifc->ui_endpoints[endpt].ue_refcnt = 0;
ifc->ui_endpoints[endpt].ue_toggle = 0;
p += ed->bLength;
}
#undef ed
LIST_INIT(&ifc->ui_pipes);
return USBD_NORMAL_COMPLETION;
bad:
if (ifc->ui_endpoints != NULL) {
kmem_free(ifc->ui_endpoints, nendpt * sizeof(struct usbd_endpoint));
ifc->ui_endpoints = NULL;
}
return USBD_INVAL;
}
示例8: usbd_set_config_index
usbd_status
usbd_set_config_index(struct usbd_device *dev, int index, int msg)
{
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
usb_config_descriptor_t cd, *cdp;
usb_bos_descriptor_t *bdp = NULL;
usbd_status err;
int i, ifcidx, nifc, len, selfpowered, power;
DPRINTFN(5, "dev=%p index=%d", dev, index, 0, 0);
if (index >= dev->ud_ddesc.bNumConfigurations &&
index != USB_UNCONFIG_INDEX) {
/* panic? */
printf("usbd_set_config_index: illegal index\n");
return USBD_INVAL;
}
/* XXX check that all interfaces are idle */
if (dev->ud_config != USB_UNCONFIG_NO) {
DPRINTF("free old config", 0, 0, 0, 0);
/* Free all configuration data structures. */
nifc = dev->ud_cdesc->bNumInterface;
for (ifcidx = 0; ifcidx < nifc; ifcidx++)
usbd_free_iface_data(dev, ifcidx);
kmem_free(dev->ud_ifaces, nifc * sizeof(struct usbd_interface));
kmem_free(dev->ud_cdesc, UGETW(dev->ud_cdesc->wTotalLength));
if (dev->ud_bdesc != NULL)
kmem_free(dev->ud_bdesc,
UGETW(dev->ud_bdesc->wTotalLength));
dev->ud_ifaces = NULL;
dev->ud_cdesc = NULL;
dev->ud_bdesc = NULL;
dev->ud_config = USB_UNCONFIG_NO;
}
if (index == USB_UNCONFIG_INDEX) {
/* We are unconfiguring the device, so leave unallocated. */
DPRINTF("set config 0", 0, 0, 0, 0);
err = usbd_set_config(dev, USB_UNCONFIG_NO);
if (err) {
DPRINTF("setting config=0 failed, err = %d", err,
0, 0, 0);
}
return err;
}
/* Get the short descriptor. */
err = usbd_get_config_desc(dev, index, &cd);
if (err) {
DPRINTF("get_config_desc=%d", err, 0, 0, 0);
return err;
}
len = UGETW(cd.wTotalLength);
cdp = kmem_alloc(len, KM_SLEEP);
if (cdp == NULL)
return USBD_NOMEM;
/* Get the full descriptor. Try a few times for slow devices. */
for (i = 0; i < 3; i++) {
err = usbd_get_desc(dev, UDESC_CONFIG, index, len, cdp);
if (!err)
break;
usbd_delay_ms(dev, 200);
}
if (err) {
DPRINTF("get_desc=%d", err, 0, 0, 0);
goto bad;
}
if (cdp->bDescriptorType != UDESC_CONFIG) {
DPRINTF("bad desc %d", cdp->bDescriptorType, 0, 0, 0);
err = USBD_INVAL;
goto bad;
}
if (USB_IS_SS(dev->ud_speed)) {
usb_bos_descriptor_t bd;
/* get short bos desc */
err = usbd_get_bos_desc(dev, index, &bd);
if (!err) {
int blen = UGETW(bd.wTotalLength);
bdp = kmem_alloc(blen, KM_SLEEP);
if (bdp == NULL) {
err = USBD_NOMEM;
goto bad;
}
/* Get the full desc */
for (i = 0; i < 3; i++) {
err = usbd_get_desc(dev, UDESC_BOS, index, blen,
bdp);
if (!err)
break;
usbd_delay_ms(dev, 200);
}
if (err || bdp->bDescriptorType != UDESC_BOS) {
DPRINTF("error %d or bad desc %d", err,
bdp->bDescriptorType, 0, 0);
kmem_free(bdp, blen);
//.........这里部分代码省略.........
示例9: usbd_fill_deviceinfo
void
usbd_fill_deviceinfo(struct usbd_device *dev, struct usb_device_info *di,
int usedev)
{
struct usbd_port *p;
int i, j, err;
di->udi_bus = device_unit(dev->ud_bus->ub_usbctl);
di->udi_addr = dev->ud_addr;
di->udi_cookie = dev->ud_cookie;
usbd_devinfo_vp(dev, di->udi_vendor, sizeof(di->udi_vendor),
di->udi_product, sizeof(di->udi_product), usedev, 1);
usbd_printBCD(di->udi_release, sizeof(di->udi_release),
UGETW(dev->ud_ddesc.bcdDevice));
if (usedev) {
usbd_status uerr = usbd_get_string(dev,
dev->ud_ddesc.iSerialNumber, di->udi_serial);
if (uerr != USBD_NORMAL_COMPLETION) {
di->udi_serial[0] = '\0';
} else {
usbd_trim_spaces(di->udi_serial);
}
} else {
di->udi_serial[0] = '\0';
if (dev->ud_serial) {
strlcpy(di->udi_serial, dev->ud_serial,
sizeof(di->udi_serial));
}
}
di->udi_vendorNo = UGETW(dev->ud_ddesc.idVendor);
di->udi_productNo = UGETW(dev->ud_ddesc.idProduct);
di->udi_releaseNo = UGETW(dev->ud_ddesc.bcdDevice);
di->udi_class = dev->ud_ddesc.bDeviceClass;
di->udi_subclass = dev->ud_ddesc.bDeviceSubClass;
di->udi_protocol = dev->ud_ddesc.bDeviceProtocol;
di->udi_config = dev->ud_config;
di->udi_power = dev->ud_selfpowered ? 0 : dev->ud_power;
di->udi_speed = dev->ud_speed;
if (dev->ud_subdevlen > 0) {
for (i = 0, j = 0; i < dev->ud_subdevlen &&
j < USB_MAX_DEVNAMES; i++) {
if (!dev->ud_subdevs[i])
continue;
strncpy(di->udi_devnames[j],
device_xname(dev->ud_subdevs[i]), USB_MAX_DEVNAMELEN);
di->udi_devnames[j][USB_MAX_DEVNAMELEN-1] = '\0';
j++;
}
} else {
j = 0;
}
for (/* j is set */; j < USB_MAX_DEVNAMES; j++)
di->udi_devnames[j][0] = 0; /* empty */
if (!dev->ud_hub) {
di->udi_nports = 0;
return;
}
const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts;
for (i = 0; i < __arraycount(di->udi_ports) && i < nports; i++) {
p = &dev->ud_hub->uh_ports[i];
if (p->up_dev)
err = p->up_dev->ud_addr;
else {
int s = UGETW(p->up_status.wPortStatus);
if (s & UPS_PORT_ENABLED)
err = USB_PORT_ENABLED;
else if (s & UPS_SUSPEND)
err = USB_PORT_SUSPENDED;
/*
* Note: UPS_PORT_POWER_SS is available only
* on 3.x, and UPS_PORT_POWER is available
* only on 2.0 or 1.1.
*/
else if (USB_IS_SS(dev->ud_speed) &&
(s & UPS_PORT_POWER_SS))
err = USB_PORT_POWERED;
else if (s & UPS_PORT_POWER)
err = USB_PORT_POWERED;
else
err = USB_PORT_DISABLED;
}
di->udi_ports[i] = err;
}
di->udi_nports = nports;
}
示例10: usbd_fill_deviceinfo_old
void
usbd_fill_deviceinfo_old(struct usbd_device *dev, struct usb_device_info_old *di,
int usedev)
{
struct usbd_port *p;
int i, j, err;
di->udi_bus = device_unit(dev->ud_bus->ub_usbctl);
di->udi_addr = dev->ud_addr;
di->udi_cookie = dev->ud_cookie;
usbd_devinfo_vp(dev, di->udi_vendor, sizeof(di->udi_vendor),
di->udi_product, sizeof(di->udi_product), usedev, 0);
usbd_printBCD(di->udi_release, sizeof(di->udi_release),
UGETW(dev->ud_ddesc.bcdDevice));
di->udi_vendorNo = UGETW(dev->ud_ddesc.idVendor);
di->udi_productNo = UGETW(dev->ud_ddesc.idProduct);
di->udi_releaseNo = UGETW(dev->ud_ddesc.bcdDevice);
di->udi_class = dev->ud_ddesc.bDeviceClass;
di->udi_subclass = dev->ud_ddesc.bDeviceSubClass;
di->udi_protocol = dev->ud_ddesc.bDeviceProtocol;
di->udi_config = dev->ud_config;
di->udi_power = dev->ud_selfpowered ? 0 : dev->ud_power;
di->udi_speed = dev->ud_speed;
if (dev->ud_subdevlen > 0) {
for (i = 0, j = 0; i < dev->ud_subdevlen &&
j < USB_MAX_DEVNAMES; i++) {
if (!dev->ud_subdevs[i])
continue;
strncpy(di->udi_devnames[j],
device_xname(dev->ud_subdevs[i]), USB_MAX_DEVNAMELEN);
di->udi_devnames[j][USB_MAX_DEVNAMELEN-1] = '\0';
j++;
}
} else {
j = 0;
}
for (/* j is set */; j < USB_MAX_DEVNAMES; j++)
di->udi_devnames[j][0] = 0; /* empty */
if (!dev->ud_hub) {
di->udi_nports = 0;
return;
}
const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts;
for (i = 0; i < __arraycount(di->udi_ports) && i < nports;
i++) {
p = &dev->ud_hub->uh_ports[i];
if (p->up_dev)
err = p->up_dev->ud_addr;
else {
int s = UGETW(p->up_status.wPortStatus);
if (s & UPS_PORT_ENABLED)
err = USB_PORT_ENABLED;
else if (s & UPS_SUSPEND)
err = USB_PORT_SUSPENDED;
else if (s & UPS_PORT_POWER)
err = USB_PORT_POWERED;
else
err = USB_PORT_DISABLED;
}
di->udi_ports[i] = err;
}
di->udi_nports = nports;
}
示例11: usbd_new_device
//.........这里部分代码省略.........
for (i = 0; i < 10; i++) {
/* Get the first 8 bytes of the device descriptor. */
err = usbd_get_initial_ddesc(dev, dd);
if (!err)
break;
usbd_delay_ms(dev, 200);
if ((i & 3) == 3)
usbd_reset_port(up->up_parent, port, &ps);
}
if (err) {
DPRINTF("addr=%d, getting first desc failed: %d", addr, err,
0, 0);
usbd_remove_device(dev, up);
return err;
}
/* Windows resets the port here, do likewise */
if (up->up_parent)
usbd_reset_port(up->up_parent, port, &ps);
if (speed == USB_SPEED_HIGH) {
/* Max packet size must be 64 (sec 5.5.3). */
if (dd->bMaxPacketSize != USB_2_MAX_CTRL_PACKET) {
#ifdef DIAGNOSTIC
printf("usbd_new_device: addr=%d bad max packet "
"size=%d. adjusting to %d.\n",
addr, dd->bMaxPacketSize, USB_2_MAX_CTRL_PACKET);
#endif
dd->bMaxPacketSize = USB_2_MAX_CTRL_PACKET;
}
}
DPRINTF("adding unit addr=%d, rev=%02x, class=%d, subclass=%d", addr,
UGETW(dd->bcdUSB), dd->bDeviceClass, dd->bDeviceSubClass);
DPRINTF("protocol=%d, maxpacket=%d, len=%d, speed=%d",
dd->bDeviceProtocol, dd->bMaxPacketSize, dd->bLength, dev->ud_speed);
if (dd->bDescriptorType != UDESC_DEVICE) {
/* Illegal device descriptor */
DPRINTF("illegal descriptor %d", dd->bDescriptorType, 0, 0, 0);
usbd_remove_device(dev, up);
return USBD_INVAL;
}
if (dd->bLength < USB_DEVICE_DESCRIPTOR_SIZE) {
DPRINTF("bad length %d", dd->bLength, 0, 0, 0);
usbd_remove_device(dev, up);
return USBD_INVAL;
}
USETW(dev->ud_ep0desc.wMaxPacketSize, dd->bMaxPacketSize);
/* Re-establish the default pipe with the new MPS. */
usbd_kill_pipe(dev->ud_pipe0);
err = usbd_setup_pipe_flags(dev, 0, &dev->ud_ep0, USBD_DEFAULT_INTERVAL,
&dev->ud_pipe0, USBD_MPSAFE);
if (err) {
DPRINTF("setup default pipe failed err %d", err, 0, 0, 0);
usbd_remove_device(dev, up);
return err;
}
/* Set the address */
DPRINTFN(5, "setting device address=%d", addr, 0, 0, 0);
err = usbd_set_address(dev, addr);
if (err) {
示例12: uirda_set_params
int
uirda_set_params(void *h, struct irda_params *p)
{
struct uirda_softc *sc = h;
usbd_status err;
int i;
u_int8_t hdr;
u_int32_t n;
u_int mask;
DPRINTF(("%s: sc=%p, speed=%d ebofs=%d maxsize=%d\n", __func__,
sc, p->speed, p->ebofs, p->maxsize));
if (sc->sc_dying)
return (EIO);
hdr = 0;
if (p->ebofs != sc->sc_params.ebofs) {
/* round up ebofs */
mask = 1 /* sc->sc_irdadesc.bmAdditionalBOFs*/;
DPRINTF(("u.s.p.: mask=0x%x, sc->ebofs=%d, p->ebofs=%d\n",
mask, sc->sc_params.ebofs, p->ebofs));
for (i = 0; i < UIRDA_NEBOFS; i++) {
DPRINTF(("u.s.p.: u_e[%d].mask=0x%x, count=%d\n",
i, uirda_ebofs[i].mask, uirda_ebofs[i].count));
if ((mask & uirda_ebofs[i].mask) &&
uirda_ebofs[i].count >= p->ebofs) {
hdr = uirda_ebofs[i].header;
goto found1;
}
}
for (i = 0; i < UIRDA_NEBOFS; i++) {
DPRINTF(("u.s.p.: u_e[%d].mask=0x%x, count=%d\n",
i, uirda_ebofs[i].mask, uirda_ebofs[i].count));
if ((mask & uirda_ebofs[i].mask)) {
hdr = uirda_ebofs[i].header;
goto found1;
}
}
/* no good value found */
return (EINVAL);
found1:
DPRINTF(("uirda_set_params: ebofs hdr=0x%02x\n", hdr));
;
}
if (hdr != 0 || p->speed != sc->sc_params.speed) {
/* find speed */
mask = UGETW(sc->sc_irdadesc.wBaudRate);
for (i = 0; i < UIRDA_NSPEEDS; i++) {
if ((mask & uirda_speeds[i].mask) &&
uirda_speeds[i].speed == p->speed) {
hdr |= uirda_speeds[i].header;
goto found2;
}
}
/* no good value found */
return (EINVAL);
found2:
DPRINTF(("uirda_set_params: speed hdr=0x%02x\n", hdr));
;
}
if (p->maxsize != sc->sc_params.maxsize) {
if (p->maxsize > IRDA_MAX_FRAME_SIZE)
return (EINVAL);
sc->sc_params.maxsize = p->maxsize;
#if 0
DPRINTF(("%s: new buffers, old size=%d\n", __func__,
sc->sc_params.maxsize));
if (p->maxsize > 10000 || p < 0) /* XXX */
return (EINVAL);
/* Change the write buffer */
mutex_enter(&sc->sc_wr_buf_lk);
if (sc->sc_wr_buf != NULL)
usbd_free_buffer(sc->sc_wr_xfer);
sc->sc_wr_buf = usbd_alloc_buffer(sc->sc_wr_xfer, p->maxsize+1);
mutex_exit(&sc->sc_wr_buf_lk);
if (sc->sc_wr_buf == NULL)
return (ENOMEM);
/* Change the read buffer */
mutex_enter(&sc->sc_rd_buf_lk);
usbd_abort_pipe(sc->sc_rd_pipe);
if (sc->sc_rd_buf != NULL)
usbd_free_buffer(sc->sc_rd_xfer);
sc->sc_rd_buf = usbd_alloc_buffer(sc->sc_rd_xfer, p->maxsize+1);
sc->sc_rd_count = 0;
if (sc->sc_rd_buf == NULL) {
mutex_exit(&sc->sc_rd_buf_lk);
return (ENOMEM);
}
sc->sc_params.maxsize = p->maxsize;
err = uirda_start_read(sc); /* XXX check */
mutex_exit(&sc->sc_rd_buf_lk);
#endif
}
if (hdr != 0 && hdr != sc->sc_wr_hdr) {
/*
* A change has occurred, transmit a 0 length frame with
//.........这里部分代码省略.........
示例13: udsir_attach
static void
udsir_attach(device_t parent, device_t self, void *aux)
{
struct udsir_softc *sc = device_private(self);
struct usbif_attach_arg *uaa = aux;
usbd_device_handle dev = uaa->device;
usbd_interface_handle iface = uaa->iface;
char *devinfop;
usb_endpoint_descriptor_t *ed;
uint8_t epcount;
int i;
struct ir_attach_args ia;
DPRINTFN(10, ("udsir_attach: sc=%p\n", sc));
sc->sc_dev = self;
aprint_naive("\n");
aprint_normal("\n");
devinfop = usbd_devinfo_alloc(dev, 0);
aprint_normal_dev(self, "%s\n", devinfop);
usbd_devinfo_free(devinfop);
sc->sc_udev = dev;
sc->sc_iface = iface;
epcount = 0;
(void)usbd_endpoint_count(iface, &epcount);
sc->sc_rd_addr = -1;
sc->sc_wr_addr = -1;
for (i = 0; i < epcount; i++) {
ed = usbd_interface2endpoint_descriptor(iface, i);
if (ed == NULL) {
aprint_error_dev(self, "couldn't get ep %d\n", i);
return;
}
if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
sc->sc_rd_addr = ed->bEndpointAddress;
sc->sc_rd_maxpsz = UGETW(ed->wMaxPacketSize);
} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
sc->sc_wr_addr = ed->bEndpointAddress;
sc->sc_wr_maxpsz = UGETW(ed->wMaxPacketSize);
}
}
if (sc->sc_rd_addr == -1 || sc->sc_wr_addr == -1) {
aprint_error_dev(self, "missing endpoint\n");
return;
}
DPRINTFN(10, ("udsir_attach: %p\n", sc->sc_udev));
usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
sc->sc_dev);
ia.ia_type = IR_TYPE_IRFRAME;
ia.ia_methods = &udsir_methods;
ia.ia_handle = sc;
sc->sc_child = config_found(self, &ia, ir_print);
selinit(&sc->sc_rd_sel);
selinit(&sc->sc_wr_sel);
return;
}
示例14: usbd_attachinterfaces
static usbd_status
usbd_attachinterfaces(device_t parent, struct usbd_device *dev,
int port, const int *locators)
{
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
struct usbif_attach_arg uiaa;
int ilocs[USBIFIFCF_NLOCS];
usb_device_descriptor_t *dd = &dev->ud_ddesc;
int nifaces;
struct usbd_interface **ifaces;
int i, j, loc;
device_t dv;
nifaces = dev->ud_cdesc->bNumInterface;
ifaces = kmem_zalloc(nifaces * sizeof(*ifaces), KM_SLEEP);
if (!ifaces)
return USBD_NOMEM;
for (i = 0; i < nifaces; i++) {
if (!dev->ud_subdevs[i]) {
ifaces[i] = &dev->ud_ifaces[i];
}
DPRINTF("interface %d %p", i, ifaces[i], 0, 0);
}
uiaa.uiaa_device = dev;
uiaa.uiaa_port = port;
uiaa.uiaa_vendor = UGETW(dd->idVendor);
uiaa.uiaa_product = UGETW(dd->idProduct);
uiaa.uiaa_release = UGETW(dd->bcdDevice);
uiaa.uiaa_configno = dev->ud_cdesc->bConfigurationValue;
uiaa.uiaa_ifaces = ifaces;
uiaa.uiaa_nifaces = nifaces;
ilocs[USBIFIFCF_PORT] = uiaa.uiaa_port;
ilocs[USBIFIFCF_VENDOR] = uiaa.uiaa_vendor;
ilocs[USBIFIFCF_PRODUCT] = uiaa.uiaa_product;
ilocs[USBIFIFCF_RELEASE] = uiaa.uiaa_release;
ilocs[USBIFIFCF_CONFIGURATION] = uiaa.uiaa_configno;
for (i = 0; i < nifaces; i++) {
if (!ifaces[i]) {
DPRINTF("interface %d claimed", i, 0, 0, 0);
continue; /* interface already claimed */
}
uiaa.uiaa_iface = ifaces[i];
uiaa.uiaa_class = ifaces[i]->ui_idesc->bInterfaceClass;
uiaa.uiaa_subclass = ifaces[i]->ui_idesc->bInterfaceSubClass;
uiaa.uiaa_proto = ifaces[i]->ui_idesc->bInterfaceProtocol;
uiaa.uiaa_ifaceno = ifaces[i]->ui_idesc->bInterfaceNumber;
DPRINTF("searching for interface %d...", i, 0, 0, 0);
DPRINTF("class %x subclass %x proto %x ifaceno %d",
uiaa.uiaa_class, uiaa.uiaa_subclass, uiaa.uiaa_proto,
uiaa.uiaa_ifaceno);
ilocs[USBIFIFCF_INTERFACE] = uiaa.uiaa_ifaceno;
if (locators != NULL) {
loc = locators[USBIFIFCF_CONFIGURATION];
if (loc != USBIFIFCF_CONFIGURATION_DEFAULT &&
loc != uiaa.uiaa_configno)
continue;
loc = locators[USBIFIFCF_INTERFACE];
if (loc != USBIFIFCF_INTERFACE_DEFAULT &&
loc != uiaa.uiaa_ifaceno)
continue;
}
KERNEL_LOCK(1, NULL);
dv = config_found_sm_loc(parent, "usbifif", ilocs, &uiaa,
usbd_ifprint, config_stdsubmatch);
KERNEL_UNLOCK_ONE(NULL);
if (!dv)
continue;
usbd_serialnumber(dv, dev);
/* claim */
ifaces[i] = NULL;
/* account for ifaces claimed by the driver behind our back */
for (j = 0; j < nifaces; j++) {
if (!ifaces[j] && !dev->ud_subdevs[j]) {
DPRINTF("interface %d claimed behind our back",
j, 0, 0, 0);
dev->ud_subdevs[j] = dv;
dev->ud_nifaces_claimed++;
}
}
}
kmem_free(ifaces, nifaces * sizeof(*ifaces));
return USBD_NORMAL_COMPLETION;
}
示例15: uhub_explore
/*
****************************************************************
* Varre as portas de uma unidade *
****************************************************************
*/
int
uhub_explore (struct usbd_device *dev)
{
struct usb_hub_descriptor *hd = &dev->hub->hubdesc;
struct uhub_softc *sc = dev->hub->hubsoftc;
struct usbd_port *up;
int err, speed;
int port, change, status;
#ifdef USB_MSG
printf ("uhub_explore (%s)\n", sc->sc_dev->nameunit);
printf ("uhub_explore: dev= %P addr = %d\n", dev, dev->address);
#endif USB_MSG
if (sc->sc_running == 0)
return (USBD_NOT_STARTED);
if (dev->depth > USB_HUB_MAX_DEPTH)
return (USBD_TOO_DEEP);
for (port = 1; port <= hd->bNbrPorts; port++)
{
up = &dev->hub->ports[port - 1];
if (err = usbd_get_port_status (dev, port, &up->status))
{
printf
( "uhub_explore (%s): erro ao ler o estado da porta %d (%s)\n",
sc->sc_dev->nameunit, port, usbd_errstr (err)
);
continue;
}
status = UGETW (up->status.wPortStatus);
change = UGETW (up->status.wPortChange);
#ifdef USB_MSG
printf
( "uhub_explore (%s) porta %d status = 0x%04X change = 0x%04X\n",
sc->sc_dev->nameunit, port, status, change
);
#endif USB_MSG
if (change & UPS_C_PORT_ENABLED)
{
#ifdef USB_MSG
printf ("uhub_explore: C_PORT_ENABLED\n");
#endif USB_MSG
usbd_clear_port_feature (dev, port, UHF_C_PORT_ENABLE);
if (change & UPS_C_CONNECT_STATUS)
{
/* Ignore the port error if the device vanished. */
#ifdef USB_MSG
printf
( "uhub_explore (%s): ignorando erro, porta %d\n",
sc->sc_dev->nameunit, port
);
#endif USB_MSG
}
elif (status & UPS_PORT_ENABLED)
{
printf
( "uhub_explore (%s): mudança inválida de habilitação, porta %d\n",
sc->sc_dev->nameunit, port
);
}
else
{
/* Port error condition */
if (up->restartcnt) /* no message first time */