Support type bcsp.

This commit is contained in:
kiyohara 2007-09-30 04:11:02 +00:00
parent 09fa5a563a
commit c9c6f7ff7e
2 changed files with 62 additions and 17 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: btuartd.8,v 1.4 2007/03/12 08:10:31 kiyohara Exp $
.\" $NetBSD: btuartd.8,v 1.5 2007/09/30 04:11:02 kiyohara Exp $
.\"
.\" Copyright (c) 2007 KIYOHARA Takashi
.\" All rights reserved.
@ -24,9 +24,9 @@
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $Id: btuartd.8,v 1.4 2007/03/12 08:10:31 kiyohara Exp $
.\" $Id: btuartd.8,v 1.5 2007/09/30 04:11:02 kiyohara Exp $
.\"
.Dd February 19, 2007
.Dd September 22, 2007
.Dt BTUARTD 8
.Os
.Sh NAME
@ -38,6 +38,7 @@
.Op Fl c Ar conffile
.Nm
.Op Fl f
.Op Fl p Op Fl o
.Op Fl i Ar init_speed
.Op Ar type
.Ar comdev speed
@ -51,7 +52,7 @@ like
.Xr com 4
and compatible devices, also configures
.Ar speed
and flow.
and flow, parity.
The
.Nm
daemon supports HCI UART.
@ -86,6 +87,8 @@ Ericsson based modules
Digianswer based cards
.It Cm texas
Texas Instruments
.It Cm bcsp
BCSP (BlueCore Serial Protocol)
.It Cm csr
Cambridge Silicon Radio Casira serial adapter or BrainBoxes serial dongle
(BL642)
@ -113,7 +116,13 @@ Run in foreground (do not detach).
Enable flow control as
.Xr com 4 .
.It Fl i Ar init_speed
Specify the initial speed for the Bluetooth module.
Specify the initial speed for the Bluetooth module. It first sets to this
value, and it initializes it if specified. Afterwards, the speed is set to
.Ar speed.
.It Fl o
Enable odd parity, if enabled parity.
.It Fl p
Enable parity (even parity).
.El
.Sh FILES
.Bl -tag -compact
@ -121,6 +130,7 @@ Specify the initial speed for the Bluetooth module.
.It Pa /var/run/btuartd.pid
.El
.Sh SEE ALSO
.Xr bcsp 4 ,
.Xr bluetooth 4 ,
.Xr btuart 4 ,
.Xr btconfig 8

View File

