blob: 40854c99bc1ecff42e8943ac506b77155ebc4fe1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 BNEP protocol definition for Linux Bluetooth stack (BlueZ).
3 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +09004
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
Jeff Kirsherc057b192013-12-06 09:13:44 -080015 along with this program; if not, see <http://www.gnu.org/licenses/>.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016*/
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#ifndef _BNEP_H
19#define _BNEP_H
20
21#include <linux/types.h>
22#include <linux/crc32.h>
23#include <net/bluetooth/bluetooth.h>
24
Szymon Janc3aad75a2011-03-21 14:19:58 +010025/* Limits */
26#define BNEP_MAX_PROTO_FILTERS 5
27#define BNEP_MAX_MULTICAST_FILTERS 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Szymon Janc3aad75a2011-03-21 14:19:58 +010029/* UUIDs */
30#define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB
31#define BNEP_UUID16 0x02
32#define BNEP_UUID32 0x04
33#define BNEP_UUID128 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Szymon Janc3aad75a2011-03-21 14:19:58 +010035#define BNEP_SVC_PANU 0x1115
36#define BNEP_SVC_NAP 0x1116
37#define BNEP_SVC_GN 0x1117
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Szymon Janc3aad75a2011-03-21 14:19:58 +010039/* Packet types */
40#define BNEP_GENERAL 0x00
41#define BNEP_CONTROL 0x01
42#define BNEP_COMPRESSED 0x02
43#define BNEP_COMPRESSED_SRC_ONLY 0x03
44#define BNEP_COMPRESSED_DST_ONLY 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Szymon Janc3aad75a2011-03-21 14:19:58 +010046/* Control types */
47#define BNEP_CMD_NOT_UNDERSTOOD 0x00
48#define BNEP_SETUP_CONN_REQ 0x01
49#define BNEP_SETUP_CONN_RSP 0x02
50#define BNEP_FILTER_NET_TYPE_SET 0x03
51#define BNEP_FILTER_NET_TYPE_RSP 0x04
52#define BNEP_FILTER_MULTI_ADDR_SET 0x05
53#define BNEP_FILTER_MULTI_ADDR_RSP 0x06
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Szymon Janc3aad75a2011-03-21 14:19:58 +010055/* Extension types */
56#define BNEP_EXT_CONTROL 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Szymon Janc3aad75a2011-03-21 14:19:58 +010058/* Response messages */
59#define BNEP_SUCCESS 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Szymon Janc3aad75a2011-03-21 14:19:58 +010061#define BNEP_CONN_INVALID_DST 0x01
62#define BNEP_CONN_INVALID_SRC 0x02
63#define BNEP_CONN_INVALID_SVC 0x03
64#define BNEP_CONN_NOT_ALLOWED 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Szymon Janc3aad75a2011-03-21 14:19:58 +010066#define BNEP_FILTER_UNSUPPORTED_REQ 0x01
67#define BNEP_FILTER_INVALID_RANGE 0x02
68#define BNEP_FILTER_INVALID_MCADDR 0x02
69#define BNEP_FILTER_LIMIT_REACHED 0x03
70#define BNEP_FILTER_DENIED_SECURITY 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Szymon Janc3aad75a2011-03-21 14:19:58 +010072/* L2CAP settings */
73#define BNEP_MTU 1691
74#define BNEP_PSM 0x0f
75#define BNEP_FLUSH_TO 0xffff
76#define BNEP_CONNECT_TO 15
77#define BNEP_FILTER_TO 15
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Szymon Janc3aad75a2011-03-21 14:19:58 +010079/* Headers */
80#define BNEP_TYPE_MASK 0x7f
81#define BNEP_EXT_HEADER 0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83struct bnep_setup_conn_req {
Szymon Janc3aad75a2011-03-21 14:19:58 +010084 __u8 type;
85 __u8 ctrl;
86 __u8 uuid_size;
87 __u8 service[0];
Eric Dumazetbc105022010-06-03 03:21:52 -070088} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90struct bnep_set_filter_req {
Szymon Janc3aad75a2011-03-21 14:19:58 +010091 __u8 type;
92 __u8 ctrl;
Al Viro1bc5d442006-11-08 00:27:57 -080093 __be16 len;
Szymon Janc3aad75a2011-03-21 14:19:58 +010094 __u8 list[0];
Eric Dumazetbc105022010-06-03 03:21:52 -070095} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97struct bnep_control_rsp {
Szymon Janc3aad75a2011-03-21 14:19:58 +010098 __u8 type;
99 __u8 ctrl;
Al Viro1bc5d442006-11-08 00:27:57 -0800100 __be16 resp;
Eric Dumazetbc105022010-06-03 03:21:52 -0700101} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103struct bnep_ext_hdr {
Szymon Janc3aad75a2011-03-21 14:19:58 +0100104 __u8 type;
105 __u8 len;
106 __u8 data[0];
Eric Dumazetbc105022010-06-03 03:21:52 -0700107} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109/* BNEP ioctl defines */
110#define BNEPCONNADD _IOW('B', 200, int)
111#define BNEPCONNDEL _IOW('B', 201, int)
112#define BNEPGETCONNLIST _IOR('B', 210, int)
113#define BNEPGETCONNINFO _IOR('B', 211, int)
Grzegorz Kolodziejczyk0477e2e2015-04-03 12:14:53 +0200114#define BNEPGETSUPPFEAT _IOR('B', 212, int)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Grzegorz Kolodziejczyk836a0612015-04-03 12:14:55 +0200116#define BNEP_SETUP_RESPONSE 0
117#define BNEP_SETUP_RSP_SENT 10
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119struct bnep_connadd_req {
Szymon Janc3aad75a2011-03-21 14:19:58 +0100120 int sock; /* Connected socket */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 __u32 flags;
122 __u16 role;
Szymon Janc3aad75a2011-03-21 14:19:58 +0100123 char device[16]; /* Name of the Ethernet device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124};
125
126struct bnep_conndel_req {
127 __u32 flags;
128 __u8 dst[ETH_ALEN];
129};
130
131struct bnep_conninfo {
132 __u32 flags;
133 __u16 role;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900134 __u16 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 __u8 dst[ETH_ALEN];
136 char device[16];
137};
138
139struct bnep_connlist_req {
140 __u32 cnum;
141 struct bnep_conninfo __user *ci;
142};
143
144struct bnep_proto_filter {
145 __u16 start;
146 __u16 end;
147};
148
149int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock);
150int bnep_del_connection(struct bnep_conndel_req *req);
151int bnep_get_connlist(struct bnep_connlist_req *req);
152int bnep_get_conninfo(struct bnep_conninfo *ci);
153
Szymon Janc3aad75a2011-03-21 14:19:58 +0100154/* BNEP sessions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155struct bnep_session {
156 struct list_head list;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 unsigned int role;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900159 unsigned long state;
160 unsigned long flags;
Peter Hurley751c10a2011-08-05 10:41:35 -0400161 atomic_t terminate;
Szymon Jancf4d7cd42011-03-21 14:20:00 +0100162 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 struct ethhdr eh;
165 struct msghdr msg;
166
167 struct bnep_proto_filter proto_filter[BNEP_MAX_PROTO_FILTERS];
Marcel Holtmanna418b892008-11-30 12:17:28 +0100168 unsigned long long mc_filter;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct socket *sock;
171 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
174void bnep_net_setup(struct net_device *dev);
175int bnep_sock_init(void);
Tobias Klausera4e2acf2008-03-05 18:47:40 -0800176void bnep_sock_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178static inline int bnep_mc_hash(__u8 *addr)
179{
Szymon Janc3aad75a2011-03-21 14:19:58 +0100180 return crc32_be(~0, addr, ETH_ALEN) >> 26;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
183#endif