1*8ee626c9Schristos /* $NetBSD: init_st.c,v 1.3 2015/06/16 23:04:14 christos Exp $ */
2486e4624Splunky
3486e4624Splunky /*-
4486e4624Splunky * Copyright (c) 2008 Iain Hibbert
5486e4624Splunky * All rights reserved.
6486e4624Splunky *
7486e4624Splunky * Redistribution and use in source and binary forms, with or without
8486e4624Splunky * modification, are permitted provided that the following conditions
9486e4624Splunky * are met:
10486e4624Splunky * 1. Redistributions of source code must retain the above copyright
11486e4624Splunky * notice, this list of conditions and the following disclaimer.
12486e4624Splunky * 2. Redistributions in binary form must reproduce the above copyright
13486e4624Splunky * notice, this list of conditions and the following disclaimer in the
14486e4624Splunky * documentation and/or other materials provided with the distribution.
15486e4624Splunky *
16486e4624Splunky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17486e4624Splunky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18486e4624Splunky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19486e4624Splunky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20486e4624Splunky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21486e4624Splunky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22486e4624Splunky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23486e4624Splunky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24486e4624Splunky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25486e4624Splunky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26486e4624Splunky */
27486e4624Splunky
28486e4624Splunky /*
29486e4624Splunky * init information in this file gleaned from hciattach(8)
30486e4624Splunky * command from BlueZ for Linux - see http://www.bluez.org/
31486e4624Splunky */
32486e4624Splunky
33486e4624Splunky #include <sys/cdefs.h>
34*8ee626c9Schristos __RCSID("$NetBSD: init_st.c,v 1.3 2015/06/16 23:04:14 christos Exp $");
35486e4624Splunky
36486e4624Splunky #include <bluetooth.h>
37486e4624Splunky #include <err.h>
38486e4624Splunky #include <errno.h>
39486e4624Splunky #include <stdlib.h>
40486e4624Splunky #include <termios.h>
41486e4624Splunky
42486e4624Splunky #include "btattach.h"
43486e4624Splunky
44486e4624Splunky #define HCI_CMD_ST_SET_UART_BAUD_RATE \
45486e4624Splunky HCI_OPCODE(HCI_OGF_VENDOR, 0x046)
46486e4624Splunky
47486e4624Splunky void
init_st(int fd,unsigned int speed)48486e4624Splunky init_st(int fd, unsigned int speed)
49486e4624Splunky {
50486e4624Splunky uint8_t rate;
51486e4624Splunky
52486e4624Splunky switch(speed) {
53486e4624Splunky case B9600: rate = 0x09; break;
54486e4624Splunky case B19200: rate = 0x0b; break;
55486e4624Splunky case B38400: rate = 0x0d; break;
56486e4624Splunky case B57600: rate = 0x0e; break;
57486e4624Splunky case B115200: rate = 0x10; break;
58486e4624Splunky case B230400: rate = 0x12; break;
59486e4624Splunky case B460800: rate = 0x13; break;
60486e4624Splunky case B921600: rate = 0x14; break;
61486e4624Splunky default:
62*8ee626c9Schristos errx(EXIT_FAILURE, "invalid speed for st: %u", speed);
63486e4624Splunky }
64486e4624Splunky
65486e4624Splunky uart_send_cmd(fd, HCI_CMD_ST_SET_UART_BAUD_RATE, &rate, sizeof(rate));
66486e4624Splunky /* wait for response? */
67486e4624Splunky /* assume it succeeded? */
68486e4624Splunky }
69