Home | History | Annotate | Line # | Download | only in bluetooth
      1  1.2  nat /*	$NetBSD: bth5.h,v 1.2 2017/09/03 23:11:19 nat Exp $	*/
      2  1.1  nat /*
      3  1.1  nat  * Copyright (c) 2017 Nathanial Sloss <nathanialsloss (at) yahoo.com.au>
      4  1.1  nat  * All rights reserved.
      5  1.1  nat  *
      6  1.1  nat  * Copyright (c) 2007 KIYOHARA Takashi
      7  1.1  nat  * All rights reserved.
      8  1.1  nat  *
      9  1.1  nat  * Redistribution and use in source and binary forms, with or without
     10  1.1  nat  * modification, are permitted provided that the following conditions
     11  1.1  nat  * are met:
     12  1.1  nat  * 1. Redistributions of source code must retain the above copyright
     13  1.1  nat  *    notice, this list of conditions and the following disclaimer.
     14  1.1  nat  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  nat  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  nat  *    documentation and/or other materials provided with the distribution.
     17  1.1  nat  *
     18  1.1  nat  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  nat  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  1.1  nat  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  1.1  nat  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     22  1.1  nat  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  1.1  nat  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  1.1  nat  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  1.1  nat  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  1.1  nat  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     27  1.1  nat  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.1  nat  * POSSIBILITY OF SUCH DAMAGE.
     29  1.1  nat  */
     30  1.1  nat 
     31  1.1  nat #ifndef _DEV_BLUETOOTH_BTH5_H_
     32  1.1  nat #define _DEV_BLUETOOTH_BTH5_H_
     33  1.1  nat 
     34  1.1  nat /*
     35  1.1  nat  * BT UART H5 (3-wire) serial protocol definitions.
     36  1.1  nat  */
     37  1.1  nat 
     38  1.1  nat /* BTH5 packet header */
     39  1.1  nat typedef struct {
     40  1.1  nat 	uint8_t flags;
     41  1.1  nat #if BYTE_ORDER == BIG_ENDIAN
     42  1.1  nat 	uint8_t plen1 :4;		/* Payload Length (bits 0-3) */
     43  1.1  nat 	uint8_t ident :4;		/* Protocol Identifier */
     44  1.1  nat #else
     45  1.1  nat 	uint8_t ident :4;		/* Protocol Identifier */
     46  1.1  nat 	uint8_t plen1 :4;		/* Payload Length (bits 0-3) */
     47  1.1  nat #endif
     48  1.1  nat 	uint8_t plen2;			/* Payload Length (bits 4-11) */
     49  1.1  nat 	uint8_t csum;			/* Checksum */
     50  1.1  nat 	u_char payload[0];
     51  1.1  nat } __packed bth5_hdr_t;
     52  1.1  nat 
     53  1.1  nat #define BTH5_FLAGS_SEQ_SHIFT	0
     54  1.1  nat #define BTH5_FLAGS_SEQ_MASK	0x07
     55  1.1  nat #define BTH5_FLAGS_SEQ(n) \
     56  1.1  nat 	(((n) & BTH5_FLAGS_SEQ_MASK) >> BTH5_FLAGS_SEQ_SHIFT)
     57  1.1  nat #define BTH5_FLAGS_ACK_SHIFT	3
     58  1.1  nat #define BTH5_FLAGS_ACK_MASK	0x38
     59  1.1  nat #define BTH5_FLAGS_ACK(n) \
     60  1.1  nat 	(((n) & BTH5_FLAGS_ACK_MASK) >> BTH5_FLAGS_ACK_SHIFT)
     61  1.1  nat #define BTH5_FLAGS_CRC_PRESENT	0x40
     62  1.1  nat #define BTH5_FLAGS_PROTOCOL_TYPE 0x80
     63  1.1  nat #define BTH5_FLAGS_PROTOCOL_REL	0x80
     64  1.1  nat 
     65  1.2  nat #define BTH5_CONFIG_ACK_MASK	0x07
     66  1.2  nat #define BTH5_CONFIG_FLOW_MASK	(1 << 7)
     67  1.2  nat 
     68  1.1  nat #define BTH5_SET_PLEN(hdrp, n)				\
     69  1.1  nat 	do {						\
     70  1.1  nat 		(hdrp)->plen1 = ((n) & 0x00f);		\
     71  1.1  nat 		(hdrp)->plen2 = ((n) >> 4);		\
     72  1.1  nat 	} while (0)
     73  1.1  nat #define BTH5_GET_PLEN(hdrp)	((hdrp)->plen1 | ((hdrp)->plen2 << 4))
     74  1.1  nat 
     75  1.1  nat #define BTH5_GET_CSUM(hdrp)						\
     76  1.1  nat 	(0xff - (uint8_t)((hdrp)->flags + ((hdrp)->plen1 << 4) +	\
     77  1.1  nat 	(hdrp)->ident + (hdrp)->plen2))
     78  1.1  nat #define BTH5_SET_CSUM(hdrp)	((hdrp)->csum = BTH5_GET_CSUM(hdrp))
     79  1.1  nat 
     80  1.1  nat 
     81  1.1  nat #define BTH5_IDENT_ACKPKT	0	/* Used by MUX Layer */
     82  1.1  nat 
     83  1.1  nat /* definitions of SLIP Layer */
     84  1.1  nat #define BTH5_SLIP_PKTSTART	0xc0
     85  1.1  nat #define BTH5_SLIP_PKTEND	BTH5_SLIP_PKTSTART
     86  1.1  nat #define BTH5_SLIP_XON		0x11
     87  1.1  nat #define BTH5_SLIP_XOFF		0x13
     88  1.1  nat #define BTH5_SLIP_ESCAPE	0xdb
     89  1.1  nat #define BTH5_SLIP_ESCAPE_PKTEND	0xdc
     90  1.1  nat #define BTH5_SLIP_ESCAPE_ESCAPE	0xdd
     91  1.1  nat #define BTH5_SLIP_ESCAPE_XON	0xde
     92  1.1  nat #define BTH5_SLIP_ESCAPE_XOFF	0xdf
     93  1.1  nat 
     94  1.1  nat 
     95  1.1  nat /* definitions of Sequencing Layer */
     96  1.1  nat #define BTH5_SEQ_TX_TIMEOUT	(hz / 4)	/* 250 msec */
     97  1.1  nat #define BTH5_SEQ_TX_WINSIZE	7
     98  1.1  nat #define BTH5_SEQ_TX_RETRY_LIMIT	20
     99  1.1  nat 
    100  1.1  nat 
    101  1.1  nat /*
    102  1.1  nat  *   Channel Allocation
    103  1.1  nat  */
    104  1.1  nat #define BTH5_CHANNEL_HCI_CMD	1	/* HCI Command and Event */
    105  1.1  nat #define BTH5_CHANNEL_HCI_EVT	4	/* HCI Command and Event */
    106  1.1  nat #define BTH5_CHANNEL_HCI_ACL	2	/* HCI ACL data */
    107  1.1  nat #define BTH5_CHANNEL_HCI_SCO	3	/* HCI SCO data */
    108  1.1  nat #define BTH5_CHANNEL_LE		15	/* Link Establishment */
    109  1.1  nat 
    110  1.1  nat 
    111  1.1  nat /*
    112  1.1  nat  *   Link Establishment Protocol
    113  1.1  nat  */
    114  1.1  nat typedef enum {
    115  1.1  nat 	le_state_shy,
    116  1.1  nat 	le_state_curious,
    117  1.1  nat 	le_state_garrulous
    118  1.1  nat } bth5_le_state_t;
    119  1.1  nat 
    120  1.1  nat #define BTH5_LE_SYNC		{ 0x01, 0x7e };
    121  1.1  nat #define BTH5_LE_SYNCRESP	{ 0x02, 0x7d };
    122  1.1  nat #define BTH5_LE_CONF		{ 0x03, 0xfc, 0x0f };
    123  1.1  nat #define BTH5_LE_CONFRESP	{ 0x04, 0x7b, 0x0f };
    124  1.1  nat 
    125  1.1  nat #define BTH5_LE_TSHY_TIMEOUT	hz	/* XXXX: 1sec ? */
    126  1.1  nat #define BTH5_LE_TCONF_TIMEOUT	hz	/* XXXX: 1sec ? */
    127  1.1  nat 
    128  1.1  nat #endif	/* !_DEV_BLUETOOTH_BTH5_H_ */
    129