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