diff --git a/android/bluetooth.c b/android/bluetooth.c
index 5a4f136..a0e2ce5 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
static bool kernel_conn_control = false;
static struct queue *unpaired_cb_list = NULL;
+static struct queue *paired_cb_list = NULL;
static void get_device_android_addr(struct device *dev, uint8_t *addr)
{
HAL_BOND_STATE_BONDING);
send_bond_state_change(dev, status, new_bond);
+}
+
+static void send_paired_notification(void *data, void *user_data)
+{
+ bt_paired_device_cb cb = data;
+ struct device *dev = user_data;
+ cb(&dev->bdaddr, dev->bdaddr_type);
}
static void update_device_state(struct device *dev, uint8_t addr_type,
queue_remove(unpaired_cb_list, cb);
}
+bool bt_paired_register(bt_paired_device_cb cb)
+{
+ if (queue_find(paired_cb_list, match_by_value, cb))
+ return false;
+
+ return queue_push_head(paired_cb_list, cb);
+}
+
+void bt_paired_unregister(bt_paired_device_cb cb)
+{
+ queue_remove(paired_cb_list, cb);
+}
+
static bool rssi_above_threshold(int old, int new)
{
/* only 8 dBm or more */
*/
update_device_state(dev, rp->addr.type, status_mgmt2hal(status), false,
!status, false);
+
+ if (status == MGMT_STATUS_SUCCESS)
+ queue_foreach(paired_cb_list, send_paired_notification, dev);
}
static uint8_t select_device_bearer(struct device *dev)
return false;
}
+ paired_cb_list = queue_new();
+ if (!paired_cb_list) {
+ error("Cannot allocate queue for paired callbacks");
+ queue_destroy(unpaired_cb_list, NULL);
+ unpaired_cb_list = NULL;
+ return false;
+ }
+
missing_settings = adapter.current_settings ^
adapter.supported_settings;
failed:
queue_destroy(unpaired_cb_list, NULL);
unpaired_cb_list = NULL;
+ queue_destroy(paired_cb_list, NULL);
+ paired_cb_list = NULL;
return false;
}
queue_destroy(unpaired_cb_list, NULL);
unpaired_cb_list = NULL;
+
+ queue_destroy(paired_cb_list, NULL);
+ paired_cb_list = NULL;
}
diff --git a/android/bluetooth.h b/android/bluetooth.h
index d09b6f2..e5d23a9 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
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);
+
+typedef void (*bt_paired_device_cb)(const bdaddr_t *addr, uint8_t type);
+bool bt_paired_register(bt_paired_device_cb cb);
+void bt_paired_unregister(bt_paired_device_cb cb);