Skip to contentSkip to conversation

Convert tools to use ELL library

RFC PATCH In review Inga Stotland 3 participants 14 messages Nov 7, 2020 – Nov 10, 2020 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Convert tools to use ELL library

This patch set is a part of ongoing effort to remove GLib dependencies from BlueZ in favor of using ELL library.

bluez/tools subdirectory is chosen as a first candidate since it provides standalone functionality making it easier to adress the issues discovered during the conversion process.

The patch set is a snapshot of *some* tools converted to use ELL as well as ELL based versions of emulator/hciemu-ell.c and shared/tester-ell.c.

Inga Stotland (10):
shared/tester-ell: Create ell-based version of tester code emulator/hciemu: Create ELL based version of hciemu tools/gap-tester: Convert to use ELL library tools/sco-tester: Convert to use ELL library tools/userchan-tester: Convert to use ELL library tools/smp-tester: Convert to use ELL library tools/bnep-tester: Convert to use ELL library tools/l2cap-tester: Convert to use ELL library tools/mgmt-tester: Convert to use ELL library tools/rfcomm-tester: Convert to use ELL library

 Makefile.am             |   8 +-
 Makefile.tools          |  34 +-
 emulator/hciemu-ell.c   | 564 ++++++++++++++++++++++++++
 src/shared/tester-ell.c | 875 ++++++++++++++++++++++++++++++++++++++++
 tools/bnep-tester.c     |   9 +-
 tools/gap-tester.c      |  87 ++--
 tools/l2cap-tester.c    | 256 ++++++------
 tools/mgmt-tester.c     |   5 +-
 tools/rfcomm-tester.c   |  92 +++--
 tools/sco-tester.c      |  33 +-
 tools/smp-tester.c      |  24 +-
 tools/userchan-tester.c |   2 -
 12 files changed, 1715 insertions(+), 274 deletions(-)
 create mode 100644 emulator/hciemu-ell.c
 create mode 100644 src/shared/tester-ell.c
Signature · 1 line
2.26.2
#1 lore raw

RFC PATCH 1/10 shared/tester-ell: Create ell-based version of tester code

Create a version of tester that uses ell primitives instead of glib:
tester-ell.c. This source is included to generate lishared-ell library. The original tester.c is built as part of libshared-glib library.

---
 Makefile.am             |   8 +-
 src/shared/tester-ell.c | 875 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 880 insertions(+), 3 deletions(-)
 create mode 100644 src/shared/tester-ell.c
Makefile.am +5 -3
index 69b95828f..952b9cc5b 100644
@@ -191,7 +191,7 @@ shared_sources = src/shared/io.h src/shared/timeout.h \
 			src/shared/crypto.h src/shared/crypto.c \
 			src/shared/ecc.h src/shared/ecc.c \
 			src/shared/ringbuf.h src/shared/ringbuf.c \
-			src/shared/tester.h src/shared/tester.c \
+			src/shared/tester.h\
 			src/shared/hci.h src/shared/hci.c \
 			src/shared/hci-crypto.h src/shared/hci-crypto.c \
 			src/shared/hfp.h src/shared/hfp.c \
@@ -218,7 +218,8 @@ src_libshared_glib_la_SOURCES = $(shared_sources) \
 				src/shared/timeout-glib.c \
 				src/shared/mainloop-glib.c \
 				src/shared/mainloop-notify.h \
-				src/shared/mainloop-notify.c
+				src/shared/mainloop-notify.c \
+				src/shared/tester.c
 
 src_libshared_mainloop_la_SOURCES = $(shared_sources) \
 				src/shared/io-mainloop.c \
@@ -232,7 +233,8 @@ src_libshared_ell_la_SOURCES = $(shared_sources) \
 				src/shared/io-ell.c \
 				src/shared/timeout-ell.c \
 				src/shared/mainloop.h \
-				src/shared/mainloop-ell.c
+				src/shared/mainloop-ell.c \
+				src/shared/tester-ell.c
 endif
 
 attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
src/shared/tester-ell.c new file +875 -0

875 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=379479

---Test result---

##############################
Test: CheckPatch - FAIL
Output:
shared/tester-ell: Create ell-based version of tester code ERROR:INITIALISED_STATIC: do not initialise statics to false #809: FILE: src/shared/tester-ell.c:761:
+ static bool terminated = false;

- total: 1 errors, 0 warnings, 901 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] shared/tester-ell: Create ell-based version of tester code" has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

##############################
Test: CheckGitLint - PASS

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS

---
Regards,
Linux Bluetooth

#3 lore raw

RFC PATCH 2/10 emulator/hciemu: Create ELL based version of hciemu

In reply to Inga Stotland

This adds a separate implementtion of hciemu code, hciemu-ell.c, that uses ELL library primitives.

---
 emulator/hciemu-ell.c | 564 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 564 insertions(+)
 create mode 100644 emulator/hciemu-ell.c
