FreeBSD kernel usb device Code
ulpt.c File Reference
#include <sys/cdefs.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/syslog.h>
#include <sys/selinfo.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include "usbdevs.h"
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
Include dependency graph for ulpt.c:

Go to the source code of this file.

Data Structures

struct  ulpt_softc
 

Macros

#define USB_DEBUG_VAR   ulpt_debug
 
#define ULPT_BSIZE   (1<<15) /* bytes */
 
#define ULPT_IFQ_MAXLEN   2 /* units */
 
#define UR_GET_DEVICE_ID   0x00
 
#define UR_GET_PORT_STATUS   0x01
 
#define UR_SOFT_RESET   0x02
 
#define LPS_NERR   0x08 /* printer no error */
 
#define LPS_SELECT   0x10 /* printer selected */
 
#define LPS_NOPAPER   0x20 /* printer out of paper */
 
#define LPS_INVERT   (LPS_SELECT|LPS_NERR)
 
#define LPS_MASK   (LPS_SELECT|LPS_NERR|LPS_NOPAPER)
 

Enumerations

enum  { ULPT_BULK_DT_WR , ULPT_BULK_DT_RD , ULPT_INTR_DT_RD , ULPT_N_TRANSFER }
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void ulpt_reset (struct ulpt_softc *)
 
static void ulpt_watchdog (void *)
 
static void ulpt_write_callback (struct usb_xfer *xfer, usb_error_t error)
 
static void ulpt_read_callback (struct usb_xfer *xfer, usb_error_t error)
 
static void ulpt_status_callback (struct usb_xfer *xfer, usb_error_t error)
 
static void ulpt_start_read (struct usb_fifo *fifo)
 
static void ulpt_stop_read (struct usb_fifo *fifo)
 
static void ulpt_start_write (struct usb_fifo *fifo)
 
static void ulpt_stop_write (struct usb_fifo *fifo)
 
static int ulpt_open (struct usb_fifo *fifo, int fflags)
 
static int unlpt_open (struct usb_fifo *fifo, int fflags)
 
static void ulpt_close (struct usb_fifo *fifo, int fflags)
 
static int ulpt_ioctl (struct usb_fifo *fifo, u_long cmd, void *data, int fflags)
 
static int ulpt_probe (device_t dev)
 
static int ulpt_attach (device_t dev)
 
static int ulpt_detach (device_t dev)
 
 DRIVER_MODULE (ulpt, uhub, ulpt_driver, ulpt_devclass, NULL, 0)
 
 MODULE_DEPEND (ulpt, usb, 1, 1, 1)
 
 MODULE_VERSION (ulpt, 1)
 
 USB_PNP_HOST_INFO (ulpt_devs)
 

Variables

static device_probe_t ulpt_probe
 
static device_attach_t ulpt_attach
 
static device_detach_t ulpt_detach
 
static usb_callback_t ulpt_write_callback
 
static usb_callback_t ulpt_read_callback
 
static usb_callback_t ulpt_status_callback
 
static usb_fifo_close_t ulpt_close
 
static usb_fifo_cmd_t ulpt_start_read
 
static usb_fifo_cmd_t ulpt_start_write
 
static usb_fifo_cmd_t ulpt_stop_read
 
static usb_fifo_cmd_t ulpt_stop_write
 
static usb_fifo_ioctl_t ulpt_ioctl
 
static usb_fifo_open_t ulpt_open
 
static usb_fifo_open_t unlpt_open
 
static struct usb_fifo_methods ulpt_fifo_methods
 
static struct usb_fifo_methods unlpt_fifo_methods
 
static const struct usb_config ulpt_config [ULPT_N_TRANSFER]
 
static const STRUCT_USB_HOST_ID ulpt_devs []
 
static devclass_t ulpt_devclass
 
static device_method_t ulpt_methods []
 
static driver_t ulpt_driver
 

Macro Definition Documentation

◆ LPS_INVERT

#define LPS_INVERT   (LPS_SELECT|LPS_NERR)

Definition at line 95 of file ulpt.c.

◆ LPS_MASK

#define LPS_MASK   (LPS_SELECT|LPS_NERR|LPS_NOPAPER)

Definition at line 96 of file ulpt.c.

◆ LPS_NERR

