Home | History | Annotate | Line # | Download | only in bluetooth
      1 /*	$NetBSD: bcsp.h,v 1.2 2007/10/02 05:40:10 junyoung Exp $	*/
      2 /*
      3  * Copyright (c) 2007 KIYOHARA Takashi
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  * POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef _DEV_BLUETOOTH_BCSP_H_
     29 #define _DEV_BLUETOOTH_BCSP_H_
     30 
     31 /*
     32  * BlueCore Serial Protocol definitions
     33  */
     34 
     35 /*
     36  * Reference to bcore-sp-012p.
     37  */
     38 /* BCSP packet header */
     39 typedef struct {
     40 	uint8_t flags;
     41 #if BYTE_ORDER == BIG_ENDIAN
     42 	uint8_t plen1 :4;		/* Payload Length (bits 0-3) */
     43 	uint8_t ident :4;		/* Protocol Identifier */
     44 #else
     45 	uint8_t ident :4;		/* Protocol Identifier */
     46 	uint8_t plen1 :4;		/* Payload Length (bits 0-3) */
     47 #endif
     48 	uint8_t plen2;			/* Payload Length (bits 4-11) */
     49 	uint8_t csum;			/* Checksum */
     50 	u_char payload[0];
     51 } __packed bcsp_hdr_t;
     52 
     53 #define BCSP_FLAGS_SEQ_SHIFT	0
     54 #define BCSP_FLAGS_SEQ_MASK	0x07
     55 #define BCSP_FLAGS_SEQ(n) \
     56 	(((n) & BCSP_FLAGS_SEQ_MASK) >> BCSP_FLAGS_SEQ_SHIFT)
     57 #define BCSP_FLAGS_ACK_SHIFT	3
     58 #define BCSP_FLAGS_ACK_MASK	0x38
     59 #define BCSP_FLAGS_ACK(n) \
     60 	(((n) & BCSP_FLAGS_ACK_MASK) >> BCSP_FLAGS_ACK_SHIFT)
     61 #define BCSP_FLAGS_CRC_PRESENT	0x40
     62 #define BCSP_FLAGS_PROTOCOL_TYPE 0x80
     63 #define BCSP_FLAGS_PROTOCOL_REL	0x80
     64 
     65 #define BCSP_SET_PLEN(hdrp, n)				\
     66 	do {						\
     67 		(hdrp)->plen1 = ((n) & 0x00f);		\
     68 		(hdrp)->plen2 = ((n) >> 4);		\
     69 	} while (0)
     70 #define BCSP_GET_PLEN(hdrp)	((hdrp)->plen1 | ((hdrp)->plen2 << 4))
     71 
     72 #define BCSP_GET_CSUM(hdrp)						\
     73 	(0xff - (uint8_t)((hdrp)->flags + ((hdrp)->plen1 << 4) +	\
     74 	(hdrp)->ident + (hdrp)->plen2))
     75 #define BCSP_SET_CSUM(hdrp)	((hdrp)->csum = BCSP_GET_CSUM(hdrp))
     76 
     77 
     78 #define BCSP_IDENT_ACKPKT	0	/* Used by MUX Layer */
     79 /* Other Protocol Identifier values described to bcore-sp-007P */
     80 
     81 
     82 /* definitions of SLIP Layer */
     83 #define BCSP_SLIP_PKTSTART	0xc0
     84 #define BCSP_SLIP_PKTEND	BCSP_SLIP_PKTSTART
     85 #define BCSP_SLIP_ESCAPE	0xdb
     86 #define BCSP_SLIP_ESCAPE_PKTEND	0xdc
     87 #define BCSP_SLIP_ESCAPE_ESCAPE	0xdd
     88 
     89 
     90 /* definitions of Sequencing Layer */
     91 #define BCSP_SEQ_TX_TIMEOUT	(hz / 4)	/* 250 msec */
     92 #define BCSP_SEQ_TX_WINSIZE	4
     93 #define BCSP_SEQ_TX_RETRY_LIMIT	20
     94 
     95 
     96 /*
     97  * Reference to bcore-sp-007p.
     98  *   Channel Allocation
     99  */
    100 #define BCSP_CHANNEL_LE		1	/* defined in [BCSPLE] */
    101 #define BCSP_CHANNEL_BCCMD	2	/* defined in [BCCMD] */
    102 #define BCSP_CHANNEL_HQ		3	/* defined in [HQ] */
    103 #define BCSP_CHANNEL_DEVMGT	4	/* defined by BlueStack */
    104 #define BCSP_CHANNEL_HCI_CMDEVT	5	/* HCI Command and Event */
    105 #define BCSP_CHANNEL_HCI_ACL	6	/* HCI ACL data */
    106 #define BCSP_CHANNEL_HCI_SCO	7	/* HCI SCO data */
    107 #define BCSP_CHANNEL_L2CAP	8	/* defined by BlueStack */
    108 #define BCSP_CHANNEL_RFCOMM	9	/* defined by BlueStack */
    109 #define BCSP_CHANNEL_SDP	10	/* defined by BlueStack */
    110 
    111 #define BCSP_CHANNEL_DFU	12	/* defined in [DFUPROT] */
    112 #define BCSP_CHANNEL_VM		13	/* Virtual Machine */
    113 
    114 
    115 /*
    116  * Reference to bcore-sp-008p ??
    117  *   Link Establishment Protocol
    118  */
    119 typedef enum {
    120 	le_state_shy,
    121 	le_state_curious,
    122 	le_state_garrulous
    123 } bcsp_le_state_t;
    124 
    125 #define BCSP_LE_SYNC		{ 0xda, 0xdc, 0xed, 0xed }
    126 #define BCSP_LE_SYNCRESP	{ 0xac, 0xaf, 0xef, 0xee }
    127 #define BCSP_LE_CONF		{ 0xad, 0xef, 0xac, 0xed }
    128 #define BCSP_LE_CONFRESP	{ 0xde, 0xad, 0xd0, 0xd0 }
    129 
    130 #define BCSP_LE_TSHY_TIMEOUT	hz	/* XXXX: 1sec ? */
    131 #define BCSP_LE_TCONF_TIMEOUT	hz	/* XXXX: 1sec ? */
    132 
    133 #endif	/* !_DEV_BLUETOOTH_BCSP_H_ */
    134