emulator/hciemu-ell.c new file +564 -0
new file mode 100644
index 000000000..40342e99b
@@ -0,0 +1,564 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012-2014, 2020  Intel Corporation. All rights reserved.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <ell/ell.h>
+
+#include "lib/bluetooth.h"
+#include "lib/hci.h"
+
+#include "monitor/bt.h"
+#include "emulator/btdev.h"
+#include "emulator/bthost.h"
+#include "src/shared/util.h"
+#include "src/shared/queue.h"
+#include "emulator/hciemu.h"
+
+struct hciemu {
+	int ref_count;
+	enum btdev_type btdev_type;
+	struct bthost *host_stack;
+	struct btdev *master_dev;
+	struct btdev *client_dev;
+	struct l_io *host_io;
+	struct l_io *master_io;
+	struct l_io *client_io;
+	struct queue *post_command_hooks;
+	char bdaddr_str[18];
+
+	hciemu_debug_func_t debug_callback;
+	hciemu_destroy_func_t debug_destroy;
+	void *debug_data;
+};
+
+struct hciemu_command_hook {
+	hciemu_command_func_t function;
+	void *user_data;
+};
+
+static void destroy_command_hook(void *data)
+{
+	struct hciemu_command_hook *hook = data;
+
+	free(hook);
+}
+
+struct run_data {
+	uint16_t opcode;
+	const void *data;
+	uint8_t len;
+};
+
+static void run_command_hook(void *data, void *user_data)
+{
+	struct hciemu_command_hook *hook = data;
+	struct run_data *run_data = user_data;
+
+	if (hook->function)
+		hook->function(run_data->opcode, run_data->data,
+					run_data->len, hook->user_data);
+}
+
+static void master_command_callback(uint16_t opcode,
+				const void *data, uint8_t len,
+				btdev_callback callback, void *user_data)
+{
+	struct hciemu *hciemu = user_data;
+	struct run_data run_data = { .opcode = opcode,
+						.data = data, .len = len };
+
+	btdev_command_default(callback);
+
+	queue_foreach(hciemu->post_command_hooks, run_command_hook, &run_data);
+}
+
+static void client_command_callback(uint16_t opcode,
+				const void *data, uint8_t len,
+				btdev_callback callback, void *user_data)
+{
+	btdev_command_default(callback);
+}
+
+static void writev_callback(const struct iovec *iov, int iovlen,
+								void *user_data)
+{
+	struct l_io *io = user_data;
+	ssize_t written;
+	int fd;
+
+	fd = l_io_get_fd(io);
+
+	written = writev(fd, iov, iovlen);
+	if (written < 0)
+		return;
+}
+
+static bool receive_bthost(struct l_io *io, void *user_data)
+{
+	struct bthost *bthost = user_data;
+	unsigned char buf[4096];
+	ssize_t len;
+	int fd;
+
+	fd = l_io_get_fd(io);
+
+	len = read(fd, buf, sizeof(buf));
+	if (len < 0)
+		return false;
+
+	bthost_receive_h4(bthost, buf, len);
+
+	return true;
+}
+
+static struct l_io *create_io_bthost(int fd, struct bthost *bthost)
+{
+	struct l_io *io;
+
+	io = l_io_new(fd);
+
+	l_io_set_close_on_destroy(io, true);
+
+	bthost_set_send_handler(bthost, writev_callback, io);
+
+	l_io_set_read_handler(io, receive_bthost, bthost, NULL);
+
+	return io;
+}
+
+static bool receive_btdev(struct l_io *io, void *user_data)
+
+{
+	struct btdev *btdev = user_data;
+	unsigned char buf[4096];
+	ssize_t len;
+	int fd;
+
+	fd = l_io_get_fd(io);
+
+	len = read(fd, buf, sizeof(buf));
+	if (len < 0) {
+		if (errno == EAGAIN || errno == EINTR)
+			return true;
+
+		return false;
+	}
+
+	if (len < 1)
+		return false;
+
+	switch (buf[0]) {
+	case BT_H4_CMD_PKT:
+	case BT_H4_ACL_PKT:
+	case BT_H4_SCO_PKT:
+		btdev_receive_h4(btdev, buf, len);
+		break;
+	}
+
+	return true;
+}
+
+static struct l_io *create_io_btdev(int fd, struct btdev *btdev)
+{
+	struct l_io *io;
+
+	io = l_io_new(fd);
+
+	l_io_set_close_on_destroy(io, true);
+
+	btdev_set_send_handler(btdev, writev_callback, io);
+
+	l_io_set_read_handler(io, receive_btdev, btdev, NULL);
+
+	return io;
+}
+
+static bool create_vhci(struct hciemu *hciemu)
+{
+	struct btdev *btdev;
+	uint8_t create_req[2];
+	ssize_t written;
+	int fd;
+
+	btdev = btdev_create(hciemu->btdev_type, 0x00);
+	if (!btdev)
+		return false;
+
+	btdev_set_command_handler(btdev, master_command_callback, hciemu);
+
+	fd = open("/dev/vhci", O_RDWR | O_NONBLOCK | O_CLOEXEC);
+	if (fd < 0) {
+		perror("Opening /dev/vhci failed");
+		btdev_destroy(btdev);
+		return false;
+	}
+
+	create_req[0] = HCI_VENDOR_PKT;
+	create_req[1] = HCI_PRIMARY;
+
+	written = write(fd, create_req, sizeof(create_req));
+	if (written < 0) {
+		close(fd);
+		btdev_destroy(btdev);
+		return false;
+	}
+
+	hciemu->master_dev = btdev;
+
+	hciemu->master_io = create_io_btdev(fd, btdev);
+
+	return true;
+}
+
+struct bthost *hciemu_client_get_host(struct hciemu *hciemu)
+{
+	if (!hciemu)
+		return NULL;
+
+	return hciemu->host_stack;
+}
+
+static bool create_stack(struct hciemu *hciemu)
+{
+	struct btdev *btdev;
+	struct bthost *bthost;
+	int sv[2];
+
+	btdev = btdev_create(hciemu->btdev_type, 0x00);
+	if (!btdev)
+		return false;
+
+	bthost = bthost_create();
+	if (!bthost) {
+		btdev_destroy(btdev);
+		return false;
+	}
+
+	btdev_set_command_handler(btdev, client_command_callback, hciemu);
+
+	if (socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC,
+								0, sv) < 0) {
+		bthost_destroy(bthost);
+		btdev_destroy(btdev);
+		return false;
+	}
+
+	hciemu->client_dev = btdev;
+	hciemu->host_stack = bthost;
+
+	hciemu->client_io = create_io_btdev(sv[0], btdev);
+	hciemu->host_io = create_io_bthost(sv[1], bthost);
+
+	return true;
+}
+
+static void start_stack(void *user_data)
+{
+	struct hciemu *hciemu = user_data;
+
+	bthost_start(hciemu->host_stack);
+}
+
+struct hciemu *hciemu_new(enum hciemu_type type)
+{
+	struct hciemu *hciemu;
+
+	hciemu = new0(struct hciemu, 1);
+	if (!hciemu)
+		return NULL;
+
+	switch (type) {
+	case HCIEMU_TYPE_BREDRLE:
+		hciemu->btdev_type = BTDEV_TYPE_BREDRLE;
+		break;
+	case HCIEMU_TYPE_BREDR:
+		hciemu->btdev_type = BTDEV_TYPE_BREDR;
+		break;
+	case HCIEMU_TYPE_LE:
+		hciemu->btdev_type = BTDEV_TYPE_LE;
+		break;
+	case HCIEMU_TYPE_LEGACY:
+		hciemu->btdev_type = BTDEV_TYPE_BREDR20;
+		break;
+	case HCIEMU_TYPE_BREDRLE50:
+		hciemu->btdev_type = BTDEV_TYPE_BREDRLE50;
+		break;
+	case HCIEMU_TYPE_BREDRLE52:
+		hciemu->btdev_type = BTDEV_TYPE_BREDRLE52;
+		break;
+	default:
+		return NULL;
+	}
+
+	hciemu->post_command_hooks = queue_new();
+	if (!hciemu->post_command_hooks) {
+		free(hciemu);
+		return NULL;
+	}
+
+	if (!create_vhci(hciemu)) {
+		queue_destroy(hciemu->post_command_hooks, NULL);
+		free(hciemu);
+		return NULL;
+	}
+
+	if (!create_stack(hciemu)) {
+		l_io_destroy(hciemu->master_io);
+		btdev_destroy(hciemu->master_dev);
+		queue_destroy(hciemu->post_command_hooks, NULL);
+		free(hciemu);
+		return NULL;
+	}
+
+	l_idle_oneshot(start_stack, hciemu, NULL);
+
+	return hciemu_ref(hciemu);
+}
+
+struct hciemu *hciemu_ref(struct hciemu *hciemu)
+{
+	if (!hciemu)
+		return NULL;
+
+	__sync_fetch_and_add(&hciemu->ref_count, 1);
+
+	return hciemu;
+}
+
+void hciemu_unref(struct hciemu *hciemu)
+{
+	if (!hciemu)
+		return;
+
+	if (__sync_sub_and_fetch(&hciemu->ref_count, 1))
+		return;
+
+	queue_destroy(hciemu->post_command_hooks, destroy_command_hook);
+
+	l_io_destroy(hciemu->host_io);
+	l_io_destroy(hciemu->client_io);
+	l_io_destroy(hciemu->master_io);
+
+	bthost_destroy(hciemu->host_stack);
+	btdev_destroy(hciemu->client_dev);
+	btdev_destroy(hciemu->master_dev);
+
+	free(hciemu);
+}
+
+static void bthost_debug(const char *str, void *user_data)
+{
+	struct hciemu *hciemu = user_data;
+
+	util_debug(hciemu->debug_callback, hciemu->debug_data,
+					"bthost: %s", str);
+}
+
+static void btdev_master_debug(const char *str, void *user_data)
+{
+	struct hciemu *hciemu = user_data;
+
+	util_debug(hciemu->debug_callback, hciemu->debug_data,
+					"btdev: %s", str);
+}
+
+static void btdev_client_debug(const char *str, void *user_data)
+{
+	struct hciemu *hciemu = user_data;
+
+	util_debug(hciemu->debug_callback, hciemu->debug_data,
+					"btdev[bthost]: %s", str);
+}
+
+bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback,
+			void *user_data, hciemu_destroy_func_t destroy)
+{
+	if (!hciemu)
+		return false;
+
+	if (hciemu->debug_destroy)
+		hciemu->debug_destroy(hciemu->debug_data);
+
+	hciemu->debug_callback = callback;
+	hciemu->debug_destroy = destroy;
+	hciemu->debug_data = user_data;
+
+	btdev_set_debug(hciemu->master_dev, btdev_master_debug, hciemu, NULL);
+	btdev_set_debug(hciemu->client_dev, btdev_client_debug, hciemu, NULL);
+	bthost_set_debug(hciemu->host_stack, bthost_debug, hciemu, NULL);
+
+	return true;
+}
+
+const char *hciemu_get_address(struct hciemu *hciemu)
+{
+	const uint8_t *addr;
+
+	if (!hciemu || !hciemu->master_dev)
+		return NULL;
+
+	addr = btdev_get_bdaddr(hciemu->master_dev);
+	sprintf(hciemu->bdaddr_str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+			addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
+	return hciemu->bdaddr_str;
+}
+
+uint8_t *hciemu_get_features(struct hciemu *hciemu)
+{
+	if (!hciemu || !hciemu->master_dev)
+		return NULL;
+
+	return btdev_get_features(hciemu->master_dev);
+}
+
+const uint8_t *hciemu_get_master_bdaddr(struct hciemu *hciemu)
+{
+	if (!hciemu || !hciemu->master_dev)
+		return NULL;
+
+	return btdev_get_bdaddr(hciemu->master_dev);
+}
+
+const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu)
+{
+	if (!hciemu || !hciemu->client_dev)
+		return NULL;
+
+	return btdev_get_bdaddr(hciemu->client_dev);
+}
+
+uint8_t hciemu_get_master_scan_enable(struct hciemu *hciemu)
+{
+	if (!hciemu || !hciemu->master_dev)
+		return 0;
+
+	return btdev_get_scan_enable(hciemu->master_dev);
+}
+
+uint8_t hciemu_get_master_le_scan_enable(struct hciemu *hciemu)
+{
+	if (!hciemu || !hciemu->master_dev)
+		return 0;
+
+	return btdev_get_le_scan_enable(hciemu->master_dev);
+}
+
+void hciemu_set_master_le_states(struct hciemu *hciemu,
+						const uint8_t *le_states)
+{
+	if (!hciemu || !hciemu->master_dev)
+		return;
+
+	btdev_set_le_states(hciemu->master_dev, le_states);
+}
+
+bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
+			hciemu_command_func_t function, void *user_data)
+{
+	struct hciemu_command_hook *hook;
+
+	if (!hciemu)
+		return false;
+
+	hook = new0(struct hciemu_command_hook, 1);
+	if (!hook)
+		return false;
+
+	hook->function = function;
+	hook->user_data = user_data;
+
+	if (!queue_push_tail(hciemu->post_command_hooks, hook)) {
+		free(hook);
+		return false;
+	}
+
+	return true;
+}
+
+bool hciemu_clear_master_post_command_hooks(struct hciemu *hciemu)
+{
+	if (!hciemu)
+		return false;
+
+	queue_remove_all(hciemu->post_command_hooks,
+					NULL, NULL, destroy_command_hook);
+	return true;
+}
+
+int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+				uint16_t opcode, hciemu_hook_func_t function,
+				void *user_data)
+{
+	enum btdev_hook_type hook_type;
+
+	if (!hciemu)
+		return -1;
+
+	switch (type) {
+	case HCIEMU_HOOK_PRE_CMD:
+		hook_type = BTDEV_HOOK_PRE_CMD;
+		break;
+	case HCIEMU_HOOK_POST_CMD:
+		hook_type = BTDEV_HOOK_POST_CMD;
+		break;
+	case HCIEMU_HOOK_PRE_EVT:
+		hook_type = BTDEV_HOOK_PRE_EVT;
+		break;
+	case HCIEMU_HOOK_POST_EVT:
+		hook_type = BTDEV_HOOK_POST_EVT;
+		break;
+	default:
+		return -1;
+	}
+
+	return btdev_add_hook(hciemu->master_dev, hook_type, opcode, function,
+								user_data);
+}
+
+bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+								uint16_t opcode)
+{
+	enum btdev_hook_type hook_type;
+
+	if (!hciemu)
+		return false;
+
+	switch (type) {
+	case HCIEMU_HOOK_PRE_CMD:
+		hook_type = BTDEV_HOOK_PRE_CMD;
+		break;
+	case HCIEMU_HOOK_POST_CMD:
+		hook_type = BTDEV_HOOK_POST_CMD;
+		break;
+	case HCIEMU_HOOK_PRE_EVT:
+		hook_type = BTDEV_HOOK_PRE_EVT;
+		break;
+	case HCIEMU_HOOK_POST_EVT:
+		hook_type = BTDEV_HOOK_POST_EVT;
+		break;
+	default:
+		return false;
+	}
+
+	return btdev_del_hook(hciemu->master_dev, hook_type, opcode);
+}
Signature · 1 line
2.26.2
#4 lore raw