#define LPS_NERR   0x08 /* printer no error */

Definition at line 92 of file ulpt.c.

◆ LPS_NOPAPER

#define LPS_NOPAPER   0x20 /* printer out of paper */

Definition at line 94 of file ulpt.c.

◆ LPS_SELECT

#define LPS_SELECT   0x10 /* printer selected */

Definition at line 93 of file ulpt.c.

◆ ULPT_BSIZE

#define ULPT_BSIZE   (1<<15) /* bytes */

Definition at line 85 of file ulpt.c.

◆ ULPT_IFQ_MAXLEN

#define ULPT_IFQ_MAXLEN   2 /* units */

Definition at line 86 of file ulpt.c.

◆ UR_GET_DEVICE_ID

#define UR_GET_DEVICE_ID   0x00

Definition at line 88 of file ulpt.c.

◆ UR_GET_PORT_STATUS

#define UR_GET_PORT_STATUS   0x01

Definition at line 89 of file ulpt.c.

◆ UR_SOFT_RESET

#define UR_SOFT_RESET   0x02

Definition at line 90 of file ulpt.c.

◆ USB_DEBUG_VAR

#define USB_DEBUG_VAR   ulpt_debug

Definition at line 72 of file ulpt.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ULPT_BULK_DT_WR 
ULPT_BULK_DT_RD 
ULPT_INTR_DT_RD 
ULPT_N_TRANSFER 

Definition at line 98 of file ulpt.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DRIVER_MODULE()

DRIVER_MODULE ( ulpt  ,
uhub  ,
ulpt_driver  ,
ulpt_devclass  ,
NULL  ,
 
)

◆ MODULE_DEPEND()

MODULE_DEPEND ( ulpt  ,
usb  ,
,
,
 
)

◆ MODULE_VERSION()

MODULE_VERSION ( ulpt  ,
 
)

◆ ulpt_attach()

◆ ulpt_close()

static void ulpt_close ( struct usb_fifo fifo,
int  fflags 
)
static

Definition at line 469 of file ulpt.c.

References ulpt_softc::sc_fflags, usb_fifo_free_buffer(), and usb_fifo_softc().

Here is the call graph for this function:

◆ ulpt_detach()

static int ulpt_detach ( device_t  dev)
static

◆ ulpt_ioctl()

static int ulpt_ioctl ( struct usb_fifo fifo,
u_long  cmd,
void *  data,
int  fflags 
)
static

Definition at line 481 of file ulpt.c.

◆ ulpt_open()

static int ulpt_open ( struct usb_fifo fifo,
int  fflags 
)
static

Definition at line 416 of file ulpt.c.

References ulpt_softc::sc_fflags, ulpt_reset(), unlpt_open, and usb_fifo_softc().

Here is the call graph for this function:

◆ ulpt_probe()

static int ulpt_probe ( device_t  dev)
static

Definition at line 505 of file ulpt.c.

References dev, error, ulpt_devs, usb_attach_arg::usb_mode, USB_MODE_HOST, and usbd_lookup_id_by_uaa().

Here is the call graph for this function:

◆ ulpt_read_callback()

◆ ulpt_reset()

static void ulpt_reset ( struct ulpt_softc sc)
static

Definition at line 169 of file ulpt.c.

References req, ulpt_softc::sc_iface_no, ulpt_softc::sc_mtx, ulpt_softc::sc_udev, UR_SOFT_RESET, USB_MS_HZ, usbd_do_request_flags(), USETW, UT_WRITE_CLASS_INTERFACE, and UT_WRITE_CLASS_OTHER.

Referenced by ulpt_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ulpt_start_read()

static void ulpt_start_read ( struct usb_fifo fifo)
static

Definition at line 384 of file ulpt.c.

References ulpt_softc::sc_xfer, ULPT_BULK_DT_RD, usb_fifo_softc(), and usbd_transfer_start().

Here is the call graph for this function:

◆ ulpt_start_write()

static void ulpt_start_write ( struct usb_fifo fifo)
static

Definition at line 400 of file ulpt.c.

References ulpt_softc::sc_xfer, ULPT_BULK_DT_WR, usb_fifo_softc(), and usbd_transfer_start().

Here is the call graph for this function:

◆ ulpt_status_callback()

