ngscopeclient 0.1-dev+51fbda87c
USB2PacketDecoder.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopeprotocols *
4* *
5* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef USB2PacketDecoder_h
36#define USB2PacketDecoder_h
37
38#include "../scopehal/PacketDecoder.h"
39#include "USB2PMADecoder.h"
40
45{
46public:
47
48 enum SymbolType
49 {
50 TYPE_PID,
51 TYPE_ADDR,
52 TYPE_ENDP,
53 TYPE_CRC5_GOOD,
54 TYPE_CRC5_BAD,
55 TYPE_CRC16_GOOD,
56 TYPE_CRC16_BAD,
57 TYPE_NFRAME,
58 TYPE_DATA,
59 TYPE_ERROR
60 };
61
62 enum Pids
63 {
64 PID_RESERVED = 0x0,
65 PID_OUT = 0x1,
66 PID_ACK = 0x2,
67 PID_DATA0 = 0x3,
68 PID_PING = 0x4,
69 PID_SOF = 0x5,
70 PID_NYET = 0x6,
71 PID_DATA2 = 0x7,
72 PID_SPLIT = 0x8,
73 PID_IN = 0x9,
74 PID_NAK = 0xa,
75 PID_DATA1 = 0xb,
76 PID_PRE_ERR = 0xc,
77 PID_SETUP = 0xd,
78 PID_STALL = 0xe,
79 PID_MDATA = 0xf
80 };
81
82 USB2PacketSymbol(SymbolType type = TYPE_PID, uint16_t data=0)
83 : m_type(type)
84 , m_data(data)
85 {
86 }
87
88 SymbolType m_type;
89 uint16_t m_data; //frame number is >1 byte
90 //in all other cases only low byte is meaningful
91
92 bool operator==(const USB2PacketSymbol& rhs) const
93 {
94 return (m_type == rhs.m_type);
95 }
96};
97
98class USB2PacketWaveform : public SparseWaveform<USB2PacketSymbol>
99{
100public:
102 virtual std::string GetText(size_t) override;
103 virtual std::string GetColor(size_t) override;
104};
105
107{
108public:
109 USB2PacketDecoder(const std::string& color);
110
111 virtual void Refresh() override;
112
113 static std::string GetProtocolName();
114
115 virtual std::vector<std::string> GetHeaders() override;
116 virtual bool GetShowDataColumn() override;
117
118 virtual bool ValidateChannel(size_t i, StreamDescriptor stream) override;
119
120 PROTOCOL_DECODER_INITPROC(USB2PacketDecoder)
121
122protected:
123 void FindPackets(USB2PacketWaveform* cap);
124 void DecodeSof(USB2PacketWaveform* cap, size_t istart, size_t& i);
125 void DecodeSetup(USB2PacketWaveform* cap, size_t istart, size_t& i);
126 void DecodeData(USB2PacketWaveform* cap, size_t istart, size_t& i);
127
128 bool VerifyCRC5(uint8_t* data);
129 uint16_t CalculateCRC16(const std::vector<uint8_t>& data);
130};
131
132#endif
Declaration of USB2PMADecoder.
Definition: PacketDecoder.h:85
A waveform sampled at irregular intervals.
Definition: Waveform.h:460
Descriptor for a single stream coming off a channel.
Definition: StreamDescriptor.h:46
Definition: USB2PacketDecoder.h:107
uint16_t CalculateCRC16(const std::vector< uint8_t > &data)
Calculates the USB CRC16.
Definition: USB2PacketDecoder.cpp:353
virtual void Refresh() override
Evaluates a filter graph node.
Definition: USB2PacketDecoder.cpp:87
bool VerifyCRC5(uint8_t *data)
Table based CRC5 implementation.
Definition: USB2PacketDecoder.cpp:379
Part of a packet.
Definition: USB2PacketDecoder.h:45
Definition: USB2PacketDecoder.h:99
virtual std::string GetColor(size_t) override
Returns the displayed color (in HTML #rrggbb or #rrggbbaa notation) of a given protocol sample.
Definition: USB2PacketDecoder.cpp:817
virtual std::string GetText(size_t) override
Returns the text representation of a given protocol sample.
Definition: USB2PacketDecoder.cpp:856