Re: [RFC PATCH BlueZ 02/10] emulator/hciemu: Create ELL based version of hciemu

Hi Inga,

Quoted 3 lines · Inga Stotland

This adds a separate implementtion of hciemu code, hciemu-ell.c, that uses ELL library primitives.

I wonder if this should really be separated like this or we just make use of struct io instead of l_io, that way we don't need to keep duplicating things on the emulator, the other option would be to drop entirely the glib version but I guess you haven't done that because there are quite a few dependencies to get rid in order to run the tester with ell.

Quoted 578 lines
---
 emulator/hciemu-ell.c | 564 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 564 insertions(+)
 create mode 100644 emulator/hciemu-ell.c
emulator/hciemu-ell.c new file +564 -1
new file mode 100644
index 000000000..40342e99b
@@ -0,0 +1,564 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012-2014, 2020  Intel Corporation. All rights reserved.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <ell/ell.h>
+
+#include "lib/bluetooth.h"
+#include "lib/hci.h"
+
+#include "monitor/bt.h"
+#include "emulator/btdev.h"
+#include "emulator/bthost.h"
+#include "src/shared/util.h"
+#include "src/shared/queue.h"
+#include "emulator/hciemu.h"
+
+struct hciemu {
+       int ref_count;
+       enum btdev_type btdev_type;
+       struct bthost *host_stack;
+       struct btdev *master_dev;
+       struct btdev *client_dev;
+       struct l_io *host_io;
+       struct l_io *master_io;
+       struct l_io *client_io;
+       struct queue *post_command_hooks;
+       char bdaddr_str[18];
+
+       hciemu_debug_func_t debug_callback;
+       hciemu_destroy_func_t debug_destroy;
+       void *debug_data;
+};
+
+struct hciemu_command_hook {
+       hciemu_command_func_t function;
+       void *user_data;
+};
+
+static void destroy_command_hook(void *data)
+{
+       struct hciemu_command_hook *hook = data;
+
+       free(hook);
+}
+
+struct run_data {
+       uint16_t opcode;
+       const void *data;
+       uint8_t len;
+};
+
+static void run_command_hook(void *data, void *user_data)
+{
+       struct hciemu_command_hook *hook = data;
+       struct run_data *run_data = user_data;
+
+       if (hook->function)
+               hook->function(run_data->opcode, run_data->data,
+                                       run_data->len, hook->user_data);
+}
+
+static void master_command_callback(uint16_t opcode,
+                               const void *data, uint8_t len,
+                               btdev_callback callback, void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+       struct run_data run_data = { .opcode = opcode,
+                                               .data = data, .len = len };
+
+       btdev_command_default(callback);
+
+       queue_foreach(hciemu->post_command_hooks, run_command_hook, &run_data);
+}
+
+static void client_command_callback(uint16_t opcode,
+                               const void *data, uint8_t len,
+                               btdev_callback callback, void *user_data)
+{
+       btdev_command_default(callback);
+}
+
+static void writev_callback(const struct iovec *iov, int iovlen,
+                                                               void *user_data)
+{
+       struct l_io *io = user_data;
+       ssize_t written;
+       int fd;
+
+       fd = l_io_get_fd(io);
+
+       written = writev(fd, iov, iovlen);
+       if (written < 0)
+               return;
+}
+
+static bool receive_bthost(struct l_io *io, void *user_data)
+{
+       struct bthost *bthost = user_data;
+       unsigned char buf[4096];
+       ssize_t len;
+       int fd;
+
+       fd = l_io_get_fd(io);
+
+       len = read(fd, buf, sizeof(buf));
+       if (len < 0)
+               return false;
+
+       bthost_receive_h4(bthost, buf, len);
+
+       return true;
+}
+
+static struct l_io *create_io_bthost(int fd, struct bthost *bthost)
+{
+       struct l_io *io;
+
+       io = l_io_new(fd);
+
+       l_io_set_close_on_destroy(io, true);
+
+       bthost_set_send_handler(bthost, writev_callback, io);
+
+       l_io_set_read_handler(io, receive_bthost, bthost, NULL);
+
+       return io;
+}
+
+static bool receive_btdev(struct l_io *io, void *user_data)
+
+{
+       struct btdev *btdev = user_data;
+       unsigned char buf[4096];
+       ssize_t len;
+       int fd;
+
+       fd = l_io_get_fd(io);
+
+       len = read(fd, buf, sizeof(buf));
+       if (len < 0) {
+               if (errno == EAGAIN || errno == EINTR)
+                       return true;
+
+               return false;
+       }
+
+       if (len < 1)
+               return false;
+
+       switch (buf[0]) {
+       case BT_H4_CMD_PKT:
+       case BT_H4_ACL_PKT:
+       case BT_H4_SCO_PKT:
+               btdev_receive_h4(btdev, buf, len);
+               break;
+       }
+
+       return true;
+}
+
+static struct l_io *create_io_btdev(int fd, struct btdev *btdev)
+{
+       struct l_io *io;
+
+       io = l_io_new(fd);
+
+       l_io_set_close_on_destroy(io, true);
+
+       btdev_set_send_handler(btdev, writev_callback, io);
+
+       l_io_set_read_handler(io, receive_btdev, btdev, NULL);
+
+       return io;
+}
+
+static bool create_vhci(struct hciemu *hciemu)
+{
+       struct btdev *btdev;
+       uint8_t create_req[2];
+       ssize_t written;
+       int fd;
+
+       btdev = btdev_create(hciemu->btdev_type, 0x00);
+       if (!btdev)
+               return false;
+
+       btdev_set_command_handler(btdev, master_command_callback, hciemu);
+
+       fd = open("/dev/vhci", O_RDWR | O_NONBLOCK | O_CLOEXEC);
+       if (fd < 0) {
+               perror("Opening /dev/vhci failed");
+               btdev_destroy(btdev);
+               return false;
+       }
+
+       create_req[0] = HCI_VENDOR_PKT;
+       create_req[1] = HCI_PRIMARY;
+
+       written = write(fd, create_req, sizeof(create_req));
+       if (written < 0) {
+               close(fd);
+               btdev_destroy(btdev);
+               return false;
+       }
+
+       hciemu->master_dev = btdev;
+
+       hciemu->master_io = create_io_btdev(fd, btdev);
+
+       return true;
+}
+
+struct bthost *hciemu_client_get_host(struct hciemu *hciemu)
+{
+       if (!hciemu)
+               return NULL;
+
+       return hciemu->host_stack;
+}
+
+static bool create_stack(struct hciemu *hciemu)
+{
+       struct btdev *btdev;
+       struct bthost *bthost;
+       int sv[2];
+
+       btdev = btdev_create(hciemu->btdev_type, 0x00);
+       if (!btdev)
+               return false;
+
+       bthost = bthost_create();
+       if (!bthost) {
+               btdev_destroy(btdev);
+               return false;
+       }
+
+       btdev_set_command_handler(btdev, client_command_callback, hciemu);
+
+       if (socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC,
+                                                               0, sv) < 0) {
+               bthost_destroy(bthost);
+               btdev_destroy(btdev);
+               return false;
+       }
+
+       hciemu->client_dev = btdev;
+       hciemu->host_stack = bthost;
+
+       hciemu->client_io = create_io_btdev(sv[0], btdev);
+       hciemu->host_io = create_io_bthost(sv[1], bthost);
+
+       return true;
+}
+
+static void start_stack(void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+
+       bthost_start(hciemu->host_stack);
+}
+
+struct hciemu *hciemu_new(enum hciemu_type type)
+{
+       struct hciemu *hciemu;
+
+       hciemu = new0(struct hciemu, 1);
+       if (!hciemu)
+               return NULL;
+
+       switch (type) {
+       case HCIEMU_TYPE_BREDRLE:
+               hciemu->btdev_type = BTDEV_TYPE_BREDRLE;
+               break;
+       case HCIEMU_TYPE_BREDR:
+               hciemu->btdev_type = BTDEV_TYPE_BREDR;
+               break;
+       case HCIEMU_TYPE_LE:
+               hciemu->btdev_type = BTDEV_TYPE_LE;
+               break;
+       case HCIEMU_TYPE_LEGACY:
+               hciemu->btdev_type = BTDEV_TYPE_BREDR20;
+               break;
+       case HCIEMU_TYPE_BREDRLE50:
+               hciemu->btdev_type = BTDEV_TYPE_BREDRLE50;
+               break;
+       case HCIEMU_TYPE_BREDRLE52:
+               hciemu->btdev_type = BTDEV_TYPE_BREDRLE52;
+               break;
+       default:
+               return NULL;
+       }
+
+       hciemu->post_command_hooks = queue_new();
+       if (!hciemu->post_command_hooks) {
+               free(hciemu);
+               return NULL;
+       }
+
+       if (!create_vhci(hciemu)) {
+               queue_destroy(hciemu->post_command_hooks, NULL);
+               free(hciemu);
+               return NULL;
+       }
+
+       if (!create_stack(hciemu)) {
+               l_io_destroy(hciemu->master_io);
+               btdev_destroy(hciemu->master_dev);
+               queue_destroy(hciemu->post_command_hooks, NULL);
+               free(hciemu);
+               return NULL;
+       }
+
+       l_idle_oneshot(start_stack, hciemu, NULL);
+
+       return hciemu_ref(hciemu);
+}
+
+struct hciemu *hciemu_ref(struct hciemu *hciemu)
+{
+       if (!hciemu)
+               return NULL;
+
+       __sync_fetch_and_add(&hciemu->ref_count, 1);
+
+       return hciemu;
+}
+
+void hciemu_unref(struct hciemu *hciemu)
+{
+       if (!hciemu)
+               return;
+
+       if (__sync_sub_and_fetch(&hciemu->ref_count, 1))
+               return;
+
+       queue_destroy(hciemu->post_command_hooks, destroy_command_hook);
+
+       l_io_destroy(hciemu->host_io);
+       l_io_destroy(hciemu->client_io);
+       l_io_destroy(hciemu->master_io);
+
+       bthost_destroy(hciemu->host_stack);
+       btdev_destroy(hciemu->client_dev);
+       btdev_destroy(hciemu->master_dev);
+
+       free(hciemu);
+}
+
+static void bthost_debug(const char *str, void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
+                                       "bthost: %s", str);
+}
+
+static void btdev_master_debug(const char *str, void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
+                                       "btdev: %s", str);
+}
+
+static void btdev_client_debug(const char *str, void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
+                                       "btdev[bthost]: %s", str);
+}
+
+bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback,
+                       void *user_data, hciemu_destroy_func_t destroy)
+{
+       if (!hciemu)
+               return false;
+
+       if (hciemu->debug_destroy)
+               hciemu->debug_destroy(hciemu->debug_data);
+
+       hciemu->debug_callback = callback;
+       hciemu->debug_destroy = destroy;
+       hciemu->debug_data = user_data;
+
+       btdev_set_debug(hciemu->master_dev, btdev_master_debug, hciemu, NULL);
+       btdev_set_debug(hciemu->client_dev, btdev_client_debug, hciemu, NULL);
+       bthost_set_debug(hciemu->host_stack, bthost_debug, hciemu, NULL);
+
+       return true;
+}
+
+const char *hciemu_get_address(struct hciemu *hciemu)
+{
+       const uint8_t *addr;
+
+       if (!hciemu || !hciemu->master_dev)
+               return NULL;
+
+       addr = btdev_get_bdaddr(hciemu->master_dev);
+       sprintf(hciemu->bdaddr_str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+                       addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
+       return hciemu->bdaddr_str;
+}
+
+uint8_t *hciemu_get_features(struct hciemu *hciemu)
+{
+       if (!hciemu || !hciemu->master_dev)
+               return NULL;
+
+       return btdev_get_features(hciemu->master_dev);
+}
+
+const uint8_t *hciemu_get_master_bdaddr(struct hciemu *hciemu)
+{
+       if (!hciemu || !hciemu->master_dev)
+               return NULL;
+
+       return btdev_get_bdaddr(hciemu->master_dev);
+}
+
+const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu)
+{
+       if (!hciemu || !hciemu->client_dev)
+               return NULL;
+
+       return btdev_get_bdaddr(hciemu->client_dev);
+}
+
+uint8_t hciemu_get_master_scan_enable(struct hciemu *hciemu)
+{
+       if (!hciemu || !hciemu->master_dev)
+               return 0;
+
+       return btdev_get_scan_enable(hciemu->master_dev);
+}
+
+uint8_t hciemu_get_master_le_scan_enable(struct hciemu *hciemu)
+{
+       if (!hciemu || !hciemu->master_dev)
+               return 0;
+
+       return btdev_get_le_scan_enable(hciemu->master_dev);
+}
+
+void hciemu_set_master_le_states(struct hciemu *hciemu,
+                                               const uint8_t *le_states)
+{
+       if (!hciemu || !hciemu->master_dev)
+               return;
+
+       btdev_set_le_states(hciemu->master_dev, le_states);
+}
+
+bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
+                       hciemu_command_func_t function, void *user_data)
+{
+       struct hciemu_command_hook *hook;
+
+       if (!hciemu)
+               return false;
+
+       hook = new0(struct hciemu_command_hook, 1);
+       if (!hook)
+               return false;
+
+       hook->function = function;
+       hook->user_data = user_data;
+
+       if (!queue_push_tail(hciemu->post_command_hooks, hook)) {
+               free(hook);
+               return false;
+       }
+
+       return true;
+}
+
+bool hciemu_clear_master_post_command_hooks(struct hciemu *hciemu)
+{
+       if (!hciemu)
+               return false;
+
+       queue_remove_all(hciemu->post_command_hooks,
+                                       NULL, NULL, destroy_command_hook);
+       return true;
+}
+
+int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+                               uint16_t opcode, hciemu_hook_func_t function,
+                               void *user_data)
+{
+       enum btdev_hook_type hook_type;
+
+       if (!hciemu)
+               return -1;
+
+       switch (type) {
+       case HCIEMU_HOOK_PRE_CMD:
+               hook_type = BTDEV_HOOK_PRE_CMD;
+               break;
+       case HCIEMU_HOOK_POST_CMD:
+               hook_type = BTDEV_HOOK_POST_CMD;
+               break;
+       case HCIEMU_HOOK_PRE_EVT:
+               hook_type = BTDEV_HOOK_PRE_EVT;
+               break;
+       case HCIEMU_HOOK_POST_EVT:
+               hook_type = BTDEV_HOOK_POST_EVT;
+               break;
+       default:
+               return -1;
+       }
+
+       return btdev_add_hook(hciemu->master_dev, hook_type, opcode, function,
+                                                               user_data);
+}
+
+bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+                                                               uint16_t opcode)
+{
+       enum btdev_hook_type hook_type;
+
+       if (!hciemu)
+               return false;
+
+       switch (type) {
+       case HCIEMU_HOOK_PRE_CMD:
+               hook_type = BTDEV_HOOK_PRE_CMD;
+               break;
+       case HCIEMU_HOOK_POST_CMD:
+               hook_type = BTDEV_HOOK_POST_CMD;
+               break;
+       case HCIEMU_HOOK_PRE_EVT:
+               hook_type = BTDEV_HOOK_PRE_EVT;
+               break;
+       case HCIEMU_HOOK_POST_EVT:
+               hook_type = BTDEV_HOOK_POST_EVT;
+               break;
+       default:
+               return false;
+       }
+
+       return btdev_del_hook(hciemu->master_dev, hook_type, opcode);
+}
--

