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 56*8c1b2355SMarcel Holtmann #define BT_SECURITY 4 57*8c1b2355SMarcel Holtmann struct bt_security { 58*8c1b2355SMarcel Holtmann __u8 level; 59*8c1b2355SMarcel Holtmann }; 60*8c1b2355SMarcel Holtmann #define BT_SECURITY_SDP 0 61*8c1b2355SMarcel Holtmann #define BT_SECURITY_LOW 1 62*8c1b2355SMarcel Holtmann #define BT_SECURITY_MEDIUM 2 63*8c1b2355SMarcel Holtmann #define BT_SECURITY_HIGH 3 64*8c1b2355SMarcel Holtmann 65c4f912e1SMarcel Holtmann #define BT_DEFER_SETUP 7 66c4f912e1SMarcel Holtmann 671da177e4SLinus Torvalds #define BT_INFO(fmt, arg...) printk(KERN_INFO "Bluetooth: " fmt "\n" , ## arg) 68d5c003b4SHarvey Harrison #define BT_ERR(fmt, arg...) printk(KERN_ERR "%s: " fmt "\n" , __func__ , ## arg) 69a418b893SMarcel Holtmann #define BT_DBG(fmt, arg...) pr_debug("%s: " fmt "\n" , __func__ , ## arg) 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* Connection and socket states */ 721da177e4SLinus Torvalds enum { 731da177e4SLinus Torvalds BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 741da177e4SLinus Torvalds BT_OPEN, 751da177e4SLinus Torvalds BT_BOUND, 761da177e4SLinus Torvalds BT_LISTEN, 771da177e4SLinus Torvalds BT_CONNECT, 781da177e4SLinus Torvalds BT_CONNECT2, 791da177e4SLinus Torvalds BT_CONFIG, 801da177e4SLinus Torvalds BT_DISCONN, 811da177e4SLinus Torvalds BT_CLOSED 821da177e4SLinus Torvalds }; 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds /* Endianness conversions */ 851da177e4SLinus Torvalds #define htobs(a) __cpu_to_le16(a) 861da177e4SLinus Torvalds #define htobl(a) __cpu_to_le32(a) 871da177e4SLinus Torvalds #define btohs(a) __le16_to_cpu(a) 881da177e4SLinus Torvalds #define btohl(a) __le32_to_cpu(a) 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds /* BD Address */ 911da177e4SLinus Torvalds typedef struct { 921da177e4SLinus Torvalds __u8 b[6]; 931da177e4SLinus Torvalds } __attribute__((packed)) bdaddr_t; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 961da177e4SLinus Torvalds #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds /* Copy, swap, convert BD Address */ 991da177e4SLinus Torvalds static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2) 1001da177e4SLinus Torvalds { 1011da177e4SLinus Torvalds return memcmp(ba1, ba2, sizeof(bdaddr_t)); 1021da177e4SLinus Torvalds } 1031da177e4SLinus Torvalds static inline void bacpy(bdaddr_t *dst, bdaddr_t *src) 1041da177e4SLinus Torvalds { 1051da177e4SLinus Torvalds memcpy(dst, src, sizeof(bdaddr_t)); 1061da177e4SLinus Torvalds } 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds void baswap(bdaddr_t *dst, bdaddr_t *src); 1091da177e4SLinus Torvalds char *batostr(bdaddr_t *ba); 1101da177e4SLinus Torvalds bdaddr_t *strtoba(char *str); 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds /* Common socket structures and functions */ 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds #define bt_sk(__sk) ((struct bt_sock *) __sk) 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds struct bt_sock { 1171da177e4SLinus Torvalds struct sock sk; 1181da177e4SLinus Torvalds bdaddr_t src; 1191da177e4SLinus Torvalds bdaddr_t dst; 1201da177e4SLinus Torvalds struct list_head accept_q; 1211da177e4SLinus Torvalds struct sock *parent; 122c4f912e1SMarcel Holtmann u32 defer_setup; 1231da177e4SLinus Torvalds }; 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds struct bt_sock_list { 1261da177e4SLinus Torvalds struct hlist_head head; 1271da177e4SLinus Torvalds rwlock_t lock; 1281da177e4SLinus Torvalds }; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds int bt_sock_register(int proto, struct net_proto_family *ops); 1311da177e4SLinus Torvalds int bt_sock_unregister(int proto); 1321da177e4SLinus Torvalds void bt_sock_link(struct bt_sock_list *l, struct sock *s); 1331da177e4SLinus Torvalds void bt_sock_unlink(struct bt_sock_list *l, struct sock *s); 1341da177e4SLinus Torvalds int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len, int flags); 1351da177e4SLinus Torvalds uint bt_sock_poll(struct file * file, struct socket *sock, poll_table *wait); 1363241ad82SMarcel Holtmann int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 1371da177e4SLinus Torvalds int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds void bt_accept_enqueue(struct sock *parent, struct sock *sk); 1401da177e4SLinus Torvalds void bt_accept_unlink(struct sock *sk); 1411da177e4SLinus Torvalds struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock); 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds /* Skb helpers */ 1441da177e4SLinus Torvalds struct bt_skb_cb { 1450d48d939SMarcel Holtmann __u8 pkt_type; 1460d48d939SMarcel Holtmann __u8 incoming; 1471da177e4SLinus Torvalds }; 1481da177e4SLinus Torvalds #define bt_cb(skb) ((struct bt_skb_cb *)(skb->cb)) 1491da177e4SLinus Torvalds 150dd0fc66fSAl Viro static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how) 1511da177e4SLinus Torvalds { 1521da177e4SLinus Torvalds struct sk_buff *skb; 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds if ((skb = alloc_skb(len + BT_SKB_RESERVE, how))) { 1551da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 1561da177e4SLinus Torvalds bt_cb(skb)->incoming = 0; 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds return skb; 1591da177e4SLinus Torvalds } 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk, unsigned long len, 1621da177e4SLinus Torvalds int nb, int *err) 1631da177e4SLinus Torvalds { 1641da177e4SLinus Torvalds struct sk_buff *skb; 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds if ((skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err))) { 1671da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 1681da177e4SLinus Torvalds bt_cb(skb)->incoming = 0; 1691da177e4SLinus Torvalds } 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds return skb; 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds static inline int skb_frags_no(struct sk_buff *skb) 1751da177e4SLinus Torvalds { 1761da177e4SLinus Torvalds register struct sk_buff *frag = skb_shinfo(skb)->frag_list; 1771da177e4SLinus Torvalds register int n = 1; 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds for (; frag; frag=frag->next, n++); 1801da177e4SLinus Torvalds return n; 1811da177e4SLinus Torvalds } 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds int bt_err(__u16 code); 1841da177e4SLinus Torvalds 1856516455dSMarcel Holtmann extern int hci_sock_init(void); 18604005dd9STobias Klauser extern void hci_sock_cleanup(void); 1876516455dSMarcel Holtmann 1886516455dSMarcel Holtmann extern int bt_sysfs_init(void); 1896516455dSMarcel Holtmann extern void bt_sysfs_cleanup(void); 1906516455dSMarcel Holtmann 191a91f2e39SMarcel Holtmann extern struct class *bt_class; 192be9d1227SMarcel Holtmann 1931da177e4SLinus Torvalds #endif /* __BLUETOOTH_H */ 194