pccard: Remove bt3c(4) driver

pccard is being removed, so remove bt3c driver since it only has PC
Card attachment. Also remove bt3cfw(8) since it's the firmware for this
driver.

Relnotes: Yes
This commit is contained in:
Warner Losh 2021-01-07 15:52:49 -07:00
parent 0d3a424a89
commit 23e124c78b
15 changed files with 4 additions and 1929 deletions

View File

@ -36,8 +36,11 @@
# xargs -n1 | sort | uniq -d;
# done
# 20210108: retire cmx driver
# 20210108: retire cmx, ng_bt3c drivers
OLD_FILES+=usr/sbin/bt3cfw
OLD_FILES+=usr/share/man/man4/cmw.4.gz
OLD_FILES+=usr/share/man/man4/ng_bt3c.4.gz
OLD_FILES+=usr/share/man/man8/bt3cfw.8.gz
# 20210107: retire a.out support
OLD_DIRS+=usr/lib/aout

View File

@ -337,7 +337,6 @@ MAN= aac.4 \
ng_atmllc.4 \
ng_bpf.4 \
ng_bridge.4 \
ng_bt3c.4 \
ng_btsocket.4 \
ng_car.4 \
ng_ccatm.4 \

View File

@ -1,132 +0,0 @@
.\" Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
.\" 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
.\"
.\" $Id: ng_bt3c.4,v 1.3 2003/09/14 23:28:51 max Exp $
.\" $FreeBSD$
.\"
.Dd December 17, 2004
.Dt NG_BT3C 4
.Os
.Sh NAME
.Nm ng_bt3c
.Nd Netgraph node type that is also a 3Com Bluetooth PC card driver
.Sh SYNOPSIS
.In sys/types.h
.In netgraph/bluetooth/include/ng_bt3c.h
.Sh DEPRECATION NOTICE
This driver is scheduled for removal prior to the release of
.Fx 13.0
.Sh DESCRIPTION
The
.Nm btccc
node type is both a persistent Netgraph node type and a driver for the
3Com Bluetooth PC card (3CRWB6096-HP).
It implements a Bluetooth HCI
UART transport layer as per chapter H4 of the Bluetooth Specification
Book v1.1.
A new node is created when the card is plugged.
.Pp
In order to use the card one
.Em MUST
download the firmware first.
Due to copyright issues the firmware cannot be provided with this driver.
The firmware can be obtained
from the Windows driver package that can be downloaded from the 3Com web
site at no charge.
The firmware name is
.Pa BT3CPCC.BIN .
To load the firmware into the card, use
.Xr bt3cfw 8 .
I am using the original firmware that came with the card on CD-ROM.
.Pp
.Dl "MD5 (BT3CPCC.BIN) = 36170fda56ea9fdbf1702c966f8a97f1"
.Pp
The node has a single hook called
.Dv hook .
Incoming bytes received on the device are re-assembled into HCI frames
(according to the length).
Full HCI frames are sent out on the hook.
HCI frames received on
.Dv hook
are transmitted out.
No modification to the data is performed in either direction.
.Sh HARDWARE
The
.Nm
driver provides support for the 3Com/HP 3CRWB6096-A PCCARD bluetooth adapter.
.Sh HOOKS
This node type supports the following hooks:
.Bl -tag -width ".Va hook"
.It Va hook
single HCI frame contained in single
.Vt mbuf
structure.
.El
.Sh CONTROL MESSAGES
This node type supports the generic control messages, plus the following:
.Bl -tag -width foo
.It Dv NGM_BT3C_NODE_GET_STATE Pq Ic get_state
Returns the current receiving state for the node.
.It Dv NGM_BT3C_NODE_SET_DEBUG Pq Ic set_debug
This command takes an integer argument and sets the current debug level
for the node.
.It Dv NGM_BT3C_NODE_GET_DEBUG Pq Ic get_debug
Returns an integer containing the current debug level for the node.
.It Dv NGM_BT3C_NODE_GET_QLEN Pq Ic get_qlen
This command takes a parameter that specifies queue number and returns
the current length of the queue for the node.
.It Dv NGM_BT3C_NODE_SET_QLEN Pq Ic set_qlen
This command takes two parameters that specify the queue number and
the maximum length of the queue and sets the maximum length of the queue for
the node.
.It Dv NGM_BT3C_NODE_GET_STAT Pq Ic get_stat
Returns various statistic information for the node, such as: number of
bytes (frames) sent, number of bytes (frames) received and number of
input (output) errors.
.It Dv NGM_BT3C_NODE_RESET_STAT Pq Ic reset_stat
Reset all statistic counters to zero.
.It Dv NGM_BT3C_NODE_DOWNLOAD_FIRMWARE
Download card firmware.
.El
.Sh SHUTDOWN
This node shuts down when the corresponding card is un-plugged.
.Sh SEE ALSO
.Xr cardbus 4 ,
.Xr netgraph 4 ,
.Xr pccbb 4 ,
.Xr pcic 4 ,
.Xr pccard.conf 5 ,
.Xr bt3cfw 8 ,
.Xr ngctl 8
.Sh HISTORY
The
.Nm btccc
node type was implemented in
.Fx 5.0 .
.Sh AUTHORS
.An Maksim Yevmenkin Aq Mt m_evmenkin@yahoo.com
.Sh BUGS
The driver is based on information obtained from
.An Jose Orlando Pereira Aq Mt jop@di.uminho.pt
and disassembled the W2K driver.

