CVS commit: src/usr.sbin/btattach

2023-02-07 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Feb  7 20:45:44 UTC 2023

Modified Files:
src/usr.sbin/btattach: btattach.c btattach.h init_bcm43xx.c

Log Message:
- Reconfigure port speed only when initial speed was different.
- Time out HCI commands instead of hanging forever.
- When bcm43xx reset fails, assume that firmware is already
  running and start line discipline.

This allows to re-attach bcm43xx without reboot.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/btattach/btattach.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/btattach/btattach.h
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/btattach/init_bcm43xx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btattach/btattach.c
diff -u src/usr.sbin/btattach/btattach.c:1.15 src/usr.sbin/btattach/btattach.c:1.16
--- src/usr.sbin/btattach/btattach.c:1.15	Fri Aug 11 11:54:08 2017
+++ src/usr.sbin/btattach/btattach.c	Tue Feb  7 20:45:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: btattach.c,v 1.15 2017/08/11 11:54:08 jmcneill Exp $	*/
+/*	$NetBSD: btattach.c,v 1.16 2023/02/07 20:45:44 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008 Iain Hibbert
@@ -27,7 +27,7 @@
 
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008 Iain Hibbert.  All rights reserved.");
-__RCSID("$NetBSD: btattach.c,v 1.15 2017/08/11 11:54:08 jmcneill Exp $");
+__RCSID("$NetBSD: btattach.c,v 1.16 2023/02/07 20:45:44 mlelstv Exp $");
 
 #include 
 #include 
@@ -40,6 +40,7 @@ __RCSID("$NetBSD: btattach.c,v 1.15 2017
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -275,9 +276,11 @@ main(int argc, char *argv[])
 	if (type->init != NULL)
 		(*type->init)(fd, speed);
 
-	if (cfsetspeed(, speed) < 0
-	|| tcsetattr(fd, TCSADRAIN, ) < 0)
-		err(EXIT_FAILURE, "tty setup failed");
+	if (speed != init_speed) {
+		if (cfsetspeed(, speed) < 0
+		|| tcsetattr(fd, TCSANOW, ) < 0)
+			err(EXIT_FAILURE, "tty setup failed");
+	}
 
 	/* start line discipline */
 	if (ioctl(fd, TIOCSLINED, type->line) < 0)
@@ -343,6 +346,12 @@ sighandler(int s)
 }
 
 static void
