2019-09-02 10:28:14 +00:00
|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "BaseQuery.h"
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-05 15:30:50 +00:00
|
|
|
|
FSecure::C3::Core::BaseQuery::BaseQuery(std::weak_ptr<DeviceBridge> sender)
|
2019-09-02 10:28:14 +00:00
|
|
|
|
: m_ReceivedOrWillBeSent(true)
|
|
|
|
|
, m_SequenceNumber(0) /// THIS IS WRONG
|
2020-02-21 13:08:40 +00:00
|
|
|
|
, m_SenderChannel(sender)
|
2019-09-02 10:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
// TODO, parse query.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-05 15:30:50 +00:00
|
|
|
|
FSecure::C3::Core::BaseQuery::BaseQuery(ResponseType responseType)
|
2019-09-02 10:28:14 +00:00
|
|
|
|
: m_ReceivedOrWillBeSent(false)
|
|
|
|
|
, m_SequenceNumber(GenerateSequenceNumber())
|
2020-02-21 13:08:40 +00:00
|
|
|
|
, m_ResponseType(responseType)
|
2019-09-02 10:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-05 15:30:50 +00:00
|
|
|
|
void FSecure::C3::Core::BaseQuery::SetResponseType(ResponseType responseType)
|
2019-09-02 10:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
m_ResponseType = responseType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-05 15:30:50 +00:00
|
|
|
|
FSecure::ByteVector FSecure::C3::Core::BaseQuery::CompileQueryHeader() const
|
2019-09-02 10:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
if (m_ResponseType == ResponseType::None)
|
|
|
|
|
return ByteVector{}.Write(GetProcedureNumber());
|
|
|
|
|
|
|
|
|
|
return ByteVector{}.Write(~GetProcedureNumber(), BuildSequenceNumberField(static_cast<std::uint8_t>(m_ResponseType)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-05 15:30:50 +00:00
|
|
|
|
std::uint8_t FSecure::C3::Core::BaseQuery::BuildSequenceNumberField(std::uint8_t statusBits) const
|
2019-09-02 10:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
return (m_SequenceNumber & (3 << s_SequenceNumberBitLength)) & (statusBits << s_SequenceNumberBitLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-05 15:30:50 +00:00
|
|
|
|
FSecure::C3::Core::BaseQuery::SequenceNumberFieldUnderlyingType FSecure::C3::Core::BaseQuery::GenerateSequenceNumber()
|
2019-09-02 10:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
static std::mutex accessMutex;
|
|
|
|
|
std::scoped_lock lock(accessMutex);
|
|
|
|
|
|
|
|
|
|
static SequenceNumberFieldUnderlyingType nextGlobalSequenceNumber = 0;
|
|
|
|
|
if (nextGlobalSequenceNumber & (3 << s_SequenceNumberBitLength))
|
|
|
|
|
return nextGlobalSequenceNumber = 0;
|
|
|
|
|
|
|
|
|
|
return nextGlobalSequenceNumber++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-05 15:30:50 +00:00
|
|
|
|
std::weak_ptr<FSecure::C3::Core::DeviceBridge> FSecure::C3::Core::BaseQuery::GetSenderChannel()
|
2019-09-02 10:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
return m_SenderChannel;
|
|
|
|
|
}
|