xref: /netbsd-src/usr.sbin/btattach/init_ericsson.c (revision 8ee626c9fa19b110a740cae0b27b2678014c2a70)
1*8ee626c9Schristos /*	$NetBSD: init_ericsson.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_ericsson.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 void
init_ericsson(int fd,unsigned int speed)45486e4624Splunky init_ericsson(int fd, unsigned int speed)
46486e4624Splunky {
47486e4624Splunky 	uint8_t rate;
48486e4624Splunky 
49486e4624Splunky 	switch(speed) {
50486e4624Splunky 	case B460800:	rate = 0x00;	break;
51486e4624Splunky 	case B230400:	rate = 0x01;	break;
52486e4624Splunky 	case B115200:	rate = 0x02;	break;
53486e4624Splunky 	case B57600:	rate = 0x03;	break;
54486e4624Splunky 	case B28800:	rate = 0x04;	break;
55486e4624Splunky 	case B14400:	rate = 0x05;	break;
56486e4624Splunky 	case B7200:	rate = 0x06;	break;
57486e4624Splunky #if defined(B3600)
58486e4624Splunky 	case B3600:	rate = 0x07;	break;
59486e4624Splunky #endif
60486e4624Splunky 	case B1800:	rate = 0x08;	break;
61486e4624Splunky #if defined(B900)
62486e4624Splunky 	case B900:	rate = 0x09;	break;
63486e4624Splunky #endif
64486e4624Splunky #if defined(B153600)
65486e4624Splunky 	case B153600:	rate = 0x10;	break;
66486e4624Splunky #endif
67486e4624Splunky 	case B76800:	rate = 0x11;	break;
68486e4624Splunky 	case B38400:	rate = 0x12;	break;
69486e4624Splunky 	case B19200:	rate = 0x13;	break;
70486e4624Splunky 	case B9600:	rate = 0x14;	break;
71486e4624Splunky 	case B4800:	rate = 0x15;	break;
72486e4624Splunky 	case B2400:	rate = 0x16;	break;
73486e4624Splunky 	case B1200:	rate = 0x17;	break;
74486e4624Splunky 	case B600:	rate = 0x18;	break;
75486e4624Splunky 	case B300:	rate = 0x19;	break;
76486e4624Splunky 	case B921600:	rate = 0x20;	break;
77486e4624Splunky 	case 200000:	rate = 0x25;	break;
78486e4624Splunky 	case 300000:	rate = 0x27;	break;
79486e4624Splunky 	case 400000:	rate = 0x2b;	break;
80486e4624Splunky 	default:
81*8ee626c9Schristos 		errx(EXIT_FAILURE, "invalid speed for ericsson: %u", speed);
82486e4624Splunky 	}
83486e4624Splunky 
84486e4624Splunky 	uart_send_cmd(fd, HCI_CMD_ERICSSON_SET_UART_BAUD_RATE, &rate, sizeof(rate));
85486e4624Splunky 	/* wait for response? */
86486e4624Splunky 	/* assume it succeeded? */
87486e4624Splunky }
88