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 721da177e4SLinus Torvalds #define BT_INFO(fmt, arg...) printk(KERN_INFO "Bluetooth: " fmt "\n" , ## arg) 73d5c003b4SHarvey Harrison #define BT_ERR(fmt, arg...) printk(KERN_ERR "%s: " fmt "\n" , __func__ , ## arg) 74a418b893SMarcel Holtmann #define BT_DBG(fmt, arg...) pr_debug("%s: " fmt "\n" , __func__ , ## arg) 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds /* Connection and socket states */ 771da177e4SLinus Torvalds enum { 781da177e4SLinus Torvalds BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 791da177e4SLinus Torvalds BT_OPEN, 801da177e4SLinus Torvalds BT_BOUND, 811da177e4SLinus Torvalds BT_LISTEN, 821da177e4SLinus Torvalds BT_CONNECT, 831da177e4SLinus Torvalds BT_CONNECT2, 841da177e4SLinus Torvalds BT_CONFIG, 851da177e4SLinus Torvalds BT_DISCONN, 861da177e4SLinus Torvalds BT_CLOSED 871da177e4SLinus Torvalds }; 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds /* BD Address */ 901da177e4SLinus Torvalds typedef struct { 911da177e4SLinus Torvalds __u8 b[6]; 9266c853ccSGustavo F. Padovan } __packed bdaddr_t; 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 951da177e4SLinus Torvalds #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds /* Copy, swap, convert BD Address */ 981da177e4SLinus Torvalds static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2) 991da177e4SLinus Torvalds { 1001da177e4SLinus Torvalds return memcmp(ba1, ba2, sizeof(bdaddr_t)); 1011da177e4SLinus Torvalds } 1021da177e4SLinus Torvalds static inline void bacpy(bdaddr_t *dst, bdaddr_t *src) 1031da177e4SLinus Torvalds { 1041da177e4SLinus Torvalds memcpy(dst, src, sizeof(bdaddr_t)); 1051da177e4SLinus Torvalds } 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds void baswap(bdaddr_t *dst, bdaddr_t *src); 1081da177e4SLinus Torvalds char *batostr(bdaddr_t *ba); 1091da177e4SLinus Torvalds bdaddr_t *strtoba(char *str); 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* Common socket structures and functions */ 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds #define bt_sk(__sk) ((struct bt_sock *) __sk) 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds struct bt_sock { 1161da177e4SLinus Torvalds struct sock sk; 1171da177e4SLinus Torvalds bdaddr_t src; 1181da177e4SLinus Torvalds bdaddr_t dst; 1191da177e4SLinus Torvalds struct list_head accept_q; 1201da177e4SLinus Torvalds struct sock *parent; 121c4f912e1SMarcel Holtmann u32 defer_setup; 1221da177e4SLinus Torvalds }; 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds struct bt_sock_list { 1251da177e4SLinus Torvalds struct hlist_head head; 1261da177e4SLinus Torvalds rwlock_t lock; 1271da177e4SLinus Torvalds }; 1281da177e4SLinus Torvalds 129ec1b4cf7SStephen Hemminger int bt_sock_register(int proto, const struct net_proto_family *ops); 1301da177e4SLinus Torvalds int bt_sock_unregister(int proto); 1311da177e4SLinus Torvalds void bt_sock_link(struct bt_sock_list *l, struct sock *s); 1321da177e4SLinus Torvalds void bt_sock_unlink(struct bt_sock_list *l, struct sock *s); 1331da177e4SLinus Torvalds int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len, int flags); 134796c86eeSMat Martineau int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock, 135796c86eeSMat Martineau struct msghdr *msg, size_t len, int flags); 1361da177e4SLinus Torvalds uint bt_sock_poll(struct file * file, struct socket *sock, poll_table *wait); 1373241ad82SMarcel Holtmann int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 1381da177e4SLinus Torvalds int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds void bt_accept_enqueue(struct sock *parent, struct sock *sk); 1411da177e4SLinus Torvalds void bt_accept_unlink(struct sock *sk); 1421da177e4SLinus Torvalds struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock); 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds /* Skb helpers */ 1451da177e4SLinus Torvalds struct bt_skb_cb { 1460d48d939SMarcel Holtmann __u8 pkt_type; 1470d48d939SMarcel Holtmann __u8 incoming; 14833e882a5SSuraj Sumangala __u16 expect; 1491c2acffbSGustavo F. Padovan __u8 tx_seq; 150e90bac06SGustavo F. Padovan __u8 retries; 1518f17154fSGustavo F. Padovan __u8 sar; 152a40c406cSJohan Hedberg unsigned short channel; 1531da177e4SLinus Torvalds }; 1541c2acffbSGustavo F. Padovan #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb)) 1551da177e4SLinus Torvalds 156dd0fc66fSAl Viro static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how) 1571da177e4SLinus Torvalds { 1581da177e4SLinus Torvalds struct sk_buff *skb; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds if ((skb = alloc_skb(len + BT_SKB_RESERVE, how))) { 1611da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 1621da177e4SLinus Torvalds bt_cb(skb)->incoming = 0; 1631da177e4SLinus Torvalds } 1641da177e4SLinus Torvalds return skb; 1651da177e4SLinus Torvalds } 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk, unsigned long len, 1681da177e4SLinus Torvalds int nb, int *err) 1691da177e4SLinus Torvalds { 1701da177e4SLinus Torvalds struct sk_buff *skb; 1711da177e4SLinus Torvalds 172e454c844SGustavo F. Padovan release_sock(sk); 1731da177e4SLinus Torvalds if ((skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err))) { 1741da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 1751da177e4SLinus Torvalds bt_cb(skb)->incoming = 0; 1761da177e4SLinus Torvalds } 177e454c844SGustavo F. Padovan lock_sock(sk); 178e454c844SGustavo F. Padovan 179e454c844SGustavo F. Padovan if (!skb && *err) 180e454c844SGustavo F. Padovan return NULL; 181e454c844SGustavo F. Padovan 182e454c844SGustavo F. Padovan *err = sock_error(sk); 183e454c844SGustavo F. Padovan if (*err) 184e454c844SGustavo F. Padovan goto out; 185e454c844SGustavo F. Padovan 186e454c844SGustavo F. Padovan if (sk->sk_shutdown) { 187e454c844SGustavo F. Padovan *err = -ECONNRESET; 188e454c844SGustavo F. Padovan goto out; 189e454c844SGustavo F. Padovan } 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds return skb; 192e454c844SGustavo F. Padovan 193e454c844SGustavo F. Padovan out: 194e454c844SGustavo F. Padovan kfree_skb(skb); 195e454c844SGustavo F. Padovan return NULL; 1961da177e4SLinus Torvalds } 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds int bt_err(__u16 code); 1991da177e4SLinus Torvalds 2006516455dSMarcel Holtmann extern int hci_sock_init(void); 20104005dd9STobias Klauser extern void hci_sock_cleanup(void); 2026516455dSMarcel Holtmann 2036516455dSMarcel Holtmann extern int bt_sysfs_init(void); 2046516455dSMarcel Holtmann extern void bt_sysfs_cleanup(void); 2056516455dSMarcel Holtmann 206aef7d97cSMarcel Holtmann extern struct dentry *bt_debugfs; 207be9d1227SMarcel Holtmann 208*64274518SGustavo F. Padovan #ifdef CONFIG_BT_L2CAP 209*64274518SGustavo F. Padovan int l2cap_init(void); 210*64274518SGustavo F. Padovan void l2cap_exit(void); 211*64274518SGustavo F. Padovan #else 212*64274518SGustavo F. Padovan static inline int l2cap_init(void) 213*64274518SGustavo F. Padovan { 214*64274518SGustavo F. Padovan return 0; 215*64274518SGustavo F. Padovan } 216*64274518SGustavo F. Padovan 217*64274518SGustavo F. Padovan static inline void l2cap_exit(void) 218*64274518SGustavo F. Padovan { 219*64274518SGustavo F. Padovan } 220*64274518SGustavo F. Padovan #endif 221*64274518SGustavo F. Padovan 222*64274518SGustavo F. Padovan #ifdef CONFIG_BT_SCO 223*64274518SGustavo F. Padovan int sco_init(void); 224*64274518SGustavo F. Padovan void sco_exit(void); 225*64274518SGustavo F. Padovan #else 226*64274518SGustavo F. Padovan static inline int sco_init(void) 227*64274518SGustavo F. Padovan { 228*64274518SGustavo F. Padovan return 0; 229*64274518SGustavo F. Padovan } 230*64274518SGustavo F. Padovan 231*64274518SGustavo F. Padovan static inline void sco_exit(void) 232*64274518SGustavo F. Padovan { 233*64274518SGustavo F. Padovan } 234*64274518SGustavo F. Padovan #endif 235*64274518SGustavo F. Padovan 2361da177e4SLinus Torvalds #endif /* __BLUETOOTH_H */ 237