From 9da8dbc9ff9483235d3988847040271ddd28dd12 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 29 Jun 2014 19:12:27 +0200 Subject: [PATCH] core: Read supported mgmt commands and set kernel_bg_scan variable --- src/adapter.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index 762560a9d..b34cf484e 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -84,6 +84,8 @@ static DBusConnection *dbus_conn = NULL; +static bool kernel_bg_scan = false; + static GList *adapter_list = NULL; static unsigned int adapter_remaining = 0; static bool powering_down = false; @@ -6705,6 +6707,9 @@ static void read_commands_complete(uint8_t status, uint16_t length, { const struct mgmt_rp_read_commands *rp = param; uint16_t num_commands, num_events; + const uint16_t *opcode; + size_t expected_len; + int i; if (status != MGMT_STATUS_SUCCESS) { error("Failed to read supported commands: %s (0x%02x)", @@ -6722,6 +6727,26 @@ static void read_commands_complete(uint8_t status, uint16_t length, DBG("Number of commands: %d", num_commands); DBG("Number of events: %d", num_events); + + expected_len = sizeof(*rp) + num_commands * sizeof(uint16_t) + + num_events * sizeof(uint16_t); + + if (length < expected_len) { + error("Too small reply for supported commands: (%u != %zu)", + length, expected_len); + return; + } + + opcode = rp->opcodes; + + for (i = 0; i < num_commands; i++) { + uint16_t op = get_le16(opcode++); + + if (op == MGMT_OP_ADD_DEVICE) { + DBG("enabling kernel background scanning"); + kernel_bg_scan = true; + } + } } static void read_version_complete(uint8_t status, uint16_t length, -- 2.47.3