2.26.2

Signature · 1 line
Luiz Augusto von Dentz

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [RFC PATCH BlueZ 02/10] emulator/hciemu: Create ELL based version of hciemu

Hi Inga,

Quoted 30 lines · Inga

Hi Luiz,

On Mon, 2020-11-09 at 10:04 -0800, Luiz Augusto von Dentz wrote:

Hi Inga,

On Fri, Nov 6, 2020 at 11:06 PM Inga Stotland <

[email protected]

Quoted 1 line

wrote:

This adds a separate implementtion of hciemu code, hciemu-ell.c,

that uses ELL library primitives.

I wonder if this should really be separated like this or we just make

use of struct io instead of l_io, that way we don't need to keep

duplicating things on the emulator, the other option would be to drop

entirely the glib version but I guess you haven't done that because

there are quite a few dependencies to get rid in order to run the

Quoted 8 lines

tester with ell.

I would've made one version of hciemu.c with the unified io, but there's a reference to g_idel_add that has equivalent in ELL, but not the internal bluez libs.

Also, hciemu is linked with android test build (android/Makefile.am) and android is a completely different animal: from what I can see it relies heavily on GLib

and I wouldn't know how to test the android stuff once I make the changes. So I chose to err on the side of caution and create a duplicate.

Im planning to remove android actually, just need to move a few things around since some unit test uses the android version.

