sys/netgraph7/bluetooth/drivers/ubtbcmfw/ubtbcmfw.c
static int
ubtbcmfw_write(struct cdev *dev, struct uio *uio, int flag)
{
	ubtbcmfw_softc_p	sc = NULL;
	u_int8_t		buf[UBTBCMFW_BSIZE];
	usbd_xfer_handle	xfer;
	usbd_status		err;
	int			n, error = 0;

	sc = devclass_get_softc(ubtbcmfw_devclass, UBTBCMFW_UNIT(dev));
	if (sc == NULL || sc->sc_dying)
		return (ENXIO);

	if (UBTBCMFW_ENDPOINT(dev) != UBTBCMFW_BULK_OUT)
		return (EOPNOTSUPP);
	if (sc->sc_bulk_out_pipe == NULL)
		return (ENXIO);

	xfer = usbd_alloc_xfer(sc->sc_udev);
	if (xfer == NULL)
		return (ENOMEM);

	sc->sc_refcnt ++;

	while ((n = (int)szmin(sizeof(buf), uio->uio_resid)) != 0) {
		error = uiomove(buf, (size_t)n, uio);
		if (error != 0)
			break;

		err = usbd_bulk_transfer(xfer, sc->sc_bulk_out_pipe,
				0, USBD_DEFAULT_TIMEOUT, buf, &n, "bcmwr");
		switch (err) {
		case USBD_NORMAL_COMPLETION:
			break;

		case USBD_INTERRUPTED:
			error = EINTR;
			break;

		case USBD_TIMEOUT:
			error = ETIMEDOUT;
			break;

		default:
			error = EIO;
			break;
		}

		if (error != 0)
			break;
	}

	usbd_free_xfer(xfer);

	if (-- sc->sc_refcnt < 0)
		usb_detach_wakeup(sc->sc_dev);

	return (error);
}
/*
 * Write into the endpoint device
 * XXX FIXME softc locking
 */
Write into the endpoint device
XXX FIXME softc locking
Write into the endpoint device XXX FIXME softc locking
static int
ubtbcmfw_write(struct cdev *dev, struct uio *uio, int flag)
{
	ubtbcmfw_softc_p	sc = NULL;
	u_int8_t		buf[UBTBCMFW_BSIZE];
	usbd_xfer_handle	xfer;
	usbd_status		err;
	int			n, error = 0;
	sc = devclass_get_softc(ubtbcmfw_devclass, UBTBCMFW_UNIT(dev));
	if (sc == NULL || sc->sc_dying)
		return (ENXIO);
	if (UBTBCMFW_ENDPOINT(dev) != UBTBCMFW_BULK_OUT)
		return (EOPNOTSUPP);
	if (sc->sc_bulk_out_pipe == NULL)
		return (ENXIO);
	xfer = usbd_alloc_xfer(sc->sc_udev);
	if (xfer == NULL)
		return (ENOMEM);
	sc->sc_refcnt ++;
	while ((n = (int)szmin(sizeof(buf), uio->uio_resid)) != 0) {
		error = uiomove(buf, (size_t)n, uio);
		if (error != 0)
			break;
		err = usbd_bulk_transfer(xfer, sc->sc_bulk_out_pipe,
				0, USBD_DEFAULT_TIMEOUT, buf, &n, "bcmwr");
		switch (err) {
		case USBD_NORMAL_COMPLETION:
			break;
		case USBD_INTERRUPTED:
			error = EINTR;
			break;
		case USBD_TIMEOUT:
			error = ETIMEDOUT;
			break;
		default:
			error = EIO;
			break;
		}
		if (error != 0)
			break;
	}
	usbd_free_xfer(xfer);
	if (-- sc->sc_refcnt < 0)
		usb_detach_wakeup(sc->sc_dev);
	return (error);
}
static int ubtbcmfw_write ( struct cdev * dev , struct uio * uio , int flag ) { ubtbcmfw_softc_p sc = NULL ; u_int8_t buf [ UBTBCMFW_BSIZE ] ; usbd_xfer_handle xfer ; usbd_status err ; int n , error = 0 ; sc = devclass_get_softc ( ubtbcmfw_devclass , UBTBCMFW_UNIT ( dev ) ) ; if ( sc == NULL || sc -> sc_dying ) return ( ENXIO ) ; if ( UBTBCMFW_ENDPOINT ( dev ) != UBTBCMFW_BULK_OUT ) return ( EOPNOTSUPP ) ; if ( sc -> sc_bulk_out_pipe == NULL ) return ( ENXIO ) ; xfer = usbd_alloc_xfer ( sc -> sc_udev ) ; if ( xfer == NULL ) return ( ENOMEM ) ; sc -> sc_refcnt ++ ; while ( ( n = ( int ) szmin ( sizeof ( buf ) , uio -> uio_resid ) ) != 0 ) { error = uiomove ( buf , ( size_t ) n , uio ) ; if ( error != 0 ) break ; err = usbd_bulk_transfer ( xfer , sc -> sc_bulk_out_pipe , 0 , USBD_DEFAULT_TIMEOUT , buf , & n , " " ) ; switch ( err ) { case USBD_NORMAL_COMPLETION : break ; case USBD_INTERRUPTED : error = EINTR ; break ; case USBD_TIMEOUT : error = ETIMEDOUT ; break ; default : error = EIO ; break ; } if ( error != 0 ) break ; } usbd_free_xfer ( xfer ) ; if ( -- sc -> sc_refcnt < 0 ) usb_detach_wakeup ( sc -> sc_dev ) ; return ( error ) ; }
Write into the endpoint device
 XXX FIXME softc locking
Write into the endpoint device XXX FIXME softc locking