source: udev/input.sh@ 1322a63

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 1322a63 was a6cd72e, checked in by Jim Gifford <clfs@…>, 19 years ago

r861@server (orig r859): jim | 2005-12-06 22:41:11 -0800

r994@server: jim | 2005-12-06 22:39:42 -0800
Updates from 077 OpenSuse Package


  • Property mode set to 100755
File size: 4.9 KB
Line 
1#!/bin/sh
2########################################################################
3#
4# Description : Input devices
5#
6# Authors : Based on Open Suse Udev Rules
7# kay.sievers@suse.de
8#
9# Adapted to : Jim Gifford
10# LFS
11#
12# Version : 00.00
13#
14# Notes :
15#
16########################################################################
17
18input_join_words() {
19 local array="$1" tmp
20 [ "$array" ] || return 0
21
22 set $array
23 tmp="$1"
24 shift
25 while [ "$#" -gt 0 ]; do
26 tmp="$tmp:$1"
27 shift
28 done
29
30 echo "$tmp"
31}
32
33input_convert_vars() {
34 i_bustype=0; i_vendor=0; i_product=0; i_version=0; i_evBits=0
35
36 if [ "$PRODUCT" ]; then
37 set -- $(IFS='/'; echo $PRODUCT '')
38 i_bustype=$((0x$1))
39 i_vendor=$((0x$2))
40 i_product=$((0x$3))
41 [ "$4" ] && i_version=$((0x$4)) # XXX
42 fi
43
44 [ "$EV" ] && i_evBits=$((0x$EV))
45
46 i_keyBits=$(input_join_words "$KEY")
47 i_relBits=$(input_join_words "$REL")
48 i_absBits=$(input_join_words "$ABS")
49 i_mscBits=$(input_join_words "$MSC")
50 i_ledBits=$(input_join_words "$LED")
51 i_sndBits=$(input_join_words "$SND")
52 i_ffBits=$( input_join_words "$FF")
53}
54
55input_match_bits() {
56 local mod_bits="$1" dev_bits="$2"
57 [ "$dev_bits" ] || return 0
58
59 local mword dword
60 mword=$((0x${mod_bits##*:}))
61 dword=$((0x${dev_bits##*:}))
62
63 while true; do
64 if [ $(( $mword & $dword != $mword )) -eq 1 ]; then
65 return 1
66 fi
67
68 mod_bits=${mod_bits%:*}
69 dev_bits=${dev_bits%:*}
70
71 case "$mod_bits-$dev_bits" in
72 *:*-*:*) continue ;;
73 *:*-*|*-*:*) return 0 ;;
74 *) return 1 ;;
75 esac
76 done
77}
78
79load_drivers() {
80 local TYPE="$1" FILENAME="$2"
81
82 ${TYPE}_map_modules < $FILENAME
83
84 for MODULE in $DRIVERS; do
85 /sbin/modprobe $MODULE || true
86 done
87}
88
89input_map_modules() {
90 local line module
91 local relBits mscBits ledBits sndBits keyBits absBits ffBits
92
93 while read line; do
94 # comments are lines that start with "#" ...
95 # be careful, they still get parsed by bash!
96 case "$line" in
97 \#*) continue ;;
98 esac
99
100 set $line
101
102 module="$1"
103 matchBits=$(($2))
104
105 bustype=$(($3))
106 vendor=$(($4))
107 product=$(($5))
108 version=$(($6))
109
110 evBits="$7"
111 keyBits="$8"
112 relBits="$9"
113
114 shift 9
115 absBits="$1"
116 cbsBits="$2"
117 ledBits="$3"
118 sndBits="$4"
119 ffBits="$5"
120 driverInfo=$(($6))
121
122 if [ $INPUT_DEVICE_ID_MATCH_BUS -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_BUS )) ] &&
123 [ $bustype -ne $i_bustype ]; then
124 continue
125 fi
126
127 if [ $INPUT_DEVICE_ID_MATCH_VENDOR -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_VENDOR )) ] &&
128 [ $vendor -ne $i_vendor ]; then
129 continue
130 fi
131
132 if [ $INPUT_DEVICE_ID_MATCH_PRODUCT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_PRODUCT )) ] &&
133 [ $product -ne $i_product ]; then
134 continue
135 fi
136
137 # version i_version $i_version < version $version
138 if [ $INPUT_DEVICE_ID_MATCH_VERSION -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_VERSION )) ] &&
139 [ $version -ge $i_version ]; then
140 continue
141 fi
142
143 if [ $INPUT_DEVICE_ID_MATCH_EVBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_EVBIT )) ] &&
144 input_match_bits "$evBits" "$i_evBits"; then
145 continue
146 fi
147 if [ $INPUT_DEVICE_ID_MATCH_KEYBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_KEYBIT )) ] &&
148 input_match_bits "$keyBits" "$i_keyBits"; then
149 continue
150 fi
151 if [ $INPUT_DEVICE_ID_MATCH_RELBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_RELBIT )) ] &&
152 input_match_bits "$relBits" "$i_relBits"; then
153 continue
154 fi
155
156 if [ $INPUT_DEVICE_ID_MATCH_ABSBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_ABSBIT )) ] &&
157 input_match_bits "$absBits" "$i_absBits"; then
158 continue
159 fi
160
161 if [ $INPUT_DEVICE_ID_MATCH_MSCBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_MSCBIT )) ] &&
162 input_match_bits "$mscBits" "$i_mscBits"; then
163 continue
164 fi
165
166 if [ $INPUT_DEVICE_ID_MATCH_LEDBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_LEDBIT )) ] &&
167 input_match_bits "$ledBits" "$i_ledBits"; then
168 continue
169 fi
170
171 if [ $INPUT_DEVICE_ID_MATCH_SNDBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_SNDBIT )) ] &&
172 input_match_bits "$sndBits" "$i_sndBits"; then
173 continue
174 fi
175
176 if [ $INPUT_DEVICE_ID_MATCH_FFBIT -eq $(( $matchBits & $INPUT_DEVICE_ID_MATCH_FFBIT )) ] &&
177 input_match_bits "$ffBits" "$i_ffBits"; then
178 continue
179 fi
180
181 if [ $matchBits -eq 0 -a $driverInfo -eq 0 ]; then
182 continue
183 fi
184
185 # It was a match!
186 case " $DRIVERS " in
187 *" $module "*)
188 : already found
189 ;;
190 *)
191 DRIVERS="$module $DRIVERS"
192 ;;
193 esac
194
195 done
196}
197
198INPUT_DEVICE_ID_MATCH_BUS=1
199INPUT_DEVICE_ID_MATCH_VENDOR=2
200INPUT_DEVICE_ID_MATCH_PRODUCT=4
201INPUT_DEVICE_ID_MATCH_VERSION=8
202INPUT_DEVICE_ID_MATCH_EVBIT=$((0x010))
203INPUT_DEVICE_ID_MATCH_KEYBIT=$((0x020))
204INPUT_DEVICE_ID_MATCH_RELBIT=$((0x040))
205INPUT_DEVICE_ID_MATCH_ABSBIT=$((0x080))
206INPUT_DEVICE_ID_MATCH_MSCBIT=$((0x100))
207INPUT_DEVICE_ID_MATCH_LEDBIT=$((0x200))
208INPUT_DEVICE_ID_MATCH_SNDBIT=$((0x400))
209INPUT_DEVICE_ID_MATCH_FFBIT=$((0x800))
210
211MAP_CURRENT="/lib/modules/$(uname -r)/modules.inputmap"
212[ -r $MAP_CURRENT ] || exit 0
213
214input_convert_vars
215load_drivers input $MAP_CURRENT
216
217exit 0
Note: See TracBrowser for help on using the repository browser.