Quoted 1,161 lines

---

 emulator/hciemu-ell.c | 564 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 564 insertions(+)
 create mode 100644 emulator/hciemu-ell.c
emulator/hciemu-ell.c +0 -0

new file mode 100644

index 000000000..40342e99b

--- /dev/null

+++ b/emulator/hciemu-ell.c

emulator/hciemu-ell.c +564 -1
@@ -0,0 +1,564 @@
 
+// SPDX-License-Identifier: LGPL-2.1-or-later
 
+/*
 
+ *
 
+ *  BlueZ - Bluetooth protocol stack for Linux
 
+ *
 
+ *  Copyright (C) 2012-2014, 2020  Intel Corporation. All rights reserved.
 
+ *
 
+ *
 
+ */
 
+
 
+#ifdef HAVE_CONFIG_H
 
+#include <config.h>
 
+#endif
 
+
 
+#define _GNU_SOURCE
 
+#include <stdio.h>
 
+#include <fcntl.h>
 
+#include <unistd.h>
 
+#include <stdlib.h>
 
+#include <string.h>
 
+#include <stdbool.h>
 
+#include <errno.h>
 
+#include <sys/socket.h>
 
+
 
+#include <ell/ell.h>
 
+
 
+#include "lib/bluetooth.h"
 
+#include "lib/hci.h"
 
+
 
+#include "monitor/bt.h"
 
+#include "emulator/btdev.h"
 
+#include "emulator/bthost.h"
 
+#include "src/shared/util.h"
 
+#include "src/shared/queue.h"
 
+#include "emulator/hciemu.h"
 
+
 
+struct hciemu {
 
+       int ref_count;
 
+       enum btdev_type btdev_type;
 
+       struct bthost *host_stack;
 
+       struct btdev *master_dev;
 
+       struct btdev *client_dev;
 
+       struct l_io *host_io;
 
+       struct l_io *master_io;
 
+       struct l_io *client_io;
 
+       struct queue *post_command_hooks;
 
+       char bdaddr_str[18];
 
+
 
+       hciemu_debug_func_t debug_callback;
 
+       hciemu_destroy_func_t debug_destroy;
 
+       void *debug_data;
 
+};
 
+
 
+struct hciemu_command_hook {
 
+       hciemu_command_func_t function;
 
+       void *user_data;
 
+};
 
+
 
+static void destroy_command_hook(void *data)
 
+{
 
+       struct hciemu_command_hook *hook = data;
 
+
 
+       free(hook);
 
+}
 
+
 
+struct run_data {
 
+       uint16_t opcode;
 
+       const void *data;
 
+       uint8_t len;
 
+};
 
+
 
+static void run_command_hook(void *data, void *user_data)
 
+{
 
+       struct hciemu_command_hook *hook = data;
 
+       struct run_data *run_data = user_data;
 
+
 
+       if (hook->function)
 
+               hook->function(run_data->opcode, run_data->data,
 
+                                       run_data->len, hook->user_data);
 
+}
 
+
 
+static void master_command_callback(uint16_t opcode,
 
+                               const void *data, uint8_t len,
 
+                               btdev_callback callback, void *user_data)
 
+{
 
+       struct hciemu *hciemu = user_data;
 
+       struct run_data run_data = { .opcode = opcode,
 
+                                               .data = data, .len = len };
 
+
 
+       btdev_command_default(callback);
 
+
 
+       queue_foreach(hciemu->post_command_hooks, run_command_hook, &run_data);
 
+}
 
+
 
+static void client_command_callback(uint16_t opcode,
 
+                               const void *data, uint8_t len,
 
+                               btdev_callback callback, void *user_data)
 
+{
 
+       btdev_command_default(callback);
 
+}
 
+
 
+static void writev_callback(const struct iovec *iov, int iovlen,
 
+                                                               void *user_data)
 
+{
 
+       struct l_io *io = user_data;
 
+       ssize_t written;
 
+       int fd;
 
+
 
+       fd = l_io_get_fd(io);
 
+
 
+       written = writev(fd, iov, iovlen);
 
+       if (written < 0)
 
+               return;
 
+}
 
+
 
+static bool receive_bthost(struct l_io *io, void *user_data)
 
+{
 
+       struct bthost *bthost = user_data;
 
+       unsigned char buf[4096];
 
+       ssize_t len;
 
+       int fd;
 
+
 
+       fd = l_io_get_fd(io);
 
+
 
+       len = read(fd, buf, sizeof(buf));
 
+       if (len < 0)
 
+               return false;
 
+
 
+       bthost_receive_h4(bthost, buf, len);
 
+
 
+       return true;
 
+}
 
+
 
+static struct l_io *create_io_bthost(int fd, struct bthost *bthost)
 
+{
 
+       struct l_io *io;
 
+
 
+       io = l_io_new(fd);
 
+
 
+       l_io_set_close_on_destroy(io, true);
 
+
 
+       bthost_set_send_handler(bthost, writev_callback, io);
 
+
 
+       l_io_set_read_handler(io, receive_bthost, bthost, NULL);
 
+
 
+       return io;
 
+}
 
+
 
+static bool receive_btdev(struct l_io *io, void *user_data)
 
+
 
+{
 
+       struct btdev *btdev = user_data;
 
+       unsigned char buf[4096];
 
+       ssize_t len;
 
+       int fd;
 
+
 
+       fd = l_io_get_fd(io);
 
+
 
+       len = read(fd, buf, sizeof(buf));
 
+       if (len < 0) {
 
+               if (errno == EAGAIN || errno == EINTR)
 
+                       return true;
 
+
 
+               return false;
 
+       }
 
+
 
+       if (len < 1)
 
+               return false;
 
+
 
+       switch (buf[0]) {
 
+       case BT_H4_CMD_PKT:
 
+       case BT_H4_ACL_PKT:
 
+       case BT_H4_SCO_PKT:
 
+               btdev_receive_h4(btdev, buf, len);
 
+               break;
 
+       }
 
+
 
+       return true;
 
+}
 
+
 
+static struct l_io *create_io_btdev(int fd, struct btdev *btdev)
 
+{
 
+       struct l_io *io;
 
+
 
+       io = l_io_new(fd);
 
+
 
+       l_io_set_close_on_destroy(io, true);
 
+
 
+       btdev_set_send_handler(btdev, writev_callback, io);
 
+
 
+       l_io_set_read_handler(io, receive_btdev, btdev, NULL);
 
+
 
+       return io;
 
+}
 
+
 
+static bool create_vhci(struct hciemu *hciemu)
 
+{
 
+       struct btdev *btdev;
 
+       uint8_t create_req[2];
 
+       ssize_t written;
 
+       int fd;
 
+
 
+       btdev = btdev_create(hciemu->btdev_type, 0x00);
 
+       if (!btdev)
 
+               return false;
 
+
 
+       btdev_set_command_handler(btdev, master_command_callback, hciemu);
 
+
 
+       fd = open("/dev/vhci", O_RDWR | O_NONBLOCK | O_CLOEXEC);
 
+       if (fd < 0) {
 
+               perror("Opening /dev/vhci failed");
 
+               btdev_destroy(btdev);
 
+               return false;
 
+       }
 
+
 
+       create_req[0] = HCI_VENDOR_PKT;
 
+       create_req[1] = HCI_PRIMARY;
 
+
 
+       written = write(fd, create_req, sizeof(create_req));
 
+       if (written < 0) {
 
+               close(fd);
 
+               btdev_destroy(btdev);
 
+               return false;
 
+       }
 
+
 
+       hciemu->master_dev = btdev;
 
+
 
+       hciemu->master_io = create_io_btdev(fd, btdev);
 
+
 
+       return true;
 
+}
 
+
 
+struct bthost *hciemu_client_get_host(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu)
 
+               return NULL;
 
+
 
+       return hciemu->host_stack;
 
+}
 
+
 
+static bool create_stack(struct hciemu *hciemu)
 
