changelog tags changeset manifest revisions annotate raw

hardware_detect.rb

changeset 25: 19405d7dd94b
parent:d3321cd85bc1
author: frsyuki@vcore
date: Fri Mar 23 20:59:50 2007 +0900 (14 years ago)
permissions: -rw-r--r--
1require "hardware_source"
2require "log"
3
4
5class HardwareDetect
6
7 class DetectedPCI
8 def initialize(vendor, device, pclass, modules)
9 @vendor = vendor
10 @device = device
11 @pclass = pclass
12 @modules = modules
13 end
14 attr_reader :vendor, :device, :pclass, :modules
15 end
16
17 class DetectedUSB
18 def initialize(vendor, device, iclass, modules)
19 @vendor = vendor
20 @device = device
21 @iclass = iclass
22 @modules = modules
23 end
24 attr_reader :vendor, :device, :iclass, :modules
25 end
26
27
28 def detectPCI
29 sourcePCI
30 pci_devices_dir_cache = @sysfs.pci_devices.to_s
31 Dir.open(pci_devices_dir_cache) {|dir|
32 dir.each {|dev|
33 dev_dir = pci_devices_dir_cache + "/" + dev
34 vendor = IO.read(dev_dir + "/vendor", 4, 2) rescue next # 開けなかったら無視
35 device = IO.read(dev_dir + "/device", 4, 2) rescue next
36 pclass = IO.read(dev_dir + "/class", 4, 2) rescue next
37 modules = [ @pcimap_v[vendor], @pcimap_vd[vendor + device], @pcimap_c[pclass] ].flatten.compact
38
39 @detected_pci.push( DetectedPCI.new(vendor, device, pclass, modules) )
40 }
41 }
42 end
43
44 def detectUSB
45 sourceUSB
46 usb_devices_dir_cache = @sysfs.usb_devices.to_s
47 Dir.open(usb_devices_dir_cache) {|dir|
48 dir.each {|dev|
49 if dev =~ /^usb[0-9]+/; next; end # usb[0-9]+はLinuxのUSBホストドライバ
50 dev_dir = usb_devices_dir_cache + "/" + dev
51
52 vendor = nil
53 device = nil
54 iclass = nil
55 modules = Array.new
56 if File.file?(dev_dir + "/idVendor") \
57 && File.file?(dev_dir + "/idProduct")
58 vendor = IO.read(dev_dir + "/idVendor", 4, 0) rescue next
59 device = IO.read(dev_dir + "/idProduct", 4, 0) rescue next
60 if @usbmap_vd.key?(vendor + device)
61 modules.concat( @usbmap_vd[vendor + device] )
62 end
63 end
64 if File.file?(dev_dir + "/bInterfaceClass")
65 bc = IO.read(dev_dir + "/bInterfaceClass", 2, 0) rescue next
66 sc = IO.read(dev_dir + "/bInterfaceSubClass", 2, 0) rescue next
67 iclass = bc + sc
68 # classでモジュール判定に使うのはBase classのみ
69 if @usbmap_ic.key?( iclass[0,2] )
70 modules.concat( @usbmap_ic[ iclass[0,2] ] )
71 end
72 end
73
74 @detected_usb.push( DetectedUSB.new(vendor, device, iclass, modules.uniq) )
75 }
76 }
77 end
78
79
80end
81
82
83
84$log.debug "#{File.basename(__FILE__, ".*")} loaded"