changelog tags changeset manifest revisions annotate raw

hardware_source.rb

changeset 25: 19405d7dd94b
parent:65718e4ef8ef
author: frsyuki@vcore
date: Fri Mar 23 20:59:50 2007 +0900 (14 years ago)
permissions: -rw-r--r--
1require "log"
2
3# pciids: http://pciids.sf.net/pci.db
4# usbids: http://www.linux-usb.org/usb.ids
5# sysmap: /boot/*ystem*
6
7class HardwareDetect
8
9
10 def sourcePCI
11 if !@pciids_v.empty?
12 return
13 end
14
15 # pciidsをロード
16 File.open(@pcidb_file, "r") {|file|
17 # col[0] col[1] col[2] col[3]
18 # v 001c PEAK-System Technik GmbH 0
19 # d 001c0001 PCAN-PCI CAN-Bus controller 0
20 file.each {|line|
21 begin
22 col = line.split("\t")
23 case (col[0])
24 when "v"
25 if col[3] != "0"; next; end
26 @pciids_v[ col[1] ] = col[2]
27 when "d"
28 @pciids_d[col[1][4,4]] = col[2]
29 #when "s"
30 # subvendor/subdeviceまでは不要
31 end
32 rescue
33 $log.debugError "invalid pciids line: #{line}"
34 end
35 }
36 }
37
38 # pcimapをロード
39 File.open(@kmodule.pcimap_file, "r") {|file|
40 file.gets # 最初の行はコメントなので飛ばす
41 file.each {|line|
42 # col[0] col[1] col[2] col[3] col[4] col[5] col[6] col[7]
43 # pci module vendor device subvendor subdevice class class_mask driver_data
44 # snd-ymfpci 0x00001073 0x00000004 0xffffffff 0xffffffff 0x00000000 0x00000000 0x0
45 begin
46 col = line.split(" ")
47 if col[1] === "0xffffffff" && col[2] == "0xffffffff"
48 # class
49 key = col[5][4,4]
50 if @pcimap_c.key?(key)
51 @pcimap_c[key].push( col[0] )
52 else
53 @pcimap_c[key] = [ col[0] ]
54 end
55 elsif col[2] === "0xffffffff"
56 # vendor
57 key = col[1][6,4]
58 if @pcimap_v.key?(key)
59 @pcimap_v[key].push( col[0] )
60 else
61 @pcimap_v[key] = [ col[0] ]
62 end
63 else
64 # vendor + device
65 key = col[1][6,4] + col[2][6,4]
66 if @pcimap_vd.key?(key)
67 @pcimap_vd[key].push( col[0] )
68 else
69 @pcimap_vd[key] = [ col[0] ]
70 end
71 end
72 rescue
73 $log.debugError "invalid pcimap line: #{line}"
74 end
75 }
76 }
77 end
78 private :sourcePCI
79
80
81
82
83 def sourceUSB
84 if !@usbids_v.empty?
85 return
86 end
87
88 # usbidsをロード
89 File.open(@usbids_file, "r") {|file|
90 file.each {|line|
91 begin
92 last_vendor = ""
93 if line[0,1] =~ /[0-9a-f]/
94 # vendor
95 # 0386 LTS
96 last_vendor = line[0,4]
97 @usbids_v[last_vendor] = line[6..-1].strip # 改行を取り除く
98 elsif line[0,1] === "\t"
99 # device
100 # 0001 PSX for USB Converter
101 if last_vendor.empty?; next; end
102 @usbids_vd[ last_vendor + line[1,4] ] = line[7..-1].strip
103 else
104 # それ以外
105 last_vendor = ""
106 end
107 rescue
108 $log.debugError "invalid usbids line: #{line}"
109 end
110 }
111 }
112
113 File.open(@kmodule.usbmap_file, "r") {|file|
114 file.gets # 最初の行はコメントなので飛ばす
115 file.each {|line|
116 begin
117 col = line.split(" ")
118 # col[0]: usb module
119 # col[2]: idVendor
120 # col[3]: idProduct
121 # col[6]: bDeviceClass
122 # col[7]: bDeviceSubClass
123 # col[8]: bDeviceProtocol
124 # col[9]: bInterfaceClass
125 # col[10]: bInterfaceSubClass
126 # col[11]: bInterfaceProtocol
127 if col[2] == "0x0000" && col[3] == "0x0000" \
128 && col[6] == "0x00" && col[7] == "0x00" && col[8] == "0x00" \
129 && col[9] != "0x00"
130 # interface class
131 key = col[9][2,2]
132 if @usbmap_ic.key?(key)
133 @usbmap_ic[key].push( col[0] )
134 else
135 @usbmap_ic[key] = [ col[0] ]
136 end
137 elsif col[2] != "0x0000"
138 # vendor + device
139 key = col[2][2,4] + col[3][2,4]
140 if @usbmap_vd.key?(key)
141 @usbmap_vd[key].push( col[0] )
142 else
143 @usbmap_vd[key] = [ col[0] ]
144 end
145 end
146 rescue
147 $log.debugError "invalid usbmap line: #{line}"
148 end
149 }
150 }
151 end
152 private :sourceUSB
153
154
155end
156
157
158
159$log.debug "#{File.basename(__FILE__, ".*")} loaded"