Andrew Gordon wrote this message on Fri, Oct 06, 2006 at 14:25 +0100: > Competent USB devices have serial numbers in them, although the current > FreeBSD USB system doesn't provide easy access to the data (the > kernel collects it as part of the device discovery, but AFAIR doesn't do > anything with it). I solved my problems in a different way (below).
I have grown to like how MacOSX uses the serial number for it's tty devices.. it lets me leave it attached to the device, and know when I plug it in, I know what tip device to us.... So, I decided to add this feature to FreeBSD.. The way the tty handles serial numbers should change, but this is a first cut... This should work for tty based USB device assuming that it has a serial number... -bash-2.05b$ ls /dev/*.F* /dev/cua.FTC9S0NT /dev/cua.FTC9S0NT.lock /dev/tty.FTC9S0NT.init /dev/cua.FTC9S0NT.init /dev/tty.FTC9S0NT /dev/tty.FTC9S0NT.lock -bash-2.05b$ ls /dev/*U0* /dev/cuaU0 /dev/cuaU0.lock /dev/ttyU0.init /dev/cuaU0.init /dev/ttyU0 /dev/ttyU0.lock I have attached the patch... Comments welcome... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."
==== //depot/vendor/freebsd/src/sys/dev/usb/ucom.c#46 - /home/jmg/p4/world/src/sys/dev/usb/ucom.c ==== --- /tmp/tmp.916.0 Sat Oct 7 03:31:28 2006 +++ /home/jmg/p4/world/src/sys/dev/usb/ucom.c Sat Oct 7 03:18:43 2006 @@ -150,6 +150,7 @@ int ucom_attach(struct ucom_softc *sc) { + char serial[USB_MAX_STRING_LEN]; struct tty *tp; int unit; @@ -167,8 +168,9 @@ tp->t_ioctl = ucomioctl; DPRINTF(("ucom_attach: tty_attach tp = %p\n", tp)); - - ttycreate(tp, TS_CALLOUT, "U%d", unit); + usbd_get_string(sc->sc_udev, + usbd_get_device_descriptor(sc->sc_udev)->iSerialNumber, serial); + ttycreateserial(tp, TS_CALLOUT, serial, "U%d", unit); DPRINTF(("ucom_attach: ttycreate: ttyU%d\n", unit)); return (0); ==== //depot/vendor/freebsd/src/sys/dev/usb/ucomvar.h#8 - /home/jmg/p4/world/src/sys/dev/usb/ucomvar.h ==== ==== //depot/vendor/freebsd/src/sys/dev/usb/uftdi.c#24 - /home/jmg/p4/world/src/sys/dev/usb/uftdi.c ==== --- /tmp/tmp.916.1 Sat Oct 7 03:31:28 2006 +++ /home/jmg/p4/world/src/sys/dev/usb/uftdi.c Sat Oct 7 03:11:16 2006 @@ -190,13 +190,11 @@ usbd_interface_handle iface; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; - char *devinfo; const char *devname; int i; usbd_status err; struct ucom_softc *ucom = &sc->sc_ucom; DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc)); - devinfo = malloc(1024, M_USBDEV, M_WAITOK); ucom->sc_dev = self; ucom->sc_udev = dev; @@ -222,9 +220,7 @@ iface = uaa->iface; } - usbd_devinfo(dev, 0, devinfo); /* USB_ATTACH_SETUP;*/ - printf("%s: %s\n", devname, devinfo); id = usbd_get_interface_descriptor(iface); ucom->sc_iface = iface; @@ -350,14 +346,12 @@ #endif DPRINTF(("uftdi: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no)); ucom_attach(&sc->sc_ucom); - free(devinfo, M_USBDEV); USB_ATTACH_SUCCESS_RETURN; bad: DPRINTF(("uftdi_attach: ATTACH ERROR\n")); ucom->sc_dying = 1; - free(devinfo, M_USBDEV); USB_ATTACH_ERROR_RETURN; } ==== //depot/vendor/freebsd/src/sys/kern/tty.c#106 - /home/jmg/p4/world/src/sys/kern/tty.c ==== --- /tmp/tmp.916.2 Sat Oct 7 03:31:28 2006 +++ /home/jmg/p4/world/src/sys/kern/tty.c Sat Oct 7 03:30:05 2006 @@ -2877,15 +2877,45 @@ * XXX: implement the init and lock devices by cloning. */ -int +static int ttycreate_internal(struct tty *tp, int flags, const char *tty, const char *ser); + +int +ttycreateserial(struct tty *tp, int flags, const char *ser, const char *fmt, ...) +{ + char namebuf[SPECNAMELEN - 3]; /* XXX space for "tty" */ + va_list ap; + int i; + + va_start(ap, fmt); + i = vsnrprintf(namebuf, sizeof namebuf, 32, fmt, ap); + va_end(ap); + KASSERT(i < sizeof namebuf, ("Too long tty name (%s)", namebuf)); + + return ttycreate_internal(tp, flags, namebuf, ser); +} + +int ttycreate(struct tty *tp, int flags, const char *fmt, ...) { char namebuf[SPECNAMELEN - 3]; /* XXX space for "tty" */ + va_list ap; + int i; + + va_start(ap, fmt); + i = vsnrprintf(namebuf, sizeof namebuf, 32, fmt, ap); + va_end(ap); + KASSERT(i < sizeof namebuf, ("Too long tty name (%s)", namebuf)); + + return ttycreate_internal(tp, flags, namebuf, NULL); +} + +static int +ttycreate_internal(struct tty *tp, int flags, const char *tty, const char *ser) +{ struct cdevsw *csw = NULL; int unit = 0; - va_list ap; struct cdev *cp; - int i, minor, sminor, sunit; + int minor, sminor, sunit; mtx_assert(&Giant, MA_OWNED); @@ -2906,49 +2936,58 @@ minor = unit2minor(unit); sminor = unit2minor(sunit); - va_start(ap, fmt); - i = vsnrprintf(namebuf, sizeof namebuf, 32, fmt, ap); - va_end(ap); - KASSERT(i < sizeof namebuf, ("Too long tty name (%s)", namebuf)); cp = make_dev(csw, minor, - UID_ROOT, GID_WHEEL, 0600, "tty%s", namebuf); + UID_ROOT, GID_WHEEL, 0600, "tty%s", tty); + if (ser != NULL) + make_dev_alias(cp, "tty.%s", ser); tp->t_dev = cp; tp->t_mdev = cp; cp->si_tty = tp; cp->si_drv1 = tp->t_sc; cp = make_dev(&ttys_cdevsw, sminor | MINOR_INIT, - UID_ROOT, GID_WHEEL, 0600, "tty%s.init", namebuf); + UID_ROOT, GID_WHEEL, 0600, "tty%s.init", tty); dev_depends(tp->t_dev, cp); + if (ser != NULL) + make_dev_alias(cp, "tty.%s.init", ser); cp->si_drv1 = tp->t_sc; cp->si_drv2 = &tp->t_init_in; cp->si_tty = tp; cp = make_dev(&ttys_cdevsw, sminor | MINOR_LOCK, - UID_ROOT, GID_WHEEL, 0600, "tty%s.lock", namebuf); + UID_ROOT, GID_WHEEL, 0600, "tty%s.lock", tty); dev_depends(tp->t_dev, cp); + if (ser != NULL) + make_dev_alias(cp, "tty.%s.lock", ser); cp->si_drv1 = tp->t_sc; cp->si_drv2 = &tp->t_lock_in; cp->si_tty = tp; if (flags & TS_CALLOUT) { cp = make_dev(csw, minor | MINOR_CALLOUT, - UID_UUCP, GID_DIALER, 0660, "cua%s", namebuf); + UID_UUCP, GID_DIALER, 0660, "cua%s", tty); dev_depends(tp->t_dev, cp); + if (ser != NULL) + make_dev_alias(cp, "cua.%s", ser); cp->si_drv1 = tp->t_sc; cp->si_tty = tp; cp = make_dev(&ttys_cdevsw, sminor | MINOR_CALLOUT | MINOR_INIT, - UID_UUCP, GID_DIALER, 0660, "cua%s.init", namebuf); + UID_UUCP, GID_DIALER, 0660, "cua%s.init", tty); + dev_depends(tp->t_dev, cp); + if (ser != NULL) + make_dev_alias(cp, "cua.%s.init", ser); dev_depends(tp->t_dev, cp); cp->si_drv1 = tp->t_sc; cp->si_drv2 = &tp->t_init_out; cp->si_tty = tp; cp = make_dev(&ttys_cdevsw, sminor | MINOR_CALLOUT | MINOR_LOCK, - UID_UUCP, GID_DIALER, 0660, "cua%s.lock", namebuf); + UID_UUCP, GID_DIALER, 0660, "cua%s.lock", tty); dev_depends(tp->t_dev, cp); + if (ser != NULL) + make_dev_alias(cp, "cua.%s.lock", ser); cp->si_drv1 = tp->t_sc; cp->si_drv2 = &tp->t_lock_out; cp->si_tty = tp;
_______________________________________________ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to "[EMAIL PROTECTED]"