From ab80ac3b2fbfe04e43282eb505e10d12b3085a07 Mon Sep 17 00:00:00 2001 From: Javier Date: Sat, 26 Jul 2014 18:36:49 +0200 Subject: add security level getter to gatosocket --- gatosocket.cpp | 31 +++++++++++++++++++++++++------ gatosocket.h | 9 +++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/gatosocket.cpp b/gatosocket.cpp index 5d30c6f..e814e8c 100644 --- a/gatosocket.cpp +++ b/gatosocket.cpp @@ -121,6 +121,29 @@ void GatoSocket::send(const QByteArray &pkt) writeNotifier->setEnabled(true); } +GatoSocket::SecurityLevel GatoSocket::securityLevel() const +{ + bt_security bt_sec; + socklen_t len = sizeof(bt_sec); + + if (::getsockopt(fd, SOL_BLUETOOTH, BT_SECURITY, &bt_sec, &len) == 0) { + switch (bt_sec.level) { + case BT_SECURITY_SDP: + return SecurityNone; + case BT_SECURITY_LOW: + return SecurityLow; + case BT_SECURITY_MEDIUM: + return SecurityMedium; + case BT_SECURITY_HIGH: + return SecurityHigh; + } + } else { + qErrnoWarning("Could not read security level from L2 socket"); + } + + return SecurityNone; +} + bool GatoSocket::transmit(const QByteArray &pkt) { int written = ::write(fd, pkt.constData(), pkt.size()); @@ -155,6 +178,8 @@ void GatoSocket::readNotify() readQueue.enqueue(buf); if (readQueue.size() == 1) { + // Read queue was empty, but now contains the item we just added. + // Signal readers there is data available. emit readyRead(); } } @@ -178,12 +203,6 @@ void GatoSocket::writeNotify() s = StateConnected; emit connected(); - - bt_security bt_sec; - len = sizeof(bt_sec); - if (::getsockopt(fd, SOL_BLUETOOTH, BT_SECURITY, &bt_sec, &len) == 0) { - qDebug() << "Established a bluetooth channel with security level " << bt_sec.level; - } } else if (s == StateConnected) { if (!writeQueue.isEmpty()) { if (transmit(writeQueue.head())) { diff --git a/gatosocket.h b/gatosocket.h index 4b4afbf..c1c025f 100644 --- a/gatosocket.h +++ b/gatosocket.h @@ -28,6 +28,13 @@ public: UnknownError }; + enum SecurityLevel { + SecurityNone, + SecurityLow, + SecurityMedium, + SecurityHigh + }; + State state() const; bool connectTo(const GatoAddress &addr, unsigned short cid); @@ -39,6 +46,8 @@ public: /** Adds a message to the tx queue. */ void send(const QByteArray &pkt); + SecurityLevel securityLevel() const; + signals: void connected(); void disconnected(); -- cgit v1.2.3