Sync usage with man page.
[netbsd-mini2440.git] / usr.sbin / btattach / init_csr.c
blobe1b3e09ecc1a19a9ba2a7644e8f821e1f6eace2d
1 /* $NetBSD: init_csr.c,v 1.1 2008/04/15 11:17:48 plunky Exp $ */
3 /*-
4 * Copyright (c) 2008 Iain Hibbert
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * init information in this file gleaned from hciattach(8)
30 * command from BlueZ for Linux - see http://www.bluez.org/
33 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: init_csr.c,v 1.1 2008/04/15 11:17:48 plunky Exp $");
36 #include <bluetooth.h>
37 #include <errno.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <termios.h>
42 #include <dev/bluetooth/bcsp.h>
44 #include "btattach.h"
46 struct bccmd {
47 uint8_t chanid;
49 struct {
50 uint16_t type;
51 uint16_t length;
52 uint16_t seqno;
53 uint16_t varid;
54 uint16_t status;
55 uint16_t payload[4];
56 } message;
57 } __attribute__ ((__packed__));
59 #define CSR_BCCMD_FIRST (1<<6)
60 #define CSR_BCCMD_LAST (1<<7)
62 #define CSR_BCCMD_MESSAGE_TYPE_GETREQ 0x0000
63 #define CSR_BCCMD_MESSAGE_TYPE_GETRESP 0x0001
64 #define CSR_BCCMD_MESSAGE_TYPE_SETREQ 0x0002
66 #define CSR_BCCMD_MESSAGE_VARID_CONFIG_UART 0x6802
67 #define CSR_BCCMD_MESSAGE_VARID_CONFIG_UART_STOPB 0x2000
68 #define CSR_BCCMD_MESSAGE_VARID_CONFIG_UART_PARENB 0x4000
69 #define CSR_BCCMD_MESSAGE_VARID_CONFIG_UART_PARODD 0x8000
71 #define CSR_BCCMD_MESSAGE_STATUS_OK 0x0000
72 #define CSR_BCCMD_MESSAGE_STATUS_NO_SUCH_VARID 0x0001
73 #define CSR_BCCMD_MESSAGE_STATUS_TOO_BIG 0x0002
74 #define CSR_BCCMD_MESSAGE_STATUS_NO_VALUE 0x0003
75 #define CSR_BCCMD_MESSAGE_STATUS_BAD_REQ 0x0004
76 #define CSR_BCCMD_MESSAGE_STATUS_NO_ACCESS 0x0005
77 #define CSR_BCCMD_MESSAGE_STATUS_READ_ONLY 0x0006
78 #define CSR_BCCMD_MESSAGE_STATUS_WRITE_ONLY 0x0007
79 #define CSR_BCCMD_MESSAGE_STATUS_ERROR 0x0008
80 #define CSR_BCCMD_MESSAGE_STATUS_PERMISION_DENIED 0x0009
82 void
83 init_csr(int fd, unsigned int speed)
85 struct bccmd cmd;
87 /* setup BlueCore command packet */
88 memset(&cmd, 0, sizeof(cmd));
90 cmd.chanid = CSR_BCCMD_LAST | CSR_BCCMD_FIRST | BCSP_CHANNEL_BCCMD;
92 cmd.message.type = htole16(CSR_BCCMD_MESSAGE_TYPE_SETREQ);
93 cmd.message.length = htole16(sizeof(cmd.message) >> 1);
94 cmd.message.seqno = htole16(0);
95 cmd.message.varid = htole16(CSR_BCCMD_MESSAGE_VARID_CONFIG_UART);
96 cmd.message.status = htole16(CSR_BCCMD_MESSAGE_STATUS_OK);
98 /* Value = (baud rate / 244.140625) | no parity | 1 stop bit. */
99 cmd.message.payload[0] = htole16((speed * 64 + 7812) / 15625);
101 uart_send_cmd(fd, HCI_CMD_CSR_EXTN, &cmd, sizeof(cmd));
102 uart_recv_cc(fd, HCI_CMD_CSR_EXTN, NULL, 0);
103 /* assume it succeeded? */