diff --git a/emulator/btdev.c b/emulator/btdev.c
index 79d2f0e..52b58ce 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
#define has_bredr(btdev) (!((btdev)->features[4] & 0x20))
#define has_le(btdev) (!!((btdev)->features[4] & 0x40))
+struct hook {
+ btdev_hook_func handler;
+ void *user_data;
+ enum btdev_hook_type type;
+ uint16_t opcode;
+};
+
+#define MAX_HOOK_ENTRIES 16
+
struct btdev {
enum btdev_type type;
btdev_send_func send_handler;
void *send_data;
+ struct hook *hook_list[MAX_HOOK_ENTRIES];
+
uint16_t manufacturer;
uint8_t version;
uint16_t revision;
break;
}
}
+
+int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
+ uint16_t opcode, btdev_hook_func handler,
+ void *user_data)
+{
+ int i;
+
+ if (!btdev)
+ return -1;
+
+ for (i = 0; i < MAX_HOOK_ENTRIES; i++) {
+ if (btdev->hook_list[i] == NULL) {
+ btdev->hook_list[i] = malloc(sizeof(struct hook));
+ if (btdev->hook_list[i] == NULL)
+ return -1;
+
+ btdev->hook_list[i]->handler = handler;
+ btdev->hook_list[i]->user_data = user_data;
+ btdev->hook_list[i]->opcode = opcode;
+ btdev->hook_list[i]->type = type;
+ return i;
+ }
+ }
+
+ return -1;
+}
diff --git a/emulator/btdev.h b/emulator/btdev.h
index 9fb023c..085093f 100644
--- a/emulator/btdev.h
+++ b/emulator/btdev.h
*/
#include <stdint.h>
+#include <stdbool.h>
#define BTDEV_RESPONSE_DEFAULT 0
#define BTDEV_RESPONSE_COMMAND_STATUS 1
typedef void (*btdev_send_func) (const void *data, uint16_t len,
void *user_data);
+typedef bool (*btdev_hook_func) (const void *data, uint16_t len,
+ void *user_data);
+
enum btdev_type {
BTDEV_TYPE_BREDRLE,
BTDEV_TYPE_BREDR,
BTDEV_TYPE_AMP,
};
+enum btdev_hook_type {
+ BTDEV_HOOK_PRE_CMD,
+ BTDEV_HOOK_POST_CMD,
+ BTDEV_HOOK_PRE_EVT,
+ BTDEV_HOOK_POST_EVT,
+};
+
struct btdev;
struct btdev *btdev_create(enum btdev_type type, uint16_t id);
void *user_data);
void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len);
+
+int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
+ uint16_t opcode, btdev_hook_func handler,
+ void *user_data);