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