Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/btattach - Reconfigure port speed only when initial...
details: https://anonhg.NetBSD.org/src/rev/48fe087059ea
branches: trunk
changeset: 373409:48fe087059ea
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Tue Feb 07 20:45:44 2023 +0000
description:
- 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.
diffstat:
usr.sbin/btattach/btattach.c | 35 ++++++++++++++++++++++++++++-------
usr.sbin/btattach/btattach.h | 4 ++--
usr.sbin/btattach/init_bcm43xx.c | 7 ++++---
3 files changed, 34 insertions(+), 12 deletions(-)
diffs (133 lines):
diff -r edbbb104bb9f -r 48fe087059ea usr.sbin/btattach/btattach.c
--- a/usr.sbin/btattach/btattach.c Tue Feb 07 20:39:01 2023 +0000
+++ b/usr.sbin/btattach/btattach.c Tue Feb 07 20:45:44 2023 +0000
@@ -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 @@
#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 @@
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 @@
}
static void
+timeout(int s)
+{
+
+}
+
+static void
hexdump(uint8_t *ptr, size_t len)
{
@@ -353,11 +362,13 @@
/*
* 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 @@
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;
}
/*
diff -r edbbb104bb9f -r 48fe087059ea usr.sbin/btattach/btattach.h
--- a/usr.sbin/btattach/btattach.h Tue Feb 07 20:39:01 2023 +0000
+++ b/usr.sbin/btattach/btattach.h Tue Feb 07 20:45:44 2023 +0000
@@ -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_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);
diff -r edbbb104bb9f -r 48fe087059ea usr.sbin/btattach/init_bcm43xx.c
--- a/usr.sbin/btattach/init_bcm43xx.c Tue Feb 07 20:39:01 2023 +0000
+++ b/usr.sbin/btattach/init_bcm43xx.c Tue Feb 07 20:45:44 2023 +0000
@@ -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 <nathanialsloss%yahoo.com.au@localhost>
@@ -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 @@
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? */
Home |
Main Index |
Thread Index |
Old Index