Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/btattach Add support for bcm 43xx devices using the...



details:   https://anonhg.NetBSD.org/src/rev/0e77fdbce97e
branches:  trunk
changeset: 825998:0e77fdbce97e
user:      nat <nat%NetBSD.org@localhost>
date:      Thu Aug 10 13:34:29 2017 +0000

description:
Add support for bcm 43xx devices using the btuart h5 protocol.

Currently It will only load 1 firmware image for rpi3.

To use change to the directory containing the firmware BCM4340A1.hcd.
Then issue: btattach -FPi 115200 bcm43xx /dev/ttydevice 921600.

Then you can use the bluetooth device btfive0.

This enables the embedded bluetooth controller on rpi3.

diffstat:

 usr.sbin/btattach/Makefile       |    5 +-
 usr.sbin/btattach/btattach.c     |   11 +++-
 usr.sbin/btattach/btattach.h     |    3 +-
 usr.sbin/btattach/init_bcm43xx.c |  110 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 124 insertions(+), 5 deletions(-)

diffs (179 lines):

diff -r 804583b7c8d3 -r 0e77fdbce97e usr.sbin/btattach/Makefile
--- a/usr.sbin/btattach/Makefile        Thu Aug 10 13:25:49 2017 +0000
+++ b/usr.sbin/btattach/Makefile        Thu Aug 10 13:34:29 2017 +0000
@@ -1,9 +1,10 @@
-# $NetBSD: Makefile,v 1.2 2009/12/06 12:55:46 kiyohara Exp $
+# $NetBSD: Makefile,v 1.3 2017/08/10 13:34:29 nat Exp $
 
 PROG=  btattach
 MAN=   btattach.8
 SRCS=  btattach.c init_bcm2035.c init_bgb2xx.c init_csr.c init_digi.c \
-       init_ericsson.c init_st.c init_stlc2500.c init_swave.c init_unistone.c
+       init_ericsson.c init_st.c init_stlc2500.c init_swave.c init_unistone.c \
+       init_bcm43xx.c
 
 DPADD+=        ${LIBBLUETOOTH} ${LIBUTIL}
 LDADD+=        -lbluetooth -lutil
