From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simone Gotti Date: Sun, 11 Apr 2004 17:09:55 +0000 Subject: Re: Little script for ISAPNP hotplug Message-Id: <200404111909.55301.simone.gotti@email.it> MIME-Version: 1 Content-Type: multipart/mixed; boundary="Boundary-00=_jvXeA9cDds/zpPP" List-Id: References: <200404092044.54429.simone.gotti@email.it> In-Reply-To: <200404092044.54429.simone.gotti@email.it> To: linux-hotplug@vger.kernel.org --Boundary-00=_jvXeA9cDds/zpPP Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks to Alexander E. Patrakov that made a similar script, I've added his functions for the conversion of the string form to the ID form in the isapnp.rc script. I've also found the bottleneck that made the bash parser very slow. So NOW the C parser isn't needed anymore, and the patch for hotplug.function was removed to. Now all works only with the 2 script: isapnp.rc and isapnp.function. I can't test it with a 2.4 kernel because I don't find the .config option for enabling the procfs isapnp support. I can't find the dir /proc/usb/pnp or /proc/usb/isapnp so I can't test it, I'll try again leter. Can someone tell me what is this option? Thanks. Bye! -- Simone Gotti --Boundary-00=_jvXeA9cDds/zpPP Content-Type: application/x-shellscript; name="isapnp.agent" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="isapnp.agent" #!/bin/sh # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # ISAPNP-specific hotplug policy agent. # # This should handle 2.4.* and 2.6.* ISAPNP (for now only coldplugging), # # Kernel ISAPNP params are: # # ACTION=%s [add or remove] # ISAPNP_ID=%08X # # Copyright (C) 2004 Simone Gotti, All Rights Reserved. # # HISTORY: # # 2004/04/08 Simone Gotti first version # 2004/04/11 Simone Gotti make the modules.isapnp parsing more fast # we don't need the isapnpmodules C program anymore. # cd /etc/hotplug . ./hotplug.functions # generated by modutils, for current 2.4.x kernels MAP_CURRENT=$MODULE_DIR/modules.isapnpmap # accumulates list of modules we may care about DRIVERS= if [ "$ISAPNP_ID" = "" ]; then mesg Bad ISAPNP agent invocation exit 1 fi # # stdin is "modules.isapnpmap" syntax # on return, ONE matching module was added to $DRIVERS # isapnp_map_modules () { local module ignored # comment line lists (current) isapnp_device_id field names read ignored while read module cardvendor carddevice driver_data vendor device_function do # comments are lines that start with "#" ... # be careful, they still get parsed by bash! case "$module" in \#*) continue ;; esac : checkmatch $module id_temp=$device_function$vendor if [ $id_temp == $CHECKED_ID ]; then DRIVERS="$module $DRIVERS" : drivers $DRIVERS break fi done } # # What to do with this ISAPNP hotplug event? # case $ACTION in add) LABEL="ISAPNP id $ISAPNP_ID" CHECKED_ID="0x`echo $ISAPNP_ID | cut -b1-4`0x`echo $ISAPNP_ID | cut -b5-8`" # on 2.4 systems, modutils maintains MAP_CURRENT if [ -r $MAP_CURRENT ]; then load_drivers isapnp $MAP_CURRENT "$LABEL" fi if [ "$DRIVERS" = "" ]; then debug_mesg "... no modules for $LABEL" exit 2 fi ;; *) debug_mesg ISAPNP $ACTION event not supported exit 1 ;; esac --Boundary-00=_jvXeA9cDds/zpPP Content-Type: application/x-shellscript; name="isapnp.rc" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="isapnp.rc" #!/bin/sh # vim: syntax=sh # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # isapnp.rc mostly to recover lost boot-time isapnp hotplug events # # Copyright (C) 2004 Simone Gotti, All Rights Reserved. # # 2004/04/08 Simone Gotti (simone.gotti@email.it) # 2004/04/11 Alexander E. Patrakov (patrakov@ums.usu.ru) # Bash functions for converting ISAPNP_STRING to ID # # PATH=/sbin:/bin:/usr/sbin:/usr/bin cd /etc/hotplug . ./hotplug.functions decode_isapnp_vendor() { echo -n $1 | od -A n -t d1 | ( read A B C printf '%x\n' $(( ( ( $A & 0x3f ) << 2) | \ ( ( $B & 0x18 ) >> 3) | \ ( ( $B & 0x07 ) <<13) | \ ( ( $C & 0x1f ) << 8) )) ) } hex_swab() { echo `echo $1 | cut -b3-4``echo $1 | cut -b1-2` } isapnp_boot_events () { # make sure the isapnp agent will run ACTION=add DOCK=0/0/0 ISAPNP_SLOT=00:00 ISAPNP_ID= export ACTION DOCK ISAPNP_ID if [ -d /sys/bus ]; then # 2.6 kernels if [ -d /sys/bus/pnp/devices/ ]; then cd /sys/bus/pnp/devices/ for ISAPNP_DEVICE in *; do # read the String id value ISAPNP_STRING=`cat $ISAPNP_DEVICE/id` #convert the string in the ISAPNP_ID rawcardvendor=`echo $ISAPNP_STRING | cut -b1-3` rawcarddevice=`echo $ISAPNP_STRING | cut -b4-7` cardvendor=`decode_isapnp_vendor $rawcardvendor` carddevice=`hex_swab $rawcarddevice` ISAPNP_ID=$carddevice$cardvendor /sbin/hotplug isapnp done fi else # Check for /proc/bus/pnp/ if [ -d /proc/bus/pnp/ ]; then cat /proc/bus/pnp/devices | while read line do ISAPNP_ID=`echo $line | cut -d' ' -f2` /sbin/hotplug isapnp done # Check for /proc/bus/isapnp/ elif [ -d /proc/bus/isapnp/ ]; then cat /proc/bus/isapnp/devices | while read line do ISAPNP_ID=`echo $line | cut -d' ' -f2` /sbin/hotplug isapnp done else echo "/proc/bus/pnp/ or /proc/bus/isapnp/ not found, Is it enabled in your kernel?" fi fi return 0 } # See how we were called. case "$1" in start) isapnp_boot_events ;; stop) # echo $"isapnp stop -- ignored" ;; status) # echo $"isapnp status -- ignored" ;; restart) # always invoke by absolute path, else PATH=$PATH: $0 stop && $0 start ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac --Boundary-00=_jvXeA9cDds/zpPP-- ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel