-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSB_Device.txt
198 lines (174 loc) · 12.9 KB
/
USB_Device.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
==================================USB Device==================================
1.qemu provides three different USB controllers that can be used:
---------------------------------------------------------------
* PIIX3 UHCI controller (called piix3-usb-uhci, default on PC)
* PIIX4 UHCI controller (called piix4-usb-uhci)
* Apple OHCI controller (called pci-ohci)
2.Definitions:
--------------
* usb-device:
The usb-device whose usb transfers are being tunneled.
* usb-guest:
The entity connecting to the usb-device and using it as if connected directly to it.
For example a virtual machine running a guest os which accesses a usb-device over the network as if it is part of the virtual machine.
* usb-host:
The entity making the usb-device available for use by a usb-guest.
For example a deamon on a machine which "exports" the usb-device over the network which then "appears" inside a virtual machine on another machine.
3.Running CLI:
--------------
# /usr/libexec/qemu-kvm -M rhel6.3.0 -cpu Penryn -enable-kvm -m 2048 -smp 2,sockets=1,cores=2,threads=1 -usbdevice tablet -name win7-sp1-64 -uuid `uuidgen` -drive file=win7sp1-virtio-64.raw,format=raw,if=none,id=drive-virtio-disk0,cache=none,werror=stop,rerror=stop -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,sndbuf=0,id=hostnet0,vhost=on,script=/etc/qemu-ifup,downscript=no -device virtio-net-pci,netdev=hostnet0,id=virtio-net-pci0,mac=05:1a:4a:32:0b:26,bus=pci.0,addr=0x3,bootindex=2 -spice disable-ticketing,port=5931 -k en-us -vga qxl -global qxl-vga.vram_size=67108864 -monitor stdio
4.check usb device in command output:
-------------------------------------
# /usr/libexec/qemu-kvm -device \? 2>&1 | grep -i usb
name "usb-hub", bus USB
name "usb-host", bus USB
name "usb-kbd", bus USB
name "usb-mouse", bus USB
name "usb-tablet", bus USB
name "usb-storage", bus USB
name "usb-ccid", bus USB, desc "CCID Rev 1.1 smartcard reader"
name "usb-redir", bus USB
name "ich9-usb-ehci1", bus PCI
name "usb-ehci", bus PCI
name "ich9-usb-uhci3", bus PCI
name "ich9-usb-uhci2", bus PCI
name "ich9-usb-uhci1", bus PCI
name "piix4-usb-uhci", bus PCI
name "piix3-usb-uhci", bus PCI
5.Hotplugging:
--------------
# cat usb_kbd_hot-plug_unplug.sh
#!/bin/bash
/usr/libexec/qemu-kvm -M rhel6.3.0 -cpu Penryn -enable-kvm -m 2048 -smp 2,sockets=1,cores=2,threads=1 -usbdevice tablet -name win7-sp1-64 -uuid `uuidgen` -drive file=win7sp1-virtio-64-copy.raw,format=raw,if=none,id=drive-virtio-disk0,cache=none,werror=stop,rerror=stop -device virtio-blk-pci,scsi=off,bus=pci.0,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,sndbuf=0,id=hostnet0,vhost=on,script=/etc/qemu-ifup,downscript=no -device virtio-net-pci,netdev=hostnet0,id=virtio-net-pci0,mac=05:1a:4a:32:0b:26,bus=pci.0,bootindex=2 -device virtio-balloon-pci,id=ballooning -spice disable-ticketing,port=5931 -k en-us -vga qxl -global qxl-vga.vram_size=67108864 -monitor unix:/tmp/monitor,server,nowait -usb &
sleep 50
for i in {1..200}
do
echo "device_add usb-kbd,id=kbd1" | nc -U /tmp/monitor
echo "info usb" | nc -U /tmp/monitor
sleep 2
echo "device_del kbd1" | nc -U /tmp/monitor
echo "info usb" | nc -U /tmp/monitor
done
6.CLI:
------
/usr/libexec/qemu-kvm -M rhel6.3.0 -cpu Penryn -enable-kvm -m 2048 -smp 2,sockets=1,cores=2,threads=1 -usb -device usb-tablet -name win7-sp1-64 -uuid 721e2d85-bdbd-41bd-b20f-b56731d17085 -drive file=win7sp1-virtio-64-copy.raw,format=raw,if=none,id=drive-virtio-disk0,cache=none,werror=stop,rerror=stop -device virtio-blk-pci,scsi=off,bus=pci.0,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,sndbuf=0,id=hostnet0,vhost=on,script=/etc/qemu-ifup,downscript=no -device virtio-net-pci,netdev=hostnet0,id=virtio-net-pci0,mac=05:1a:4a:32:0b:26,bus=pci.0,bootindex=2 -device virtio-balloon-pci,id=ballooning -spice disable-ticketing,port=5931 -k en-us -vga qxl -global qxl-vga.vram_size=67108864 -monitor stdio -device usb-kbd,id=kbd1 -device usb-mouse,id=mouse1 -device usb-ccid,id=ccid1 -device usb-hub,id=usbhub1 -device usb-ehci,id=ehci -device usb-host,hostbus=2,hostaddr=9,id=hostdev1,bus=ehci.0,port=1
passthrough physical usb stick.
-device usb-host,hostbus=1,hostaddr=2,id=hostdev,port=$num ----->hostbus+hostaddr
-device usb-host,vendorid=$vid,productid=$pid,port=$num where $vid and $pid is output of lsusb in host ------>vendorid+produceid
...-usb -device usb-tablet
...-usb -device usb-kbd,id=kbd1
...-usb -device usb-mouse,id=mouse1
...-device usb-ehci,id=ehci
(qemu) info usbhost
Bus 2, Addr 8, Port 1.7, Speed 480 Mb/s
Class 00: USB device 0951:1642, DT 101 G2
Bus 2, Addr 9, Port 1.5, Speed 480 Mb/s
Class 00: USB device 0930:6545, DT 101 G2
(qemu) device_add usb-host,hostbus=2,hostaddr=8,id=hostdev1,bus=ehci.0,port=1
(qemu) info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
Device 1.1, Port 1, Speed 480 Mb/s, Product DT 101 G2
(qemu) device_add usb-host,hostbus=2,hostaddr=9,id=hostdev2,bus=ehci.0,port=2
(qemu) info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
Device 1.1, Port 1, Speed 480 Mb/s, Product DT 101 G2
Device 1.2, Port 2, Speed 480 Mb/s, Product DT 101 G2
(qemu) device_del hostdev1
(qemu) info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
Device 1.2, Port 2, Speed 480 Mb/s, Product DT 101 G2
(qemu) device_del hostdev2
(qemu) info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
7.Boot guest with emulated USB stick and physical USB stick assigned from host:
-------------------------------------------------------------------------------
# /usr/libexec/qemu-kvm -M rhel6.3.0 -cpu Penryn -enable-kvm -m 2048 -smp 2,sockets=1,cores=2,threads=1 -usb -device usb-tablet -name win7-sp1-64 -uuid 721e2d85-bdbd-41bd-b20f-b56731d17085 -drive file=win7sp1-virtio-64-copy.raw,format=raw,if=none,id=drive-virtio-disk0,cache=none,werror=stop,rerror=stop -device virtio-blk-pci,scsi=off,bus=pci.0,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,sndbuf=0,id=hostnet0,vhost=on,script=/etc/qemu-ifup,downscript=no -device virtio-net-pci,netdev=hostnet0,id=virtio-net-pci0,mac=05:1a:4a:32:0b:26,bus=pci.0,bootindex=2 -device virtio-balloon-pci,id=ballooning -spice disable-ticketing,port=5931 -k en-us -vga qxl -global qxl-vga.vram_size=67108864 -monitor stdio -device usb-ehci,id=ehci -device usb-host,hostbus=2,hostaddr=8,id=hostdev1,bus=ehci.0,port=1 -drive file=usb-storage.qcow2,if=none,id=storage0,media=disk,cache=none,format=qcow2 -device usb-storage,drive=storage0,id=usb-storage0
(qemu) info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
Device 1.1, Port 1, Speed 480 Mb/s, Product DT 101 G2
Device 1.3, Port 2, Speed 480 Mb/s, Product QEMU USB MSD
8.Boot guest with two physical USB stick redirected from usb-host:
------------------------------------------------------------------
After guest started, connect to guest with spicy and make sure check "auto redirect newly plugged in USB devices". Then usb redirection should work if you:
spice window has keyboard focus, then plug a usb device in usb-host, spicy is contained in spice-gtk-tools rpm package (included in spice-gtk package in brew).
# spicy -h 10.66.11.229 -p 5931
Note: spicec program (provided by spice-client packages) doesn't have a menubar, you need spicy for test this function.
# /usr/libexec/qemu-kvm -M rhel6.3.0 -cpu Penryn -enable-kvm -m 2048 -smp 2,sockets=1,cores=2,threads=1 -usb -device usb-tablet -name win7-sp1-64 -uuid `uuidgen` -drive file=win7sp1-virtio-64-copy.raw,format=raw,if=none,id=drive-virtio-disk0,cache=none,werror=stop,rerror=stop -device virtio-blk-pci,scsi=off,bus=pci.0,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,sndbuf=0,id=hostnet0,vhost=on,script=/etc/qemu-ifup,downscript=no -device virtio-net-pci,netdev=hostnet0,id=virtio-net-pci0,mac=05:1a:4a:02:0b:46,bus=pci.0,bootindex=2 -device virtio-balloon-pci,id=ballooning -spice disable-ticketing,port=5931 -k en-us -vga qxl -global qxl-vga.vram_size=67108864 -monitor stdio -readconfig /home/ich9-ehci-uhci.cfg -chardev spicevmc,name=usbredir,id=usbredirchardev1 -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1,bus=ehci.0,debug=1 -chardev spicevmc,name=usbredir,id=usbredirchardev2 -device usb-redir,chardev=usbredirchardev2,id=usbredirdev2,bus=ehci.0,debug=2
(qemu) __com.redhat_drive_add file=usb-storage.qcow2,id=storage0,media=disk,cache=none,format=qcow2
(qemu) device_add usb-storage,drive=storage0,id=usb-storage0
(qemu) device_del usb-storage0
9.check usb mouse in guest:
---------------------------
# /usr/libexec/qemu-kvm -M rhel6.3.0 -cpu Penryn -enable-kvm -m 2048 -smp 2,sockets=1,cores=2,threads=1 -name win7-sp1-64 -uuid `uuidgen` -drive file=/home/win7sp1-virtio-64-copy.raw,format=raw,if=none,id=drive-virtio-disk0,cache=none,werror=stop,rerror=stop -device virtio-blk-pci,scsi=off,bus=pci.0,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,sndbuf=0,id=hostnet0,vhost=on,script=/etc/qemu-ifup,downscript=no -device virtio-net-pci,netdev=hostnet0,id=virtio-net-pci0,mac=05:1a:4a:02:0b:46,bus=pci.0,bootindex=2 -device virtio-balloon-pci,id=ballooning -spice disable-ticketing,port=5931 -k en-us -vga qxl -global qxl-vga.vram_size=67108864 -monitor stdio -usb
(qemu) info usb
(qemu) device_add usb-mouse,id=mouse1
(qemu) info usb
Device 0.1, Port 2, Speed 12 Mb/s, Product QEMU USB Mouse
(qemu) info mice
* Mouse #1: QEMU USB Mouse
Mouse #0: QEMU PS/2 Mouse
(qemu) mouse_set 0
(qemu) info mice
* Mouse #0: QEMU PS/2 Mouse
Mouse #1: QEMU USB Mouse
10. usb and port.
-----------------
10.1 uhci controller has two ports by default, assign usb 1.0 device(usb-tablet, usb-kbd, usb-mouse) to uhci controller with port number specified.
occupy the two ports without any hub.
sample:
...-usb -device usb-tablet,id=tablet,port=1 -device usb-kbd,id=tablet,port=2
10.2 with one hub assigned, hub has 8 ports available.
sample:
...-usb -device usb-tablet,id=tablet,port=1 -device usb-hub,id=hub,port=2 -device usb-kbd,id=kbd,port=2.1 -device usb-mouse,id=mouse,port=2.2
11.ich9-ehci-uhci.cfg can be found here.
http://git.engineering.redhat.com/?p=users/ehabkost/qemu-kvm-rhel6.git;a=blob;f=docs/ich9-ehci-uhci.cfg;hb=HEAD
13.passthrough USB stick.
e.g1:...-device usb-host,bus=ehci.0,vendorid=0930,productid=6545
e.g2:...-device usb-host,hostbus=2,hostaddr=3,id=hostdev2,bus=ehci.0,port=2
e.g3:...-usbdevice host:0951:1642
# lsusb | grep Kingston
Bus 002 Device 003: ID 0951:1642 Kingston Technology DT101 G2
14.USB-ccid-passthrough/USB-ccid.
...-chardev socket,server,host=0.0.0.0,port=2001,id=ccid,nowait -usb -device usb-ccid,port=1 -device ccid-card-passthru,chardev=ccid
...-usb -device usb-ccid -device ccid-card-emulated,backend=certificates,cert1=cert1,cert2=cert2,cert3=cert3
15.about the uhci, ehci and xhci controller.
uhci can handle usb 1.1.
ehci can handle usb 2.0.
ehci with uhci companions can handle both usb 1.1 + 2.0.
xhci can handle usb 1.1, 2.0 and 3.0 devices, i.e. everything.
16.USB 2.0 sticks which support 1.1 too have a section like this:
Device Qualifier (for other device speed):
[ more stuff here ]
USB 3.0 stick must be passed through using ehci (or xhci).
17.how to use xHCI controller.
qemu ${other_vm_args} \
-drive if=none,id=stick,file=/path/to/file.img \
-device nec-usb-xhci,id=xhci \
-device usb-storage,bus=xhci.0,drive=stick
18.sanity testing - filter
The filter property takes a string consisting of filter rules, the format for a rule is:
<class>:<vendor>:<product>:<version>:<allow>
Use the value -1 to designate it to accept any value for a particular field.
Use the class -1 to use the class by default.
Use the version -1 to use the class by default.(here version='2.0')
1). the filter option:
e.g:...-device usb-redir,id=redir1,bus=ehci.0,port=1,filter='0x08:0x0781:0x5567:0x0200:*0*|-1:-1:-1:-1:*1*'
The usb device with vendor id 0x0781 and product id 0x5567 can't be redirected to guest. But all other usb devices can be redirected.
2).the filter option:
e.g:...-device usb-redir,id=redir1,bus=ehci.0,port=1,filter='0x08:0x0781:0x5567:0x0200:*1*|-1:-1:-1:-1:*0*'
The usb device with vendor id 0x0781 and product id 0x5567 can be redirected to guest. But all other usb devices can't be redirected.
19.Use the virt-viewer for usb-redirection.
http://www.spice-space.org/download.html
> spice://$host_addr:$port
> vnc://$host_addr:$port
20.USB-ccid-passthrough.
1)...-spice addr=127.0.0.1,port=5931,disable-ticketing -usb -chardev spicevmc,name=smartcard,id=ccid -device usb-ccid -device ccid-card-passthru,chardev=ccid
OR:
2)...-chardev socket,server,host=$IP,port=4000,id=ccid,nowait -usb -device usb-ccid,port=$num -device ccid-card-passthru,chardev=ccid
# lsusb
Bus 003 Device 004: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1 / SCR3310 SmartCard Reader
# usbredirserver -p 4000 04e6:5116
Install coolkey and esc in guest('smart card manager' for windows).
# yum install esc coolkey
# service pcscd restart
# remote-viewer --spice-smartcard spice://$IP:$port