diff options
-rw-r--r-- | Bluetooth.cpp | 17 | ||||
-rw-r--r-- | Bluetooth.h | 7 | ||||
-rw-r--r-- | LinuxBluetooth.cpp | 2 |
3 files changed, 14 insertions, 12 deletions
diff --git a/Bluetooth.cpp b/Bluetooth.cpp index 9c32740..e634233 100644 --- a/Bluetooth.cpp +++ b/Bluetooth.cpp @@ -86,23 +86,18 @@ void AttPdu::makeReadByType(ByteBuffer &bytes, uint16_t startHandle, uint16_t en bytes.write16le(uuid.value); } -void AttPdu::checkType(ByteBuffer &bytes, AttPduType type) { - if (bytes.getSize() == 0) { - throw BluetoothException("PDU is too small"); - } +vector<AttributeData> AttPdu::parse(ByteBuffer &bytes, AttPduType type) { + DF << "bytes: " << bytes.toString(); - bytes.setCursor(0); AttPduType t = (AttPduType) bytes.read8(); + if (t == INVALID_HANDLE) { + return vector<AttributeData>(); + } + if (t != type) { throw BluetoothException("Unexpected type: " + to_string(t)); } -} - -vector<AttributeData> AttPdu::parse(ByteBuffer &bytes, AttPduType type) { - DF << "bytes: " << bytes.toString(); - - checkType(bytes, type); if (bytes.getSize() < 4) { throw BluetoothException("Bad READ_BY_GROUP_TYPE_RES packet, expected at least 4 octets, got " + to_string(bytes.getSize())); diff --git a/Bluetooth.h b/Bluetooth.h index 80e0193..e840f37 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -79,6 +79,9 @@ private: class BluetoothGattCharacteristic { public: + virtual ~BluetoothGattCharacteristic() { + }; + virtual BluetoothGattService &getService() const = 0; virtual const boost::uuids::uuid getUuid() const = 0; @@ -86,6 +89,9 @@ public: class BluetoothGattService { public: + virtual ~BluetoothGattService() { + }; + virtual BluetoothDevice &getDevice() const = 0; virtual boost::uuids::uuid getUuid() const = 0; @@ -134,6 +140,7 @@ protected: enum AttPduType { ERROR = 0x00, + INVALID_HANDLE = 0x01, READ_BY_TYPE_REQ = 0x08, READ_BY_TYPE_RES = 0x09, READ_BY_GROUP_TYPE_REQ = 0x10, diff --git a/LinuxBluetooth.cpp b/LinuxBluetooth.cpp index 7733592..3d5cded 100644 --- a/LinuxBluetooth.cpp +++ b/LinuxBluetooth.cpp @@ -213,7 +213,7 @@ void LinuxBluetoothDevice::discoverServices() { } while (startHandle != 0xffff); for (auto &s : services) { - D << "service: " << to_string(s->getUuid()); + D << "service: " << to_string(s->getUuid()) << ", handle: " << s->getHandle() << ", end group handle: " << s->getEndGroupHandle(); } for (auto &s : services) { |