source: udev/input_device.sh@ 82d6361

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 82d6361 was 7e161ea, checked in by Jim Gifford <clfs@…>, 19 years ago

r833@server (orig r831): jim | 2005-12-05 10:42:24 -0800
Added: udev package for Cross-LFS. Work in Progress

  • Property mode set to 100755
File size: 7.7 KB
Line 
1#!/bin/bash
2# $Id$
3#
4# input-device specific hotplug policy agent.
5#
6# This should handle 2.6.* input hotplugging,
7# with a consistent framework for adding device and driver
8# specific handling.
9#
10# Normally, adding a input device will modprobe handler(s) for
11# this device.
12#
13# Kernel input hotplug params include (not all of them may be available):
14#
15# ACTION=%s [add or remove]
16# PRODUCT=%x/%x/%x/%x
17# NAME=%s
18# PHYS=%s
19# EV=%lx
20# KEY=%lx %lx ...
21# REL=%lx
22# ABS=%lx %lx ...
23# MSC=%lx
24# LED=%lx
25# SND=%lx
26# FF=%lx %lx ...
27#
28: ${ACTION?Bad invocation: \$ACTION is not set}
29
30cd /etc/hotplug
31. ./hotplug.functions
32
33# generated by module-init-tools
34MAP_CURRENT=$MODULE_DIR/modules.inputmap
35
36# used for kernel drivers that don't show up in MAP_CURRENT
37# or to overwrite default from MAP_CURRENT
38#
39MAP_HANDMAP=$HOTPLUG_DIR/input.handmap
40
41# Each modules.inputmap format line corresponds to one entry in a
42# MODULE_DEVICE_TABLE(input,...) declaration in a kernel file.
43#
44matchBits=0
45i_bustype=0
46i_vendor=0
47i_product=0
48i_version=0
49i_evBits=0
50
51input_join_words ()
52{
53 local name=$1; shift
54 local tmp=$1; shift
55 while [ "$#" -gt 0 ]; do
56 tmp="$tmp:$1"; shift
57 done
58 eval $name=\$tmp
59}
60
61input_convert_vars ()
62{
63 if [ "$PRODUCT" != "" ]; then
64 set -- `IFS=/; echo $PRODUCT`
65 i_bustype=$((0x$1))
66 i_vendor=$((0x$2))
67 i_product=$((0x$3))
68 i_version=$((0x$4))
69 fi
70
71 if [ "$EV" != "" ]; then
72 i_evBits=$((0x$EV))
73 fi
74
75 input_join_words i_keyBits $KEY
76 # for a in $KEY; do i_keyBits="${i_keyBits:+$i_keyBits:}${a}"; done
77 input_join_words i_relBits $REL
78 input_join_words i_absBits $ABS
79 input_join_words i_mscBits $MSC
80 input_join_words i_ledBits $LED
81 input_join_words i_sndBits $SND
82 input_join_words i_ffBits $FF
83}
84
85INPUT_DEVICE_ID_MATCH_BUS=1
86INPUT_DEVICE_ID_MATCH_VENDOR=2
87INPUT_DEVICE_ID_MATCH_PRODUCT=4
88INPUT_DEVICE_ID_MATCH_VERSION=8
89INPUT_DEVICE_ID_MATCH_EVBIT=$((0x010))
90INPUT_DEVICE_ID_MATCH_KEYBIT=$((0x020))
91INPUT_DEVICE_ID_MATCH_RELBIT=$((0x040))
92INPUT_DEVICE_ID_MATCH_ABSBIT=$((0x080))
93INPUT_DEVICE_ID_MATCH_MSCBIT=$((0x100))
94INPUT_DEVICE_ID_MATCH_LEDBIT=$((0x200))
95INPUT_DEVICE_ID_MATCH_SNDBIT=$((0x400))
96INPUT_DEVICE_ID_MATCH_FFBIT=$((0x800))
97
98
99input_match_bits ()
100{
101 local mod_bits=$1 dev_bits=$2
102
103 mword=$((0x${mod_bits##*:}))
104 dword=$((0x${dev_bits##*:}))
105
106 while true; do
107 if [ $(( $mword & $dword != $mword )) -eq 1 ]; then
108 return 1
109 fi
110
111 mod_bits=${mod_bits%:*}
112 dev_bits=${dev_bits%:*}
113
114 case "$mod_bits-$dev_bits" in
115 *:*-*:* )
116 : continue
117 ;;
118 *:*-*|*-*:* )
119 return 0
120 ;;
121 * )
122 return 1
123 ;;
124 esac
125 done
126}
127
128#
129# stdin is "modules.inputmap" syntax
130# on return, all matching modules were added to $DRIVERS
131#
132input_map_modules ()
133{
134 local line module
135 local relBits mscBits ledBits sndBits keyBits absBits ffBits
136
137 while read line
138 do
139 # comments are lines that start with "#" ...
140 # be careful, they still get parsed by bash!
141 case "$line" in
142 \#*|"") continue ;;
143 esac
144
145 set $line
146
147 module=$1
148 matchBits=$(($2))
149
150 bustype=$(($3))
151 vendor=$(($4))
152 product=$(($5))
153 vendor=$(($6))
154
155 evBits=$(($7))
156 keyBits=$8
157 relBits=$(($9))
158
159 shift 9
160 absBits=$(($1))
161 cbsBits=$(($2))
162 ledBits=$(($3))
163 sndBits=$(($4))
164 ffBits=$(($5))
165 driverInfo=$(($6))
166
167 : checkmatch $module
168
169 : bustype $bustype $i_bustype
170 if [ $INPUT_DEVICE_ID_MATCH_BUS -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_BUS )) ] &&
171 [ $bustype -ne $i_bustype ]; then
172 continue
173 fi
174
175 : vendor $vendor $i_vendor
176 if [ $INPUT_DEVICE_ID_MATCH_VENDOR -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_VENDOR )) ] &&
177 [ $vendor -ne $i_vendor ]; then
178 continue
179 fi
180
181 : product $product $i_product
182 if [ $INPUT_DEVICE_ID_MATCH_PRODUCT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_PRODUCT )) ] &&
183 [ $product -ne $i_product ]; then
184 continue
185 fi
186
187 # version i_version $i_version < version $version
188 if [ $INPUT_DEVICE_ID_MATCH_VERSION -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_VERSION )) ] &&
189 [ $version -ge $i_version ]; then
190 continue
191 fi
192
193 : evBits $evBits $i_evBits
194 if [ $INPUT_DEVICE_ID_MATCH_EVBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_EVBIT )) ] &&
195 [ $evBits -ne $(( $evBits & $i_evBits)) ]; then
196 continue
197 fi
198 : keyBits $keyBits $i_keyBits
199 if [ $INPUT_DEVICE_ID_MATCH_KEYBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_KEYBIT )) ] &&
200 input_match_bits "$keyBits" "$i_keyBits"; then
201 continue
202 fi
203 : relBits $relBits $i_relBits
204 if [ $INPUT_DEVICE_ID_MATCH_RELBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_RELBIT )) ] &&
205 [ $relBits -ne $(( $relBits & $i_relBits)) ]; then
206 continue
207 fi
208
209 : absBits $absBits $i_absBits
210 if [ $INPUT_DEVICE_ID_MATCH_ABSBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_ABSBIT )) ] &&
211 input_match_bits "$absBits" "$i_absBits"; then
212 continue
213 fi
214
215 : mscBits $mscBits $i_mscBits
216 if [ $INPUT_DEVICE_ID_MATCH_MSCBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_MSCBIT )) ] &&
217 [ $mscBits -ne $(( $mscBits & $i_mscBits)) ]; then
218 continue
219 fi
220
221 : ledBits $ledBits $_ledBits
222 if [ $INPUT_DEVICE_ID_MATCH_LEDBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_LEDBIT )) ] &&
223 input_match_bits "$ledBits" "$i_ledBits"; then
224 continue
225 fi
226
227 : sndBits $sndBits $i_sndBits
228 if [ $INPUT_DEVICE_ID_MATCH_SNDBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_SNDBIT )) ] &&
229 [ $sndBits -ne $(( $sndBits & $i_sndBits)) ]; then
230 continue
231 fi
232
233 : ffBits $ffBits $i_ffBits
234 if [ $INPUT_DEVICE_ID_MATCH_FFBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_FFBIT )) ] &&
235 input_match_bits "$ffBits" "$i_ffBits"; then
236 continue
237 fi
238
239 : driverInfo $driverInfo
240 if [ $matchBits -eq 0 -a $driverInfo -eq 0 ]; then
241 continue
242 fi
243
244 # It was a match!
245 case " $DRIVERS " in
246 *" $module "* )
247 : already found
248 ;;
249 * )
250 DRIVERS="$module $DRIVERS"
251 ;;
252 esac
253 : drivers $DRIVERS
254 done
255}
256
257#
258# What to do with this INPUT hotplug event?
259#
260case $ACTION in
261
262 add)
263
264 # If hwup does initialize the device there is nothing more to do
265 if [ -x /sbin/hwup ] && /sbin/hwup ${1:+$1-}devpath-$DEVPATH -o hotplug; then
266 : nix
267 else
268
269 input_convert_vars
270
271 FOUND=""
272 LABEL="INPUT product $PRODUCT"
273
274 # cope with special driver module configurations first. So we can
275 # overwrite default settings in MAP_CURRENT
276 if [ -r $MAP_HANDMAP ]; then
277 load_drivers usb $MAP_HANDMAP "$LABEL"
278 FOUND="$FOUND${DRIVERS:+ $DRIVERS}"
279 fi
280
281 if [ -r $MAP_CURRENT -a -z "$FOUND" ]; then
282 load_drivers input $MAP_CURRENT "$LABEL"
283 fi
284
285 fi
286
287 ;;
288
289 remove)
290
291 if [ -x /sbin/hwdown ] && /sbin/hwdown ${1:+$1-}devpath-$DEVPATH -o hotplug; then
292 : nix
293 fi
294
295 ;;
296
297 *)
298 debug_mesg INPUT $ACTION event not supported
299 exit 1
300 ;;
301
302esac
Note: See TracBrowser for help on using the repository browser.