| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |    BlueZ - Bluetooth protocol stack for Linux | 
					
						
							|  |  |  |    Copyright (C) 2000-2001 Qualcomm Incorporated | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |    it under the terms of the GNU General Public License version 2 as | 
					
						
							|  |  |  |    published by the Free Software Foundation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
					
						
							|  |  |  |    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. | 
					
						
							|  |  |  |    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY | 
					
						
							|  |  |  |    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES  | 
					
						
							|  |  |  |    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN  | 
					
						
							|  |  |  |    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  | 
					
						
							|  |  |  |    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,  | 
					
						
							|  |  |  |    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS  | 
					
						
							|  |  |  |    SOFTWARE IS DISCLAIMED. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef __BLUETOOTH_H
 | 
					
						
							|  |  |  | #define __BLUETOOTH_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <asm/types.h>
 | 
					
						
							|  |  |  | #include <asm/byteorder.h>
 | 
					
						
							|  |  |  | #include <linux/list.h>
 | 
					
						
							|  |  |  | #include <linux/poll.h>
 | 
					
						
							|  |  |  | #include <net/sock.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef AF_BLUETOOTH
 | 
					
						
							|  |  |  | #define AF_BLUETOOTH	31
 | 
					
						
							|  |  |  | #define PF_BLUETOOTH	AF_BLUETOOTH
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Reserv for core and drivers use */ | 
					
						
							|  |  |  | #define BT_SKB_RESERVE	8
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BTPROTO_L2CAP	0
 | 
					
						
							|  |  |  | #define BTPROTO_HCI	1
 | 
					
						
							|  |  |  | #define BTPROTO_SCO	2
 | 
					
						
							|  |  |  | #define BTPROTO_RFCOMM	3
 | 
					
						
							|  |  |  | #define BTPROTO_BNEP	4
 | 
					
						
							|  |  |  | #define BTPROTO_CMTP	5
 | 
					
						
							|  |  |  | #define BTPROTO_HIDP	6
 | 
					
						
							|  |  |  | #define BTPROTO_AVDTP	7
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SOL_HCI		0
 | 
					
						
							|  |  |  | #define SOL_L2CAP	6
 | 
					
						
							|  |  |  | #define SOL_SCO		17
 | 
					
						
							|  |  |  | #define SOL_RFCOMM	18
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-15 21:58:04 +01:00
										 |  |  | #define BT_SECURITY	4
 | 
					
						
							|  |  |  | struct bt_security { | 
					
						
							|  |  |  | 	__u8 level; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #define BT_SECURITY_SDP		0
 | 
					
						
							|  |  |  | #define BT_SECURITY_LOW		1
 | 
					
						
							|  |  |  | #define BT_SECURITY_MEDIUM	2
 | 
					
						
							|  |  |  | #define BT_SECURITY_HIGH	3
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-15 21:52:16 +01:00
										 |  |  | #define BT_DEFER_SETUP	7
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-03 11:14:36 +02:00
										 |  |  | #define BT_FLUSHABLE	8
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BT_FLUSHABLE_OFF	0
 | 
					
						
							|  |  |  | #define BT_FLUSHABLE_ON		1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-23 18:06:04 -07:00
										 |  |  | #define BT_POWER	9
 | 
					
						
							|  |  |  | struct bt_power { | 
					
						
							|  |  |  | 	__u8 force_active; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #define BT_POWER_FORCE_ACTIVE_OFF 0
 | 
					
						
							|  |  |  | #define BT_POWER_FORCE_ACTIVE_ON  1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #define BT_INFO(fmt, arg...) printk(KERN_INFO "Bluetooth: " fmt "\n" , ## arg)
 | 
					
						
							| 
									
										
										
										
											2008-11-30 12:17:28 +01:00
										 |  |  | #define BT_ERR(fmt, arg...)  printk(KERN_ERR "%s: " fmt "\n" , __func__ , ## arg)
 | 
					
						
							|  |  |  | #define BT_DBG(fmt, arg...)  pr_debug("%s: " fmt "\n" , __func__ , ## arg)
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Connection and socket states */ | 
					
						
							|  |  |  | enum { | 
					
						
							|  |  |  | 	BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ | 
					
						
							|  |  |  | 	BT_OPEN, | 
					
						
							|  |  |  | 	BT_BOUND, | 
					
						
							|  |  |  | 	BT_LISTEN, | 
					
						
							|  |  |  | 	BT_CONNECT, | 
					
						
							|  |  |  | 	BT_CONNECT2, | 
					
						
							|  |  |  | 	BT_CONFIG, | 
					
						
							|  |  |  | 	BT_DISCONN, | 
					
						
							|  |  |  | 	BT_CLOSED | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* BD Address */ | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	__u8 b[6]; | 
					
						
							| 
									
										
										
										
											2010-07-19 02:00:13 -03:00
										 |  |  | } __packed bdaddr_t; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
 | 
					
						
							|  |  |  | #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Copy, swap, convert BD Address */ | 
					
						
							|  |  |  | static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return memcmp(ba1, ba2, sizeof(bdaddr_t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | static inline void bacpy(bdaddr_t *dst, bdaddr_t *src) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	memcpy(dst, src, sizeof(bdaddr_t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void baswap(bdaddr_t *dst, bdaddr_t *src); | 
					
						
							|  |  |  | char *batostr(bdaddr_t *ba); | 
					
						
							|  |  |  | bdaddr_t *strtoba(char *str); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Common socket structures and functions */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define bt_sk(__sk) ((struct bt_sock *) __sk)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct bt_sock { | 
					
						
							|  |  |  | 	struct sock sk; | 
					
						
							|  |  |  | 	bdaddr_t    src; | 
					
						
							|  |  |  | 	bdaddr_t    dst; | 
					
						
							|  |  |  | 	struct list_head accept_q; | 
					
						
							|  |  |  | 	struct sock *parent; | 
					
						
							| 
									
										
										
										
											2009-01-15 21:52:16 +01:00
										 |  |  | 	u32 defer_setup; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct bt_sock_list { | 
					
						
							|  |  |  | 	struct hlist_head head; | 
					
						
							|  |  |  | 	rwlock_t          lock; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-05 05:58:39 +00:00
										 |  |  | int  bt_sock_register(int proto, const struct net_proto_family *ops); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | int  bt_sock_unregister(int proto); | 
					
						
							|  |  |  | void bt_sock_link(struct bt_sock_list *l, struct sock *s); | 
					
						
							|  |  |  | void bt_sock_unlink(struct bt_sock_list *l, struct sock *s); | 
					
						
							| 
									
										
										
										
											2011-06-07 11:18:06 +02:00
										 |  |  | int  bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock, | 
					
						
							|  |  |  | 				struct msghdr *msg, size_t len, int flags); | 
					
						
							| 
									
										
										
										
											2010-09-08 10:05:27 -07:00
										 |  |  | int  bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock, | 
					
						
							|  |  |  | 			struct msghdr *msg, size_t len, int flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | uint bt_sock_poll(struct file * file, struct socket *sock, poll_table *wait); | 
					
						
							| 
									
										
										
										
											2008-07-14 20:13:50 +02:00
										 |  |  | int  bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | int  bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void bt_accept_enqueue(struct sock *parent, struct sock *sk); | 
					
						
							|  |  |  | void bt_accept_unlink(struct sock *sk); | 
					
						
							|  |  |  | struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Skb helpers */ | 
					
						
							|  |  |  | struct bt_skb_cb { | 
					
						
							| 
									
										
										
										
											2005-08-09 20:30:28 -07:00
										 |  |  | 	__u8 pkt_type; | 
					
						
							|  |  |  | 	__u8 incoming; | 
					
						
							| 
									
										
										
										
											2010-07-14 13:02:17 +05:30
										 |  |  | 	__u16 expect; | 
					
						
							| 
									
										
										
										
											2009-08-20 22:25:57 -03:00
										 |  |  | 	__u8 tx_seq; | 
					
						
							| 
									
										
										
										
											2009-08-20 22:26:00 -03:00
										 |  |  | 	__u8 retries; | 
					
						
							| 
									
										
										
										
											2009-08-20 22:26:03 -03:00
										 |  |  | 	__u8 sar; | 
					
						
							| 
									
										
										
										
											2010-12-08 00:21:07 +02:00
										 |  |  | 	unsigned short channel; | 
					
						
							| 
									
										
										
										
											2011-05-23 18:06:04 -07:00
										 |  |  | 	__u8 force_active; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-20 22:25:57 -03:00
										 |  |  | #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-07 07:46:04 +01:00
										 |  |  | static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((skb = alloc_skb(len + BT_SKB_RESERVE, how))) { | 
					
						
							|  |  |  | 		skb_reserve(skb, BT_SKB_RESERVE); | 
					
						
							|  |  |  | 		bt_cb(skb)->incoming  = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return skb; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-07 11:18:06 +02:00
										 |  |  | static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk, | 
					
						
							|  |  |  | 					unsigned long len, int nb, int *err) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-21 16:31:11 -03:00
										 |  |  | 	release_sock(sk); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if ((skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err))) { | 
					
						
							|  |  |  | 		skb_reserve(skb, BT_SKB_RESERVE); | 
					
						
							|  |  |  | 		bt_cb(skb)->incoming  = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-21 16:31:11 -03:00
										 |  |  | 	lock_sock(sk); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!skb && *err) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*err = sock_error(sk); | 
					
						
							|  |  |  | 	if (*err) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sk->sk_shutdown) { | 
					
						
							|  |  |  | 		*err = -ECONNRESET; | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return skb; | 
					
						
							| 
									
										
										
										
											2010-09-21 16:31:11 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  | 	kfree_skb(skb); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int bt_err(__u16 code); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-28 19:20:48 +02:00
										 |  |  | extern int hci_sock_init(void); | 
					
						
							| 
									
										
										
										
											2008-03-05 18:47:03 -08:00
										 |  |  | extern void hci_sock_cleanup(void); | 
					
						
							| 
									
										
										
										
											2005-10-28 19:20:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | extern int bt_sysfs_init(void); | 
					
						
							|  |  |  | extern void bt_sysfs_cleanup(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-21 05:27:45 +01:00
										 |  |  | extern struct dentry *bt_debugfs; | 
					
						
							| 
									
										
										
										
											2005-11-08 09:57:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-07 20:08:52 -02:00
										 |  |  | #ifdef CONFIG_BT_L2CAP
 | 
					
						
							|  |  |  | int l2cap_init(void); | 
					
						
							|  |  |  | void l2cap_exit(void); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | static inline int l2cap_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void l2cap_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_BT_SCO
 | 
					
						
							|  |  |  | int sco_init(void); | 
					
						
							|  |  |  | void sco_exit(void); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | static inline int sco_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void sco_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif /* __BLUETOOTH_H */
 |