Diff between 78cbdd40b2c4a10f7b6de53dc82663f2eaed523e and d6c1d96051c5efda7996f95892704ce63e0d4bee

Changed Files

File Additions Deletions Status
Makefile.tools +1 -0 modified
emulator/le.c +4 -0 modified
emulator/phy.c +67 -0 added
emulator/phy.h +30 -0 added

Full Patch

diff --git a/Makefile.tools b/Makefile.tools
index ef4162b..bc827fe 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -49,6 +49,7 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 				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
@@ -42,6 +42,7 @@
 #include "monitor/mainloop.h"
 #include "monitor/bt.h"
 
+#include "phy.h"
 #include "le.h"
 
 #define WHITE_LIST_SIZE		16
@@ -57,6 +58,7 @@
 struct bt_le {
 	volatile int ref_count;
 	int vhci_fd;
+	struct bt_phy *phy;
 	struct bt_crypto *crypto;
 
 	uint8_t  event_mask[16];
@@ -1181,6 +1183,7 @@ struct bt_le *bt_le_new(void)
 
 	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);
@@ -1205,6 +1208,7 @@ void bt_le_unref(struct bt_le *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
@@ -0,0 +1,67 @@
+/*
+ *
+ *  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
@@ -0,0 +1,30 @@
+/*
+ *
+ *  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);