File: /usr/src/linux/include/net/bluetooth/bluez.h
1 /*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23 */
24
25 /*
26 * $Id: bluez.h,v 1.4 2001/08/03 04:19:49 maxk Exp $
27 */
28
29 #ifndef __IF_BLUEZ_H
30 #define __IF_BLUEZ_H
31
32 #include <net/sock.h>
33
34 #define BLUEZ_MAX_PROTO 2
35
36 /* Reserv for core and drivers use */
37 #define BLUEZ_SKB_RESERVE 8
38
39 #ifndef MIN
40 #define MIN(a,b) ((a) < (b) ? (a) : (b))
41 #endif
42
43 /* Debugging */
44 #ifdef BLUEZ_DEBUG
45
46 #define HCI_CORE_DEBUG 1
47 #define HCI_SOCK_DEBUG 1
48 #define HCI_UART_DEBUG 1
49 #define HCI_USB_DEBUG 1
50 //#define HCI_DATA_DUMP 1
51
52 #define L2CAP_DEBUG 1
53
54 #endif /* BLUEZ_DEBUG */
55
56 extern void bluez_dump(char *pref, __u8 *buf, int count);
57
58 #define INF(fmt, arg...) printk(KERN_INFO fmt "\n" , ## arg)
59 #define DBG(fmt, arg...) printk(KERN_INFO __FUNCTION__ ": " fmt "\n" , ## arg)
60 #define ERR(fmt, arg...) printk(KERN_ERR __FUNCTION__ ": " fmt "\n" , ## arg)
61
62 #ifdef HCI_DATA_DUMP
63 #define DMP(buf, len) bluez_dump(__FUNCTION__, buf, len)
64 #else
65 #define DMP(D...)
66 #endif
67
68 /* ----- Sockets ------ */
69 struct bluez_sock_list {
70 struct sock *head;
71 rwlock_t lock;
72 };
73
74 extern int bluez_sock_register(int proto, struct net_proto_family *ops);
75 extern int bluez_sock_unregister(int proto);
76
77 extern void bluez_sock_link(struct bluez_sock_list *l, struct sock *s);
78 extern void bluez_sock_unlink(struct bluez_sock_list *l, struct sock *s);
79
80 /* ----- SKB helpers ----- */
81 struct bluez_skb_cb {
82 int incomming;
83 };
84 #define bluez_cb(skb) ((struct bluez_skb_cb *)(skb->cb))
85
86 static inline struct sk_buff *bluez_skb_alloc(unsigned int len, int how)
87 {
88 struct sk_buff *skb;
89
90 if ((skb = alloc_skb(len + BLUEZ_SKB_RESERVE, how))) {
91 skb_reserve(skb, BLUEZ_SKB_RESERVE);
92 bluez_cb(skb)->incomming = 0;
93 }
94 return skb;
95 }
96
97 static inline struct sk_buff *bluez_skb_send_alloc(struct sock *sk, unsigned long len,
98 int nb, int *err)
99 {
100 struct sk_buff *skb;
101
102 if ((skb = sock_alloc_send_skb(sk, len + BLUEZ_SKB_RESERVE, nb, err))) {
103 skb_reserve(skb, BLUEZ_SKB_RESERVE);
104 bluez_cb(skb)->incomming = 0;
105 }
106
107 return skb;
108 }
109
110 static inline int skb_frags_no(struct sk_buff *skb)
111 {
112 register struct sk_buff *frag = skb_shinfo(skb)->frag_list;
113 register int n = 1;
114
115 for (; frag; frag=frag->next, n++);
116 return n;
117 }
118
119 extern int hci_core_init(void);
120 extern int hci_core_cleanup(void);
121 extern int hci_sock_init(void);
122 extern int hci_sock_cleanup(void);
123
124 #endif /* __IF_BLUEZ_H */
125