2021-05-27 10:59:22 -04:00
|
|
|
/*
|
|
|
|
sdt.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sdt.h"
|
|
|
|
|
|
|
|
namespace ACN {
|
|
|
|
namespace SDT {
|
|
|
|
|
|
|
|
params_t::params_t(PDU::Stream stream) {
|
2021-06-18 08:46:30 -04:00
|
|
|
Expiry = stream->readType<decltype(Expiry)>();
|
|
|
|
auto packed = stream->readType<uint8_t>();
|
|
|
|
NAK_Outbound = packed >> 7;
|
|
|
|
reserved = packed & 0xef;
|
|
|
|
NAKholdoff = stream->readType<decltype(NAKholdoff)>();
|
|
|
|
NAKmodulus = stream->readType<decltype(NAKmodulus)>();
|
|
|
|
NAKmaxwait = stream->readType<decltype(NAKmaxwait)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
join_data_t::join_data_t(PDU::Stream stream) {
|
2021-06-18 08:46:30 -04:00
|
|
|
mid = stream->readType<decltype(mid)>();
|
|
|
|
number = stream->readType<decltype(number)>();
|
|
|
|
reciprocal = stream->readType<decltype(reciprocal)>();
|
|
|
|
sequence = stream->readType<decltype(sequence)>();
|
|
|
|
reliable = stream->readType<decltype(reliable)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
destination = UDP::address_t(stream);
|
|
|
|
parameters = params_t(stream);
|
2021-06-18 08:46:30 -04:00
|
|
|
expiry = stream->readType<decltype(expiry)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
join_accept_data_t::join_accept_data_t(PDU::Stream stream) {
|
|
|
|
uint8_t buf[16];
|
|
|
|
stream->read(buf, sizeof(buf));
|
|
|
|
leader = UUID::uuid(buf);
|
2021-06-18 08:46:30 -04:00
|
|
|
number = stream->readType<decltype(number)>();
|
|
|
|
mid = stream->readType<decltype(mid)>();
|
|
|
|
reliable = stream->readType<decltype(reliable)>();
|
|
|
|
reciprocal = stream->readType<decltype(reciprocal)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
join_refuse_data_t::join_refuse_data_t(PDU::Stream stream) {
|
|
|
|
uint8_t buf[16];
|
|
|
|
stream->read(buf, sizeof(buf));
|
|
|
|
leader = UUID::uuid(buf);
|
2021-06-18 08:46:30 -04:00
|
|
|
number = stream->readType<decltype(number)>();
|
|
|
|
mid = stream->readType<decltype(mid)>();
|
|
|
|
reliable = stream->readType<decltype(reliable)>();
|
|
|
|
code = stream->readType<decltype(code)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
nak_data_t::nak_data_t(PDU::Stream stream) {
|
|
|
|
uint8_t buf[16];
|
|
|
|
stream->read(buf, sizeof(buf));
|
|
|
|
leader = UUID::uuid(buf);
|
2021-06-18 08:46:30 -04:00
|
|
|
number = stream->readType<decltype(number)>();
|
|
|
|
mid = stream->readType<decltype(mid)>();
|
|
|
|
reliable = stream->readType<decltype(reliable)>();
|
|
|
|
missed_first = stream->readType<decltype(missed_first)>();
|
|
|
|
missed_last = stream->readType<decltype(missed_last)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
wrapper_data_t::wrapper_data_t(PDU::Stream stream) {
|
2021-06-18 08:46:30 -04:00
|
|
|
number = stream->readType<decltype(number)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
compare to another sessionID
|
|
|
|
*/
|
|
|
|
bool SessionId::operator== (const SessionId & other) const {
|
|
|
|
return ((other.cid == cid) &
|
|
|
|
(other.number == number) &
|
|
|
|
(other.protocol == protocol));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constuct a sequenced channel with an owner and a direction.
|
|
|
|
|
|
|
|
@param owner the owner of the channel
|
|
|
|
@param direction the direction of channel communication
|
|
|
|
*/
|
|
|
|
Channel::Channel(std::shared_ptr<Component> owner, Direction direction) {
|
|
|
|
owner_ = owner;
|
|
|
|
direction_ = direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
deconstructor that closes the channel cleanly.
|
|
|
|
*/
|
|
|
|
Channel::~Channel() {
|
|
|
|
// TODO: close the channel.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Construct a new session.
|
|
|
|
*/
|
|
|
|
Session::Session() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
deconstructor that leaves the session gracefully.
|
|
|
|
*/
|
|
|
|
Session::~Session() {
|
|
|
|
// TODO: Disconnect the session.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
get the ID of the session
|
|
|
|
*/
|
|
|
|
SessionId Session::id() {
|
|
|
|
SessionId ret;
|
|
|
|
ret.cid = leader->cid();
|
|
|
|
ret.number = number_;
|
|
|
|
ret.protocol = protocol_;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pdu::Pdu(PDU::Stream stream)
|
|
|
|
: PDU::Pdu(stream, 1) // vectors are 1 octet
|
|
|
|
{
|
|
|
|
// if (stream->fail()) return;
|
|
|
|
// if (!buffer_->good()) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
client_pdu_header_t::client_pdu_header_t(PDU::Stream stream) {
|
2021-06-18 08:46:30 -04:00
|
|
|
protocol = stream->readType<decltype(protocol)>();
|
|
|
|
association = stream->readType<decltype(association)>();
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ClientPdu::ClientPdu(PDU::Stream stream)
|
|
|
|
: PDU::Pdu(stream, 2) // vectors are 2 octets (MID)
|
|
|
|
{
|
|
|
|
if (stream->fail()) return;
|
2021-06-18 08:46:30 -04:00
|
|
|
if (!stream_->good()) return;
|
2021-05-27 10:59:22 -04:00
|
|
|
|
|
|
|
if (flags_.hasHeader)
|
2021-06-18 08:46:30 -04:00
|
|
|
setHeader(new client_pdu_header_t(stream_));
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // SDT
|
|
|
|
}; // ACN
|