bnep.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. BNEP protocol definition for Linux Bluetooth stack (BlueZ).
  4. Copyright (C) 2002 Maxim Krasnyansky <[email protected]>
  5. */
  6. #ifndef _BNEP_H
  7. #define _BNEP_H
  8. #include <linux/types.h>
  9. #include <linux/crc32.h>
  10. #include <net/bluetooth/bluetooth.h>
  11. /* Limits */
  12. #define BNEP_MAX_PROTO_FILTERS 5
  13. #define BNEP_MAX_MULTICAST_FILTERS 20
  14. /* UUIDs */
  15. #define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB
  16. #define BNEP_UUID16 0x02
  17. #define BNEP_UUID32 0x04
  18. #define BNEP_UUID128 0x16
  19. #define BNEP_SVC_PANU 0x1115
  20. #define BNEP_SVC_NAP 0x1116
  21. #define BNEP_SVC_GN 0x1117
  22. /* Packet types */
  23. #define BNEP_GENERAL 0x00
  24. #define BNEP_CONTROL 0x01
  25. #define BNEP_COMPRESSED 0x02
  26. #define BNEP_COMPRESSED_SRC_ONLY 0x03
  27. #define BNEP_COMPRESSED_DST_ONLY 0x04
  28. /* Control types */
  29. #define BNEP_CMD_NOT_UNDERSTOOD 0x00
  30. #define BNEP_SETUP_CONN_REQ 0x01
  31. #define BNEP_SETUP_CONN_RSP 0x02
  32. #define BNEP_FILTER_NET_TYPE_SET 0x03
  33. #define BNEP_FILTER_NET_TYPE_RSP 0x04
  34. #define BNEP_FILTER_MULTI_ADDR_SET 0x05
  35. #define BNEP_FILTER_MULTI_ADDR_RSP 0x06
  36. /* Extension types */
  37. #define BNEP_EXT_CONTROL 0x00
  38. /* Response messages */
  39. #define BNEP_SUCCESS 0x00
  40. #define BNEP_CONN_INVALID_DST 0x01
  41. #define BNEP_CONN_INVALID_SRC 0x02
  42. #define BNEP_CONN_INVALID_SVC 0x03
  43. #define BNEP_CONN_NOT_ALLOWED 0x04
  44. #define BNEP_FILTER_UNSUPPORTED_REQ 0x01
  45. #define BNEP_FILTER_INVALID_RANGE 0x02
  46. #define BNEP_FILTER_INVALID_MCADDR 0x02
  47. #define BNEP_FILTER_LIMIT_REACHED 0x03
  48. #define BNEP_FILTER_DENIED_SECURITY 0x04
  49. /* L2CAP settings */
  50. #define BNEP_MTU 1691
  51. #define BNEP_PSM 0x0f
  52. #define BNEP_FLUSH_TO 0xffff
  53. #define BNEP_CONNECT_TO 15
  54. #define BNEP_FILTER_TO 15
  55. /* Headers */
  56. #define BNEP_TYPE_MASK 0x7f
  57. #define BNEP_EXT_HEADER 0x80
  58. struct bnep_setup_conn_req {
  59. __u8 type;
  60. __u8 ctrl;
  61. __u8 uuid_size;
  62. __u8 service[];
  63. } __packed;
  64. struct bnep_set_filter_req {
  65. __u8 type;
  66. __u8 ctrl;
  67. __be16 len;
  68. __u8 list[];
  69. } __packed;
  70. struct bnep_control_rsp {
  71. __u8 type;
  72. __u8 ctrl;
  73. __be16 resp;
  74. } __packed;
  75. struct bnep_ext_hdr {
  76. __u8 type;
  77. __u8 len;
  78. __u8 data[];
  79. } __packed;
  80. /* BNEP ioctl defines */
  81. #define BNEPCONNADD _IOW('B', 200, int)
  82. #define BNEPCONNDEL _IOW('B', 201, int)
  83. #define BNEPGETCONNLIST _IOR('B', 210, int)
  84. #define BNEPGETCONNINFO _IOR('B', 211, int)
  85. #define BNEPGETSUPPFEAT _IOR('B', 212, int)
  86. #define BNEP_SETUP_RESPONSE 0
  87. #define BNEP_SETUP_RSP_SENT 10
  88. struct bnep_connadd_req {
  89. int sock; /* Connected socket */
  90. __u32 flags;
  91. __u16 role;
  92. char device[16]; /* Name of the Ethernet device */
  93. };
  94. struct bnep_conndel_req {
  95. __u32 flags;
  96. __u8 dst[ETH_ALEN];
  97. };
  98. struct bnep_conninfo {
  99. __u32 flags;
  100. __u16 role;
  101. __u16 state;
  102. __u8 dst[ETH_ALEN];
  103. char device[16];
  104. };
  105. struct bnep_connlist_req {
  106. __u32 cnum;
  107. struct bnep_conninfo __user *ci;
  108. };
  109. struct bnep_proto_filter {
  110. __u16 start;
  111. __u16 end;
  112. };
  113. int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock);
  114. int bnep_del_connection(struct bnep_conndel_req *req);
  115. int bnep_get_connlist(struct bnep_connlist_req *req);
  116. int bnep_get_conninfo(struct bnep_conninfo *ci);
  117. /* BNEP sessions */
  118. struct bnep_session {
  119. struct list_head list;
  120. unsigned int role;
  121. unsigned long state;
  122. unsigned long flags;
  123. atomic_t terminate;
  124. struct task_struct *task;
  125. struct ethhdr eh;
  126. struct msghdr msg;
  127. struct bnep_proto_filter proto_filter[BNEP_MAX_PROTO_FILTERS];
  128. unsigned long long mc_filter;
  129. struct socket *sock;
  130. struct net_device *dev;
  131. };
  132. void bnep_net_setup(struct net_device *dev);
  133. int bnep_sock_init(void);
  134. void bnep_sock_cleanup(void);
  135. static inline int bnep_mc_hash(__u8 *addr)
  136. {
  137. return crc32_be(~0, addr, ETH_ALEN) >> 26;
  138. }
  139. #endif