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.
This commit is contained in:
parent
90a9edb7b9
commit
e5d9803b71
@ -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
|
||||
|
@ -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>
|
||||
@ -61,6 +61,13 @@ static const struct devtype types[] = {
|
||||
.init = &init_bcm2035,
|
||||
.speed = B115200,
|
||||
},
|
||||
{
|
||||
.name = "bcm43xx",
|
||||
.line = "bth5",
|
||||
.descr = "Broadcom BCM43xx",
|
||||
.init = &init_bcm43xx,
|
||||
.speed = B115200,
|
||||
},
|
||||
{
|
||||
.name = "bcsp",
|
||||
.line = "bcsp",
|
||||
|
@ -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 @@ struct devtype {
|
||||
};
|
||||
|
||||
devinit_t init_bcm2035;
|
||||
devinit_t init_bcm43xx;
|
||||
devinit_t init_bgb2xx;
|
||||
devinit_t init_csr;
|
||||
devinit_t init_digi;
|
||||
|
110
usr.sbin/btattach/init_bcm43xx.c
Normal file
110
usr.sbin/btattach/init_bcm43xx.c
Normal file
@ -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));
|
||||
}
|
Loading…
Reference in New Issue
Block a user