View File

@ -769,7 +769,6 @@ options NETGRAPH_ASYNC
options NETGRAPH_ATMLLC
options NETGRAPH_ATM_ATMPIF
options NETGRAPH_BLUETOOTH # ng_bluetooth(4)
options NETGRAPH_BLUETOOTH_BT3C # ng_bt3c(4)
options NETGRAPH_BLUETOOTH_HCI # ng_hci(4)
options NETGRAPH_BLUETOOTH_L2CAP # ng_l2cap(4)
options NETGRAPH_BLUETOOTH_SOCKET # ng_btsocket(4)

View File

@ -4259,7 +4259,6 @@ netgraph/atm/sscop/ng_sscop.c optional ngatm_sscop \
netgraph/atm/uni/ng_uni.c optional ngatm_uni \
compile-with "${NORMAL_C} -I$S/contrib/ngatm"
netgraph/bluetooth/common/ng_bluetooth.c optional netgraph_bluetooth
netgraph/bluetooth/drivers/bt3c/ng_bt3c_pccard.c optional netgraph_bluetooth_bt3c
netgraph/bluetooth/drivers/h4/ng_h4.c optional netgraph_bluetooth_h4
netgraph/bluetooth/drivers/ubt/ng_ubt.c optional netgraph_bluetooth_ubt usb
netgraph/bluetooth/drivers/ubt/ng_ubt_intel.c optional netgraph_bluetooth_ubt usb

View File

@ -6,7 +6,6 @@ SUBDIR= \
hci \
l2cap \
socket \
bt3c \
ubt \
ubtbcmfw

View File

@ -1,12 +0,0 @@
# $Id: Makefile,v 1.2 2002/11/24 20:50:56 max Exp $
# $FreeBSD$
.PATH: ${SRCTOP}/sys/netgraph/bluetooth/drivers/bt3c
CFLAGS+= -I${SRCTOP}/sys/netgraph/bluetooth/include \
-I${SRCTOP}/sys/netgraph/bluetooth/drivers/bt3c
KMOD= ng_bt3c
SRCS= ng_bt3c_pccard.c bus_if.h card_if.h device_if.h pccarddevs.h
.include <bsd.kmod.mk>

File diff suppressed because it is too large Load Diff

View File

