Home | History | Annotate | Line # | Download | only in btattach
      1  1.3  christos /*	$NetBSD: init_ericsson.c,v 1.3 2015/06/16 23:04:14 christos Exp $	*/
      2  1.1    plunky 
      3  1.1    plunky /*-
      4  1.1    plunky  * Copyright (c) 2008 Iain Hibbert
      5  1.1    plunky  * All rights reserved.
      6  1.1    plunky  *
      7  1.1    plunky  * Redistribution and use in source and binary forms, with or without
      8  1.1    plunky  * modification, are permitted provided that the following conditions
      9  1.1    plunky  * are met:
     10  1.1    plunky  * 1. Redistributions of source code must retain the above copyright
     11  1.1    plunky  *    notice, this list of conditions and the following disclaimer.
     12  1.1    plunky  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1    plunky  *    notice, this list of conditions and the following disclaimer in the
     14  1.1    plunky  *    documentation and/or other materials provided with the distribution.
     15  1.1    plunky  *
     16  1.1    plunky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1    plunky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1    plunky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1    plunky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1    plunky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1    plunky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1    plunky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1    plunky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1    plunky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1    plunky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1    plunky  */
     27  1.1    plunky 
     28  1.1    plunky /*
     29  1.1    plunky  * init information in this file gleaned from hciattach(8)
     30  1.1    plunky  * command from BlueZ for Linux - see http://www.bluez.org/
     31  1.1    plunky  */
     32  1.1    plunky 
     33  1.1    plunky #include <sys/cdefs.h>
     34  1.3  christos __RCSID("$NetBSD: init_ericsson.c,v 1.3 2015/06/16 23:04:14 christos Exp $");
     35  1.1    plunky 
     36  1.1    plunky #include <bluetooth.h>
     37  1.1    plunky #include <err.h>
     38  1.1    plunky #include <errno.h>
     39  1.1    plunky #include <stdlib.h>
     40  1.1    plunky #include <termios.h>
     41  1.1    plunky 
     42  1.1    plunky #include "btattach.h"
     43  1.1    plunky 
     44  1.1    plunky void
     45  1.1    plunky init_ericsson(int fd, unsigned int speed)
     46  1.1    plunky {
     47  1.1    plunky 	uint8_t rate;
     48  1.1    plunky 
     49  1.1    plunky 	switch(speed) {
     50  1.1    plunky 	case B460800:	rate = 0x00;	break;
     51  1.1    plunky 	case B230400:	rate = 0x01;	break;
     52  1.1    plunky 	case B115200:	rate = 0x02;	break;
     53  1.1    plunky 	case B57600:	rate = 0x03;	break;
     54  1.1    plunky 	case B28800:	rate = 0x04;	break;
     55  1.1    plunky 	case B14400:	rate = 0x05;	break;
     56  1.1    plunky 	case B7200:	rate = 0x06;	break;
     57  1.1    plunky #if defined(B3600)
     58  1.1    plunky 	case B3600:	rate = 0x07;	break;
     59  1.1    plunky #endif
     60  1.1    plunky 	case B1800:	rate = 0x08;	break;
     61  1.1    plunky #if defined(B900)
     62  1.1    plunky 	case B900:	rate = 0x09;	break;
     63  1.1    plunky #endif
     64  1.1    plunky #if defined(B153600)
     65  1.1    plunky 	case B153600:	rate = 0x10;	break;
     66  1.1    plunky #endif
     67  1.1    plunky 	case B76800:	rate = 0x11;	break;
     68  1.1    plunky 	case B38400:	rate = 0x12;	break;
     69  1.1    plunky 	case B19200:	rate = 0x13;	break;
     70  1.1    plunky 	case B9600:	rate = 0x14;	break;
     71  1.1    plunky 	case B4800:	rate = 0x15;	break;
     72  1.1    plunky 	case B2400:	rate = 0x16;	break;
     73  1.1    plunky 	case B1200:	rate = 0x17;	break;
     74  1.1    plunky 	case B600:	rate = 0x18;	break;
     75  1.1    plunky 	case B300:	rate = 0x19;	break;
     76  1.1    plunky 	case B921600:	rate = 0x20;	break;
     77  1.1    plunky 	case 200000:	rate = 0x25;	break;
     78  1.1    plunky 	case 300000:	rate = 0x27;	break;
     79  1.1    plunky 	case 400000:	rate = 0x2b;	break;
     80  1.1    plunky 	default:
     81  1.3  christos 		errx(EXIT_FAILURE, "invalid speed for ericsson: %u", speed);
     82  1.1    plunky 	}
     83  1.1    plunky 
     84  1.1    plunky 	uart_send_cmd(fd, HCI_CMD_ERICSSON_SET_UART_BAUD_RATE, &rate, sizeof(rate));
     85  1.1    plunky 	/* wait for response? */
     86  1.1    plunky 	/* assume it succeeded? */
     87  1.1    plunky }
     88