@ -1,4 +1,4 @@
/* $NetBSD: btuartd.c,v 1.2 2007/06/12 10:05:24 kiyohara Exp $ */
/* $NetBSD: btuartd.c,v 1.3 2007/09/30 04:11:02 kiyohara Exp $ */
/*
* Copyright (c) 2006, 2007 KIYOHARA Takashi
* All rights reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: btuartd.c,v 1.2 2007/06/12 10:05:24 kiyohara Exp $");
__RCSID("$NetBSD: btuartd.c,v 1.3 2007/09/30 04:11:02 kiyohara Exp $");
#include <sys/param.h>
#include <sys/ioctl.h>
@ -58,13 +58,15 @@ struct btuartd_conf {
char comdev[PATH_MAX];
int speed;
int flow;
int parity;
int odd; /* odd parity */
int init_speed;
};
static void usage(void);
static int read_config(int, struct btuartd_conf **, char *);
static void btuartd_sigcaught(int);
static int btuart_setting(int, int, int, int, int);
static int btuart_setting(int, int, int, int, int, int, int);
static int btuartd(int, struct btuartd_conf *);
@ -83,6 +85,7 @@ static struct hcitypetbl {
{ "stlc2500", BTUART_HCITYPE_STLC2500 },
{ "bt2000c", BTUART_HCITYPE_BT2000C },
{ "bcm2035", BTUART_HCITYPE_BCM2035 },
{ "bcsp", BTUART_HCITYPE_BCSP },
{ "*", BTUART_HCITYPE_ANY },
{ NULL },
};
@ -93,7 +96,7 @@ usage()
{
const char *progname = getprogname();
printf("usage: %s [-f] [-i init_speed] [type] comdev speed\n",
printf("usage: %s [-f] [-p [-o]] [-i init_speed] [type] comdev speed\n",
progname);
printf(" %s [-d] [-c conffile]\n", progname);
printf(" comdev: com device. e.g. /dev/dty00\n");
@ -102,10 +105,12 @@ usage()
}
static int
btuart_setting(int comfd, int type, int speed, int flow, int init_speed)
btuart_setting(int comfd, int type, int speed, int flow, int parity, int odd,
int init_speed)
{
struct termios t;
int rv;
char *line;
tcflush(comfd, TCIOFLUSH);
if ((rv = tcgetattr(comfd, &t)) == -1) {
@ -116,6 +121,11 @@ btuart_setting(int comfd, int type, int speed, int flow, int init_speed)
t.c_cflag |= CLOCAL;
if (flow)
t.c_cflag |= CRTSCTS;
if (parity) {
t.c_cflag |= PARENB;
if (odd)
t.c_cflag |= PARODD;
}
tcflush(comfd, TCIOFLUSH);
if ((rv = cfsetspeed(&t, speed)) == -1) {
@ -127,12 +137,15 @@ btuart_setting(int comfd, int type, int speed, int flow, int init_speed)
return rv;
}
/* set btuart discipline */
if ((rv = ioctl(comfd, TIOCSLINED, "btuart")) == -1) {
/* set btuart or bcsp discipline */
line = (type != BTUART_HCITYPE_BCSP) ? "btuart" : "bcsp";
if ((rv = ioctl(comfd, TIOCSLINED, line)) == -1) {
syslog(LOG_ERR,
"ioctl TIOCSLINE btuart failed: %s", strerror(errno));
"ioctl TIOCSLINE %s failed: %s", line, strerror(errno));
return rv;
}
if (type == BTUART_HCITYPE_BCSP)
return rv;
if (init_speed != B0)
if ((rv = ioctl(comfd, BTUART_INITSPEED, &init_speed)) == -1) {
@ -208,6 +221,8 @@ read_config(int onbtuart, struct btuartd_conf **btuartd_conf, char *conffile)
}
(*btuartd_conf)[nbtuart].type = hcitypetbl[j].hcitype;
(*btuartd_conf)[nbtuart].flow = 0;
(*btuartd_conf)[nbtuart].parity = 0;
(*btuartd_conf)[nbtuart].odd = 0;
(*btuartd_conf)[nbtuart].init_speed = B0;
while (1 /* CONSTCOND */) {
@ -216,6 +231,10 @@ read_config(int onbtuart, struct btuartd_conf **btuartd_conf, char *conffile)
if (strstr(&buf[n], "flow") == &buf[n])
(*btuartd_conf)[nbtuart].flow = 1;
else if (strstr(&buf[n], "parity") == &buf[n])
(*btuartd_conf)[nbtuart].parity = 1;
else if (strstr(&buf[n], "odd") == &buf[n])
(*btuartd_conf)[nbtuart].odd = 1;
else if (strstr(&buf[n], "init_speed") == &buf[n]) {
n += strcspn(&buf[n], " \t");
n += strspn(&buf[n], " \t");
@ -233,6 +252,8 @@ read_config(int onbtuart, struct btuartd_conf **btuartd_conf, char *conffile)
}
if (nbtuart == -1)
break;
if (!(*btuartd_conf)[nbtuart].parity)
(*btuartd_conf)[nbtuart].odd = 0;
nbtuart++;
}
if (nbtuart < onbtuart && threshold > BTUARTD_CONF_MIN) {
@ -284,7 +305,8 @@ btuartd(int nbtuart, struct btuartd_conf *btuartd_conf)
(btuartd_conf[i].flow == 1) ? " flow" : "", strbuf);
error = btuart_setting(comfd,
btuartd_conf[i].type, btuartd_conf[i].speed,
btuartd_conf[i].flow, btuartd_conf[i].init_speed);
btuartd_conf[i].flow, btuartd_conf[i].parity,
btuartd_conf[i].odd, btuartd_conf[i].init_speed);
if (error != 0) {
close(comfd);
syslog(LOG_ERR, "btuart setting failed: %s",
@ -319,19 +341,19 @@ main(int argc, char *argv[])
extern int optind;
struct btuartd_conf *btuartd_conf;
int nbtuart, ch, i, status;
int type, init_speed, flow, debug;
int type, init_speed, flow, parity, odd, debug;
char *conffile;
const char *progname = getprogname();
conffile = BTUARTD_CONFFILE;
init_speed = B0;
flow = 0;
flow = parity = odd = 0;
debug = 0;
nbtuart = 0;
btuartd_conf = malloc(sizeof(struct btuartd_conf) * BTUARTD_CONF_MIN);
while ((ch = getopt(argc, argv, "c:dfi:")) != -1) {
while ((ch = getopt(argc, argv, "c:dfi:op")) != -1) {
switch (ch) {
case 'c':
conffile = optarg;
@ -349,6 +371,14 @@ main(int argc, char *argv[])
init_speed = atoi(optarg);
break;
case 'o':
odd = 1;
break;
case 'p':
parity = 1;
break;
case '?':
default:
usage();
@ -357,6 +387,9 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
if (!parity)
odd = 0;
openlog(progname, LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_DAEMON);
if (argc == 0) {
@ -403,6 +436,8 @@ main(int argc, char *argv[])
sizeof(btuartd_conf[0].comdev));;
btuartd_conf[0].speed = atoi(argv[1]);
btuartd_conf[0].flow = flow;
btuartd_conf[0].parity = parity;
btuartd_conf[0].odd = odd;
btuartd_conf[0].init_speed = init_speed;
nbtuart = 1;
}