@ -1,108 +0,0 @@
/*
* ng_bt3c_var.h
*/
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
* 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $Id: ng_bt3c_var.h,v 1.1 2002/11/24 19:46:54 max Exp $
* $FreeBSD$
*
* XXX XXX XX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
*
* Based on information obrained from: Jose Orlando Pereira <jop@di.uminho.pt>
* and disassembled w2k driver.
*
* XXX XXX XX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
*
*/
#ifndef _NG_BT3C_VAR_H_
#define _NG_BT3C_VAR_H_
/* Debug printf's */
#define NG_BT3C_ALERT if (sc->debug >= NG_BT3C_ALERT_LEVEL) device_printf
#define NG_BT3C_ERR if (sc->debug >= NG_BT3C_ERR_LEVEL) device_printf
#define NG_BT3C_WARN if (sc->debug >= NG_BT3C_WARN_LEVEL) device_printf
#define NG_BT3C_INFO if (sc->debug >= NG_BT3C_INFO_LEVEL) device_printf
/* Device registers */
#define BT3C_DATA_L 0x00 /* data low byte */
#define BT3C_DATA_H 0x01 /* high byte */
#define BT3C_ADDR_L 0x02 /* address low byte */
#define BT3C_ADDR_H 0x03 /* high byte */
#define BT3C_CONTROL 0x04 /* control */
#define BT3C_FIFO_SIZE 256
/* Device softc structure */
struct bt3c_softc {
/* Device specific */
device_t dev; /* pointer back to device */
int iobase_rid; /* iobase RID */
struct resource *iobase; /* iobase */
bus_space_tag_t iot; /* I/O tag */
bus_space_handle_t ioh; /* I/O handle */
int irq_rid; /* irq RID */
struct resource *irq; /* irq */
void *irq_cookie; /* irq cookie */
/* Netgraph specific */
node_p node; /* pointer back to node */
hook_p hook; /* hook */
ng_bt3c_node_debug_ep debug; /* debug level */
u_int16_t flags; /* device flags */
#define BT3C_ANTENNA_OUT (1 << 0) /* antena is out */
#define BT3C_XMIT (1 << 1) /* xmit in progress */
ng_bt3c_node_state_ep state; /* receiving state */
ng_bt3c_node_stat_ep stat; /* statistic */
#define NG_BT3C_STAT_PCKTS_SENT(s) (s).pckts_sent ++
#define NG_BT3C_STAT_BYTES_SENT(s, n) (s).bytes_sent += (n)
#define NG_BT3C_STAT_PCKTS_RECV(s) (s).pckts_recv ++
#define NG_BT3C_STAT_BYTES_RECV(s, n) (s).bytes_recv += (n)
#define NG_BT3C_STAT_OERROR(s) (s).oerrors ++
#define NG_BT3C_STAT_IERROR(s) (s).ierrors ++
#define NG_BT3C_STAT_RESET(s) bzero(&(s), sizeof((s)))
u_int32_t status; /* from ISR */
void *ith; /* ithread handler */
struct mbuf *m; /* current frame */
u_int32_t want; /* # of chars we want */
struct ifqueue inq; /* queue of incoming mbuf's */
struct ifqueue outq; /* queue of outgoing mbuf's */
#define BT3C_DEFAULTQLEN 12 /* XXX max. size of out queue */
};
typedef struct bt3c_softc bt3c_softc_t;
typedef struct bt3c_softc * bt3c_softc_p;
#endif /* ndef _NG_BT3C_VAR_H_ */

View File

@ -1,112 +0,0 @@
/*
* ng_bt3c.h
*/
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
* 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $Id: ng_bt3c.h,v 1.1 2002/11/24 19:47:05 max Exp $
* $FreeBSD$
*
* XXX XXX XX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
*
* Based on information obrained from: Jose Orlando Pereira <jop@di.uminho.pt>
* and disassembled w2k driver.
*
* XXX XXX XX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
*
*/
#ifndef _NG_BT3C_H_
#define _NG_BT3C_H_
/**************************************************************************
**************************************************************************
** Netgraph node hook name, type name and type cookie and commands
**************************************************************************
**************************************************************************/
#define NG_BT3C_NODE_TYPE "btccc" /* XXX can't use bt3c in pccard.conf */
#define NG_BT3C_HOOK "hook"
#define NGM_BT3C_COOKIE 1014752016
/* Debug levels */
#define NG_BT3C_ALERT_LEVEL 1
#define NG_BT3C_ERR_LEVEL 2
#define NG_BT3C_WARN_LEVEL 3
#define NG_BT3C_INFO_LEVEL 4
/* Node states */
#define NG_BT3C_W4_PKT_IND 1 /* wait for packet indicator */
#define NG_BT3C_W4_PKT_HDR 2 /* wait for packet header */
#define NG_BT3C_W4_PKT_DATA 3 /* wait for packet data */
/**************************************************************************
**************************************************************************
** BT3C node command/event parameters
**************************************************************************
**************************************************************************/
#define NGM_BT3C_NODE_GET_STATE 1 /* get node state */
typedef u_int16_t ng_bt3c_node_state_ep;
#define NGM_BT3C_NODE_SET_DEBUG 2 /* set debug level */
#define NGM_BT3C_NODE_GET_DEBUG 3 /* get debug level */
typedef u_int16_t ng_bt3c_node_debug_ep;
#define NGM_BT3C_NODE_GET_QLEN 4 /* get queue length */
#define NGM_BT3C_NODE_SET_QLEN 5 /* set queue length */
typedef struct {
int32_t queue; /* queue index */
#define NGM_BT3C_NODE_IN_QUEUE 1 /* incoming queue */
#define NGM_BT3C_NODE_OUT_QUEUE 2 /* outgoing queue */
int32_t qlen; /* queue length */
} ng_bt3c_node_qlen_ep;
#define NGM_BT3C_NODE_GET_STAT 6 /* get statistic */
typedef struct {
u_int32_t pckts_recv; /* # of packets received */
u_int32_t bytes_recv; /* # of bytes received */
u_int32_t pckts_sent; /* # of packets sent */
u_int32_t bytes_sent; /* # of bytes sent */
u_int32_t oerrors; /* # of output errors */
u_int32_t ierrors; /* # of input errors */
} ng_bt3c_node_stat_ep;
#define NGM_BT3C_NODE_RESET_STAT 7 /* reset statistic */
#define NGM_BT3C_NODE_DOWNLOAD_FIRMWARE 8 /* download firmware */
typedef struct {
u_int32_t block_address;
u_int16_t block_size; /* in words */
u_int16_t block_alignment; /* in bytes */
} ng_bt3c_firmware_block_ep;
#endif /* ndef _NG_BT3C_H_ */

