bnep.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. BNEP protocol definition for Linux Bluetooth stack (BlueZ).
  3. Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License, version 2, as
  6. published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef _BNEP_H
  15. #define _BNEP_H
  16. #include <linux/types.h>
  17. #include <linux/crc32.h>
  18. #include <net/bluetooth/bluetooth.h>
  19. /* Limits */
  20. #define BNEP_MAX_PROTO_FILTERS 5
  21. #define BNEP_MAX_MULTICAST_FILTERS 20
  22. /* UUIDs */
  23. #define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB
  24. #define BNEP_UUID16 0x02
  25. #define BNEP_UUID32 0x04
  26. #define BNEP_UUID128 0x16
  27. #define BNEP_SVC_PANU 0x1115
  28. #define BNEP_SVC_NAP 0x1116
  29. #define BNEP_SVC_GN 0x1117
  30. /* Packet types */
  31. #define BNEP_GENERAL 0x00
  32. #define BNEP_CONTROL 0x01
  33. #define BNEP_COMPRESSED 0x02
  34. #define BNEP_COMPRESSED_SRC_ONLY 0x03
  35. #define BNEP_COMPRESSED_DST_ONLY 0x04
  36. /* Control types */
  37. #define BNEP_CMD_NOT_UNDERSTOOD 0x00
  38. #define BNEP_SETUP_CONN_REQ 0x01
  39. #define BNEP_SETUP_CONN_RSP 0x02
  40. #define BNEP_FILTER_NET_TYPE_SET 0x03
  41. #define BNEP_FILTER_NET_TYPE_RSP 0x04
  42. #define BNEP_FILTER_MULTI_ADDR_SET 0x05
  43. #define BNEP_FILTER_MULTI_ADDR_RSP 0x06
  44. /* Extension types */
  45. #define BNEP_EXT_CONTROL 0x00
  46. /* Response messages */
  47. #define BNEP_SUCCESS 0x00
  48. #define BNEP_CONN_INVALID_DST 0x01
  49. #define BNEP_CONN_INVALID_SRC 0x02
  50. #define BNEP_CONN_INVALID_SVC 0x03
  51. #define BNEP_CONN_NOT_ALLOWED 0x04
  52. #define BNEP_FILTER_UNSUPPORTED_REQ 0x01
  53. #define BNEP_FILTER_INVALID_RANGE 0x02
  54. #define BNEP_FILTER_INVALID_MCADDR 0x02
  55. #define BNEP_FILTER_LIMIT_REACHED 0x03
  56. #define BNEP_FILTER_DENIED_SECURITY 0x04
  57. /* L2CAP settings */
  58. #define BNEP_MTU 1691
  59. #define BNEP_PSM 0x0f
  60. #define BNEP_FLUSH_TO 0xffff
  61. #define BNEP_CONNECT_TO 15
  62. #define BNEP_FILTER_TO 15
  63. /* Headers */
  64. #define BNEP_TYPE_MASK 0x7f
  65. #define BNEP_EXT_HEADER 0x80
  66. struct bnep_setup_conn_req {
  67. __u8 type;
  68. __u8 ctrl;
  69. __u8 uuid_size;
  70. __u8 service[0];
  71. } __packed;
  72. struct bnep_set_filter_req {
  73. __u8 type;
  74. __u8 ctrl;
  75. __be16 len;
  76. __u8 list[0];
  77. } __packed;
  78. struct bnep_control_rsp {
  79. __u8 type;
  80. __u8 ctrl;
  81. __be16 resp;
  82. } __packed;
  83. struct bnep_ext_hdr {
  84. __u8 type;
  85. __u8 len;
  86. __u8 data[0];
  87. } __packed;
  88. /* BNEP ioctl defines */
  89. #define BNEPCONNADD _IOW('B', 200, int)
  90. #define BNEPCONNDEL _IOW('B', 201, int)
  91. #define BNEPGETCONNLIST _IOR('B', 210, int)
  92. #define BNEPGETCONNINFO _IOR('B', 211, int)
  93. #define BNEPGETSUPPFEAT _IOR('B', 212, int)
  94. #define BNEP_SETUP_RESPONSE 0
  95. #define BNEP_SETUP_RSP_SENT 10
  96. struct bnep_connadd_req {
  97. int sock; /* Connected socket */
  98. __u32 flags;
  99. __u16 role;
  100. char device[16]; /* Name of the Ethernet device */
  101. };
  102. struct bnep_conndel_req {
  103. __u32 flags;
  104. __u8 dst[ETH_ALEN];
  105. };
  106. struct bnep_conninfo {
  107. __u32 flags;
  108. __u16 role;
  109. __u16 state;
  110. __u8 dst[ETH_ALEN];
  111. char device[16];
  112. };
  113. struct bnep_connlist_req {
  114. __u32 cnum;
  115. struct bnep_conninfo __user *ci;
  116. };
  117. struct bnep_proto_filter {
  118. __u16 start;
  119. __u16 end;
  120. };
  121. int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock);
  122. int bnep_del_connection(struct bnep_conndel_req *req);
  123. int bnep_get_connlist(struct bnep_connlist_req *req);
  124. int bnep_get_conninfo(struct bnep_conninfo *ci);
  125. /* BNEP sessions */
  126. struct bnep_session {
  127. struct list_head list;
  128. unsigned int role;
  129. unsigned long state;
  130. unsigned long flags;
  131. atomic_t terminate;
  132. struct task_struct *task;
  133. struct ethhdr eh;
  134. struct msghdr msg;
  135. struct bnep_proto_filter proto_filter[BNEP_MAX_PROTO_FILTERS];
  136. unsigned long long mc_filter;
  137. struct socket *sock;
  138. struct net_device *dev;
  139. };
  140. void bnep_net_setup(struct net_device *dev);
  141. int bnep_sock_init(void);
  142. void bnep_sock_cleanup(void);
  143. static inline int bnep_mc_hash(__u8 *addr)
  144. {
  145. return crc32_be(~0, addr, ETH_ALEN) >> 26;
  146. }
  147. #endif