+timeout(int s)
+{
+
+}
+
+static void
 hexdump(uint8_t *ptr, size_t len)
 {
 
@@ -353,11 +362,13 @@ hexdump(uint8_t *ptr, size_t len)
 /*
  * send HCI comamnd
  */
-void
+int
 uart_send_cmd(int fd, uint16_t opcode, void *buf, size_t len)
 {
 	struct iovec iov[2];
 	hci_cmd_hdr_t hdr;
+	int r;
+	struct sigaction oaction, taction;
 
 	hdr.type = HCI_CMD_PKT;
 	hdr.opcode = htole16(opcode);
@@ -379,7 +390,17 @@ uart_send_cmd(int fd, uint16_t opcode, v
 	if (writev(fd, iov, __arraycount(iov)) < 0)
 		err(EXIT_FAILURE, "writev");
 
-	tcdrain(fd);
+	taction.sa_handler = timeout,
+	sigemptyset(_mask);
+	taction.sa_flags = 0,
+
+	sigaction(SIGALRM, , );
+	alarm(1);
+	r = tcdrain(fd);
+	alarm(0);
+	sigaction(SIGALRM, , NULL);
+
+	return r;
 }
 
 /*

Index: src/usr.sbin/btattach/btattach.h
diff -u src/usr.sbin/btattach/btattach.h:1.4 src/usr.sbin/btattach/btattach.h:1.5
--- src/usr.sbin/btattach/btattach.h:1.4	Thu Aug 10 13:34:29 2017
+++ src/usr.sbin/btattach/btattach.h	Tue Feb  7 20:45:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: btattach.h,v 1.4 2017/08/10 13:34:29 nat Exp $	*/
+/*	$NetBSD: btattach.h,v 1.5 2023/02/07 20:45:44 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008 Iain Hibbert
@@ -50,6 +50,6 @@ devinit_t init_stlc2500;
 devinit_t init_swave;
 devinit_t init_unistone;
 
-void uart_send_cmd(int, uint16_t, void *, size_t);
+int uart_send_cmd(int, uint16_t, void *, size_t);
 size_t uart_recv_ev(int, uint8_t, void *, size_t);
 size_t uart_recv_cc(int, uint16_t, void *, size_t);

Index: src/usr.sbin/btattach/init_bcm43xx.c
diff -u src/usr.sbin/btattach/init_bcm43xx.c:1.5 src/usr.sbin/btattach/init_bcm43xx.c:1.6
--- src/usr.sbin/btattach/init_bcm43xx.c:1.5	Sun Sep  3 22:54:12 2017
+++ src/usr.sbin/btattach/init_bcm43xx.c	Tue Feb  7 20:45:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_bcm43xx.c,v 1.5 2017/09/03 22:54:12 nat Exp $	*/
+/*	$NetBSD: init_bcm43xx.c,v 1.6 2023/02/07 20:45:44 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2017 Nathanial Sloss 
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: init_bcm43xx.c,v 1.5 2017/09/03 22:54:12 nat Exp $");
+__RCSID("$NetBSD: init_bcm43xx.c,v 1.6 2023/02/07 20:45:44 mlelstv Exp $");
 
 #include 
 
@@ -102,7 +102,8 @@ init_bcm43xx(int fd, unsigned int speed)
 	memset(rate, 0, sizeof(rate));
 	memset(local_name, 0, sizeof(local_name));
 
-	uart_send_cmd(fd, HCI_CMD_RESET, NULL, 0);
+	if (uart_send_cmd(fd, HCI_CMD_RESET, NULL, 0))
+		return;
 	uart_recv_cc(fd, HCI_CMD_RESET, , sizeof(resp));
 	/* assume it succeeded? */
 



CVS commit: src/usr.sbin/btattach

2023-02-07 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Feb  7 20:45:44 UTC 2023

Modified Files:
src/usr.sbin/btattach: btattach.c btattach.h init_bcm43xx.c

Log Message:
- Reconfigure port speed only when initial speed was different.
- Time out HCI commands instead of hanging forever.
- When bcm43xx reset fails, assume that firmware is already
  running and start line discipline.

This allows to re-attach bcm43xx without reboot.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/btattach/btattach.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/btattach/btattach.h
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/btattach/init_bcm43xx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/btattach

2010-03-09 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Mar  9 10:54:01 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.8

Log Message:
Sort sections. Try to improve description of -t.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/btattach/btattach.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btattach/btattach.8
diff -u src/usr.sbin/btattach/btattach.8:1.4 src/usr.sbin/btattach/btattach.8:1.5
--- src/usr.sbin/btattach/btattach.8:1.4	Mon Mar  8 18:35:51 2010
+++ src/usr.sbin/btattach/btattach.8	Tue Mar  9 10:54:01 2010
@@ -1,4 +1,4 @@
-.\ $NetBSD: btattach.8,v 1.4 2010/03/08 18:35:51 kiyohara Exp $
+.\ $NetBSD: btattach.8,v 1.5 2010/03/09 10:54:01 wiz Exp $
 .\
 .\ Copyright (c) 2007 KIYOHARA Takashi
 .\ All rights reserved.
@@ -113,10 +113,10 @@
 .Pp
 Only the super-user may attach a Bluetooth HCI interface.
 .Pp
-Test mode guess speed by received link-establish packet from HCI.
-Or
-.Xr btuart 4
-, if not respond.
+Test mode tries to guess the speed using the received link-establish
+packet from HCI, or
+.Xr btuart 4 ,
+if there is no response.
 .Sh FILES
 .Bl -tag -compact
 .It Pa /var/run/btattach- Ns Bro tty Brc Ns .pid
@@ -126,10 +126,6 @@
 .Xr bluetooth 4 ,
 .Xr btuart 4 ,
 .Xr btconfig 8
-.Sh BUGS
-Not all
-.Ar type
-initializations have been tested.
 .Sh HISTORY
 The
 .Nm
@@ -140,3 +136,7 @@
 .Sh AUTHORS
 .An KIYOHARA Takashi Aq kiyoh...@kk.iij4u.or.jp
 .An Iain Hibbert
+.Sh BUGS
+Not all
+.Ar type
+initializations have been tested.



CVS commit: src/usr.sbin/btattach

2010-03-09 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Mar  9 10:54:01 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.8

Log Message:
Sort sections. Try to improve description of -t.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/btattach/btattach.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/btattach

2010-03-08 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Mon Mar  8 17:41:11 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.c

Log Message:
Add options 'no parity'(-P) and 'disable flow control'(-F).
Also default enable parity for bcsp.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/btattach/btattach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btattach/btattach.c
diff -u src/usr.sbin/btattach/btattach.c:1.6 src/usr.sbin/btattach/btattach.c:1.7
--- src/usr.sbin/btattach/btattach.c:1.6	Wed Feb 17 09:49:41 2010
+++ src/usr.sbin/btattach/btattach.c	Mon Mar  8 17:41:11 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: btattach.c,v 1.6 2010/02/17 09:49:41 plunky Exp $	*/
+/*	$NetBSD: btattach.c,v 1.7 2010/03/08 17:41:11 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 2008 Iain Hibbert
@@ -27,7 +27,7 @@
 
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008 Iain Hibbert.  All rights reserved.);
-__RCSID($NetBSD: btattach.c,v 1.6 2010/02/17 09:49:41 plunky Exp $);
+__RCSID($NetBSD: btattach.c,v 1.7 2010/03/08 17:41:11 kiyohara Exp $);
 
 #include sys/ioctl.h
 #include sys/param.h
@@ -64,7 +64,7 @@
 	.name = bcsp,
 	.line = bcsp,
 	.descr = Generic BlueCore Serial Protocol,
-	.cflag = CRTSCTS,
+	.cflag = CRTSCTS | PARENB,
 	.speed = B57600,
 },
 {
@@ -150,21 +150,26 @@
 	const struct devtype *type;
 	struct termios tio;
 	unsigned int init_speed, speed;
-	tcflag_t cflag;
+	tcflag_t cflag, Cflag;
 	int fd, ch, i;
 	const char *name;
 	char *ptr;
 
 	init_speed = 0;
 	cflag = CLOCAL;
+	Cflag = 0;
 	name = btuart;
 
-	while ((ch = getopt(argc, argv, dfi:op)) != -1) {
+	while ((ch = getopt(argc, argv, dFfi:oPp)) != -1) {
 		switch (ch) {
 		case 'd':
 			opt_debug++;
 			break;
 
+		case 'F':
+			Cflag |= CRTSCTS;
+			break;
+
 		case 'f':
 			cflag |= CRTSCTS;
 			break;
@@ -180,6 +185,10 @@
 			cflag |= (PARENB | PARODD);
 			break;
 
+		case 'P':
+			Cflag |= PARENB;
+			break;
+
 		case 'p':
 			cflag |= PARENB;
 			break;
@@ -228,6 +237,7 @@
 
 	cfmakeraw(tio);
 	tio.c_cflag |= (cflag | type-cflag);
+	tio.c_cflag = ~Cflag;
 
 	if (cfsetspeed(tio, init_speed)  0
 	|| tcsetattr(fd, TCSANOW, tio)  0
@@ -276,13 +286,15 @@
 	size_t i;
 
 	fprintf(stderr,
-		Usage: %s [-dfop] [-i speed] [type] tty speed\n
+		Usage: %s [-dFfoPp] [-i speed] [type] tty speed\n
 		\n
 		Where:\n
 		\t-d  debug mode (no detach, dump io)\n
+		\t-F  disable flow control\n
 		\t-f  enable flow control\n
 		\t-i speedinit speed\n
 		\t-o  odd parity\n
+		\t-P  no parity\n
 		\t-p  even parity\n
 		\n
 		Known types:\n



CVS commit: src/usr.sbin/btattach

2010-03-08 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Mon Mar  8 17:41:11 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.c

Log Message:
Add options 'no parity'(-P) and 'disable flow control'(-F).
Also default enable parity for bcsp.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/btattach/btattach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/btattach

2010-03-08 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Mon Mar  8 17:59:52 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.c

Log Message:
Add option 'test mode'(-t).
  Can test your Bluetooth module via com-port.
  This mode guess speed for bcsp(4) or btuart(4), if not respond.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/btattach/btattach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/btattach

2010-03-08 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Mon Mar  8 21:19:29 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.c

Log Message:
fix compilation errors


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/btattach/btattach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btattach/btattach.c
diff -u src/usr.sbin/btattach/btattach.c:1.8 src/usr.sbin/btattach/btattach.c:1.9
--- src/usr.sbin/btattach/btattach.c:1.8	Mon Mar  8 17:59:52 2010
+++ src/usr.sbin/btattach/btattach.c	Mon Mar  8 21:19:29 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: btattach.c,v 1.8 2010/03/08 17:59:52 kiyohara Exp $	*/
+/*	$NetBSD: btattach.c,v 1.9 2010/03/08 21:19:29 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2008 Iain Hibbert
@@ -27,7 +27,7 @@
 
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008 Iain Hibbert.  All rights reserved.);
-__RCSID($NetBSD: btattach.c,v 1.8 2010/03/08 17:59:52 kiyohara Exp $);
+__RCSID($NetBSD: btattach.c,v 1.9 2010/03/08 21:19:29 plunky Exp $);
 
 #include sys/ioctl.h
 #include sys/param.h
@@ -522,7 +522,9 @@
 test(const char *tty, tcflag_t cflag, tcflag_t Cflag)
 {
 	struct termios tio;
-	int fd, guessed, i, j, k, n;
+	int fd, guessed;
+	size_t i, j, k;
+	ssize_t n;
 	unsigned char buf[32];
 	const int bauds[] = {
 		 57600,		/* BCSP specific default */
@@ -573,11 +575,12 @@
 	for (i = 0; i  __arraycount(bauds); i++) {
 		if (cfsetspeed(tio, bauds[i])  0
 		|| tcsetattr(fd, TCSANOW, tio)  0
-		|| tcflush(fd, TCIOFLUSH)  0)
+		|| tcflush(fd, TCIOFLUSH)  0) {
 			if (bauds[i]  115200)
 continue;
 			else
 err(EXIT_FAILURE, tty setup failed);
+		}
 
 		if (opt_debug)
 			printf(  try with B%d\n, bauds[i]);
@@ -600,7 +603,7 @@
 
 			err(EXIT_FAILURE, read);
 		} else {
-			if (n  sizeof(bcsp_lepkt))
+			if ((size_t)n  sizeof(bcsp_lepkt))
 continue;
 			for (j = 0; j  n - sizeof(bcsp_lepkt); j++) {
 for (k = 0; k  sizeof(bcsp_lepkt); k++) 



CVS commit: src/usr.sbin/btattach

2010-03-08 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Mon Mar  8 21:48:42 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.c

Log Message:
use %zd for ssize_t argument


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/btattach/btattach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/btattach

2010-03-08 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Mon Mar  8 21:48:42 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.c

Log Message:
use %zd for ssize_t argument


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/btattach/btattach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btattach/btattach.c
diff -u src/usr.sbin/btattach/btattach.c:1.9 src/usr.sbin/btattach/btattach.c:1.10
--- src/usr.sbin/btattach/btattach.c:1.9	Mon Mar  8 21:19:29 2010
+++ src/usr.sbin/btattach/btattach.c	Mon Mar  8 21:48:42 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: btattach.c,v 1.9 2010/03/08 21:19:29 plunky Exp $	*/
+/*	$NetBSD: btattach.c,v 1.10 2010/03/08 21:48:42 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2008 Iain Hibbert
@@ -27,7 +27,7 @@
 
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008 Iain Hibbert.  All rights reserved.);
-__RCSID($NetBSD: btattach.c,v 1.9 2010/03/08 21:19:29 plunky Exp $);
+__RCSID($NetBSD: btattach.c,v 1.10 2010/03/08 21:48:42 plunky Exp $);
 
 #include sys/ioctl.h
 #include sys/param.h
@@ -589,7 +589,7 @@
 
 		n = read(fd, buf, sizeof(buf));
 		if (opt_debug  1)
-			printf(  %dbyte read\n, n);
+			printf(  %zd bytes read\n, n);
 		if (n  0) {
 			if (i == 0  errno == EAGAIN) {
 printf(This module is *maybe* supported by btuart(4).\n



CVS commit: src/usr.sbin/btattach

2010-02-17 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Wed Feb 17 09:49:41 UTC 2010

Modified Files:
src/usr.sbin/btattach: btattach.c

Log Message:
sort entries in structure
clarify init name type for CSR modules


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/btattach/btattach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.