View File

@ -5,7 +5,6 @@
SUBDIR= \
bluetooth-config \
bt3cfw \
btpand \
hccontrol \
hcsecd \

View File

@ -1,11 +0,0 @@
# $Id: Makefile,v 1.5 2003/08/14 20:06:00 max Exp $
# $FreeBSD$
PACKAGE= bluetooth
PROG= bt3cfw
MAN= bt3cfw.8
WARNS?= 2
LIBADD+= netgraph
.include <bsd.prog.mk>

View File

@ -1,18 +0,0 @@
# $FreeBSD$
# Autogenerated - do NOT edit!
DIRDEPS = \
gnu/lib/csu \
include \
include/xlocale \
lib/${CSU_DIR} \
lib/libc \
lib/libcompiler_rt \
lib/libnetgraph \
.include <dirdeps.mk>
.if ${DEP_RELDIR} == ${_DEP_RELDIR}
# local dependencies - needed for -jN in clean tree
.endif

View File

@ -1,73 +0,0 @@
.\" Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
.\" 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
.\"
.\" $Id: bt3cfw.8,v 1.4 2003/05/21 00:34:51 max Exp $
.\" $FreeBSD$
.\"
.Dd November 11, 2002
.Dt BT3CFW 8
.Os
.Sh NAME
.Nm bt3cfw
.Nd firmware download utility for 3Com Bluetooth PC card driver
.Sh SYNOPSIS
.Nm
.Op Fl h
.Fl f Ar Firmware_file_name
.Fl n Ar Netgraph_node_name
.Sh DESCRIPTION
The
.Nm
utility connects to the specified Netgraph driver node of type
.Dv BTCCC
and downloads the specified firmware file.
.Pp
Due to copyright issues, I will no longer provide firmware with the card
driver.
The firmware can be obtained from the Windows driver package that
can be downloaded from the 3COM web site at no charge.
The firmware name is
.Pa BT3CPCC.BIN .
I am using the original firmware that came with the card on CD-ROM.
.Pp
.Dl "MD5 (BT3CPCC.BIN) = 36170fda56ea9fdbf1702c966f8a97f1"
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl f Ar Firmware_file_name
Specify firmware file name for download.
.It Fl h
Display usage message and exit.
.It Fl n Ar Netgraph_node_name
Connect to the specified Netgraph driver node of type
.Dv BTCCC .
.El
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
.Xr ng_bt3c 4
.Sh AUTHORS
.An Maksim Yevmenkin Aq Mt m_evmenkin@yahoo.com
.Sh BUGS
Please report if found.

View File

