diff --git a/Makefile.tools b/Makefile.tools
index ef4162b..bc827fe 100644
--- a/Makefile.tools
+++ b/Makefile.tools
emulator/btdev.h emulator/btdev.c \
emulator/bthost.h emulator/bthost.c \
emulator/smp.c \
+ emulator/phy.h emulator/phy.c \
emulator/amp.h emulator/amp.c \
emulator/le.h emulator/le.c
emulator_btvirt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la
diff --git a/emulator/le.c b/emulator/le.c
index a3f2e1b..a39cdde 100644
--- a/emulator/le.c
+++ b/emulator/le.c
#include "monitor/mainloop.h"
#include "monitor/bt.h"
+#include "phy.h"
#include "le.h"
#define WHITE_LIST_SIZE 16
struct bt_le {
volatile int ref_count;
int vhci_fd;
+ struct bt_phy *phy;
struct bt_crypto *crypto;
uint8_t event_mask[16];
mainloop_add_fd(hci->vhci_fd, EPOLLIN, vhci_read_callback, hci, NULL);
+ hci->phy = bt_phy_new();
hci->crypto = bt_crypto_new();
return bt_le_ref(hci);
return;
bt_crypto_unref(hci->crypto);
+ bt_phy_unref(hci->phy);
mainloop_remove_fd(hci->vhci_fd);
diff --git a/emulator/phy.c b/emulator/phy.c
new file mode 100644
index 0000000..30808df
--- /dev/null
+++ b/emulator/phy.c
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2011-2012 Intel Corporation
+ * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include "phy.h"
+
+struct bt_phy {
+ volatile int ref_count;
+};
+
+struct bt_phy *bt_phy_new(void)
+{
+ struct bt_phy *phy;
+
+ phy = calloc(1, sizeof(*phy));
+ if (!phy)
+ return NULL;
+
+ return bt_phy_ref(phy);
+}
+
+struct bt_phy *bt_phy_ref(struct bt_phy *phy)
+{
+ if (!phy)
+ return NULL;
+
+ __sync_fetch_and_add(&phy->ref_count, 1);
+
+ return phy;
+}
+
+void bt_phy_unref(struct bt_phy *phy)
+{
+ if (!phy)
+ return;
+
+ if (__sync_sub_and_fetch(&phy->ref_count, 1))
+ return;
+
+ free(phy);
+}
diff --git a/emulator/phy.h b/emulator/phy.h
new file mode 100644
index 0000000..a070e03
--- /dev/null
+++ b/emulator/phy.h
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2011-2012 Intel Corporation
+ * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct bt_phy;
+
+struct bt_phy *bt_phy_new(void);
+
+struct bt_phy *bt_phy_ref(struct bt_phy *phy);
+void bt_phy_unref(struct bt_phy *phy);