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 <sys/cdefs.h> __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 <sys/ioctl.h> #include <sys/param.h> @@ -40,6 +40,7 @@ __RCSID("$NetBSD: btattach.c,v 1.15 2017 #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <signal.h> #include <termios.h> #include <unistd.h> #include <util.h> @@ -275,9 +276,11 @@ main(int argc, char *argv[]) if (type->init != NULL) (*type->init)(fd, speed); - if (cfsetspeed(&tio, speed) < 0 - || tcsetattr(fd, TCSADRAIN, &tio) < 0) - err(EXIT_FAILURE, "tty setup failed"); + if (speed != init_speed) { + if (cfsetspeed(&tio, speed) < 0 + || tcsetattr(fd, TCSANOW, &tio) < 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(&taction.sa_mask); + taction.sa_flags = 0, + + sigaction(SIGALRM, &taction, &oaction); + alarm(1); + r = tcdrain(fd); + alarm(0); + sigaction(SIGALRM, &oaction, 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 <nathanialsl...@yahoo.com.au> @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__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 <sys/param.h> @@ -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, &resp, sizeof(resp)); /* assume it succeeded? */