Check if the remote LE is connectable when creating a device
Before issue Discover All Primary Service the advertising event type
needs to be evaluated to avoid connection attempts to non-connectable
devices. For non-connectable devices, CreateDevice creates the device
instance however no Services/UUIDs will be exposed.
diff --git a/src/adapter.c b/src/adapter.c
index eb03149..857b2cc 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -56,6 +56,9 @@
#include "agent.h"
#include "storage.h"
+#define ADV_TYPE_IND 0x00
+#define ADV_TYPE_DIRECT_IND 0x01
+
#define IO_CAPABILITY_DISPLAYONLY 0x00
#define IO_CAPABILITY_DISPLAYYESNO 0x01
#define IO_CAPABILITY_KEYBOARDONLY 0x02
@@ -1694,6 +1697,17 @@
return DEVICE_TYPE_DUALMODE;
}
+static gboolean event_is_connectable(uint8_t type)
+{
+ switch (type) {
+ case ADV_TYPE_IND:
+ case ADV_TYPE_DIRECT_IND:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
static DBusMessage *create_device(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -1727,6 +1741,20 @@
if (!device)
return NULL;
+ if (type == DEVICE_TYPE_LE && !event_is_connectable(dev->evt_type)) {
+ /* Device is not connectable */
+ const char *path = device_get_path(device);
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(msg);
+
+ dbus_message_append_args(reply,
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ return reply;
+ }
+
err = device_browse(device, conn, msg, NULL, FALSE);
if (err < 0)
return failed_strerror(msg, -err);