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