Skip to contentSkip to conversation

btattach: Use HCI UART vendor specific setup kernel calls

RFC In review Frederic Danis 2 participants 5 messages Apr 2, 2015 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

cover btattach: Use HCI UART vendor specific setup kernel calls

This series of patches uses the new IOCTLs introduced in RFC "Move HCI UART vendor specific setup to kernel" previously sent.

Frederic Danis (3):
btattach: Add SetDevType ioctl call
btattach: Add SetBaudRate ioctl call
btattach: Increase timeout for raw user channel creation

 tools/btattach.c  | 38 ++++++++++++++++++++++++++++++++------
 tools/hciattach.h |  2 ++
 2 files changed, 34 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

RFC 1/3 btattach: Add SetDevType ioctl call

---
 tools/btattach.c  | 22 +++++++++++++++++-----
 tools/hciattach.h |  1 +
 2 files changed, 18 insertions(+), 5 deletions(-)
tools/btattach.c +17 -5
index b7948a3..63620e4 100644
@@ -106,7 +106,7 @@ static void local_version_callback(const void *data, uint8_t size,
 }
 
 static int attach_proto(const char *path, unsigned int proto,
-						unsigned int flags)
+					unsigned int flags, const char *type)
 {
 	int fd, dev_id;
 
@@ -120,6 +120,14 @@ static int attach_proto(const char *path, unsigned int proto,
 		return -1;
 	}
 
+	if (type) {
+		if (ioctl(fd, HCIUARTSETDEVTYPE, type) < 0) {
+			perror("Failed to set device type");
+			close(fd);
+			return -1;
+		}
+	}
+
 	if (ioctl(fd, HCIUARTSETPROTO, proto) < 0) {
 		perror("Failed to set protocol");
 		close(fd);
@@ -193,6 +201,7 @@ static void usage(void)
 static const struct option main_options[] = {
 	{ "bredr",   required_argument, NULL, 'B' },
 	{ "amp",     required_argument, NULL, 'A' },
+	{ "type",    required_argument, NULL, 't' },
 	{ "version", no_argument,       NULL, 'v' },
 	{ "help",    no_argument,       NULL, 'h' },
 	{ }
@@ -200,7 +209,7 @@ static const struct option main_options[] = {
 
 int main(int argc, char *argv[])
 {
-	const char *bredr_path = NULL, *amp_path = NULL;
+	const char *bredr_path = NULL, *amp_path = NULL, *type = NULL;
 	bool raw_device = false;
 	sigset_t mask;
 	int exit_status, count = 0;
@@ -208,7 +217,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "B:A:Rvh",
+		opt = getopt_long(argc, argv, "B:A:t:Rvh",
 						main_options, NULL);
 		if (opt < 0)
 			break;
@@ -220,6 +229,9 @@ int main(int argc, char *argv[])
 		case 'A':
 			amp_path = optarg;
 			break;
+		case 't':
+			type = optarg;
+			break;
 		case 'R':
 			raw_device = true;
 			break;
@@ -258,7 +270,7 @@ int main(int argc, char *argv[])
 		if (raw_device)
 			flags = (1 << HCI_UART_RAW_DEVICE);
 
-		fd = attach_proto(bredr_path, HCI_UART_H4, flags);
+		fd = attach_proto(bredr_path, HCI_UART_H4, flags, type);
 		if (fd >= 0) {
 			mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
 			count++;
@@ -277,7 +289,7 @@ int main(int argc, char *argv[])
 		if (raw_device)
 			flags = (1 << HCI_UART_RAW_DEVICE);
 
-		fd = attach_proto(amp_path, HCI_UART_H4, flags);
+		fd = attach_proto(amp_path, HCI_UART_H4, flags, type);
 		if (fd >= 0) {
 			mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
 			count++;
tools/hciattach.h +1 -0
index 2aaf075..8a199e9 100644
@@ -32,6 +32,7 @@
 #define HCIUARTGETDEVICE	_IOR('U', 202, int)
 #define HCIUARTSETFLAGS		_IOW('U', 203, int)
 #define HCIUARTGETFLAGS		_IOR('U', 204, int)
+#define HCIUARTSETDEVTYPE	_IOW('U', 205, int)
 
 #define HCI_UART_H4	0
 #define HCI_UART_BCSP	1
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [RFC 1/3] btattach: Add SetDevType ioctl call

Hi Fred,

Quoted 70 lines

---
tools/btattach.c | 22 +++++++++++++++++-----
tools/hciattach.h | 1 +

2 files changed, 18 insertions(+), 5 deletions(-)
tools/btattach.c +15 -3
index b7948a3..63620e4 100644
@@ -106,7 +106,7 @@ static void local_version_callback(const void *data, uint8_t size,
 }
 
 static int attach_proto(const char *path, unsigned int proto,
-						unsigned int flags)
+					unsigned int flags, const char *type)
 {
 	int fd, dev_id;
 
@@ -120,6 +120,14 @@ static int attach_proto(const char *path, unsigned int proto,
 		return -1;
 	}
 
+	if (type) {
+		if (ioctl(fd, HCIUARTSETDEVTYPE, type) < 0) {
+			perror("Failed to set device type");
+			close(fd);
+			return -1;
+		}
+	}
+
 	if (ioctl(fd, HCIUARTSETPROTO, proto) < 0) {
 		perror("Failed to set protocol");
 		close(fd);
@@ -193,6 +201,7 @@ static void usage(void)
 static const struct option main_options[] = {
 	{ "bredr",   required_argument, NULL, 'B' },
 	{ "amp",     required_argument, NULL, 'A' },
+	{ "type",    required_argument, NULL, 't' },
 	{ "version", no_argument,       NULL, 'v' },
 	{ "help",    no_argument,       NULL, 'h' },
 	{ }
@@ -200,7 +209,7 @@ static const struct option main_options[] = {
 
 int main(int argc, char *argv[])
 {
-	const char *bredr_path = NULL, *amp_path = NULL;
+	const char *bredr_path = NULL, *amp_path = NULL, *type = NULL;
 	bool raw_device = false;
 	sigset_t mask;
 	int exit_status, count = 0;
@@ -208,7 +217,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "B:A:Rvh",
+		opt = getopt_long(argc, argv, "B:A:t:Rvh",
 						main_options, NULL);
 		if (opt < 0)
 			break;
@@ -220,6 +229,9 @@ int main(int argc, char *argv[])
 		case 'A':
 			amp_path = optarg;
 			break;
+		case 't':
+			type = optarg;
+			break;
 		case 'R':
 			raw_device = true;
 			break;

tools/btattach.c int main(int argc, char *argv[]) · line 273

Quoted 5 lines
tools/btattach.c +1 -1
@@ -258,7 +270,7 @@ int main(int argc, char *argv[])
 		if (raw_device)
 			flags = (1 << HCI_UART_RAW_DEVICE);
 
-		fd = attach_proto(bredr_path, HCI_UART_H4, flags);
+		fd = attach_proto(bredr_path, HCI_UART_H4, flags, type);

I think the real feature you want to add here is the ability to choose different HCI_UART_* types. So lets define a list of types that we support. This should just be drivers/vendors and not all different chips like in hciattach.

However you need to do a lot of input verification checks here. For example AMP implies H:4 at the moment.

The kernel calls is PROTO at the moment and with that we most likely should just call it --protocol / -p here. If not specified it defaults to H:4.

Regards

Marcel

#3 lore raw

RFC 2/3 btattach: Add SetBaudRate ioctl call

In reply to Frederic Danis
---
 tools/btattach.c  | 22 ++++++++++++++++++----
 tools/hciattach.h |  1 +
 2 files changed, 19 insertions(+), 4 deletions(-)
tools/btattach.c +18 -4
index 63620e4..d97429e 100644
@@ -106,7 +106,8 @@ static void local_version_callback(const void *data, uint8_t size,
 }
 
 static int attach_proto(const char *path, unsigned int proto,
-					unsigned int flags, const char *type)
+					unsigned int flags, const char *type,
+					unsigned int speed)
 {
 	int fd, dev_id;
 
@@ -128,6 +129,14 @@ static int attach_proto(const char *path, unsigned int proto,
 		}
 	}
 
+	if (speed) {
+		if (ioctl(fd, HCIUARTSETBAUDRATE, speed) < 0) {
+			perror("Failed to set speed");
+			close(fd);
+			return -1;
+		}
+	}
+
 	if (ioctl(fd, HCIUARTSETPROTO, proto) < 0) {
 		perror("Failed to set protocol");
 		close(fd);
@@ -202,6 +211,7 @@ static const struct option main_options[] = {
 	{ "bredr",   required_argument, NULL, 'B' },
 	{ "amp",     required_argument, NULL, 'A' },
 	{ "type",    required_argument, NULL, 't' },
+	{ "speed",   required_argument, NULL, 's' },
 	{ "version", no_argument,       NULL, 'v' },
 	{ "help",    no_argument,       NULL, 'h' },
 	{ }
@@ -210,6 +220,7 @@ static const struct option main_options[] = {
 int main(int argc, char *argv[])
 {
 	const char *bredr_path = NULL, *amp_path = NULL, *type = NULL;
+	unsigned int speed = 0;
 	bool raw_device = false;
 	sigset_t mask;
 	int exit_status, count = 0;
@@ -217,7 +228,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "B:A:t:Rvh",
+		opt = getopt_long(argc, argv, "B:A:t:s:Rvh",
 						main_options, NULL);
 		if (opt < 0)
 			break;
@@ -229,6 +240,9 @@ int main(int argc, char *argv[])
 		case 'A':
 			amp_path = optarg;
 			break;
+		case 's':
+			speed = atoi(optarg);
+			break;
 		case 't':
 			type = optarg;
 			break;
@@ -270,7 +284,7 @@ int main(int argc, char *argv[])
 		if (raw_device)
 			flags = (1 << HCI_UART_RAW_DEVICE);
 
-		fd = attach_proto(bredr_path, HCI_UART_H4, flags, type);
+		fd = attach_proto(bredr_path, HCI_UART_H4, flags, type, speed);
 		if (fd >= 0) {
 			mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
 			count++;
@@ -289,7 +303,7 @@ int main(int argc, char *argv[])
 		if (raw_device)
 			flags = (1 << HCI_UART_RAW_DEVICE);
 
-		fd = attach_proto(amp_path, HCI_UART_H4, flags, type);
+		fd = attach_proto(amp_path, HCI_UART_H4, flags, type, speed);
 		if (fd >= 0) {
 			mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
 			count++;
tools/hciattach.h +1 -0
index 8a199e9..2a084f7 100644
@@ -33,6 +33,7 @@
 #define HCIUARTSETFLAGS		_IOW('U', 203, int)
 #define HCIUARTGETFLAGS		_IOR('U', 204, int)
 #define HCIUARTSETDEVTYPE	_IOW('U', 205, int)
+#define HCIUARTSETBAUDRATE	_IOW('U', 206, int)
 
 #define HCI_UART_H4	0
 #define HCI_UART_BCSP	1
Signature · 1 line
1.9.1
#4 lore raw

RFC 3/3 btattach: Increase timeout for raw user channel creation

In reply to Frederic Danis

As Bluetooth controller initialization is now performed in kernel, it can take longer time to get user channel socket.
So move timeout from 1.5 seconds to 6 seconds.

---
 tools/btattach.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/btattach.c +1 -1
index d97429e..8fc5868 100644
@@ -153,7 +153,7 @@ static int attach_proto(const char *path, unsigned int proto,
 	printf("Device index %d attached\n", dev_id);
 
 	if (flags & (1 << HCI_UART_RAW_DEVICE)) {
-		unsigned int attempts = 6;
+		unsigned int attempts = 24;
 		struct bt_hci *hci;
 
 		while (attempts-- > 0) {
Signature · 1 line
1.9.1