bluetooth.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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. /*
  21.  *  $Id: bluetooth.h,v 1.9 2002/05/06 21:11:55 maxk Exp $
  22.  */
  23. #ifndef __BLUETOOTH_H
  24. #define __BLUETOOTH_H
  25. #include <asm/types.h>
  26. #include <asm/byteorder.h>
  27. #include <linux/poll.h>
  28. #include <net/sock.h>
  29. #ifndef AF_BLUETOOTH
  30. #define AF_BLUETOOTH 31
  31. #define PF_BLUETOOTH AF_BLUETOOTH
  32. #endif
  33. /* Reserv for core and drivers use */
  34. #define BLUEZ_SKB_RESERVE       8
  35. #ifndef MIN
  36. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  37. #endif
  38. #define BTPROTO_L2CAP   0
  39. #define BTPROTO_HCI     1
  40. #define BTPROTO_SCO    2
  41. #define BTPROTO_RFCOMM 3
  42. #define BTPROTO_BNEP 4
  43. #define SOL_HCI     0
  44. #define SOL_L2CAP   6
  45. #define SOL_SCO     17
  46. #define SOL_RFCOMM  18
  47. /* Debugging */
  48. #ifdef CONFIG_BLUEZ_DEBUG
  49. #define HCI_CORE_DEBUG 1
  50. #define HCI_SOCK_DEBUG 1
  51. #define HCI_UART_DEBUG 1
  52. #define HCI_USB_DEBUG 1
  53. //#define HCI_DATA_DUMP 1
  54. #define L2CAP_DEBUG 1
  55. #define SCO_DEBUG 1
  56. #define AF_BLUETOOTH_DEBUG 1
  57. #endif /* CONFIG_BLUEZ_DEBUG */
  58. extern void bluez_dump(char *pref, __u8 *buf, int count);
  59. #if __GNUC__ <= 2 && __GNUC_MINOR__ < 95
  60. #define __func__ __FUNCTION__
  61. #endif
  62. #define BT_INFO(fmt, arg...) printk(KERN_INFO fmt "n" , ## arg)
  63. #define BT_DBG(fmt, arg...)  printk(KERN_INFO "%s: " fmt "n" , __func__ , ## arg)
  64. #define BT_ERR(fmt, arg...)  printk(KERN_ERR  "%s: " fmt "n" , __func__ , ## arg)
  65. #ifdef HCI_DATA_DUMP
  66. #define BT_DMP(buf, len)    bluez_dump(__func__, buf, len)
  67. #else
  68. #define BT_DMP(D...)
  69. #endif
  70. /* Connection and socket states */
  71. enum {
  72. BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
  73. BT_OPEN,
  74. BT_BOUND,
  75. BT_LISTEN,
  76. BT_CONNECT,
  77. BT_CONNECT2,
  78. BT_CONFIG,
  79. BT_DISCONN,
  80. BT_CLOSED
  81. };
  82. /* Endianness conversions */
  83. #define htobs(a) __cpu_to_le16(a)
  84. #define htobl(a) __cpu_to_le32(a)
  85. #define btohs(a) __le16_to_cpu(a)
  86. #define btohl(a) __le32_to_cpu(a)
  87. /* BD Address */
  88. typedef struct {
  89. __u8 b[6];
  90. } __attribute__((packed)) bdaddr_t;
  91. #define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
  92. #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
  93. /* Copy, swap, convert BD Address */
  94. static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2)
  95. {
  96. return memcmp(ba1, ba2, sizeof(bdaddr_t));
  97. }
  98. static inline void bacpy(bdaddr_t *dst, bdaddr_t *src)
  99. {
  100. memcpy(dst, src, sizeof(bdaddr_t));
  101. }
  102. void baswap(bdaddr_t *dst, bdaddr_t *src);
  103. char *batostr(bdaddr_t *ba);
  104. bdaddr_t *strtoba(char *str);
  105. /* Common socket structures and functions */
  106. #define bluez_pi(sk) ((struct bluez_pinfo *) &sk->protinfo)
  107. #define bluez_sk(pi) ((struct sock *) 
  108. ((void *)pi - (unsigned long)(&((struct sock *)0)->protinfo)))
  109. struct bluez_pinfo {
  110. bdaddr_t src;
  111. bdaddr_t dst;
  112. struct list_head accept_q;
  113. struct sock *parent;
  114. };
  115. struct bluez_sock_list {
  116. struct sock *head;
  117. rwlock_t     lock;
  118. };
  119. int  bluez_sock_register(int proto, struct net_proto_family *ops);
  120. int  bluez_sock_unregister(int proto);
  121. void bluez_sock_init(struct socket *sock, struct sock *sk);
  122. void bluez_sock_link(struct bluez_sock_list *l, struct sock *s);
  123. void bluez_sock_unlink(struct bluez_sock_list *l, struct sock *s);
  124. int  bluez_sock_recvmsg(struct socket *sock, struct msghdr *msg, int len, int flags, struct scm_cookie *scm);
  125. uint bluez_sock_poll(struct file * file, struct socket *sock, poll_table *wait);
  126. int  bluez_sock_w4_connect(struct sock *sk, int flags);
  127. void bluez_accept_enqueue(struct sock *parent, struct sock *sk);
  128. struct sock * bluez_accept_dequeue(struct sock *parent, struct socket *newsock);
  129. /* Skb helpers */
  130. struct bluez_skb_cb {
  131. int    incomming;
  132. };
  133. #define bluez_cb(skb) ((struct bluez_skb_cb *)(skb->cb)) 
  134. static inline struct sk_buff *bluez_skb_alloc(unsigned int len, int how)
  135. {
  136. struct sk_buff *skb;
  137. if ((skb = alloc_skb(len + BLUEZ_SKB_RESERVE, how))) {
  138. skb_reserve(skb, BLUEZ_SKB_RESERVE);
  139. bluez_cb(skb)->incomming  = 0;
  140. }
  141. return skb;
  142. }
  143. static inline struct sk_buff *bluez_skb_send_alloc(struct sock *sk, unsigned long len, 
  144.        int nb, int *err)
  145. {
  146. struct sk_buff *skb;
  147. if ((skb = sock_alloc_send_skb(sk, len + BLUEZ_SKB_RESERVE, nb, err))) {
  148. skb_reserve(skb, BLUEZ_SKB_RESERVE);
  149. bluez_cb(skb)->incomming  = 0;
  150. }
  151. return skb;
  152. }
  153. static inline int skb_frags_no(struct sk_buff *skb)
  154. {
  155. register struct sk_buff *frag = skb_shinfo(skb)->frag_list;
  156. register int n = 1;
  157. for (; frag; frag=frag->next, n++);
  158. return n;
  159. }
  160. int hci_core_init(void);
  161. int hci_core_cleanup(void);
  162. int hci_sock_init(void);
  163. int hci_sock_cleanup(void);
  164. int bterr(__u16 code);
  165. #ifndef MODULE_LICENSE
  166. #define MODULE_LICENSE(x)
  167. #endif
  168. #ifndef list_for_each_safe
  169. #define list_for_each_safe(pos, n, head) 
  170. for (pos = (head)->next, n = pos->next; pos != (head); 
  171. pos = n, n = pos->next)
  172. #endif
  173. #endif /* __BLUETOOTH_H */