+{
 
+       struct btdev *btdev;
 
+       struct bthost *bthost;
 
+       int sv[2];
 
+
 
+       btdev = btdev_create(hciemu->btdev_type, 0x00);
 
+       if (!btdev)
 
+               return false;
 
+
 
+       bthost = bthost_create();
 
+       if (!bthost) {
 
+               btdev_destroy(btdev);
 
+               return false;
 
+       }
 
+
 
+       btdev_set_command_handler(btdev, client_command_callback, hciemu);
 
+
 
+       if (socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC,
 
+                                                               0, sv) < 0) {
 
+               bthost_destroy(bthost);
 
+               btdev_destroy(btdev);
 
+               return false;
 
+       }
 
+
 
+       hciemu->client_dev = btdev;
 
+       hciemu->host_stack = bthost;
 
+
 
+       hciemu->client_io = create_io_btdev(sv[0], btdev);
 
+       hciemu->host_io = create_io_bthost(sv[1], bthost);
 
+
 
+       return true;
 
+}
 
+
 
+static void start_stack(void *user_data)
 
+{
 
+       struct hciemu *hciemu = user_data;
 
+
 
+       bthost_start(hciemu->host_stack);
 
+}
 
+
 
+struct hciemu *hciemu_new(enum hciemu_type type)
 
+{
 
+       struct hciemu *hciemu;
 
+
 
+       hciemu = new0(struct hciemu, 1);
 
+       if (!hciemu)
 
+               return NULL;
 
+
 
+       switch (type) {
 
+       case HCIEMU_TYPE_BREDRLE:
 
+               hciemu->btdev_type = BTDEV_TYPE_BREDRLE;
 
+               break;
 
+       case HCIEMU_TYPE_BREDR:
 
+               hciemu->btdev_type = BTDEV_TYPE_BREDR;
 
+               break;
 
+       case HCIEMU_TYPE_LE:
 
+               hciemu->btdev_type = BTDEV_TYPE_LE;
 
+               break;
 
+       case HCIEMU_TYPE_LEGACY:
 
+               hciemu->btdev_type = BTDEV_TYPE_BREDR20;
 
+               break;
 
+       case HCIEMU_TYPE_BREDRLE50:
 
+               hciemu->btdev_type = BTDEV_TYPE_BREDRLE50;
 
+               break;
 
+       case HCIEMU_TYPE_BREDRLE52:
 
+               hciemu->btdev_type = BTDEV_TYPE_BREDRLE52;
 
+               break;
 
+       default:
 
+               return NULL;
 
+       }
 
+
 
+       hciemu->post_command_hooks = queue_new();
 
+       if (!hciemu->post_command_hooks) {
 
+               free(hciemu);
 
+               return NULL;
 
+       }
 
+
 
+       if (!create_vhci(hciemu)) {
 
+               queue_destroy(hciemu->post_command_hooks, NULL);
 
+               free(hciemu);
 
+               return NULL;
 
+       }
 
+
 
+       if (!create_stack(hciemu)) {
 
+               l_io_destroy(hciemu->master_io);
 
+               btdev_destroy(hciemu->master_dev);
 
+               queue_destroy(hciemu->post_command_hooks, NULL);
 
+               free(hciemu);
 
+               return NULL;
 
+       }
 
+
 
+       l_idle_oneshot(start_stack, hciemu, NULL);
 
+
 
+       return hciemu_ref(hciemu);
 
+}
 
+
 
+struct hciemu *hciemu_ref(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu)
 
+               return NULL;
 
+
 
+       __sync_fetch_and_add(&hciemu->ref_count, 1);
 
+
 
+       return hciemu;
 
+}
 
+
 
+void hciemu_unref(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu)
 
+               return;
 
+
 
+       if (__sync_sub_and_fetch(&hciemu->ref_count, 1))
 
+               return;
 
+
 
+       queue_destroy(hciemu->post_command_hooks, destroy_command_hook);
 
+
 
+       l_io_destroy(hciemu->host_io);
 
+       l_io_destroy(hciemu->client_io);
 
+       l_io_destroy(hciemu->master_io);
 
+
 
+       bthost_destroy(hciemu->host_stack);
 
+       btdev_destroy(hciemu->client_dev);
 
+       btdev_destroy(hciemu->master_dev);
 
+
 
+       free(hciemu);
 
+}
 
+
 
+static void bthost_debug(const char *str, void *user_data)
 
+{
 
+       struct hciemu *hciemu = user_data;
 
+
 
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
 
+                                       "bthost: %s", str);
 
+}
 
+
 
+static void btdev_master_debug(const char *str, void *user_data)
 
+{
 
+       struct hciemu *hciemu = user_data;
 
+
 
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
 
+                                       "btdev: %s", str);
 
+}
 
+
 
+static void btdev_client_debug(const char *str, void *user_data)
 
+{
 
+       struct hciemu *hciemu = user_data;
 
+
 
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
 
+                                       "btdev[bthost]: %s", str);
 
+}
 
+
 
+bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback,
 
+                       void *user_data, hciemu_destroy_func_t destroy)
 
+{
 
+       if (!hciemu)
 
+               return false;
 
+
 
+       if (hciemu->debug_destroy)
 
+               hciemu->debug_destroy(hciemu->debug_data);
 
+
 
+       hciemu->debug_callback = callback;
 
+       hciemu->debug_destroy = destroy;
 
+       hciemu->debug_data = user_data;
 
+
 
+       btdev_set_debug(hciemu->master_dev, btdev_master_debug, hciemu, NULL);
 
+       btdev_set_debug(hciemu->client_dev, btdev_client_debug, hciemu, NULL);
 
+       bthost_set_debug(hciemu->host_stack, bthost_debug, hciemu, NULL);
 
+
 
+       return true;
 
+}
 
+
 
+const char *hciemu_get_address(struct hciemu *hciemu)
 
+{
 
+       const uint8_t *addr;
 
+
 
+       if (!hciemu || !hciemu->master_dev)
 
+               return NULL;
 
+
 
+       addr = btdev_get_bdaddr(hciemu->master_dev);
 
+       sprintf(hciemu->bdaddr_str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
 
+                       addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
 
+       return hciemu->bdaddr_str;
 
+}
 
+
 
+uint8_t *hciemu_get_features(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu || !hciemu->master_dev)
 
+               return NULL;
 
+
 
+       return btdev_get_features(hciemu->master_dev);
 
+}
 
+
 
+const uint8_t *hciemu_get_master_bdaddr(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu || !hciemu->master_dev)
 
+               return NULL;
 
+
 
+       return btdev_get_bdaddr(hciemu->master_dev);
 
+}
 
+
 
+const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu || !hciemu->client_dev)
 
+               return NULL;
 
+
 
+       return btdev_get_bdaddr(hciemu->client_dev);
 
+}
 
+
 
+uint8_t hciemu_get_master_scan_enable(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu || !hciemu->master_dev)
 
+               return 0;
 
+
 
+       return btdev_get_scan_enable(hciemu->master_dev);
 
+}
 
+
 
+uint8_t hciemu_get_master_le_scan_enable(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu || !hciemu->master_dev)
 
+               return 0;
 
+
 
+       return btdev_get_le_scan_enable(hciemu->master_dev);
 
+}
 
+
 
+void hciemu_set_master_le_states(struct hciemu *hciemu,
 
+                                               const uint8_t *le_states)
 
+{
 
+       if (!hciemu || !hciemu->master_dev)
 
+               return;
 
+
 
+       btdev_set_le_states(hciemu->master_dev, le_states);
 
+}
 
+
 
+bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
 
+                       hciemu_command_func_t function, void *user_data)
 
+{
 
+       struct hciemu_command_hook *hook;
 
+
 
+       if (!hciemu)
 
+               return false;
 
+
 
+       hook = new0(struct hciemu_command_hook, 1);
 
+       if (!hook)
 
+               return false;
 
+
 
+       hook->function = function;
 
+       hook->user_data = user_data;
 
+
 
+       if (!queue_push_tail(hciemu->post_command_hooks, hook)) {
 
+               free(hook);
 
+               return false;
 
+       }
 
+
 
+       return true;
 
+}
 
+
 
+bool hciemu_clear_master_post_command_hooks(struct hciemu *hciemu)
 
+{
 
+       if (!hciemu)
 
+               return false;
 
+
 
+       queue_remove_all(hciemu->post_command_hooks,
 
+                                       NULL, NULL, destroy_command_hook);
 
+       return true;
 
+}
 
+
 
+int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
 
+                               uint16_t opcode, hciemu_hook_func_t function,
 
+                               void *user_data)
 
+{
 
+       enum btdev_hook_type hook_type;
 
+
 
+       if (!hciemu)
 
+               return -1;
 
+
 
+       switch (type) {
 
+       case HCIEMU_HOOK_PRE_CMD:
 
+               hook_type = BTDEV_HOOK_PRE_CMD;
 
+               break;
 
+       case HCIEMU_HOOK_POST_CMD:
 
+               hook_type = BTDEV_HOOK_POST_CMD;
 
+               break;
 
+       case HCIEMU_HOOK_PRE_EVT:
 
+               hook_type = BTDEV_HOOK_PRE_EVT;
 
+               break;
 
+       case HCIEMU_HOOK_POST_EVT:
 
+               hook_type = BTDEV_HOOK_POST_EVT;
 
+               break;
 
+       default:
 
+               return -1;
 
+       }
 
+
 
+       return btdev_add_hook(hciemu->master_dev, hook_type, opcode, function,
 
+                                                               user_data);
 
+}
 
+
 
+bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
 
+                                                               uint16_t opcode)
 
+{
 
+       enum btdev_hook_type hook_type;
 
+
 
+       if (!hciemu)
 
+               return false;
 
+
 
+       switch (type) {
 
+       case HCIEMU_HOOK_PRE_CMD:
 
+               hook_type = BTDEV_HOOK_PRE_CMD;
 
+               break;
 
+       case HCIEMU_HOOK_POST_CMD:
 
+               hook_type = BTDEV_HOOK_POST_CMD;
 
+               break;
 
+       case HCIEMU_HOOK_PRE_EVT:
 
+               hook_type = BTDEV_HOOK_PRE_EVT;
 
+               break;
 
+       case HCIEMU_HOOK_POST_EVT:
 
+               hook_type = BTDEV_HOOK_POST_EVT;
 
+               break;
 
+       default:
 
+               return false;
 
+       }
 
+
 
+       return btdev_del_hook(hciemu->master_dev, hook_type, opcode);
 
+}
 
--

2.26.2

Signature · 1 line
Luiz Augusto von Dentz
#7 lore raw

RFC PATCH 3/10 tools/gap-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools     |  6 ++--
 tools/gap-tester.c | 87 ++++++++++++++++++++++++++--------------------
 2 files changed, 51 insertions(+), 42 deletions(-)
Makefile.tools +2 -4
index d5fdf2d89..259427443 100644
@@ -146,14 +146,12 @@ tools_smp_tester_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-glib.la $(GLIB_LIBS)
 
 tools_gap_tester_SOURCES = tools/gap-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_gap_tester_LDADD =  lib/libbluetooth-internal.la \
-				gdbus/libgdbus-internal.la \
-				src/libshared-glib.la \
-				$(GLIB_LIBS) $(DBUS_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 
 tools_sco_tester_SOURCES = tools/sco-tester.c monitor/bt.h \
 				emulator/hciemu.h emulator/hciemu.c \
tools/gap-tester.c +49 -38

144 lines not on this page · raw message

Signature · 1 line
2.26.2
#8 lore raw

RFC PATCH 4/10 tools/sco-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools     |  4 ++--
 tools/sco-tester.c | 33 ++++++++++++++-------------------
 2 files changed, 16 insertions(+), 21 deletions(-)
Makefile.tools +2 -2
index 259427443..15613a5c9 100644
@@ -154,12 +154,12 @@ tools_gap_tester_LDADD =  lib/libbluetooth-internal.la \
 				src/libshared-ell.la $(ell_ldadd)
 
 tools_sco_tester_SOURCES = tools/sco-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_sco_tester_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-glib.la $(GLIB_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 
 tools_hci_tester_SOURCES = tools/hci-tester.c monitor/bt.h
 tools_hci_tester_LDADD = src/libshared-glib.la $(GLIB_LIBS)
tools/sco-tester.c +14 -19
index 2b8dc0d4a..c3c43a1c3 100644
@@ -17,7 +17,7 @@
 #include <errno.h>
 #include <stdbool.h>
 
-#include <glib.h>
+#include <ell/ell.h>
 
 #include "lib/bluetooth.h"
 #include "lib/sco.h"
@@ -36,7 +36,7 @@ struct test_data {
 	uint16_t mgmt_index;
 	struct hciemu *hciemu;
 	enum hciemu_type hciemu_type;
-	unsigned int io_id;
+	struct l_io *io;
 	bool disable_esco;
 };
 
@@ -196,20 +196,21 @@ static void test_data_free(void *test_data)
 {
 	struct test_data *data = test_data;
 
-	if (data->io_id > 0)
-		g_source_remove(data->io_id);
+	if (data->io) {
+		l_io_destroy(data->io);
+		data->io = NULL;
+	}
 
-	free(data);
+	l_free(data);
 }
 
 #define test_sco_full(name, data, setup, func, _disable_esco) \
 	do { \
 		struct test_data *user; \
-		user = malloc(sizeof(struct test_data)); \
+		user = l_new(struct test_data, 1); \
 		if (!user) \
 			break; \
 		user->hciemu_type = HCIEMU_TYPE_BREDRLE; \
-		user->io_id = 0; \
 		user->test_data = data; \
 		user->disable_esco = _disable_esco; \
 		tester_add_full(name, data, \
@@ -474,17 +475,14 @@ static int connect_sco_sock(struct test_data *data, int sk)
 	return 0;
 }
 
-static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
-							gpointer user_data)
+static bool sco_connect_cb(struct l_io *io, void *user_data)
 {
 	struct test_data *data = tester_get_data();
 	const struct sco_client_data *scodata = data->test_data;
 	int err, sk_err, sk;
 	socklen_t len = sizeof(sk_err);
 
-	data->io_id = 0;
-
-	sk = g_io_channel_unix_get_fd(io);
+	sk = l_io_get_fd(io);
 
 	if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0)
 		err = -errno;
@@ -501,13 +499,12 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
 	else
 		tester_test_passed();
 
-	return FALSE;
+	return false;
 }
 
 static void test_connect(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
-	GIOChannel *io;
 	int sk;
 
 	sk = create_sco_sock(data);
@@ -522,12 +519,10 @@ static void test_connect(const void *test_data)
 		return;
 	}
 
-	io = g_io_channel_unix_new(sk);
-	g_io_channel_set_close_on_unref(io, TRUE);
-
-	data->io_id = g_io_add_watch(io, G_IO_OUT, sco_connect_cb, NULL);
+	data->io = l_io_new(sk);
+	l_io_set_close_on_destroy(data->io, true);
 
-	g_io_channel_unref(io);
+	l_io_set_write_handler(data->io, sco_connect_cb, NULL, NULL);
 
 	tester_print("Connect in progress");
 }
Signature · 1 line
2.26.2
#9 lore raw

RFC PATCH 5/10 tools/userchan-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools          | 4 ++--
 tools/userchan-tester.c | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)
