From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Brownell Date: Sat, 24 Mar 2001 02:49:26 +0000 Subject: Re: the match_flags support MIME-Version: 1 Content-Type: multipart/mixed; boundary="----=_NextPart_000_1991_01C0B3C9.FBE71E00" Message-Id: List-Id: References: In-Reply-To: To: linux-hotplug@vger.kernel.org This is a multi-part message in MIME format. ------=_NextPart_000_1991_01C0B3C9.FBE71E00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I merged this and fixed some of the bugs. Here's the updated version of "usb.agent" ... works on one RH7 system, haven't yet tried on a distro with bash1. It's not in CVS yet (but the various cleanup-only patches are). Matt, this uses "range_lo <= bcdVersion < range_hi" for the range test. - Dave ----- Original Message ----- From: "Gioele Barabucci" To: Sent: Friday, March 09, 2001 8:07 AM Subject: the match_flags support And also this is done... As always test and retest, I have only one USB device (a non working HP scanner) untill I will take that ZIP100. -- Gioele Barabucci (Gb]) ) mailto:gioele@gioelebarabucci.com ) http://www.gioelebarabucci.com ) ) I've been and now I've gone ) ) /Magic Pie^Oasis ------=_NextPart_000_1991_01C0B3C9.FBE71E00 Content-Type: application/octet-stream; name="usb.agent" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="usb.agent" #!/bin/bash=0A= #=0A= # USB-specific hotplug policy agent.=0A= #=0A= # This should handle 2.2.18+ and 2.4.* USB hotplugging,=0A= # with a consistent framework for adding device and driver=0A= # specific treatments.=0A= #=0A= # Kernel USB hotplug params include:=0A= # =0A= # ACTION=3D%s [add or remove]=0A= # PRODUCT=3D%x/%x/%x=0A= # INTERFACE=3D%d/%d/%d=0A= # TYPE=3D%d/%d/%d=0A= #=0A= # And if usbdevfs is configured, also:=0A= #=0A= # DEVFS=3D/proc/bus/usb=0A= # DEVICE=3D/proc/bus/usb/%03d/%03d=0A= #=0A= # If usbdevfs is mounted on /proc/bus/usb, $DEVICE is a file which=0A= # can be read to get the device's current configuration descriptor.=0A= # (The "usbmodules" utility helps do that.)=0A= #=0A= # On systems using Linux 2.4.* kernels, be sure to use the right=0A= # modutils (2.4.2+). That ensures that hotplugging uses the list=0A= # of modules installed for your kernel, rather than the one that's=0A= # included here for use on systems without MODULE_DEVICE_TABLE=0A= # support.=0A= #=0A= #=0A= # HISTORY:=0A= #=0A= # 14-Mar-2001 Cleanup, bitmask the match_flags=0A= # 26-Feb-2001 Cleanup, support comments (Gioele Barabucci)=0A= # 23-Jan-2001 Update 2.2 handling; unfortunately there's no "feature=0A= # test" that can work robustly=0A= # 05-Jan-2001 Quick hack for kernel 2.4.0 and modutils 2.4.1=0A= # 03-Jan-2001 Initial version of "new" hotplug agent, using feedback=0A= # and contributions from Adam Richter, Ryan VanderBijl,=0A= # Norbert Preining, Florian Lohoff, David Brownell and=0A= # others. To replace the original /etc/usb/policy. (db)=0A= # 15-Feb-2001 Remove use of "<<" (Adam Richter)=0A= #=0A= # $Id: usb.agent,v 1.9 2001/02/28 01:03:59 dbrownell Exp $=0A= #=0A= =0A= if [ -f /etc/sysconfig/usb ]; then=0A= . /etc/sysconfig/usb=0A= if [ "$USBD_ENABLE" =3D "false" ]; then=0A= exit 0=0A= fi=0A= fi=0A= =0A= cd /etc/hotplug=0A= . hotplug.functions=0A= # DEBUG=3Dyes export DEBUG=0A= =0A= # generated by modutils, for current 2.4.x kernels=0A= MAP_CURRENT=3D$MODULE_DIR/modules.usbmap=0A= =0A= # used if MAP_CURRENT is missing; for 2.2.x kernels=0A= MAP_DISTMAP=3D$HOTPLUG_DIR/usb.distmap=0A= =0A= #=0A= # used for kernel drivers that don't show up in CURRENT or DISTMAP,=0A= # currently input drivers (joysticks, UPSs, etc) and usb storage;=0A= #=0A= MAP_HANDMAP=3D$HOTPLUG_DIR/usb.handmap=0A= =0A= #=0A= # used to run config scripts for user mode drivers (jPhoto, gPhoto2,=0A= # rio500 tools, etc) ... instead of naming kernel modules, it names=0A= # config scripts (which mustn't overlap with kernel modules). Those=0A= # could change $DEVICE permissions, etc.=0A= #=0A= MAP_USERMAP=3D$HOTPLUG_DIR/usb.usermap=0A= =0A= =0A= # accumulates list of modules we may care about=0A= DRIVERS=3D""=0A= =0A= if [ "$PRODUCT" =3D "" -o "$ACTION" =3D "" ]; then=0A= mesg Bad USB agent invocation=0A= exit 1=0A= fi=0A= =0A= # we can't "unset IFS" on bash1, so save a copy=0A= DEFAULT_IFS=3D"$IFS"=0A= =0A= #=0A= # Each modules.usbmap format line corresponds to one entry in a=0A= # MODULE_DEVICE_TABLE(usb,...) declaration in a kernel file.=0A= #=0A= # Think of it as a database column with up to three "match specs"=0A= # to associate kernel modules with particular devices or classes=0A= # of device. The match specs provide a reasonably good filtering=0A= # mechanism, but some driver probe() routines need to provide=0A= # extra filtering.=0A= #=0A= declare -i usb_idVendor usb_idProduct usb_bcdDevice=0A= declare -i usb_bDeviceClass usb_bDeviceSubClass usb_bDeviceProtocol=0A= declare -i usb_bInterfaceClass usb_bInterfaceSubClass = usb_bInterfaceProtocol=0A= =0A= usb_convert_vars ()=0A= {=0A= if [ "$AWK" =3D "" ]; then=0A= mesg "can't find awk!"=0A= exit 1=0A= fi=0A= =0A= set `echo $PRODUCT | $AWK -F/ '{print "0x" $1, "0x" $2, "0x" $3 }'` = ''=0A= usb_idVendor=3D$1=0A= usb_idProduct=3D$2=0A= usb_bcdDevice=3D$3=0A= =0A= if [ "$TYPE" !=3D "" ]; then=0A= IFS=3D/=0A= set $TYPE ''=0A= usb_bDeviceClass=3D$1=0A= usb_bDeviceSubClass=3D$2=0A= usb_bDeviceProtocol=3D$3=0A= IFS=3D"$DEFAULT_IFS"=0A= else=0A= # out-of-range values=0A= usb_bDeviceClass=3D1000=0A= usb_bDeviceSubClass=3D1000=0A= usb_bDeviceProtocol=3D1000=0A= fi=0A= =0A= if [ "$INTERFACE" !=3D "" ]; then=0A= IFS=3D/=0A= set $INTERFACE ''=0A= usb_bInterfaceClass=3D$1=0A= usb_bInterfaceSubClass=3D$2=0A= usb_bInterfaceProtocol=3D$3=0A= IFS=3D"$DEFAULT_IFS"=0A= else=0A= # out-of-range values=0A= usb_bInterfaceClass=3D1000=0A= usb_bInterfaceSubClass=3D1000=0A= usb_bInterfaceProtocol=3D1000=0A= fi=0A= }=0A= =0A= declare -i USB_MATCH_VENDOR=3D0x0001=0A= declare -i USB_MATCH_PRODUCT=3D0x0002=0A= declare -i USB_MATCH_DEV_LO=3D0x0004=0A= declare -i USB_MATCH_DEV_HI=3D0x0008=0A= declare -i USB_MATCH_DEV_CLASS=3D0x0010=0A= declare -i USB_MATCH_DEV_SUBCLASS=3D0x0020=0A= declare -i USB_MATCH_DEV_PROTOCOL=3D0x0040=0A= declare -i USB_MATCH_INT_CLASS=3D0x0080=0A= declare -i USB_MATCH_INT_SUBCLASS=3D0x0100=0A= declare -i USB_MATCH_INT_PROTOCOL=3D0x0200=0A= =0A= #=0A= # stdin is "modules.usbmap" syntax=0A= # on return, all matching modules were added to $DRIVERS=0A= #=0A= usb_map_modules ()=0A= {=0A= # convert the usb_device_id fields to integers as we read them =0A= local line module=0A= declare -i match_flags=0A= declare -i idVendor idProduct bcdDevice_lo bcdDevice_hi=0A= declare -i bDeviceClass bDeviceSubClass bDeviceProtocol=0A= declare -i bInterfaceClass bInterfaceSubClass bInterfaceProtocol=0A= =0A= # look at each usb_device_id entry=0A= # collect all matches in $DRIVERS=0A= =0A= while read line=0A= do=0A= # comments are lines that start with "#" ...=0A= # be careful, they still get parsed by bash!=0A= case "$line" in=0A= \#*) continue ;;=0A= esac=0A= =0A= set $line=0A= =0A= module=3D$1=0A= match_flags=3D$2=0A= =0A= idVendor=3D$3=0A= idProduct=3D$4=0A= bcdDevice_lo=3D$5=0A= bcdDevice_hi=3D$6=0A= =0A= bDeviceClass=3D$7=0A= bDeviceSubClass=3D$8=0A= bDeviceProtocol=3D$9=0A= =0A= shift 9=0A= bInterfaceClass=3D$1=0A= bInterfaceSubClass=3D$2=0A= bInterfaceProtocol=3D$3=0A= =0A= : checkmatch $module=0A= =0A= : idVendor $idVendor $usb_idVendor=0A= if [ $USB_MATCH_VENDOR -eq $(( $match_flags & $USB_MATCH_VENDOR = )) ] && =0A= [ $idVendor -ne $usb_idVendor ]; then=0A= continue=0A= fi=0A= =0A= : idProduct $idProduct $usb_idProduct=0A= if [ $USB_MATCH_PRODUCT -eq $(( $match_flags & $USB_MATCH_PRODUCT )) ] = &&=0A= [ $idProduct -ne $usb_idProduct ]; then=0A= continue=0A= fi=0A= =0A= : bcdDevice range $bcdDevice_hi $bcdDevice_lo actual $usb_bcdDevice=0A= if [ $USB_MATCH_DEV_LO -eq $(( $match_flags & $USB_MATCH_DEV_LO )) ] &&=0A= [ $usb_bcdDevice -lt $bcdDevice_lo ]; then=0A= continue=0A= fi=0A= =0A= # bcdDevice_lo <=3D bcdDevice < bcdDevice_hi=0A= if [ $USB_MATCH_DEV_HI -eq $(( $match_flags & $USB_MATCH_DEV_HI )) ] &&=0A= [ $usb_bcdDevice -ge $bcdDevice_hi ]; then=0A= continue=0A= fi=0A= =0A= : bDeviceClass $bDeviceClass $usb_bDeviceClass=0A= if [ $USB_MATCH_DEV_CLASS -eq $(( $match_flags & $USB_MATCH_DEV_CLASS = )) ] &&=0A= [ $bDeviceClass -ne $usb_bDeviceClass ]; then=0A= continue=0A= fi=0A= : bDeviceSubClass $bDeviceSubClass $usb_bDeviceSubClass=0A= if [ $USB_MATCH_DEV_SUBCLASS -eq $(( $match_flags & = $USB_MATCH_DEV_SUBCLASS )) ] &&=0A= [ $bDeviceSubClass -ne $usb_bDeviceSubClass ]; then=0A= continue=0A= fi=0A= : bDeviceProtocol $bDeviceProtocol $usb_bDeviceProtocol=0A= if [ $USB_MATCH_DEV_PROTOCOL -eq $(( $match_flags & = $USB_MATCH_DEV_PROTOCOL )) ] &&=0A= [ $bDeviceProtocol -ne $usb_bDeviceProtocol ]; then=0A= continue=0A= fi=0A= =0A= # NOTE: for now, this only checks the first of perhaps=0A= # several interfaces for this device.=0A= =0A= : bInterfaceClass $bInterfaceClass $usb_bInterfaceClass=0A= if [ $USB_MATCH_INT_CLASS -eq $(( $match_flags & $USB_MATCH_INT_CLASS = )) ] &&=0A= [ $bInterfaceClass -ne $usb_bInterfaceClass ]; then=0A= continue=0A= fi=0A= : bInterfaceSubClass $bInterfaceSubClass $usb_bInterfaceSubClass=0A= if [ $USB_MATCH_INT_SUBCLASS -eq $(( $match_flags & = $USB_MATCH_INT_SUBCLASS )) ] &&=0A= [ $bInterfaceSubClass -ne $usb_bInterfaceSubClass ]; then=0A= continue=0A= fi=0A= : bInterfaceProtocol $bInterfaceProtocol $usb_bInterfaceProtocol=0A= if [ $USB_MATCH_INT_PROTOCOL -eq $(( $match_flags & = $USB_MATCH_INT_PROTOCOL )) ] &&=0A= [ $bInterfaceProtocol -ne $usb_bInterfaceProtocol ]; then=0A= continue=0A= fi=0A= =0A= # It was a match!=0A= DRIVERS=3D"$module $DRIVERS"=0A= : drivers $DRIVERS=0A= done=0A= }=0A= =0A= =0A= #=0A= # What to do with this USB hotplug event?=0A= #=0A= case $ACTION in=0A= =0A= add)=0A= usb_convert_vars=0A= =0A= FOUND=3Dfalse=0A= LABEL=3D"USB product $PRODUCT"=0A= =0A= # on 2.4 systems, modutils 2.4.2+ maintains MAP_CURRENT=0A= # ... otherwise we can't rely on it (sigh)=0A= case "$KERNEL" in=0A= 2.4.*|2.5.*)=0A= if [ -r $MAP_CURRENT ]; then=0A= load_drivers usb $MAP_CURRENT "$LABEL"=0A= fi;;=0A= *)=0A= if [ -r $MAP_DISTMAP ]; then=0A= load_drivers usb $MAP_DISTMAP "$LABEL"=0A= fi;;=0A= esac=0A= if [ "$DRIVERS" !=3D "" ]; then=0A= FOUND=3Dtrue=0A= fi=0A= =0A= # cope with special driver module configurations=0A= # (mostly HID devices, until input can hotplug)=0A= if [ -r $MAP_HANDMAP ]; then=0A= load_drivers usb $MAP_HANDMAP "$LABEL"=0A= if [ "$DRIVERS" !=3D "" ]; then=0A= FOUND=3Dtrue=0A= fi=0A= fi=0A= =0A= # some devices have user-mode drivers (no kernel module, but config)=0A= if [ "$FOUND" =3D "false" -a -r $MAP_USERMAP ]; then=0A= MODPROBE=3D:=0A= load_drivers usb $MAP_USERMAP "$LABEL"=0A= if [ "$DRIVERS" !=3D "" ]; then=0A= FOUND=3Dtrue=0A= fi=0A= fi=0A= =0A= if [ "$FOUND" =3D "false" ]; then=0A= mesg "... no drivers for $LABEL"=0A= exit 2=0A= fi=0A= =0A= ;;=0A= =0A= *)=0A= mesg USB $ACTION event not supported=0A= exit 1=0A= ;;=0A= =0A= esac=0A= ------=_NextPart_000_1991_01C0B3C9.FBE71E00-- _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel