1 // Copyright 2014, Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
11 "github.com/google/gopacket"
16 // Generator python layers/test_creator.py --link_type USB --name USB dongle.pcap
17 // http://wiki.wireshark.org/SampleCaptures#Sample_Captures
19 // testPacketUSB0 is the packet:
20 // 02:41:04.689546 INTERRUPT COMPLETE to 2:1:1
21 // 0x0000: 0038 4a3b 0088 ffff 4301 8101 0200 2d00 .8J;....C.....-.
22 // 0x0010: c0d3 5b50 0000 0000 8a85 0a00 0000 0000 ..[P............
23 // 0x0020: 0100 0000 0100 0000 0000 0000 0000 0000 ................
24 // 0x0030: 8000 0000 0000 0000 0002 0000 0000 0000 ................
26 var testPacketUSB0 = []byte{
27 0x00, 0x38, 0x4a, 0x3b, 0x00, 0x88, 0xff, 0xff, 0x43, 0x01, 0x81, 0x01, 0x02, 0x00, 0x2d, 0x00,
28 0xc0, 0xd3, 0x5b, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x85, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 func TestPacketUSB0(t *testing.T) {
35 p := gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.Default)
36 if p.ErrorLayer() != nil {
37 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
39 checkLayers(p, []gopacket.LayerType{LayerTypeUSB, LayerTypeUSBInterrupt}, t)
41 if got, ok := p.Layer(LayerTypeUSB).(*USB); ok {
44 Contents: []uint8{0x0, 0x38, 0x4a, 0x3b, 0x0, 0x88, 0xff, 0xff, 0x43, 0x1, 0x81, 0x1, 0x2, 0x0, 0x2d, 0x0, 0xc0, 0xd3, 0x5b, 0x50, 0x0, 0x0, 0x0, 0x0, 0x8a, 0x85, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0},
45 Payload: []uint8{0x4},
47 ID: 0xffff88003b4a3800,
48 EventType: USBEventTypeComplete,
49 TransferType: USBTransportTypeInterrupt,
54 TimestampSec: 1348195264,
55 TimestampUsec: 689546,
63 if !reflect.DeepEqual(got, want) {
64 t.Errorf("USB packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
69 func BenchmarkDecodePacketUSB0(b *testing.B) {
70 for i := 0; i < b.N; i++ {
71 gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.NoCopy)