void *send_data;
unsigned int inquiry_id;
+ unsigned int inquiry_timeout_id;
struct hook *hook_list[MAX_HOOK_ENTRIES];
int sent = data->sent_count;
int i;
+ /*Report devices only once and wait for inquiry timeout*/
+ if (data->iter == MAX_BTDEV_ENTRIES)
+ return true;
+
for (i = data->iter; i < MAX_BTDEV_ENTRIES; i++) {
/*Lets sent 10 inquiry results at once */
if (sent + 10 == data->sent_count)
data->sent_count++;
}
}
-
data->iter = i;
/* Check if we sent already required amount of responses*/
if (data->num_resp && data->sent_count == data->num_resp)
goto finish;
- if (i == MAX_BTDEV_ENTRIES)
- goto finish;
-
return true;
finish:
btdev->inquiry_id = 0;
+ if (btdev->inquiry_timeout_id > 0) {
+ timeout_remove(btdev->inquiry_timeout_id);
+ btdev->inquiry_timeout_id = 0;
+ }
+
finish:
free(data);
}
+static bool inquiry_timeout(void *user_data)
+{
+ struct inquiry_data *data = user_data;
+ struct btdev *btdev = data->btdev;
+ struct bt_hci_evt_inquiry_complete ic;
+
+ timeout_remove(btdev->inquiry_id);
+ btdev->inquiry_timeout_id = 0;
+
+ /* Inquiry is stopped, send Inquiry complete event. */
+ ic.status = BT_HCI_ERR_SUCCESS;
+ send_event(btdev, BT_HCI_EVT_INQUIRY_COMPLETE, &ic, sizeof(ic));
+
+ return false;
+}
+
static void inquiry_cmd(struct btdev *btdev, const void *cmd)
{
const struct bt_hci_cmd_inquiry *inq_cmd = cmd;
struct inquiry_data *data;
struct bt_hci_evt_inquiry_complete ic;
int status = BT_HCI_ERR_HARDWARE_FAILURE;
+ unsigned int inquiry_len_ms;
if (btdev->inquiry_id > 0) {
status = BT_HCI_ERR_COMMAND_DISALLOWED;
data->btdev = btdev;
data->num_resp = inq_cmd->num_resp;
+ /* Add timeout to cancel inquiry */
+ inquiry_len_ms = 1280 * inq_cmd->length;
+ if (inquiry_len_ms)
+ btdev->inquiry_timeout_id = timeout_add(inquiry_len_ms,
+ inquiry_timeout,
+ data, NULL);
+
btdev->inquiry_id = timeout_add(DEFAULT_INQUIRY_INTERVAL,
inquiry_callback, data,
inquiry_destroy);
return;
}
+ timeout_remove(btdev->inquiry_timeout_id);
+ btdev->inquiry_timeout_id = 0;
timeout_remove(btdev->inquiry_id);
btdev->inquiry_id = 0;