11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds BlueZ - Bluetooth protocol stack for Linux 31da177e4SLinus Torvalds Copyright (C) 2000-2001 Qualcomm Incorporated 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds This program is free software; you can redistribute it and/or modify 81da177e4SLinus Torvalds it under the terms of the GNU General Public License version 2 as 91da177e4SLinus Torvalds published by the Free Software Foundation; 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 121da177e4SLinus Torvalds OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 131da177e4SLinus Torvalds FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 141da177e4SLinus Torvalds IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 151da177e4SLinus Torvalds CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 161da177e4SLinus Torvalds WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 171da177e4SLinus Torvalds ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 181da177e4SLinus Torvalds OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 211da177e4SLinus Torvalds COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 221da177e4SLinus Torvalds SOFTWARE IS DISCLAIMED. 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #ifndef __BLUETOOTH_H 261da177e4SLinus Torvalds #define __BLUETOOTH_H 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds #include <asm/types.h> 291da177e4SLinus Torvalds #include <asm/byteorder.h> 301da177e4SLinus Torvalds #include <linux/list.h> 311da177e4SLinus Torvalds #include <linux/poll.h> 321da177e4SLinus Torvalds #include <net/sock.h> 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds #ifndef AF_BLUETOOTH 351da177e4SLinus Torvalds #define AF_BLUETOOTH 31 361da177e4SLinus Torvalds #define PF_BLUETOOTH AF_BLUETOOTH 371da177e4SLinus Torvalds #endif 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds /* Reserv for core and drivers use */ 401da177e4SLinus Torvalds #define BT_SKB_RESERVE 8 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #define BTPROTO_L2CAP 0 431da177e4SLinus Torvalds #define BTPROTO_HCI 1 441da177e4SLinus Torvalds #define BTPROTO_SCO 2 451da177e4SLinus Torvalds #define BTPROTO_RFCOMM 3 461da177e4SLinus Torvalds #define BTPROTO_BNEP 4 471da177e4SLinus Torvalds #define BTPROTO_CMTP 5 481da177e4SLinus Torvalds #define BTPROTO_HIDP 6 491da177e4SLinus Torvalds #define BTPROTO_AVDTP 7 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds #define SOL_HCI 0 521da177e4SLinus Torvalds #define SOL_L2CAP 6 531da177e4SLinus Torvalds #define SOL_SCO 17 541da177e4SLinus Torvalds #define SOL_RFCOMM 18 551da177e4SLinus Torvalds 568c1b2355SMarcel Holtmann #define BT_SECURITY 4 578c1b2355SMarcel Holtmann struct bt_security { 588c1b2355SMarcel Holtmann __u8 level; 598c1b2355SMarcel Holtmann }; 608c1b2355SMarcel Holtmann #define BT_SECURITY_SDP 0 618c1b2355SMarcel Holtmann #define BT_SECURITY_LOW 1 628c1b2355SMarcel Holtmann #define BT_SECURITY_MEDIUM 2 638c1b2355SMarcel Holtmann #define BT_SECURITY_HIGH 3 648c1b2355SMarcel Holtmann 65c4f912e1SMarcel Holtmann #define BT_DEFER_SETUP 7 66c4f912e1SMarcel Holtmann 67e702112fSAndrei Emeltchenko #define BT_FLUSHABLE 8 68e702112fSAndrei Emeltchenko 69e702112fSAndrei Emeltchenko #define BT_FLUSHABLE_OFF 0 70e702112fSAndrei Emeltchenko #define BT_FLUSHABLE_ON 1 71e702112fSAndrei Emeltchenko 7214b12d0bSJaikumar Ganesh #define BT_POWER 9 7314b12d0bSJaikumar Ganesh struct bt_power { 7414b12d0bSJaikumar Ganesh __u8 force_active; 7514b12d0bSJaikumar Ganesh }; 7614b12d0bSJaikumar Ganesh #define BT_POWER_FORCE_ACTIVE_OFF 0 7714b12d0bSJaikumar Ganesh #define BT_POWER_FORCE_ACTIVE_ON 1 7814b12d0bSJaikumar Ganesh 791da177e4SLinus Torvalds #define BT_INFO(fmt, arg...) printk(KERN_INFO "Bluetooth: " fmt "\n" , ## arg) 80d5c003b4SHarvey Harrison #define BT_ERR(fmt, arg...) printk(KERN_ERR "%s: " fmt "\n" , __func__ , ## arg) 81a418b893SMarcel Holtmann #define BT_DBG(fmt, arg...) pr_debug("%s: " fmt "\n" , __func__ , ## arg) 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds /* Connection and socket states */ 841da177e4SLinus Torvalds enum { 851da177e4SLinus Torvalds BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 861da177e4SLinus Torvalds BT_OPEN, 871da177e4SLinus Torvalds BT_BOUND, 881da177e4SLinus Torvalds BT_LISTEN, 891da177e4SLinus Torvalds BT_CONNECT, 901da177e4SLinus Torvalds BT_CONNECT2, 911da177e4SLinus Torvalds BT_CONFIG, 921da177e4SLinus Torvalds BT_DISCONN, 931da177e4SLinus Torvalds BT_CLOSED 941da177e4SLinus Torvalds }; 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds /* BD Address */ 971da177e4SLinus Torvalds typedef struct { 981da177e4SLinus Torvalds __u8 b[6]; 9966c853ccSGustavo F. Padovan } __packed bdaddr_t; 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 1021da177e4SLinus Torvalds #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds /* Copy, swap, convert BD Address */ 1051da177e4SLinus Torvalds static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2) 1061da177e4SLinus Torvalds { 1071da177e4SLinus Torvalds return memcmp(ba1, ba2, sizeof(bdaddr_t)); 1081da177e4SLinus Torvalds } 1091da177e4SLinus Torvalds static inline void bacpy(bdaddr_t *dst, bdaddr_t *src) 1101da177e4SLinus Torvalds { 1111da177e4SLinus Torvalds memcpy(dst, src, sizeof(bdaddr_t)); 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds void baswap(bdaddr_t *dst, bdaddr_t *src); 1151da177e4SLinus Torvalds char *batostr(bdaddr_t *ba); 1161da177e4SLinus Torvalds bdaddr_t *strtoba(char *str); 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds /* Common socket structures and functions */ 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds #define bt_sk(__sk) ((struct bt_sock *) __sk) 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds struct bt_sock { 1231da177e4SLinus Torvalds struct sock sk; 1241da177e4SLinus Torvalds bdaddr_t src; 1251da177e4SLinus Torvalds bdaddr_t dst; 1261da177e4SLinus Torvalds struct list_head accept_q; 1271da177e4SLinus Torvalds struct sock *parent; 128c4f912e1SMarcel Holtmann u32 defer_setup; 1291da177e4SLinus Torvalds }; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds struct bt_sock_list { 1321da177e4SLinus Torvalds struct hlist_head head; 1331da177e4SLinus Torvalds rwlock_t lock; 1341da177e4SLinus Torvalds }; 1351da177e4SLinus Torvalds 136ec1b4cf7SStephen Hemminger int bt_sock_register(int proto, const struct net_proto_family *ops); 1371da177e4SLinus Torvalds int bt_sock_unregister(int proto); 1381da177e4SLinus Torvalds void bt_sock_link(struct bt_sock_list *l, struct sock *s); 1391da177e4SLinus Torvalds void bt_sock_unlink(struct bt_sock_list *l, struct sock *s); 140*5a9d0a3fSWaldemar Rymarkiewicz int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock, 141*5a9d0a3fSWaldemar Rymarkiewicz struct msghdr *msg, size_t len, int flags); 142796c86eeSMat Martineau int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock, 143796c86eeSMat Martineau struct msghdr *msg, size_t len, int flags); 1441da177e4SLinus Torvalds uint bt_sock_poll(struct file * file, struct socket *sock, poll_table *wait); 1453241ad82SMarcel Holtmann int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 1461da177e4SLinus Torvalds int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds void bt_accept_enqueue(struct sock *parent, struct sock *sk); 1491da177e4SLinus Torvalds void bt_accept_unlink(struct sock *sk); 1501da177e4SLinus Torvalds struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock); 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds /* Skb helpers */ 1531da177e4SLinus Torvalds struct bt_skb_cb { 1540d48d939SMarcel Holtmann __u8 pkt_type; 1550d48d939SMarcel Holtmann __u8 incoming; 15633e882a5SSuraj Sumangala __u16 expect; 1571c2acffbSGustavo F. Padovan __u8 tx_seq; 158e90bac06SGustavo F. Padovan __u8 retries; 1598f17154fSGustavo F. Padovan __u8 sar; 160a40c406cSJohan Hedberg unsigned short channel; 16114b12d0bSJaikumar Ganesh __u8 force_active; 1621da177e4SLinus Torvalds }; 1631c2acffbSGustavo F. Padovan #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb)) 1641da177e4SLinus Torvalds 165dd0fc66fSAl Viro static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how) 1661da177e4SLinus Torvalds { 1671da177e4SLinus Torvalds struct sk_buff *skb; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds if ((skb = alloc_skb(len + BT_SKB_RESERVE, how))) { 1701da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 1711da177e4SLinus Torvalds bt_cb(skb)->incoming = 0; 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds return skb; 1741da177e4SLinus Torvalds } 1751da177e4SLinus Torvalds 176*5a9d0a3fSWaldemar Rymarkiewicz static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk, 177*5a9d0a3fSWaldemar Rymarkiewicz unsigned long len, int nb, int *err) 1781da177e4SLinus Torvalds { 1791da177e4SLinus Torvalds struct sk_buff *skb; 1801da177e4SLinus Torvalds 181e454c844SGustavo F. Padovan release_sock(sk); 1821da177e4SLinus Torvalds if ((skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err))) { 1831da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 1841da177e4SLinus Torvalds bt_cb(skb)->incoming = 0; 1851da177e4SLinus Torvalds } 186e454c844SGustavo F. Padovan lock_sock(sk); 187e454c844SGustavo F. Padovan 188e454c844SGustavo F. Padovan if (!skb && *err) 189e454c844SGustavo F. Padovan return NULL; 190e454c844SGustavo F. Padovan 191e454c844SGustavo F. Padovan *err = sock_error(sk); 192e454c844SGustavo F. Padovan if (*err) 193e454c844SGustavo F. Padovan goto out; 194e454c844SGustavo F. Padovan 195e454c844SGustavo F. Padovan if (sk->sk_shutdown) { 196e454c844SGustavo F. Padovan *err = -ECONNRESET; 197e454c844SGustavo F. Padovan goto out; 198e454c844SGustavo F. Padovan } 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds return skb; 201e454c844SGustavo F. Padovan 202e454c844SGustavo F. Padovan out: 203e454c844SGustavo F. Padovan kfree_skb(skb); 204e454c844SGustavo F. Padovan return NULL; 2051da177e4SLinus Torvalds } 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds int bt_err(__u16 code); 2081da177e4SLinus Torvalds 2096516455dSMarcel Holtmann extern int hci_sock_init(void); 21004005dd9STobias Klauser extern void hci_sock_cleanup(void); 2116516455dSMarcel Holtmann 2126516455dSMarcel Holtmann extern int bt_sysfs_init(void); 2136516455dSMarcel Holtmann extern void bt_sysfs_cleanup(void); 2146516455dSMarcel Holtmann 215aef7d97cSMarcel Holtmann extern struct dentry *bt_debugfs; 216be9d1227SMarcel Holtmann 21764274518SGustavo F. Padovan #ifdef CONFIG_BT_L2CAP 21864274518SGustavo F. Padovan int l2cap_init(void); 21964274518SGustavo F. Padovan void l2cap_exit(void); 22064274518SGustavo F. Padovan #else 22164274518SGustavo F. Padovan static inline int l2cap_init(void) 22264274518SGustavo F. Padovan { 22364274518SGustavo F. Padovan return 0; 22464274518SGustavo F. Padovan } 22564274518SGustavo F. Padovan 22664274518SGustavo F. Padovan static inline void l2cap_exit(void) 22764274518SGustavo F. Padovan { 22864274518SGustavo F. Padovan } 22964274518SGustavo F. Padovan #endif 23064274518SGustavo F. Padovan 23164274518SGustavo F. Padovan #ifdef CONFIG_BT_SCO 23264274518SGustavo F. Padovan int sco_init(void); 23364274518SGustavo F. Padovan void sco_exit(void); 23464274518SGustavo F. Padovan #else 23564274518SGustavo F. Padovan static inline int sco_init(void) 23664274518SGustavo F. Padovan { 23764274518SGustavo F. Padovan return 0; 23864274518SGustavo F. Padovan } 23964274518SGustavo F. Padovan 24064274518SGustavo F. Padovan static inline void sco_exit(void) 24164274518SGustavo F. Padovan { 24264274518SGustavo F. Padovan } 24364274518SGustavo F. Padovan #endif 24464274518SGustavo F. Padovan 2451da177e4SLinus Torvalds #endif /* __BLUETOOTH_H */ 246