◆ ulpt_stop_read()

static void ulpt_stop_read ( struct usb_fifo fifo)
static

Definition at line 392 of file ulpt.c.

References ulpt_softc::sc_xfer, ULPT_BULK_DT_RD, usb_fifo_softc(), and usbd_transfer_stop().

Here is the call graph for this function:

◆ ulpt_stop_write()

static void ulpt_stop_write ( struct usb_fifo fifo)
static

Definition at line 408 of file ulpt.c.

References ulpt_softc::sc_xfer, ULPT_BULK_DT_WR, usb_fifo_softc(), and usbd_transfer_stop().

Here is the call graph for this function:

◆ ulpt_watchdog()

static void ulpt_watchdog ( void *  arg)
static

Definition at line 726 of file ulpt.c.

References ulpt_softc::sc_fflags, ulpt_softc::sc_mtx, ulpt_softc::sc_watchdog, ulpt_softc::sc_xfer, ULPT_INTR_DT_RD, ulpt_watchdog(), usb_callout_reset, and usbd_transfer_start().

Referenced by ulpt_attach(), and ulpt_watchdog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ulpt_write_callback()

◆ unlpt_open()

static int unlpt_open ( struct usb_fifo fifo,
int  fflags 
)
static

◆ USB_PNP_HOST_INFO()

USB_PNP_HOST_INFO ( ulpt_devs  )

Variable Documentation

◆ ulpt_attach

device_attach_t ulpt_attach
static

Definition at line 127 of file ulpt.c.

◆ ulpt_close

usb_fifo_close_t ulpt_close
static

Definition at line 137 of file ulpt.c.

◆ ulpt_config

const struct usb_config ulpt_config[ULPT_N_TRANSFER]
static
Initial value:
= {
.type = UE_BULK,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_OUT,
.bufsize = ULPT_BSIZE,
.flags = {.pipe_bof = 1,.proxy_buffer = 1},
.callback = &ulpt_write_callback,
},
.type = UE_BULK,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.bufsize = ULPT_BSIZE,
.flags = {.pipe_bof = 1,.short_xfer_ok = 1,.proxy_buffer = 1},
.callback = &ulpt_read_callback,
},
.type = UE_CONTROL,
.endpoint = 0x00,
.direction = UE_DIR_ANY,
.bufsize = sizeof(struct usb_device_request) + 1,
.callback = &ulpt_status_callback,
.timeout = 1000,
},
}
static usb_callback_t ulpt_write_callback
Definition: ulpt.c:130
#define ULPT_BSIZE
Definition: ulpt.c:85
static usb_callback_t ulpt_status_callback
Definition: ulpt.c:132
static usb_callback_t ulpt_read_callback
Definition: ulpt.c:131
@ ULPT_INTR_DT_RD
Definition: ulpt.c:101
@ ULPT_BULK_DT_WR
Definition: ulpt.c:99
@ ULPT_BULK_DT_RD
Definition: ulpt.c:100
#define UE_DIR_ANY
Definition: usb.h:535
#define UE_ADDR_ANY
Definition: usb.h:537
#define UE_BULK
Definition: usb.h:543
#define UE_DIR_IN
Definition: usb.h:531
#define UE_DIR_OUT
Definition: usb.h:532
#define UE_CONTROL
Definition: usb.h:541

Definition at line 354 of file ulpt.c.

Referenced by ulpt_attach().

◆ ulpt_detach

device_detach_t ulpt_detach
static

Definition at line 128 of file ulpt.c.

Referenced by ulpt_attach().

◆ ulpt_devclass

devclass_t ulpt_devclass
static

Definition at line 743 of file ulpt.c.

◆ ulpt_devs

const STRUCT_USB_HOST_ID ulpt_devs[]
static
Initial value:
= {
}
#define UIPROTO_PRINTER_1284
Definition: usb.h:465
#define UISUBCLASS_PRINTER
Definition: usb.h:462
#define UIPROTO_PRINTER_BI
Definition: usb.h:464
#define UICLASS_PRINTER
Definition: usb.h:461
#define UIPROTO_PRINTER_UNI
Definition: usb.h:463
#define USB_IFACE_SUBCLASS(isc)
Definition: usbdi.h:388
#define USB_IFACE_CLASS(ic)
Definition: usbdi.h:385
#define USB_IFACE_PROTOCOL(ip)
Definition: usbdi.h:391