Makefile.tools +2 -2
index 15613a5c9..7c29e115b 100644
@@ -165,12 +165,12 @@ tools_hci_tester_SOURCES = tools/hci-tester.c monitor/bt.h
 tools_hci_tester_LDADD = src/libshared-glib.la $(GLIB_LIBS)
 
 tools_userchan_tester_SOURCES = tools/userchan-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_userchan_tester_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-glib.la $(GLIB_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 endif
 
 if TOOLS
tools/userchan-tester.c +0 -2
index c17644fb8..21c853221 100644
@@ -18,8 +18,6 @@
 #include <errno.h>
 #include <stdbool.h>
 
-#include <glib.h>
-
 #include "lib/bluetooth.h"
 #include "lib/hci.h"
 #include "lib/mgmt.h"
Signature · 1 line
2.26.2
#10 lore raw

RFC PATCH 6/10 tools/smp-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools     |  4 ++--
 tools/smp-tester.c | 24 +++++++++---------------
 2 files changed, 11 insertions(+), 17 deletions(-)
Makefile.tools +2 -2
index 7c29e115b..83c30252d 100644
@@ -138,12 +138,12 @@ tools_bnep_tester_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-glib.la $(GLIB_LIBS)
 
 tools_smp_tester_SOURCES = tools/smp-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_smp_tester_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-glib.la $(GLIB_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 
 tools_gap_tester_SOURCES = tools/gap-tester.c monitor/bt.h \
 				emulator/hciemu.h emulator/hciemu-ell.c \
tools/smp-tester.c +9 -15
index 7823b6b17..b7843c73d 100644
@@ -18,7 +18,7 @@
 #include <stdbool.h>
 #include <sys/socket.h>
 
-#include <glib.h>
+#include <ell/ell.h>
 
 #include "lib/bluetooth.h"
 #include "lib/hci.h"
@@ -41,7 +41,6 @@ struct test_data {
 	uint16_t mgmt_index;
 	struct hciemu *hciemu;
 	enum hciemu_type hciemu_type;
-	unsigned int io_id;
 	uint8_t ia[6];
 	uint8_t ia_type;
 	uint8_t ra[6];
@@ -223,11 +222,6 @@ static void test_post_teardown(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
 
-	if (data->io_id > 0) {
-		g_source_remove(data->io_id);
-		data->io_id = 0;
-	}
-
 	if (data->crypto) {
 		bt_crypto_unref(data->crypto);
 		data->crypto = NULL;
@@ -287,7 +281,7 @@ static const struct smp_req_rsp nval_req_1[] = {
 
 static const struct smp_data smp_server_nval_req_1_test = {
 	.req = nval_req_1,
-	.req_count = G_N_ELEMENTS(nval_req_1),
+	.req_count = L_ARRAY_SIZE(nval_req_1),
 };
 
 static const uint8_t smp_nval_req_2[7] = { 0x01 };
@@ -300,7 +294,7 @@ static const struct smp_req_rsp srv_nval_req_1[] = {
 
 static const struct smp_data smp_server_nval_req_2_test = {
 	.req = srv_nval_req_1,
-	.req_count = G_N_ELEMENTS(srv_nval_req_1),
+	.req_count = L_ARRAY_SIZE(srv_nval_req_1),
 };
 
 static const uint8_t smp_nval_req_3[] = { 0x01, 0xff };
@@ -313,7 +307,7 @@ static const struct smp_req_rsp srv_nval_req_2[] = {
 
 static const struct smp_data smp_server_nval_req_3_test = {
 	.req = srv_nval_req_2,
-	.req_count = G_N_ELEMENTS(srv_nval_req_2),
+	.req_count = L_ARRAY_SIZE(srv_nval_req_2),
 };
 
 static const uint8_t smp_basic_req_1[] = {	0x01,	/* Pairing Request */
@@ -347,7 +341,7 @@ static const struct smp_req_rsp srv_basic_req_1[] = {
 
 static const struct smp_data smp_server_basic_req_1_test = {
 	.req = srv_basic_req_1,
-	.req_count = G_N_ELEMENTS(srv_basic_req_1),
+	.req_count = L_ARRAY_SIZE(srv_basic_req_1),
 };
 
 static const struct smp_req_rsp cli_basic_req_1[] = {
@@ -361,7 +355,7 @@ static const struct smp_req_rsp cli_basic_req_1[] = {
 
 static const struct smp_data smp_client_basic_req_1_test = {
 	.req = cli_basic_req_1,
-	.req_count = G_N_ELEMENTS(cli_basic_req_1),
+	.req_count = L_ARRAY_SIZE(cli_basic_req_1),
 };
 
 static const uint8_t smp_basic_req_2[] = {	0x01,	/* Pairing Request */
@@ -384,7 +378,7 @@ static const struct smp_req_rsp cli_basic_req_2[] = {
 
 static const struct smp_data smp_client_basic_req_2_test = {
 	.req = cli_basic_req_2,
-	.req_count = G_N_ELEMENTS(cli_basic_req_1),
+	.req_count = L_ARRAY_SIZE(cli_basic_req_1),
 	.mitm = true,
 };
 
@@ -423,7 +417,7 @@ static const struct smp_req_rsp cli_sc_req_1[] = {
 
 static const struct smp_data smp_client_sc_req_1_test = {
 	.req = cli_sc_req_1,
-	.req_count = G_N_ELEMENTS(cli_sc_req_1),
+	.req_count = L_ARRAY_SIZE(cli_sc_req_1),
 	.sc = true,
 };
 
@@ -449,7 +443,7 @@ static const struct smp_req_rsp cli_sc_req_2[] = {
 
 static const struct smp_data smp_client_sc_req_2_test = {
 	.req = cli_sc_req_2,
-	.req_count = G_N_ELEMENTS(cli_sc_req_2),
+	.req_count = L_ARRAY_SIZE(cli_sc_req_2),
 	.sc = true,
 };
 
Signature · 1 line
2.26.2
#11 lore raw

RFC PATCH 7/10 tools/bnep-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools      | 4 ++--
 tools/bnep-tester.c | 9 +--------
 2 files changed, 3 insertions(+), 10 deletions(-)
Makefile.tools +2 -2
index 83c30252d..8c79a528d 100644
@@ -130,12 +130,12 @@ tools_rfcomm_tester_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-glib.la $(GLIB_LIBS)
 
 tools_bnep_tester_SOURCES = tools/bnep-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_bnep_tester_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-glib.la $(GLIB_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 
 tools_smp_tester_SOURCES = tools/smp-tester.c monitor/bt.h \
 				emulator/hciemu.h emulator/hciemu-ell.c \
tools/bnep-tester.c +1 -8
index 5e4d7fb6d..dab913862 100644
@@ -18,7 +18,7 @@
 #include <errno.h>
 #include <stdbool.h>
 
-#include <glib.h>
+#include <ell/ell.h>
 
 #include "lib/bluetooth.h"
 #include "lib/bnep.h"
@@ -37,7 +37,6 @@ struct test_data {
 	struct hciemu *hciemu;
 	enum hciemu_type hciemu_type;
 	const void *test_data;
-	unsigned int io_id;
 	uint16_t conn_handle;
 };
 
@@ -192,11 +191,6 @@ static void test_post_teardown(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
 
-	if (data->io_id > 0) {
-		g_source_remove(data->io_id);
-		data->io_id = 0;
-	}
-
 	hciemu_unref(data->hciemu);
 	data->hciemu = NULL;
 }
@@ -282,7 +276,6 @@ static void test_basic(const void *test_data)
 			break; \
 		user->hciemu_type = HCIEMU_TYPE_BREDR; \
 		user->test_data = data; \
-		user->io_id = 0; \
 		tester_add_full(name, data, \
 				test_pre_setup, setup, func, NULL, \
 				test_post_teardown, 2, user, test_data_free); \
Signature · 1 line
2.26.2
#12 lore raw

RFC PATCH 8/10 tools/l2cap-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools       |   4 +-
 tools/l2cap-tester.c | 256 +++++++++++++++++++++----------------------
 2 files changed, 130 insertions(+), 130 deletions(-)
Makefile.tools +2 -2
index 8c79a528d..03264cff9 100644
@@ -114,12 +114,12 @@ tools_mgmt_tester_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-glib.la $(GLIB_LIBS)
 
 tools_l2cap_tester_SOURCES = tools/l2cap-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_l2cap_tester_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-glib.la $(GLIB_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 
 tools_rfcomm_tester_SOURCES = tools/rfcomm-tester.c monitor/bt.h \
 				emulator/hciemu.h emulator/hciemu.c \
tools/l2cap-tester.c +128 -128

627 lines not on this page · raw message

Signature · 1 line
2.26.2
#13 lore raw

RFC PATCH 9/10 tools/mgmt-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools      | 4 ++--
 tools/mgmt-tester.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
Makefile.tools +2 -2
index 03264cff9..e65547c3f 100644
@@ -106,12 +106,12 @@ tools_3dsp_SOURCES = tools/3dsp.c monitor/bt.h
 tools_3dsp_LDADD = src/libshared-mainloop.la
 
 tools_mgmt_tester_SOURCES = tools/mgmt-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_mgmt_tester_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-glib.la $(GLIB_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 
 tools_l2cap_tester_SOURCES = tools/l2cap-tester.c monitor/bt.h \
 				emulator/hciemu.h emulator/hciemu-ell.c \
tools/mgmt-tester.c +3 -2
index d8554411f..75f6457d2 100644
@@ -18,7 +18,7 @@
 #include <errno.h>
 #include <unistd.h>
 
-#include <glib.h>
+#include <ell/ell.h>
 
 #include "lib/bluetooth.h"
 #include "lib/hci.h"
@@ -130,7 +130,8 @@ static void read_info_callback(uint8_t status, uint16_t length,
 	tester_print("  Name: %s", rp->name);
 	tester_print("  Short name: %s", rp->short_name);
 
-	if (strcmp(hciemu_get_address(data->hciemu), addr)) {
+	if (!hciemu_get_address(data->hciemu) ||
+			(strcmp(hciemu_get_address(data->hciemu), addr))) {
 		tester_pre_setup_failed();
 		return;
 	}
Signature · 1 line
2.26.2
#14 lore raw

RFC PATCH 10/10 tools/rfcomm-tester: Convert to use ELL library

In reply to Inga Stotland

This reworks the source code to use ELL primitives and removes dependecies on GLib.

---
 Makefile.tools        |  4 +-
 tools/rfcomm-tester.c | 92 ++++++++++++++++++++++++-------------------
 2 files changed, 53 insertions(+), 43 deletions(-)
Makefile.tools +2 -2
index e65547c3f..2f86c839c 100644
@@ -122,12 +122,12 @@ tools_l2cap_tester_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-ell.la $(ell_ldadd)
 
 tools_rfcomm_tester_SOURCES = tools/rfcomm-tester.c monitor/bt.h \
-				emulator/hciemu.h emulator/hciemu.c \
+				emulator/hciemu.h emulator/hciemu-ell.c \
 				emulator/btdev.h emulator/btdev.c \
 				emulator/bthost.h emulator/bthost.c \
 				emulator/smp.c
 tools_rfcomm_tester_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-glib.la $(GLIB_LIBS)
+				src/libshared-ell.la $(ell_ldadd)
 
 tools_bnep_tester_SOURCES = tools/bnep-tester.c monitor/bt.h \
 				emulator/hciemu.h emulator/hciemu-ell.c \
tools/rfcomm-tester.c +51 -41

210 lines not on this page · raw message

Signature · 1 line
2.26.2