bluetooth.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. BlueZ - Bluetooth protocol stack for Linux
  3. Copyright (C) 2000-2001 Qualcomm Incorporated
  4. Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License version 2 as
  7. published by the Free Software Foundation;
  8. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  10. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  11. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  12. CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  13. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
  17. COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
  18. SOFTWARE IS DISCLAIMED.
  19. */
  20. #ifndef __BLUETOOTH_H
  21. #define __BLUETOOTH_H
  22. #include <asm/types.h>
  23. #include <asm/byteorder.h>
  24. #include <linux/list.h>
  25. #include <linux/poll.h>
  26. #include <net/sock.h>
  27. #ifndef AF_BLUETOOTH
  28. #define AF_BLUETOOTH 31
  29. #define PF_BLUETOOTH AF_BLUETOOTH
  30. #endif
  31. /* Reserv for core and drivers use */
  32. #define BT_SKB_RESERVE 8
  33. #define BTPROTO_L2CAP 0
  34. #define BTPROTO_HCI 1
  35. #define BTPROTO_SCO 2
  36. #define BTPROTO_RFCOMM 3
  37. #define BTPROTO_BNEP 4
  38. #define BTPROTO_CMTP 5
  39. #define BTPROTO_HIDP 6
  40. #define BTPROTO_AVDTP 7
  41. #define SOL_HCI 0
  42. #define SOL_L2CAP 6
  43. #define SOL_SCO 17
  44. #define SOL_RFCOMM 18
  45. #define BT_SECURITY 4
  46. struct bt_security {
  47. __u8 level;
  48. __u8 key_size;
  49. };
  50. #define BT_SECURITY_SDP 0
  51. #define BT_SECURITY_LOW 1
  52. #define BT_SECURITY_MEDIUM 2
  53. #define BT_SECURITY_HIGH 3
  54. #define BT_DEFER_SETUP 7
  55. #define BT_FLUSHABLE 8
  56. #define BT_FLUSHABLE_OFF 0
  57. #define BT_FLUSHABLE_ON 1
  58. #define BT_POWER 9
  59. struct bt_power {
  60. __u8 force_active;
  61. };
  62. #define BT_POWER_FORCE_ACTIVE_OFF 0
  63. #define BT_POWER_FORCE_ACTIVE_ON 1
  64. __attribute__((format (printf, 2, 3)))
  65. int bt_printk(const char *level, const char *fmt, ...);
  66. #define BT_INFO(fmt, arg...) bt_printk(KERN_INFO, pr_fmt(fmt), ##arg)
  67. #define BT_ERR(fmt, arg...) bt_printk(KERN_ERR, pr_fmt(fmt), ##arg)
  68. #define BT_DBG(fmt, arg...) pr_debug(fmt "\n", ##arg)
  69. /* Connection and socket states */
  70. enum {
  71. BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
  72. BT_OPEN,
  73. BT_BOUND,
  74. BT_LISTEN,
  75. BT_CONNECT,
  76. BT_CONNECT2,
  77. BT_CONFIG,
  78. BT_DISCONN,
  79. BT_CLOSED
  80. };
  81. /* BD Address */
  82. typedef struct {
  83. __u8 b[6];
  84. } __packed bdaddr_t;
  85. #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
  86. #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
  87. /* Copy, swap, convert BD Address */
  88. static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2)
  89. {
  90. return memcmp(ba1, ba2, sizeof(bdaddr_t));
  91. }
  92. static inline void bacpy(bdaddr_t *dst, bdaddr_t *src)
  93. {
  94. memcpy(dst, src, sizeof(bdaddr_t));
  95. }
  96. void baswap(bdaddr_t *dst, bdaddr_t *src);
  97. char *batostr(bdaddr_t *ba);
  98. bdaddr_t *strtoba(char *str);
  99. /* Common socket structures and functions */
  100. #define bt_sk(__sk) ((struct bt_sock *) __sk)
  101. struct bt_sock {
  102. struct sock sk;
  103. bdaddr_t src;
  104. bdaddr_t dst;
  105. struct list_head accept_q;
  106. struct sock *parent;
  107. u32 defer_setup;
  108. };
  109. struct bt_sock_list {
  110. struct hlist_head head;
  111. rwlock_t lock;
  112. };
  113. int bt_sock_register(int proto, const struct net_proto_family *ops);
  114. int bt_sock_unregister(int proto);
  115. void bt_sock_link(struct bt_sock_list *l, struct sock *s);
  116. void bt_sock_unlink(struct bt_sock_list *l, struct sock *s);
  117. int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
  118. struct msghdr *msg, size_t len, int flags);
  119. int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
  120. struct msghdr *msg, size_t len, int flags);
  121. uint bt_sock_poll(struct file * file, struct socket *sock, poll_table *wait);
  122. int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
  123. int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
  124. void bt_accept_enqueue(struct sock *parent, struct sock *sk);
  125. void bt_accept_unlink(struct sock *sk);
  126. struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock);
  127. /* Skb helpers */
  128. struct bt_skb_cb {
  129. __u8 pkt_type;
  130. __u8 incoming;
  131. __u16 expect;
  132. __u8 tx_seq;
  133. __u8 retries;
  134. __u8 sar;
  135. unsigned short channel;
  136. __u8 force_active;
  137. };
  138. #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
  139. static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
  140. {
  141. struct sk_buff *skb;
  142. if ((skb = alloc_skb(len + BT_SKB_RESERVE, how))) {
  143. skb_reserve(skb, BT_SKB_RESERVE);
  144. bt_cb(skb)->incoming = 0;
  145. }
  146. return skb;
  147. }
  148. static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
  149. unsigned long len, int nb, int *err)
  150. {
  151. struct sk_buff *skb;
  152. release_sock(sk);
  153. if ((skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err))) {
  154. skb_reserve(skb, BT_SKB_RESERVE);
  155. bt_cb(skb)->incoming = 0;
  156. }
  157. lock_sock(sk);
  158. if (!skb && *err)
  159. return NULL;
  160. *err = sock_error(sk);
  161. if (*err)
  162. goto out;
  163. if (sk->sk_shutdown) {
  164. *err = -ECONNRESET;
  165. goto out;
  166. }
  167. return skb;
  168. out:
  169. kfree_skb(skb);
  170. return NULL;
  171. }
  172. int bt_to_errno(__u16 code);
  173. extern int hci_sock_init(void);
  174. extern void hci_sock_cleanup(void);
  175. extern int bt_sysfs_init(void);
  176. extern void bt_sysfs_cleanup(void);
  177. extern struct dentry *bt_debugfs;
  178. #ifdef CONFIG_BT_L2CAP
  179. int l2cap_init(void);
  180. void l2cap_exit(void);
  181. #else
  182. static inline int l2cap_init(void)
  183. {
  184. return 0;
  185. }
  186. static inline void l2cap_exit(void)
  187. {
  188. }
  189. #endif
  190. #ifdef CONFIG_BT_SCO
  191. int sco_init(void);
  192. void sco_exit(void);
  193. #else
  194. static inline int sco_init(void)
  195. {
  196. return 0;
  197. }
  198. static inline void sco_exit(void)
  199. {
  200. }
  201. #endif
  202. #endif /* __BLUETOOTH_H */