xref: /netbsd-src/sys/netbt/bluetooth.h (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: bluetooth.h,v 1.8 2008/09/08 23:36:55 gmcgarry Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005 Iain Hibbert.
5  * Copyright (c) 2006 Itronix Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of Itronix Inc. may not be used to endorse
17  *    or promote products derived from this software without specific
18  *    prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _NETBT_BLUETOOTH_H_
34 #define _NETBT_BLUETOOTH_H_
35 
36 #include <sys/socket.h>
37 #include <sys/types.h>
38 
39 /*
40  * Bluetooth Address Family Protocol Numbers
41  */
42 #define BTPROTO_HCI	1
43 #define BTPROTO_L2CAP	2
44 #define BTPROTO_RFCOMM	3
45 #define BTPROTO_SCO	4
46 
47 /* All sizes are in bytes */
48 #define BLUETOOTH_BDADDR_SIZE	6
49 
50 /*
51  * Bluetooth device address
52  */
53 typedef struct {
54 	uint8_t	b[BLUETOOTH_BDADDR_SIZE];
55 } __packed bdaddr_t;
56 
57 /*
58  * bdaddr utility functions
59  */
60 static __inline int
61 bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
62 {
63 
64 	return (a->b[0] == b->b[0] && a->b[1] == b->b[1]
65 		&& a->b[2] == b->b[2] && a->b[3] == b->b[3]
66 		&& a->b[4] == b->b[4] && a->b[5] == b->b[5]);
67 }
68 
69 static __inline int
70 bdaddr_any(const bdaddr_t *a)
71 {
72 
73 	return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0
74 		&& a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
75 }
76 
77 static __inline void
78 bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
79 {
80 
81 	d->b[0] = s->b[0];
82 	d->b[1] = s->b[1];
83 	d->b[2] = s->b[2];
84 	d->b[3] = s->b[3];
85 	d->b[4] = s->b[4];
86 	d->b[5] = s->b[5];
87 }
88 
89 /*
90  * Socket address used by Bluetooth protocols
91  */
92 struct sockaddr_bt {
93 	uint8_t		bt_len;
94 	sa_family_t	bt_family;
95 	bdaddr_t	bt_bdaddr;
96 	uint16_t	bt_psm;
97 	uint8_t		bt_channel;
98 	uint8_t		bt_zero[5];
99 };
100 
101 /* Note: this is actually 6 bytes including terminator */
102 #define BDADDR_ANY	((const bdaddr_t *) "\000\000\000\000\000")
103 
104 #ifdef _KERNEL
105 
106 MALLOC_DECLARE(M_BLUETOOTH);
107 
108 /*
109  * Bluetooth Protocol API callback methods
110  */
111 struct mbuf;
112 struct btproto {
113 	void (*connecting)(void *);
114 	void (*connected)(void *);
115 	void (*disconnected)(void *, int);
116 	void *(*newconn)(void *, struct sockaddr_bt *, struct sockaddr_bt *);
117 	void (*complete)(void *, int);
118 	void (*linkmode)(void *, int);
119 	void (*input)(void *, struct mbuf *);
120 };
121 
122 /*
123  * Debugging stuff
124  */
125 #include "opt_bluetooth.h"
126 
127 #ifdef BLUETOOTH_DEBUG
128 extern int bluetooth_debug;
129 # define DPRINTF(fmt, args...)	do {			\
130 	if (bluetooth_debug)				\
131 		printf("%s: "fmt, __func__ , ##args);	\
132 } while (/* CONSTCOND */0)
133 
134 # define DPRINTFN(n, fmt, args...)	do {		\
135 	if (bluetooth_debug > (n))			\
136 		printf("%s: "fmt, __func__ , ##args);	\
137 } while (/* CONSTCOND */0)
138 
139 # define UNKNOWN(value)			\
140 		printf("%s: %s = %d unknown!\n", __func__, #value, (value));
141 #else
142 # define DPRINTF(...) ((void)0)
143 # define DPRINTFN(...) ((void)0)
144 # define UNKNOWN(x) ((void)0)
145 #endif	/* BLUETOOTH_DEBUG */
146 
147 extern kmutex_t *bt_lock;
148 
149 #endif	/* _KERNEL */
150 
151 #endif	/* _NETBT_BLUETOOTH_H_ */
152