Definition at line 487 of file ulpt.c.

Referenced by ulpt_probe().

◆ ulpt_driver

driver_t ulpt_driver
static
Initial value:
= {
.name = "ulpt",
.methods = ulpt_methods,
.size = sizeof(struct ulpt_softc),
}
static device_method_t ulpt_methods[]
Definition: ulpt.c:745

Definition at line 752 of file ulpt.c.

◆ ulpt_fifo_methods

struct usb_fifo_methods ulpt_fifo_methods
static
Initial value:
= {
.f_close = &ulpt_close,
.f_ioctl = &ulpt_ioctl,
.f_open = &ulpt_open,
.f_start_read = &ulpt_start_read,
.f_start_write = &ulpt_start_write,
.f_stop_read = &ulpt_stop_read,
.f_stop_write = &ulpt_stop_write,
.basename[0] = "ulpt",
}
static usb_fifo_close_t ulpt_close
Definition: ulpt.c:137
static usb_fifo_ioctl_t ulpt_ioctl
Definition: ulpt.c:142
static usb_fifo_cmd_t ulpt_start_read
Definition: ulpt.c:138
static usb_fifo_cmd_t ulpt_start_write
Definition: ulpt.c:139
static usb_fifo_cmd_t ulpt_stop_read
Definition: ulpt.c:140
static usb_fifo_cmd_t ulpt_stop_write
Definition: ulpt.c:141
static usb_fifo_open_t ulpt_open
Definition: ulpt.c:143

Definition at line 146 of file ulpt.c.

Referenced by ulpt_attach().

◆ ulpt_ioctl

usb_fifo_ioctl_t ulpt_ioctl
static

Definition at line 142 of file ulpt.c.

◆ ulpt_methods

device_method_t ulpt_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, ulpt_probe),
DEVMETHOD(device_attach, ulpt_attach),
DEVMETHOD(device_detach, ulpt_detach),
DEVMETHOD_END
}
static device_attach_t ulpt_attach
Definition: ulpt.c:127
static device_detach_t ulpt_detach
Definition: ulpt.c:128
static device_probe_t ulpt_probe
Definition: ulpt.c:126

Definition at line 745 of file ulpt.c.

◆ ulpt_open

usb_fifo_open_t ulpt_open
static

Definition at line 143 of file ulpt.c.

◆ ulpt_probe

device_probe_t ulpt_probe
static

Definition at line 126 of file ulpt.c.

◆ ulpt_read_callback

usb_callback_t ulpt_read_callback
static

Definition at line 131 of file ulpt.c.

◆ ulpt_start_read

usb_fifo_cmd_t ulpt_start_read
static

Definition at line 138 of file ulpt.c.

◆ ulpt_start_write

usb_fifo_cmd_t ulpt_start_write
static

Definition at line 139 of file ulpt.c.

◆ ulpt_status_callback

usb_callback_t ulpt_status_callback
static

Definition at line 132 of file ulpt.c.

◆ ulpt_stop_read

usb_fifo_cmd_t ulpt_stop_read
static

Definition at line 140 of file ulpt.c.

◆ ulpt_stop_write

usb_fifo_cmd_t ulpt_stop_write
static

Definition at line 141 of file ulpt.c.

◆ ulpt_write_callback

usb_callback_t ulpt_write_callback
static

Definition at line 130 of file ulpt.c.

◆ unlpt_fifo_methods

struct usb_fifo_methods unlpt_fifo_methods
static
Initial value:
= {
.f_close = &ulpt_close,
.f_ioctl = &ulpt_ioctl,
.f_open = &unlpt_open,
.f_start_read = &ulpt_start_read,
.f_start_write = &ulpt_start_write,
.f_stop_read = &ulpt_stop_read,
.f_stop_write = &ulpt_stop_write,
.basename[0] = "unlpt",
}
static usb_fifo_open_t unlpt_open
Definition: ulpt.c:144

Definition at line 157 of file ulpt.c.

Referenced by ulpt_attach().

◆ unlpt_open

usb_fifo_open_t unlpt_open
static

Definition at line 144 of file ulpt.c.

Referenced by ulpt_open().