diff --git a/android/bluetooth.c b/android/bluetooth.c
index 96f6101..99e2aab 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
#include "lib/uuid.h"
#include "src/shared/util.h"
#include "src/shared/mgmt.h"
+#include "src/shared/queue.h"
#include "src/eir.h"
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
static bool kernel_conn_control = false;
+static struct queue *unpaired_cb_list = NULL;
+
static void get_device_android_addr(struct device *dev, uint8_t *addr)
{
/*
error("Failed to remove device");
}
+static bool match_by_value(const void *data, const void *user_data)
+{
+ return data == user_data;
+}
+
+bool bt_unpaired_register(bt_unpaired_device_cb cb)
+{
+ if (queue_find(unpaired_cb_list, match_by_value, cb))
+ return false;
+
+ return queue_push_head(unpaired_cb_list, cb);
+}
+
+void bt_unpaired_unregister(bt_unpaired_device_cb cb)
+{
+ queue_remove(unpaired_cb_list, cb);
+}
+
static bool rssi_above_threshold(int old, int new)
{
/* only 8 dBm or more */
status);
}
+static void send_unpaired_notification(void *data, void *user_data)
+{
+ bt_unpaired_device_cb cb = data;
+ struct mgmt_addr_info *addr = user_data;
+
+ cb(&addr->bdaddr, addr->type);
+}
+
static void unpair_device_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
update_device_state(dev, rp->addr.type, HAL_STATUS_SUCCESS, false,
false, false);
+
+ /* Cast rp->addr to (void *) since queue_foreach don't take const */
+ queue_foreach(unpaired_cb_list, send_unpaired_notification,
+ (void *)&rp->addr);
}
static void handle_remove_bond_cmd(const void *buf, uint16_t len)
DBG("mode 0x%x", mode);
+ unpaired_cb_list = queue_new();
+ if (!unpaired_cb_list) {
+ error("Can not allocate queue for unpaired callbacks");
+ return false;
+ }
+
missing_settings = adapter.current_settings ^
adapter.supported_settings;
/* Fail if controller does not support LE */
if (!(adapter.supported_settings & MGMT_SETTING_LE)) {
error("LE Mode not supported by controller");
- return false;
+ goto failed;
}
/* If LE it is not yet enabled then enable it */
/* Fail if controller does not support BR/EDR */
if (!(adapter.supported_settings & MGMT_SETTING_BREDR)) {
error("BR/EDR Mode not supported");
- return false;
+ goto failed;
}
/* Enable BR/EDR if it is not enabled */
break;
default:
error("Unknown mode 0x%x", mode);
- return false;
+ goto failed;
}
hal_ipc = ipc;
G_N_ELEMENTS(cmd_handlers));
return true;
+
+failed:
+ queue_destroy(unpaired_cb_list, NULL);
+ return false;
}
void bt_bluetooth_unregister(void)
ipc_unregister(hal_ipc, HAL_SERVICE_ID_CORE);
hal_ipc = NULL;
+
+ queue_destroy(unpaired_cb_list, NULL);
}
diff --git a/android/bluetooth.h b/android/bluetooth.h
index ac7f3ad..fffb3cc 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
bool bt_auto_connect_add(const bdaddr_t *addr);
void bt_auto_connect_remove(const bdaddr_t *addr);
+
+typedef void (*bt_unpaired_device_cb)(const bdaddr_t *addr, uint8_t type);
+bool bt_unpaired_register(bt_unpaired_device_cb cb);
+void bt_unpaired_unregister(bt_unpaired_device_cb cb);