aboutsummaryrefslogtreecommitdiff
path: root/LinuxBluetooth.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LinuxBluetooth.cpp')
-rw-r--r--LinuxBluetooth.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/LinuxBluetooth.cpp b/LinuxBluetooth.cpp
index 5a00f53..3efa7e5 100644
--- a/LinuxBluetooth.cpp
+++ b/LinuxBluetooth.cpp
@@ -1,3 +1,5 @@
+#include "Bluetooth.h"
+
#include <string.h>
#include <stropts.h>
#include <sys/select.h>
@@ -10,8 +12,6 @@
#include <sstream>
#include <iomanip>
-#include "Bluetooth.h"
-
// Got to love magic constants. Taken from bluez.git/tools/btgatt-client.c
#define ATT_CID 4
@@ -33,7 +33,7 @@ public:
~LinuxBluetoothAdapter();
- void runScan(void (*callback)(BluetoothDevice &device));
+ void runScan(void (*callback)(BluetoothDevice &device)) override;
BluetoothDevice &getDevice(Mac &mac) override;
@@ -155,7 +155,7 @@ void LinuxBluetoothDevice::discoverServices() {
DF;
uint8_t buffer[MAX_MTU];
- ByteBuffer out = ByteBuffer(buffer, MAX_MTU, 0);
+ ByteBuffer out = ByteBuffer(buffer, MAX_MTU);
AttPdu::makeReadByGroupType(out, 0x0001, 0xffff, UUID_PRIMARY_SERVICE);
@@ -165,9 +165,14 @@ void LinuxBluetoothDevice::discoverServices() {
D << "written=" << written;
ssize_t r = read(l2cap, buffer, MAX_MTU);
- ByteBuffer in = ByteBuffer(buffer, MAX_MTU, r);
- D << "read: " << r << " bytes";
+ if (r == -1) {
+ throw BluetoothException(this, "read(): " + errnoAsString());
+ }
+
+ ByteBuffer in = ByteBuffer(buffer, r);
+
+ D << "read: " << r << " bytes: " << in.toString();
vector<AttributeData> values = AttPdu::parseReadByGroupType(in);
@@ -192,7 +197,7 @@ LinuxBluetoothAdapter::LinuxBluetoothAdapter(int hciDeviceId) :
D << "HCI socket: " << hciSocket;
if (hciSocket == -1) {
- throw BluetoothException(this, "Could not open HCI device " + hciDeviceId);
+ throw BluetoothException(this, "Could not open HCI device " + to_string(hciDeviceId));
}
hci_filter_clear(&hciFilter);
@@ -222,12 +227,12 @@ void LinuxBluetoothAdapter::startScan() {
struct hci_dev_info di;
if (hci_devinfo(hciDeviceId, &di) < 0) {
- throw BluetoothException(this, "hci_devinfo: " + hciDeviceId);
+ throw BluetoothException(this, "HCI adapter is not up: " + to_string(hciDeviceId));
}
D << "hciDeviceId.dev_id=" << di.dev_id;
D << "hciDeviceId.bdaddr=" << parseMac(di.bdaddr).str();
- D << "hciDeviceId.flags=" << hex << setw(8) << setfill('0') << di.flags;
+ D << "hciDeviceId.flags=" << setw(8) << setfill('0') << hex << di.flags;
D << "hciDeviceId.flags RUNNING = " << hci_test_bit(HCI_RUNNING, &di.flags);
D << "hciDeviceId.flags UP = " << hci_test_bit(HCI_UP, &di.flags);
D << "hciDeviceId.flags PSCAN = " << hci_test_bit(HCI_PSCAN, &di.flags);