int uslcom_param(void *vsc, int portno, struct termios *t) { struct uslcom_softc *sc = (struct uslcom_softc *)vsc; usbd_status err; usb_device_request_t req; int data; if (t->c_ospeed <= 0 || t->c_ospeed > 921600) return (EINVAL); req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_BAUD_RATE; USETW(req.wValue, USLCOM_BAUD_REF / t->c_ospeed); USETW(req.wIndex, portno); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_udev, &req, NULL); if (err) return (EIO); if (ISSET(t->c_cflag, CSTOPB)) data = USLCOM_STOP_BITS_2; else data = USLCOM_STOP_BITS_1; if (ISSET(t->c_cflag, PARENB)) { if (ISSET(t->c_cflag, PARODD)) data |= USLCOM_PARITY_ODD; else data |= USLCOM_PARITY_EVEN; } else data |= USLCOM_PARITY_NONE; switch (ISSET(t->c_cflag, CSIZE)) { case CS5: data |= USLCOM_SET_DATA_BITS(5); break; case CS6: data |= USLCOM_SET_DATA_BITS(6); break; case CS7: data |= USLCOM_SET_DATA_BITS(7); break; case CS8: data |= USLCOM_SET_DATA_BITS(8); break; } req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_DATA; USETW(req.wValue, data); USETW(req.wIndex, portno); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_udev, &req, NULL); if (err) return (EIO); #if 0 /* XXX flow control */ if (ISSET(t->c_cflag, CRTSCTS)) /* rts/cts flow ctl */ } else if (ISSET(t->c_iflag, IXON|IXOFF)) {
void umct_set_baudrate(struct umct_softc *sc, u_int rate, int cts) { usb_device_request_t req; uDWord arate; u_int val; if (sc->sc_product == USB_PRODUCT_MCT_SITECOM_USB232 || sc->sc_product == USB_PRODUCT_BELKIN_F5U109) { switch (rate) { case 300: val = 0x01; break; case 600: val = 0x02; break; case 1200: val = 0x03; break; case 2400: val = 0x04; break; case 4800: val = 0x06; break; case 9600: val = 0x08; break; case 19200: val = 0x09; break; case 38400: val = 0x0a; break; case 57600: val = 0x0b; break; case 115200: val = 0x0c; break; default: val = -1; break; } } else { val = UMCT_BAUD_RATE(rate); } USETDW(arate, val); req.bmRequestType = UMCT_SET_REQUEST; req.bRequest = REQ_SET_BAUD_RATE; USETW(req.wValue, 0); USETW(req.wIndex, sc->sc_iface_number); USETW(req.wLength, LENGTH_BAUD_RATE); /* XXX should check */ (void)usbd_do_request(sc->sc_udev, &req, arate); /* unknown request, required after setting baud rate */ USETDW(arate, 0); req.bmRequestType = UMCT_SET_REQUEST; req.bRequest = REQ_UNKNOWN1; USETW(req.wValue, 0); USETW(req.wIndex, sc->sc_iface_number); USETW(req.wLength, LENGTH_UNKNOWN1); (void)usbd_do_request(sc->sc_udev, &req, arate); /* update CTS, also required after setting baud rate */ USETDW(arate, cts); req.bmRequestType = UMCT_SET_REQUEST; req.bRequest = REQ_SET_CTS; USETW(req.wValue, 0); USETW(req.wIndex, sc->sc_iface_number); USETW(req.wLength, LENGTH_SET_CTS); (void)usbd_do_request(sc->sc_udev, &req, arate); }
static int u3g_sierra_reinit(usbd_device_handle dev) { /* Some Sierra devices presents themselves as a umass device with * Windows drivers on it. After installation of the driver, it * reinits into a * 3G serial device. */ usb_device_request_t req; usb_config_descriptor_t *cdesc; /* Get the config descriptor */ cdesc = usbd_get_config_descriptor(dev); if (cdesc == NULL) return (UMATCH_NONE); req.bmRequestType = UT_VENDOR; req.bRequest = UR_SET_INTERFACE; USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); USETW(req.wIndex, UHF_PORT_CONNECTION); USETW(req.wLength, 0); (void) usbd_do_request(dev, &req, 0); return (UMATCH_HIGHEST); /* Match to prevent umass from attaching */ }
int uhidev_set_report(struct uhidev_softc *sc, int type, int id, void *data, int len) { usb_device_request_t req; char *buf = data; int actlen = len; /* Prepend the reportID. */ if (id > 0) { len++; buf = malloc(len, M_TEMP, M_WAITOK); buf[0] = id; memcpy(buf + 1, data, len - 1); } req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UR_SET_REPORT; USETW2(req.wValue, type, id); USETW(req.wIndex, sc->sc_ifaceno); USETW(req.wLength, len); if (usbd_do_request(sc->sc_udev, &req, buf)) actlen = -1; if (id > 0) free(buf, M_TEMP, len); return (actlen); }
static int moscom_open(void *vsc, int portno) { struct moscom_softc *sc = vsc; usb_device_request_t req; if (sc->sc_ucom.sc_dying) return (EIO); /* Purge FIFOs or odd things happen */ if (moscom_cmd(sc, MOSCOM_FIFO, 0x00) != 0) return (EIO); if (moscom_cmd(sc, MOSCOM_FIFO, MOSCOM_FIFO_EN | MOSCOM_FIFO_RXCLR | MOSCOM_FIFO_TXCLR | MOSCOM_FIFO_DMA_BLK | MOSCOM_FIFO_RXLVL_MASK) != 0) return (EIO); /* Magic tell device we're ready for data command */ req.bmRequestType = UT_WRITE_VENDOR_DEVICE; req.bRequest = MOSCOM_WRITE; USETW(req.wValue, 0x08); USETW(req.wIndex, MOSCOM_INT); USETW(req.wLength, 0); if (usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL) != 0) return (EIO); return (0); }
Static usbd_status uvscom_readstat(struct uvscom_softc *sc) { usb_device_request_t req; usbd_status err; uint16_t r; DPRINTF(("%s: send readstat\n", USBDEVNAME(sc->sc_dev))); req.bmRequestType = UT_READ_VENDOR_DEVICE; req.bRequest = UVSCOM_READ_STATUS; USETW(req.wValue, 0); USETW(req.wIndex, 0); USETW(req.wLength, 2); err = usbd_do_request(sc->sc_udev, &req, &r); if (err) { printf("%s: uvscom_readstat: %s\n", USBDEVNAME(sc->sc_dev), usbd_errstr(err)); return (err); } DPRINTF(("%s: uvscom_readstat: r = %d\n", USBDEVNAME(sc->sc_dev), r)); return (USBD_NORMAL_COMPLETION); }
void uslcom_set(void *vsc, int portno, int reg, int onoff) { struct uslcom_softc *sc = vsc; usb_device_request_t req; int ctl; switch (reg) { case UCOM_SET_DTR: ctl = onoff ? USLCOM_CTRL_DTR_ON : 0; ctl |= USLCOM_CTRL_DTR_SET; break; case UCOM_SET_RTS: ctl = onoff ? USLCOM_CTRL_RTS_ON : 0; ctl |= USLCOM_CTRL_RTS_SET; break; case UCOM_SET_BREAK: uslcom_break(sc, portno, onoff); return; default: return; } req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_CTRL; USETW(req.wValue, ctl); USETW(req.wIndex, portno); USETW(req.wLength, 0); usbd_do_request(sc->sc_udev, &req, NULL); }
usbd_status uplcom_set_crtscts(struct uplcom_softc *sc) { usb_device_request_t req; usbd_status err; DPRINTF(("uplcom_set_crtscts: on\n")); req.bmRequestType = UT_WRITE_VENDOR_DEVICE; req.bRequest = UPLCOM_SET_REQUEST; USETW(req.wValue, 0); if (sc->sc_type == UPLCOM_TYPE_HX) USETW(req.wIndex, UPLCOM_SET_CRTSCTS_HX); else USETW(req.wIndex, UPLCOM_SET_CRTSCTS_0); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_udev, &req, 0); if (err) { DPRINTF(("uplcom_set_crtscts: failed, err=%s\n", usbd_errstr(err))); return (err); } return (USBD_NORMAL_COMPLETION); }
usbd_status uplcom_set_line_coding(struct uplcom_softc *sc, usb_cdc_line_state_t *state) { usb_device_request_t req; usbd_status err; DPRINTF(("uplcom_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n", UGETDW(state->dwDTERate), state->bCharFormat, state->bParityType, state->bDataBits)); if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) { DPRINTF(("uplcom_set_line_coding: already set\n")); return (USBD_NORMAL_COMPLETION); } req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UCDC_SET_LINE_CODING; USETW(req.wValue, 0); USETW(req.wIndex, sc->sc_iface_number); USETW(req.wLength, UCDC_LINE_STATE_LENGTH); err = usbd_do_request(sc->sc_udev, &req, state); if (err) { DPRINTF(("uplcom_set_line_coding: failed, err=%s\n", usbd_errstr(err))); return (err); } sc->sc_line_state = *state; return (USBD_NORMAL_COMPLETION); }
usbd_status umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state) { usb_device_request_t req; usbd_status err; usb_cdc_abstract_state_t ast; DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature, state)); req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UCDC_SET_COMM_FEATURE; USETW(req.wValue, feature); USETW(req.wIndex, sc->sc_ctl_iface_no); USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH); USETW(ast.wState, state); err = usbd_do_request(sc->sc_udev, &req, &ast); if (err) { DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n", feature, usbd_errstr(err))); return (err); } return (USBD_NORMAL_COMPLETION); }
static int u3g_huawei_reinit(usbd_device_handle dev) { /* The Huawei device presents itself as a umass device with Windows * drivers on it. After installation of the driver, it reinits into a * 3G serial device. */ usb_device_request_t req; usb_config_descriptor_t *cdesc; /* Get the config descriptor */ cdesc = usbd_get_config_descriptor(dev); if (cdesc == NULL) return (UMATCH_NONE); /* One iface means umass mode, more than 1 (4 usually) means 3G mode */ if (cdesc->bNumInterface > 1) return (UMATCH_VENDOR_PRODUCT); req.bmRequestType = UT_WRITE_DEVICE; req.bRequest = UR_SET_FEATURE; USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); USETW(req.wIndex, UHF_PORT_SUSPEND); USETW(req.wLength, 0); (void) usbd_do_request(dev, &req, 0); return (UMATCH_HIGHEST); /* Match to prevent umass from attaching */ }
static int ufoma_activate_state(struct ufoma_softc *sc, int state) { usb_device_request_t req; int err; struct ucom_softc *ucom = &sc->sc_ucom; req.bmRequestType = UT_WRITE_VENDOR_INTERFACE; req.bRequest = UMCPC_ACTIVATE_MODE; USETW(req.wValue, state); USETW(req.wIndex, sc->sc_ctl_iface_no); USETW(req.wLength, 0); err = usbd_do_request(ucom->sc_udev, &req, NULL); if(err){ printf("%s:ACTIVATE:%s\n", device_get_nameunit(ucom->sc_dev), usbd_errstr(err)); return EIO; } err = tsleep(&sc->sc_currentmode, PZERO|PCATCH, "fmaact", UFOMA_MAX_TIMEOUT*hz); if(err){ printf("%s:NO response", device_get_nameunit(ucom->sc_dev)); return EIO; } if(sc->sc_currentmode != state){ return EIO; } return 0; }
void uftdi_set(void *vsc, int portno, int reg, int onoff) { struct uftdi_softc *sc = vsc; usb_device_request_t req; int ctl; DPRINTF(("uftdi_set: sc=%p, port=%d reg=%d onoff=%d\n", vsc, portno, reg, onoff)); switch (reg) { case UCOM_SET_DTR: ctl = onoff ? FTDI_SIO_SET_DTR_HIGH : FTDI_SIO_SET_DTR_LOW; break; case UCOM_SET_RTS: ctl = onoff ? FTDI_SIO_SET_RTS_HIGH : FTDI_SIO_SET_RTS_LOW; break; case UCOM_SET_BREAK: uftdi_break(sc, portno, onoff); return; default: return; } req.bmRequestType = UT_WRITE_VENDOR_DEVICE; req.bRequest = FTDI_SIO_MODEM_CTRL; USETW(req.wValue, ctl); USETW(req.wIndex, portno); USETW(req.wLength, 0); DPRINTFN(2,("uftdi_set: reqtype=0x%02x req=0x%02x value=0x%04x " "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest, UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength))); (void)usbd_do_request(sc->sc_udev, &req, NULL); }
static usbd_status uplcom_set_crtscts(struct uplcom_softc *sc) { usb_device_request_t req; usbd_status err; DPRINTF(("uplcom_set_crtscts: on\n")); req.bmRequestType = UT_WRITE_VENDOR_DEVICE; req.bRequest = UPLCOM_SET_REQUEST; USETW(req.wValue, 0); if (sc->sc_chiptype == TYPE_PL2303X) USETW(req.wIndex, UPLCOM_SET_CRTSCTS_PL2303X); else USETW(req.wIndex, UPLCOM_SET_CRTSCTS); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_ucom.sc_udev, &req, 0); if (err) { printf("%s: uplcom_set_crtscts: %s\n", device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err)); return (err); } return (USBD_NORMAL_COMPLETION); }
static int ufoma_link_state(struct ufoma_softc *sc) { usb_device_request_t req; struct ucom_softc *ucom = &sc->sc_ucom; int err; req.bmRequestType = UT_WRITE_VENDOR_INTERFACE; req.bRequest = UMCPC_SET_LINK; USETW(req.wValue, UMCPC_CM_MOBILE_ACM); USETW(req.wIndex, sc->sc_ctl_iface_no); USETW(req.wLength, sc->sc_modetable[0]); err = usbd_do_request(ucom->sc_udev, &req, sc->sc_modetable); if(err){ printf("SET_LINK:%d\n", err); return EIO; } err = tsleep(&sc->sc_currentmode, PZERO|PCATCH, "fmalnk", hz); if(err){ printf("NO response"); return EIO; } if(sc->sc_currentmode != UMCPC_ACM_MODE_DEACTIVATED){ return EIO; } return 0; }
int ubsa_request(struct ubsa_softc *sc, int portno, u_int8_t request, u_int16_t value) { usb_device_request_t req; usbd_status err; if (sc->sc_quadumts) req.bmRequestType = UT_WRITE_CLASS_INTERFACE; else req.bmRequestType = UT_WRITE_VENDOR_DEVICE; if (portno >= UBSA_MAXCONN) { printf("%s: ubsa_request: invalid port(%d)#\n", device_xname(sc->sc_dev), portno); return USBD_INVAL; } req.bRequest = request; USETW(req.wValue, value); USETW(req.wIndex, sc->sc_iface_number[portno]); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_udev, &req, 0); if (err) printf("%s: ubsa_request: %s\n", device_xname(sc->sc_dev), usbd_errstr(err)); return (err); }
void uipaq_rts(struct uipaq_softc* sc, int onoff) { usb_device_request_t req; usbd_status err; int retries = 3; DPRINTF(("%s: uipaq_rts: onoff=%x\n", device_xname(sc->sc_dev), onoff)); /* Avoid sending unnecessary requests */ if (onoff && (sc->sc_lcr & UCDC_LINE_RTS)) return; if (!onoff && !(sc->sc_lcr & UCDC_LINE_RTS)) return; req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UCDC_SET_CONTROL_LINE_STATE; sc->sc_lcr = onoff ? sc->sc_lcr | UCDC_LINE_RTS : sc->sc_lcr & ~UCDC_LINE_RTS; USETW(req.wValue, sc->sc_lcr); USETW(req.wIndex, 0x0); USETW(req.wLength, 0); while (retries) { err = usbd_do_request(sc->sc_udev, &req, NULL); if (!err) break; retries--; } }
void uipaq_dtr(struct uipaq_softc* sc, int onoff) { usb_device_request_t req; usbd_status err; int retries = 3; DPRINTF(("%s: uipaq_dtr: onoff=%x\n", device_xname(sc->sc_dev), onoff)); /* Avoid sending unnecessary requests */ if (onoff && (sc->sc_lcr & UCDC_LINE_DTR)) return; if (!onoff && !(sc->sc_lcr & UCDC_LINE_DTR)) return; /* Other parameters depend on reg */ req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UCDC_SET_CONTROL_LINE_STATE; sc->sc_lcr = onoff ? sc->sc_lcr | UCDC_LINE_DTR : sc->sc_lcr & ~UCDC_LINE_DTR; USETW(req.wValue, sc->sc_lcr); USETW(req.wIndex, 0x0); USETW(req.wLength, 0); /* Fire off the request a few times if necessary */ while (retries) { err = usbd_do_request(sc->sc_udev, &req, NULL); if (!err) break; retries--; } }
void umsm_set(void *addr, int portno, int reg, int onoff) { struct umsm_softc *sc = addr; usb_device_request_t req; int ls; switch (reg) { case UCOM_SET_DTR: if (sc->sc_dtr == onoff) return; sc->sc_dtr = onoff; break; case UCOM_SET_RTS: if (sc->sc_rts == onoff) return; sc->sc_rts = onoff; break; default: return; } /* build a usb request */ ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) | (sc->sc_rts ? UCDC_LINE_RTS : 0); req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UCDC_SET_CONTROL_LINE_STATE; USETW(req.wValue, ls); USETW(req.wIndex, sc->sc_iface_no); USETW(req.wLength, 0); (void)usbd_do_request(sc->sc_udev, &req, 0); }
static usbd_status uplcom_pl2303x_init(struct uplcom_softc *sc) { usb_device_request_t req; usbd_status err; int i; for (i = 0; i < N_PL2302X_INIT; i++) { req.bmRequestType = pl2303x[i].req_type; req.bRequest = pl2303x[i].request; USETW(req.wValue, pl2303x[i].value); USETW(req.wIndex, pl2303x[i].index); USETW(req.wLength, pl2303x[i].length); err = usbd_do_request(sc->sc_udev, &req, 0); if (err) { aprint_error_dev(sc->sc_dev, "uplcom_pl2303x_init failed: %s\n", usbd_errstr(err)); return (EIO); } } return (0); }
int ubcmtp_raw_mode(struct ubcmtp_softc *sc, int enable) { usb_device_request_t r; usbd_status err; uint8_t buf[8]; /* type 3 has no raw mode */ if (sc->dev_type->type >= UBCMTP_TYPE3) return (0); r.bRequest = UR_GET_REPORT; r.bmRequestType = UT_READ_CLASS_INTERFACE; USETW2(r.wValue, UHID_FEATURE_REPORT, 0); USETW(r.wIndex, 0); USETW(r.wLength, UBCMTP_WELLSPRING_MODE_LEN); err = usbd_do_request(sc->sc_udev, &r, buf); if (err != USBD_NORMAL_COMPLETION) { printf("%s: %s: failed to get feature report\n", sc->sc_dev.dv_xname, __func__); return (err); } /* toggle first byte and write everything back */ buf[0] = (enable ? UBCMTP_WELLSPRING_MODE_RAW : UBCMTP_WELLSPRING_MODE_HID); r.bRequest = UR_SET_REPORT; r.bmRequestType = UT_WRITE_CLASS_INTERFACE; USETW2(r.wValue, UHID_FEATURE_REPORT, 0); USETW(r.wIndex, 0); USETW(r.wLength, UBCMTP_WELLSPRING_MODE_LEN); err = usbd_do_request(sc->sc_udev, &r, buf); if (err != USBD_NORMAL_COMPLETION) { printf("%s: %s: failed to toggle raw mode\n", sc->sc_dev.dv_xname, __func__); return (err); } return (0); }
/* * uslsa_set_flow() does some magic to set up hardware flow control */ static void uslsa_set_flow(struct uslsa_softc *sc, tcflag_t cflag, tcflag_t iflag) { uint8_t mysterydata[16]; usb_device_request_t req; usbd_status err; DPRINTF(("uslsa_set_flow: cflag = 0x%x, iflag = 0x%x\n", cflag, iflag)); req.bmRequestType = USLSA_REQUEST_GET; req.bRequest = USLSA_REQ_GET_MODEM; USETW(req.wValue, 0); USETW(req.wIndex, 0); USETW(req.wLength, 16); err = usbd_do_request(sc->sc_udev, &req, mysterydata); if (err) printf("%s: uslsa_set_flow: %s\n", USBDEVNAME(sc->sc_dev), usbd_errstr(err)); if (ISSET(cflag, CRTSCTS)) { mysterydata[0] &= ~0x7b; mysterydata[0] |= 0x09; mysterydata[4] = 0x80; } else { mysterydata[0] &= ~0x7b; mysterydata[0] |= 0x01; mysterydata[4] = 0x40; } req.bmRequestType = USLSA_REQUEST_SET; req.bRequest = USLSA_REQ_SET_MODEM; USETW(req.wValue, 0); USETW(req.wIndex, 0); USETW(req.wLength, 16); err = usbd_do_request(sc->sc_udev, &req, mysterydata); if (err) printf("%s: uslsa_set_flow: %s\n", USBDEVNAME(sc->sc_dev), usbd_errstr(err)); }
/* From FreeBSD's usbdi_util.c */ usbd_status usbd_set_protocol(usbd_interface_handle iface, int report) { usb_interface_descriptor_t *id = usbd_get_interface_descriptor(iface); usbd_device_handle dev; usb_device_request_t req; usbd_interface2device_handle(iface, &dev); req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UR_SET_PROTOCOL; USETW(req.wValue, report); USETW(req.wIndex, id->bInterfaceNumber); USETW(req.wLength, 0); return (usbd_do_request(dev, &req, 0)); }
usbd_status usbd_get_hub_status(usbd_device_handle dev, usb_hub_status_t *st) { usb_device_request_t req; req.bmRequestType = UT_READ_CLASS_DEVICE; req.bRequest = UR_GET_STATUS; USETW(req.wValue, 0); USETW(req.wIndex, 0); USETW(req.wLength, sizeof(usb_hub_status_t)); return (usbd_do_request(dev, &req, st)); }
/* From FreeBSD's usbdi_util.c */ usbd_status usbd_set_idle(usbd_interface_handle iface, int duration, int id) { usb_interface_descriptor_t *ifd = usbd_get_interface_descriptor(iface); usbd_device_handle dev; usb_device_request_t req; usbd_interface2device_handle(iface, &dev); req.bmRequestType = UT_WRITE_CLASS_INTERFACE; req.bRequest = UR_SET_IDLE; USETW2(req.wValue, duration, id); USETW(req.wIndex, ifd->bInterfaceNumber); USETW(req.wLength, 0); return (usbd_do_request(dev, &req, 0)); }
usbd_status usbd_get_config(usbd_device_handle dev, u_int8_t *conf) { usb_device_request_t req; req.bmRequestType = UT_READ_DEVICE; req.bRequest = UR_GET_CONFIG; USETW(req.wValue, 0); USETW(req.wIndex, 0); USETW(req.wLength, 1); return (usbd_do_request(dev, &req, conf)); }
usbd_status usbd_set_port_feature(usbd_device_handle dev, int port, int sel) { usb_device_request_t req; req.bmRequestType = UT_WRITE_CLASS_OTHER; req.bRequest = UR_SET_FEATURE; USETW(req.wValue, sel); USETW(req.wIndex, port); USETW(req.wLength, 0); return (usbd_do_request(dev, &req, 0)); }
usbd_status usbd_clear_hub_feature(usbd_device_handle dev, int sel) { usb_device_request_t req; req.bmRequestType = UT_WRITE_CLASS_DEVICE; req.bRequest = UR_CLEAR_FEATURE; USETW(req.wValue, sel); USETW(req.wIndex, 0); USETW(req.wLength, 0); return (usbd_do_request(dev, &req, 0)); }
usbd_status usbd_get_port_status(usbd_device_handle dev, int port, usb_port_status_t *ps) { usb_device_request_t req; req.bmRequestType = UT_READ_CLASS_OTHER; req.bRequest = UR_GET_STATUS; USETW(req.wValue, 0); USETW(req.wIndex, port); USETW(req.wLength, sizeof *ps); return (usbd_do_request(dev, &req, ps)); }
usbd_status usbd_set_address(usbd_device_handle dev, int addr) { usb_device_request_t req; req.bmRequestType = UT_WRITE_DEVICE; req.bRequest = UR_SET_ADDRESS; USETW(req.wValue, addr); USETW(req.wIndex, 0); USETW(req.wLength, 0); return usbd_do_request(dev, &req, 0); }