Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a9a644a6ef8b
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c947f5d973d0
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 29, 2020

  1. Copy the full SHA
    92ef380 View commit details
  2. Copy the full SHA
    c947f5d View commit details
1 change: 1 addition & 0 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ set(SCOPEPROTOCOLS_SOURCES
DVIDecoder.cpp
Ethernet10BaseTDecoder.cpp
Ethernet100BaseTDecoder.cpp
Ethernet1000BaseXDecoder.cpp
EthernetAutonegotiationDecoder.cpp
EthernetGMIIDecoder.cpp
EthernetRGMIIDecoder.cpp
154 changes: 154 additions & 0 deletions scopeprotocols/Ethernet1000BaseXDecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#include "scopeprotocols.h"
#include <algorithm>

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

Ethernet1000BaseXDecoder::Ethernet1000BaseXDecoder(string color)
: EthernetProtocolDecoder(color)
{
//Digital inputs, so need to undo some stuff for the PHY layer decodes
m_signalNames.clear();
m_channels.clear();

//Add inputs. We take a single 8b10b coded stream
m_signalNames.push_back("data");
m_channels.push_back(NULL);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accessors

string Ethernet1000BaseXDecoder::GetProtocolName()
{
return "Ethernet - 1000BaseX";
}

bool Ethernet1000BaseXDecoder::ValidateChannel(size_t i, OscilloscopeChannel* channel)
{
if( (i == 0) && (dynamic_cast<IBM8b10bDecoder*>(channel) != NULL) )
return true;
return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

void Ethernet1000BaseXDecoder::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "1000BaseX(%s)", m_channels[0]->m_displayname.c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

void Ethernet1000BaseXDecoder::Refresh()
{
ClearPackets();

//Get the input data
if(m_channels[0] == NULL)
{
SetData(NULL);
return;
}
auto data = dynamic_cast<IBM8b10bWaveform*>(m_channels[0]->GetData());
if(data == NULL)
{
SetData(NULL);
return;
}

//Create the output capture
auto cap = new EthernetWaveform;
cap->m_timescale = data->m_timescale;
cap->m_startTimestamp = data->m_startTimestamp;
cap->m_startPicoseconds = data->m_startPicoseconds;

size_t len = data->m_samples.size();
for(size_t i=0; i < len; i++)
{
//Ignore idles and autonegotiation for now

auto symbol = data->m_samples[i];

//Set of recovered bytes and timestamps
vector<uint8_t> bytes;
vector<uint64_t> starts;
vector<uint64_t> ends;

//K27.7 is a start-of-frame
if(symbol.m_control && (symbol.m_data == 0xfb) )
{
bytes.push_back(0x55);
starts.push_back(data->m_offsets[i]);
ends.push_back(data->m_offsets[i] + data->m_durations[i]);
}

//Discard anything else
else
continue;

i++;

//Decode frame data until we see a control or error character.
//Any control character would mean end-of-frame or error.
bool error = false;
while(i < len)
{
symbol = data->m_samples[i];

//Expect K29.7 end of frame
if(symbol.m_control)
{
if(symbol.m_data != 0xfd)
error = true;
break;
}

bytes.push_back(symbol.m_data);
starts.push_back(data->m_offsets[i]);
ends.push_back(data->m_offsets[i] + data->m_durations[i]);
i++;
}

//TODO: if error, create a single giant "ERROR" frame block? or what

//Crunch the data
if(!error)
BytesToFrames(bytes, starts, ends, cap);
}

SetData(cap);
}
54 changes: 54 additions & 0 deletions scopeprotocols/Ethernet1000BaseXDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of Ethernet1000BaseXDecoder
*/
#ifndef Ethernet1000BaseXDecoder_h
#define Ethernet1000BaseXDecoder_h

#include "../scopehal/ProtocolDecoder.h"

class Ethernet1000BaseXDecoder : public EthernetProtocolDecoder
{
public:
Ethernet1000BaseXDecoder(std::string color);

virtual void Refresh();
static std::string GetProtocolName();
virtual void SetDefaultName();

virtual bool ValidateChannel(size_t i, OscilloscopeChannel* channel);

PROTOCOL_DECODER_INITPROC(Ethernet1000BaseXDecoder)
};

#endif
75 changes: 63 additions & 12 deletions scopeprotocols/EthernetProtocolDecoder.cpp
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ vector<string> EthernetProtocolDecoder::GetHeaders()
vector<string> ret;
ret.push_back("Dest MAC");
ret.push_back("Src MAC");
ret.push_back("VLAN");
ret.push_back("Ethertype");
return ret;
}
@@ -166,10 +167,6 @@ void EthernetProtocolDecoder::BytesToFrames(
cap->m_durations.push_back( (ends[i] - start) / cap->m_timescale );
cap->m_samples.push_back(segment);

//Reset for next block of the frame
segment.m_type = EthernetFrameSegment::TYPE_SRC_MAC;
segment.m_data.clear();

//Format the content for display
char tmp[64];
snprintf(tmp, sizeof(tmp), "%02x:%02x:%02x:%02x:%02x:%02x",
@@ -180,6 +177,10 @@ void EthernetProtocolDecoder::BytesToFrames(
segment.m_data[4],
segment.m_data[5]);
pack->m_headers["Dest MAC"] = tmp;

//Reset for next block of the frame
segment.m_type = EthernetFrameSegment::TYPE_SRC_MAC;
segment.m_data.clear();
}

break;
@@ -202,10 +203,6 @@ void EthernetProtocolDecoder::BytesToFrames(
cap->m_durations.push_back( (ends[i] - start) / cap->m_timescale);
cap->m_samples.push_back(segment);

//Reset for next block of the frame
segment.m_type = EthernetFrameSegment::TYPE_ETHERTYPE;
segment.m_data.clear();

//Format the content for display
char tmp[64];
snprintf(tmp, sizeof(tmp),"%02x:%02x:%02x:%02x:%02x:%02x",
@@ -216,6 +213,10 @@ void EthernetProtocolDecoder::BytesToFrames(
segment.m_data[4],
segment.m_data[5]);
pack->m_headers["Src MAC"] = tmp;

//Reset for next block of the frame
segment.m_type = EthernetFrameSegment::TYPE_ETHERTYPE;
segment.m_data.clear();
}

break;
@@ -238,10 +239,6 @@ void EthernetProtocolDecoder::BytesToFrames(
cap->m_durations.push_back( (ends[i] - start) / cap->m_timescale);
cap->m_samples.push_back(segment);

//Reset for next block of the frame
segment.m_type = EthernetFrameSegment::TYPE_PAYLOAD;
segment.m_data.clear();

//Format the content for display
uint16_t ethertype = (segment.m_data[0] << 8) | segment.m_data[1];
char tmp[64];
@@ -270,6 +267,46 @@ void EthernetProtocolDecoder::BytesToFrames(
pack->m_headers["Ethertype"] = tmp;
break;
}

//Reset for next block of the frame
segment.m_type = EthernetFrameSegment::TYPE_PAYLOAD;
segment.m_data.clear();

//It's an 802.1q tag, decode the VLAN header
if(ethertype == 0x8100)
segment.m_type = EthernetFrameSegment::TYPE_VLAN_TAG;
}

break;

case EthernetFrameSegment::TYPE_VLAN_TAG:

//Start of tag? Record start time
if(segment.m_data.empty())
{
start = starts[i];
cap->m_offsets.push_back(start / cap->m_timescale);
}

//Add the data
segment.m_data.push_back(bytes[i]);

//Are we done? Add it
if(segment.m_data.size() == 2)
{
cap->m_durations.push_back( (ends[i] - start) / cap->m_timescale);
cap->m_samples.push_back(segment);

uint16_t tag = (segment.m_data[0] << 8) | segment.m_data[1];

//Reset for the internal ethertype
segment.m_type = EthernetFrameSegment::TYPE_ETHERTYPE;
segment.m_data.clear();

//Format the content for display
char tmp[64];
snprintf(tmp, sizeof(tmp),"%d", tag & 0xfff);
pack->m_headers["VLAN"] = tmp;
}

break;
@@ -418,6 +455,20 @@ string EthernetProtocolDecoder::GetText(int i)
return tmp;
}

case EthernetFrameSegment::TYPE_VLAN_TAG:
{
uint16_t tag = (sample.m_data[0] << 8) | sample.m_data[1];

snprintf(tmp, sizeof(tmp), "VLAN %d, PCP %d",
tag & 0xfff, tag >> 13);
string sret = tmp;
if(tag & 0x1000)
sret += ", DE";
return sret;
}
break;


case EthernetFrameSegment::TYPE_ETHERTYPE:
{
if(sample.m_data.size() != 2)
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.cpp
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ void ScopeProtocolStaticInit()
AddDecoderClass(DVIDecoder);
AddDecoderClass(Ethernet10BaseTDecoder);
AddDecoderClass(Ethernet100BaseTDecoder);
AddDecoderClass(Ethernet1000BaseXDecoder);
AddDecoderClass(EthernetGMIIDecoder);
AddDecoderClass(EthernetRGMIIDecoder);
AddDecoderClass(EthernetAutonegotiationDecoder);
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.h
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@
#include "EthernetRGMIIDecoder.h"
#include "Ethernet10BaseTDecoder.h"
#include "Ethernet100BaseTDecoder.h"
#include "Ethernet1000BaseXDecoder.h"
#include "EyeBitRateMeasurementDecoder.h"
#include "EyeDecoder2.h"
#include "EyeHeightMeasurementDecoder.h"