OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/usb/usb_device_filter.h" | 5 #include "device/usb/usb_device_filter.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "device/usb/usb_descriptors.h" | |
9 #include "device/usb/usb_device.h" | 8 #include "device/usb/usb_device.h" |
| 9 #include "device/usb/usb_interface.h" |
10 | 10 |
11 namespace device { | 11 namespace device { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const char kProductIdKey[] = "productId"; | 15 const char kProductIdKey[] = "productId"; |
16 const char kVendorIdKey[] = "vendorId"; | 16 const char kVendorIdKey[] = "vendorId"; |
17 const char kInterfaceClassKey[] = "interfaceClass"; | 17 const char kInterfaceClassKey[] = "interfaceClass"; |
18 const char kInterfaceSubclassKey[] = "interfaceSubclass"; | 18 const char kInterfaceSubclassKey[] = "interfaceSubclass"; |
19 const char kInterfaceProtocolKey[] = "interfaceProtocol"; | 19 const char kInterfaceProtocolKey[] = "interfaceProtocol"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return false; | 62 return false; |
63 } | 63 } |
64 | 64 |
65 if (product_id_set_ && device->product_id() != product_id_) { | 65 if (product_id_set_ && device->product_id() != product_id_) { |
66 return false; | 66 return false; |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 if (interface_class_set_) { | 70 if (interface_class_set_) { |
71 bool foundMatch = false; | 71 bool foundMatch = false; |
72 const UsbConfigDescriptor& config = device->GetConfiguration(); | 72 scoped_refptr<const UsbConfigDescriptor> config = device->ListInterfaces(); |
73 | 73 |
74 // TODO(reillyg): Check device configuration if the class is not defined at | 74 // TODO(reillyg): Check device configuration if the class is not defined at |
75 // a per-interface level. This is not really important because most devices | 75 // a per-interface level. This is not really important because most devices |
76 // have per-interface classes. The only counter-examples I know of are hubs. | 76 // have per-interface classes. The only counter-examples I know of are hubs. |
77 | 77 |
78 for (UsbInterfaceDescriptor::Iterator ifaceIt = config.interfaces.begin(); | 78 for (size_t i = 0; i < config->GetNumInterfaces() && !foundMatch; ++i) { |
79 ifaceIt != config.interfaces.end() && !foundMatch; | 79 scoped_refptr<const UsbInterfaceDescriptor> iface = |
80 ++ifaceIt) { | 80 config->GetInterface(i); |
81 if (ifaceIt->interface_class == interface_class_ && | 81 |
82 (!interface_subclass_set_ || | 82 for (size_t j = 0; j < iface->GetNumAltSettings() && !foundMatch; ++j) { |
83 (ifaceIt->interface_subclass == interface_subclass_ && | 83 scoped_refptr<const UsbInterfaceAltSettingDescriptor> altSetting = |
84 (!interface_protocol_set_ || | 84 iface->GetAltSetting(j); |
85 ifaceIt->interface_protocol == interface_protocol_)))) { | 85 |
86 foundMatch = true; | 86 if (altSetting->GetInterfaceClass() == interface_class_ && |
| 87 (!interface_subclass_set_ || |
| 88 (altSetting->GetInterfaceSubclass() == interface_subclass_ && |
| 89 (!interface_protocol_set_ || |
| 90 altSetting->GetInterfaceProtocol() == interface_protocol_)))) { |
| 91 foundMatch = true; |
| 92 } |
87 } | 93 } |
88 } | 94 } |
89 | 95 |
90 if (!foundMatch) { | 96 if (!foundMatch) { |
91 return false; | 97 return false; |
92 } | 98 } |
93 } | 99 } |
94 | 100 |
95 return true; | 101 return true; |
96 } | 102 } |
(...skipping 28 matching lines...) Expand all Loading... |
125 i != filters.end(); | 131 i != filters.end(); |
126 ++i) { | 132 ++i) { |
127 if (i->Matches(device)) { | 133 if (i->Matches(device)) { |
128 return true; | 134 return true; |
129 } | 135 } |
130 } | 136 } |
131 return false; | 137 return false; |
132 } | 138 } |
133 | 139 |
134 } // namespace device | 140 } // namespace device |
OLD | NEW |