@ -1,230 +0,0 @@
/*-
* bt3cfw.c
*
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com>
* 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $Id: bt3cfw.c,v 1.2 2003/05/21 22:40:29 max Exp $
* $FreeBSD$
*/
#include <sys/types.h>
#include <errno.h>
#include <netgraph.h>
#include <netgraph/bluetooth/include/ng_bt3c.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#define BT3CFW_IDENT "bt3cfw"
#define BT3CFW_MAX_FIRMWARE_SIZE 0xffff
/* Convert hex ASCII to int4 */
static int
hexa2int4(const char *a)
{
if ('0' <= *a && *a <= '9')
return (*a - '0');
if ('A' <= *a && *a <= 'F')
return (*a - 'A' + 0xa);
if ('a' <= *a && *a <= 'f')
return (*a - 'a' + 0xa);
syslog(LOG_ERR, "Invalid hex character: '%c' (%#x)", *a, *a);
exit(255);
}
/* Convert hex ASCII to int8 */
static int
hexa2int8(const char *a)
{
return ((hexa2int4(a) << 4) | hexa2int4(a + 1));
}
/* Convert hex ASCII to int16 */
static int
hexa2int16(const char *a)
{
return ((hexa2int8(a) << 8) | hexa2int8(a + 2));
}
/* Convert hex ASCII to int32 */
static int
hexa2int32(const char *a)
{
return ((hexa2int16(a) << 16) | hexa2int16(a + 4));
}
/* Display usage() and exit */
static void
usage(void)
{
syslog(LOG_ERR, "Usage: %s -f FirmwareFile -n NodeName", BT3CFW_IDENT);
exit(255);
}
/* Main */
int
main(int argc, char *argv[])
{
FILE *firmware_file = NULL;
char buffer[80], path[NG_PATHSIZ],
*firmware_filename = NULL;
uint8_t *firmware = NULL;
int firmware_size, opt, cs, ds;
memset(path, 0, sizeof(path));
openlog(BT3CFW_IDENT, LOG_NDELAY|LOG_PID|LOG_PERROR, LOG_USER);
while ((opt = getopt(argc, argv, "f:hn:")) != -1) {
switch (opt) {
case 'f':
firmware_filename = optarg;
break;
case 'n':
snprintf(path, sizeof(path), "%s:", optarg);
break;
case 'h':
default:
usage();
/* NOT REACHED */
}
}
if (firmware_filename == NULL || path[0] == 0)
usage();
/* NOT REACHED */
firmware = (uint8_t *) calloc(BT3CFW_MAX_FIRMWARE_SIZE,
sizeof(uint8_t));
if (firmware == NULL) {
syslog(LOG_ERR, "Could not allocate firmware buffer");
exit(255);
}
if ((firmware_file = fopen(firmware_filename, "r")) == NULL) {
syslog(LOG_ERR, "Could not open BT3C firmware file %s. %s (%d)",
firmware_filename, strerror(errno), errno);
exit(255);
}
firmware_size = 0;
while (fgets(buffer, sizeof(buffer), firmware_file)) {
int i, size, address, cs, fcs;
size = hexa2int8(buffer + 2);
address = hexa2int32(buffer + 4);
fcs = hexa2int8(buffer + 2 + size * 2);
if (buffer[1] == '3') {
ng_bt3c_firmware_block_ep *block = NULL;
uint16_t *data = NULL;
block = (ng_bt3c_firmware_block_ep *)
(firmware + firmware_size);
firmware_size += sizeof(*block);
if (firmware_size >= BT3CFW_MAX_FIRMWARE_SIZE) {
syslog(LOG_ERR, "Could not add new firmware " \
"block. Firmware file %s is " \
"too big, firmware_size=%d",
firmware_filename,
firmware_size);
exit(255);
}
block->block_address = address;
block->block_size = (size - 4) / 2;
block->block_alignment = (block->block_size * 2) % 3;
if (block->block_alignment != 0)
block->block_alignment = 3 - block->block_alignment;
firmware_size += (block->block_size * 2);
firmware_size += block->block_alignment;
if (firmware_size >= BT3CFW_MAX_FIRMWARE_SIZE) {
syslog(LOG_ERR, "Could not add new firmware " \
"data. Firmware file %s is " \
"too big, firmware_size=%d",
firmware_filename,
firmware_size);
exit(255);
}
/* First part of the cheksum: size and address */
cs = 0;
for (i = 0; i < 5; i++)
cs += hexa2int8(buffer + 2 + i * 2);
/* Data + second part of the cheksum: data */
data = (uint16_t *)(block + 1);
for (i = 0; i < block->block_size; i++) {
data[i] = hexa2int16(buffer + (i * 4) + 12);
cs += (((data[i] & 0xff00) >> 8) & 0xff);
cs += (data[i] & 0x00ff);
}
} else
for (cs = 0, i = 0; i < size; i++)
cs += hexa2int8(buffer + 2 + i * 2);
if (((cs + fcs) & 0xff) != 0xff) {
syslog(LOG_ERR, "Invalid firmware file %s. Checksum " \
"error, cs=%#x, fcs=%#x, checksum=%#x",
firmware_filename, (cs & 0xff), fcs,
((cs + fcs) & 0xff));
exit(255);
}
}
/* Send firmware to the card */
if (NgMkSockNode(NULL, &cs, &ds) < 0) {
syslog(LOG_ERR, "Could not create Netgraph socket. %s (%d)",
strerror(errno), errno);
exit(255);
}
if (NgSendMsg(cs, path, NGM_BT3C_COOKIE,
NGM_BT3C_NODE_DOWNLOAD_FIRMWARE,
(void const *) firmware, firmware_size) < 0) {
syslog(LOG_ERR, "Could not send Netgraph message. %s (%d)",
strerror(errno), errno);
exit(255);
}
free(firmware);
firmware = NULL;
fclose(firmware_file);
return (0);
}