summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-12-27 05:22:52 +0100
committerJavier <dev.git@javispedro.com>2015-12-27 05:22:52 +0100
commit52fada92f5e502f77ad19486a98b896fdf667d85 (patch)
treeed52ee36df9f8360623335f85c64958b5add985b
parentc4da0adbbd4f83bf47b71046f01cd9f12742ec7e (diff)
downloadsapd-52fada92f5e502f77ad19486a98b896fdf667d85.tar.gz
sapd-52fada92f5e502f77ad19486a98b896fdf667d85.zip
fix fragmentation header parsing
-rw-r--r--hostmanageragent.cc2
-rw-r--r--hostmanagerconn.cc4
-rw-r--r--sapbtpeer.cc2
-rw-r--r--saprotocol.cc11
-rw-r--r--saprotocol.h15
-rw-r--r--sapsocket.cc18
-rw-r--r--sapsocket.h2
-rw-r--r--webproxyagent.cc1
8 files changed, 37 insertions, 18 deletions
diff --git a/hostmanageragent.cc b/hostmanageragent.cc
index ec7172b..3cc67c2 100644
--- a/hostmanageragent.cc
+++ b/hostmanageragent.cc
@@ -48,7 +48,7 @@ void HostManagerAgent::registerServices(SAPManager *manager)
channel.setChannelId(103);
channel.setPayloadType(SAPChannelInfo::PayloadJson);
- channel.setQoSType(SAPChannelInfo::QoSReliabilityDisable);
+ channel.setQoSType(SAPChannelInfo::QoSUnrestrictedInOrder);
channel.setQoSDataRate(SAPChannelInfo::QoSDataRateLow);
channel.setQoSPriority(SAPChannelInfo::QoSPriorityHigh);
service.addChannel(channel);
diff --git a/hostmanagerconn.cc b/hostmanagerconn.cc
index 87bed09..18c61c9 100644
--- a/hostmanagerconn.cc
+++ b/hostmanagerconn.cc
@@ -27,7 +27,7 @@ void HostManagerConn::sendMessage(const QJsonObject &msg)
QJsonDocument doc(msg);
QByteArray data = doc.toJson(QJsonDocument::Compact);
qDebug() << "Send JSON:" << data;
- _socket->send(doc.toJson(QJsonDocument::Compact));
+ _socket->send(QByteArray(2, '\0') + data);
}
void HostManagerConn::handleMessage(const QJsonObject &msg)
@@ -167,6 +167,8 @@ void HostManagerConn::handleMessageReceived()
return;
}
+ data.remove(0, 2); // Remove still-unknown header
+
qDebug() << "Got JSON:" << QString::fromUtf8(data);
QJsonParseError error;
diff --git a/sapbtpeer.cc b/sapbtpeer.cc
index 188c37b..94f370a 100644
--- a/sapbtpeer.cc
+++ b/sapbtpeer.cc
@@ -5,7 +5,7 @@
#include "sapsocket.h"
#include "sapbtpeer.h"
-#define PROTO_DEBUG 0
+#define PROTO_DEBUG 1
SAPBTPeer::SAPBTPeer(SAProtocol::Role role, QBluetoothSocket *socket, QObject *parent) :
SAPPeer(role, socket->localAddress().toString(), socket->peerAddress().toString(), parent),
diff --git a/saprotocol.cc b/saprotocol.cc
index 00c083f..b27c01e 100644
--- a/saprotocol.cc
+++ b/saprotocol.cc
@@ -229,14 +229,17 @@ QByteArray SAProtocol::packFrame(quint16 sessionId, const QByteArray &data, Fram
return packFrame(frame);
}
-SAProtocol::DataFrame SAProtocol::unpackDataFrame(const QByteArray &data, bool withSeqNum)
+SAProtocol::DataFrame SAProtocol::unpackDataFrame(const QByteArray &data, bool withSeqNum, bool withFragStatus)
{
DataFrame frame;
int offset = 0;
frame.withSeqNum = withSeqNum;
+ frame.withFragStatus = withFragStatus;
if (withSeqNum) {
frame.seqNum = read<quint16>(data, offset);
- frame.unk_1 = read<quint8>(data, offset);
+ }
+ if (withFragStatus) {
+ frame.fragStatus = static_cast<SAProtocol::FragmentStatus>(read<quint8>(data, offset));
}
frame.data = data.mid(offset);
return frame;
@@ -247,7 +250,9 @@ QByteArray SAProtocol::packDataFrame(const DataFrame &frame)
QByteArray data;
if (frame.withSeqNum) {
append<quint16>(data, frame.seqNum);
- append<quint8>(data, frame.unk_1);
+ }
+ if (frame.withFragStatus) {
+ append<quint8>(data, frame.fragStatus);
}
data.append(frame.data);
return data;
diff --git a/saprotocol.h b/saprotocol.h
index 8d78dc4..68434c1 100644
--- a/saprotocol.h
+++ b/saprotocol.h
@@ -93,15 +93,22 @@ public:
static QByteArray packFrame(const Frame& frame);
static QByteArray packFrame(quint16 sessionId, const QByteArray &data, FrameType type = FrameData);
+ enum FragmentStatus {
+ FragmentNone = 0,
+ FragmentMiddle = 1,
+ FragmentLast = 3
+ };
+
struct DataFrame {
bool withSeqNum; // (not actually present in frame)
- // The following fields are only present if "withSeqNum":
- quint16 seqNum; // Monotonically increasing, but only for certain sessions...
- quint8 unk_1; // No idea, seems to be always 0
+ // The following field is only present if "withSeqNum":
+ quint16 seqNum; // Monotonically increasing
+ bool withFragStatus; // (not actually present in frame)
+ FragmentStatus fragStatus;
QByteArray data;
};
- static DataFrame unpackDataFrame(const QByteArray &data, bool withSeqNum);
+ static DataFrame unpackDataFrame(const QByteArray &data, bool withSeqNum, bool withFragStatus);
static QByteArray packDataFrame(const DataFrame& frame);
enum ControlFrameType {
diff --git a/sapsocket.cc b/sapsocket.cc
index cc6ea2e..c8219a9 100644
--- a/sapsocket.cc
+++ b/sapsocket.cc
@@ -7,7 +7,7 @@
#include "sapsocket.h"
#define DELAYED_ACK_TIME 1000
-#define RESEND_TIME 10000
+#define RESEND_TIME 5000
#define WINDOW_SIZE_MSGS 10
SAPSocket::SAPSocket(SAPConnection *conn, int sessionId, const SAPChannelInfo &chanInfo) :
@@ -92,7 +92,10 @@ void SAPSocket::setOpen(bool open)
void SAPSocket::acceptIncomingData(const QByteArray &data)
{
- SAProtocol::DataFrame frame = SAProtocol::unpackDataFrame(data, isWithSeqNum());
+ SAProtocol::DataFrame frame = SAProtocol::unpackDataFrame(data,
+ isReliable(), supportsFragmentation());
+
+ qDebug() << data.mid(0, 6).toHex() << frame.data.mid(0, 6).toHex();
if (isReliable()) {
quint16 expectedSeqNum = _inLastSeqNum + 1;
@@ -167,10 +170,10 @@ bool SAPSocket::isReliable() const
return _info.qosType() == SAPChannelInfo::QoSReliabilityEnable;
}
-bool SAPSocket::isWithSeqNum() const
+bool SAPSocket::supportsFragmentation() const
{
- return _info.qosType() == SAPChannelInfo::QoSReliabilityDisable ||
- _info.qosType() == SAPChannelInfo::QoSReliabilityEnable;
+ return _info.qosType() == SAPChannelInfo::QoSReliabilityEnable ||
+ _info.qosType() == SAPChannelInfo::QoSReliabilityDisable;
}
void SAPSocket::sendBlockAck(int seqNum)
@@ -184,9 +187,10 @@ void SAPSocket::sendBlockAck(int seqNum)
void SAPSocket::sendPacket(int seqNum, const QByteArray &data)
{
SAProtocol::DataFrame frame;
- frame.withSeqNum = isWithSeqNum();
+ frame.withSeqNum = isReliable();
frame.seqNum = seqNum;
- frame.unk_1 = 0; // Is this related to fragmentation?
+ frame.withFragStatus = supportsFragmentation();
+ frame.fragStatus = SAProtocol::FragmentNone;
frame.data = data;
peer()->writeDataToSession(_sessionId, SAProtocol::packDataFrame(frame));
}
diff --git a/sapsocket.h b/sapsocket.h
index ce3c98b..59fcb3c 100644
--- a/sapsocket.h
+++ b/sapsocket.h
@@ -44,7 +44,7 @@ protected:
private:
bool isReliable() const;
- bool isWithSeqNum() const;
+ bool supportsFragmentation() const;
void sendBlockAck(int seqNum);
void sendPacket(int seqNum, const QByteArray &data);
diff --git a/webproxyagent.cc b/webproxyagent.cc
index 0b1a753..c9d5580 100644
--- a/webproxyagent.cc
+++ b/webproxyagent.cc
@@ -23,6 +23,7 @@ WebProxyAgent* WebProxyAgent::instance()
void WebProxyAgent::peerFound(SAPPeer *peer)
{
+ Q_UNUSED(peer);
}
void WebProxyAgent::requestConnection(SAPConnectionRequest *request)