diff -r 804583b7c8d3 -r 0e77fdbce97e usr.sbin/btattach/btattach.c
--- a/usr.sbin/btattach/btattach.c      Thu Aug 10 13:25:49 2017 +0000
+++ b/usr.sbin/btattach/btattach.c      Thu Aug 10 13:34:29 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btattach.c,v 1.13 2015/06/16 23:04:14 christos Exp $   */
+/*     $NetBSD: btattach.c,v 1.14 2017/08/10 13:34:29 nat 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.13 2015/06/16 23:04:14 christos Exp $");
+__RCSID("$NetBSD: btattach.c,v 1.14 2017/08/10 13:34:29 nat Exp $");
 
 #include <sys/ioctl.h>
 #include <sys/param.h>
@@ -62,6 +62,13 @@
        .speed = B115200,
     },
     {
+       .name = "bcm43xx",
+       .line = "bth5",
+       .descr = "Broadcom BCM43xx",
+       .init = &init_bcm43xx,
+       .speed = B115200,
+    },
+    {
        .name = "bcsp",
        .line = "bcsp",
        .descr = "Generic BlueCore Serial Protocol",
diff -r 804583b7c8d3 -r 0e77fdbce97e usr.sbin/btattach/btattach.h
--- a/usr.sbin/btattach/btattach.h      Thu Aug 10 13:25:49 2017 +0000
+++ b/usr.sbin/btattach/btattach.h      Thu Aug 10 13:34:29 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btattach.h,v 1.3 2009/12/06 12:55:46 kiyohara Exp $    */
+/*     $NetBSD: btattach.h,v 1.4 2017/08/10 13:34:29 nat Exp $ */
 
 /*-
  * Copyright (c) 2008 Iain Hibbert
@@ -40,6 +40,7 @@
 };
 
 devinit_t init_bcm2035;
+devinit_t init_bcm43xx;
 devinit_t init_bgb2xx;
 devinit_t init_csr;
 devinit_t init_digi;
diff -r 804583b7c8d3 -r 0e77fdbce97e usr.sbin/btattach/init_bcm43xx.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/btattach/init_bcm43xx.c  Thu Aug 10 13:34:29 2017 +0000
@@ -0,0 +1,110 @@
+/*     $NetBSD: init_bcm43xx.c,v 1.1 2017/08/10 13:34:29 nat Exp $     */
+
+/*-
+ * Copyright (c) 2017 Iain Hibbert
+ * All rights reserved.
+ *
+ * Copyright (c) 2008 Iain Hibbert
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * init information in this file gleaned from hciattach(8)
+ * command from BlueZ for Linux - see http://www.bluez.org/
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: init_bcm43xx.c,v 1.1 2017/08/10 13:34:29 nat Exp $");
+
+#include <bluetooth.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "btattach.h"
+
+#define HCI_CMD_BCM43XX_SET_UART_BAUD_RATE     \
+       HCI_OPCODE(HCI_OGF_VENDOR, 0x018)
+
+#define HCI_CMD_BCM43XX_SET_BDADDR             \
+       HCI_OPCODE(HCI_OGF_VENDOR, 0x006)
+
+#define HCI_CMD_43XXFWDN                       \
+       HCI_OPCODE(HCI_OGF_VENDOR, 0x02e)
+
+void
+init_bcm43xx(int fd, unsigned int speed)
+{
+       uint8_t rate[6];
+       uint8_t fw_buf[1024];
+       char fw[] = "./BCM43430A1.hcd";
+       int nr, fwfd, fw_len;
+       uint8_t resp[7];
+       uint8_t name[20];
+       uint16_t fw_cmd;
+
+       memset(rate, 0, sizeof(rate));
+
+       uart_send_cmd(fd, HCI_CMD_RESET, NULL, 0);
+       uart_recv_cc(fd, HCI_CMD_RESET, &resp, sizeof(resp));
+       /* assume it succeeded? */
+
+       fwfd = open(fw, O_RDONLY);
+       if (fwfd < 0) {
+               fprintf(stderr, "Unable to open firmware: %s\n", fw);
+               return;
+       }
+
+       uart_send_cmd(fd, HCI_CMD_43XXFWDN, NULL, 0);
+       uart_recv_cc(fd, HCI_CMD_43XXFWDN, &resp, sizeof(resp));
+               sleep(1);
+
+       while (read(fwfd, &fw_buf[1], 3) == 3) {
+               fw_buf[0] = HCI_CMD_PKT;
+               fw_len = fw_buf[3];
+               if (read(fwfd, &fw_buf[4], fw_len) != fw_len)
+                       break;
+               fw_cmd = fw_buf[2] << 8 | fw_buf[1];
+               uart_send_cmd(fd, fw_cmd, &fw_buf[4], fw_len);
+               uart_recv_cc(fd, fw_cmd, &resp, sizeof(resp));
+       }
+       
+       close(fwfd);
+               
+       sleep(4);
+       uart_send_cmd(fd, HCI_CMD_RESET, NULL, 0);
+       uart_recv_cc(fd, HCI_CMD_RESET, &resp, sizeof(resp));
+       /* assume it succeeded? */
+
+       rate[2] = speed;
+       rate[3] = speed >> 8;
+       rate[4] = speed >> 16;
+       rate[5] = speed >> 24;
+
+       uart_send_cmd(fd, HCI_CMD_BCM43XX_SET_UART_BAUD_RATE, &rate, sizeof(rate));
+       uart_recv_cc(fd, HCI_CMD_BCM43XX_SET_UART_BAUD_RATE, &resp, sizeof(resp));
+}



Home | Main Index | Thread Index | Old Index