blob: e7ee5314f39a1e6a611dd3f0bd59c10c012ae699 [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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#ifndef _BNEP_H
20#define _BNEP_H
21
22#include <linux/types.h>
23#include <linux/crc32.h>
24#include <net/bluetooth/bluetooth.h>
25
Szymon Janc3aad75a2011-03-21 14:19:58 +010026/* Limits */
27#define BNEP_MAX_PROTO_FILTERS 5
28#define BNEP_MAX_MULTICAST_FILTERS 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Szymon Janc3aad75a2011-03-21 14:19:58 +010030/* UUIDs */
31#define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB
32#define BNEP_UUID16 0x02
33#define BNEP_UUID32 0x04
34#define BNEP_UUID128 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Szymon Janc3aad75a2011-03-21 14:19:58 +010036#define BNEP_SVC_PANU 0x1115
37#define BNEP_SVC_NAP 0x1116
38#define BNEP_SVC_GN 0x1117
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Szymon Janc3aad75a2011-03-21 14:19:58 +010040/* Packet types */
41#define BNEP_GENERAL 0x00
42#define BNEP_CONTROL 0x01
43#define BNEP_COMPRESSED 0x02
44#define BNEP_COMPRESSED_SRC_ONLY 0x03
45#define BNEP_COMPRESSED_DST_ONLY 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Szymon Janc3aad75a2011-03-21 14:19:58 +010047/* Control types */
48#define BNEP_CMD_NOT_UNDERSTOOD 0x00
49#define BNEP_SETUP_CONN_REQ 0x01
50#define BNEP_SETUP_CONN_RSP 0x02
51#define BNEP_FILTER_NET_TYPE_SET 0x03
52#define BNEP_FILTER_NET_TYPE_RSP 0x04
53#define BNEP_FILTER_MULTI_ADDR_SET 0x05
54#define BNEP_FILTER_MULTI_ADDR_RSP 0x06
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Szymon Janc3aad75a2011-03-21 14:19:58 +010056/* Extension types */
57#define BNEP_EXT_CONTROL 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Szymon Janc3aad75a2011-03-21 14:19:58 +010059/* Response messages */
60#define BNEP_SUCCESS 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Szymon Janc3aad75a2011-03-21 14:19:58 +010062#define BNEP_CONN_INVALID_DST 0x01
63#define BNEP_CONN_INVALID_SRC 0x02
64#define BNEP_CONN_INVALID_SVC 0x03
65#define BNEP_CONN_NOT_ALLOWED 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Szymon Janc3aad75a2011-03-21 14:19:58 +010067#define BNEP_FILTER_UNSUPPORTED_REQ 0x01
68#define BNEP_FILTER_INVALID_RANGE 0x02
69#define BNEP_FILTER_INVALID_MCADDR 0x02
70#define BNEP_FILTER_LIMIT_REACHED 0x03
71#define BNEP_FILTER_DENIED_SECURITY 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Szymon Janc3aad75a2011-03-21 14:19:58 +010073/* L2CAP settings */
74#define BNEP_MTU 1691
75#define BNEP_PSM 0x0f
76#define BNEP_FLUSH_TO 0xffff
77#define BNEP_CONNECT_TO 15
78#define BNEP_FILTER_TO 15
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Szymon Janc3aad75a2011-03-21 14:19:58 +010080/* Headers */
81#define BNEP_TYPE_MASK 0x7f
82#define BNEP_EXT_HEADER 0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84struct bnep_setup_conn_req {
Szymon Janc3aad75a2011-03-21 14:19:58 +010085 __u8 type;
86 __u8 ctrl;
87 __u8 uuid_size;
88 __u8 service[0];
Eric Dumazetbc105022010-06-03 03:21:52 -070089} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91struct bnep_set_filter_req {
Szymon Janc3aad75a2011-03-21 14:19:58 +010092 __u8 type;
93 __u8 ctrl;
Al Viro1bc5d442006-11-08 00:27:57 -080094 __be16 len;
Szymon Janc3aad75a2011-03-21 14:19:58 +010095 __u8 list[0];
Eric Dumazetbc105022010-06-03 03:21:52 -070096} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98struct bnep_control_rsp {
Szymon Janc3aad75a2011-03-21 14:19:58 +010099 __u8 type;
100 __u8 ctrl;
Al Viro1bc5d442006-11-08 00:27:57 -0800101 __be16 resp;
Eric Dumazetbc105022010-06-03 03:21:52 -0700102} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104struct bnep_ext_hdr {
Szymon Janc3aad75a2011-03-21 14:19:58 +0100105 __u8 type;
106 __u8 len;
107 __u8 data[0];
Eric Dumazetbc105022010-06-03 03:21:52 -0700108} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110/* BNEP ioctl defines */
111#define BNEPCONNADD _IOW('B', 200, int)
112#define BNEPCONNDEL _IOW('B', 201, int)
113#define BNEPGETCONNLIST _IOR('B', 210, int)
114#define BNEPGETCONNINFO _IOR('B', 211, int)
115
116struct bnep_connadd_req {
Szymon Janc3aad75a2011-03-21 14:19:58 +0100117 int sock; /* Connected socket */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 __u32 flags;
119 __u16 role;
Szymon Janc3aad75a2011-03-21 14:19:58 +0100120 char device[16]; /* Name of the Ethernet device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
123struct bnep_conndel_req {
124 __u32 flags;
125 __u8 dst[ETH_ALEN];
126};
127
128struct bnep_conninfo {
129 __u32 flags;
130 __u16 role;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900131 __u16 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 __u8 dst[ETH_ALEN];
133 char device[16];
134};
135
136struct bnep_connlist_req {
137 __u32 cnum;
138 struct bnep_conninfo __user *ci;
139};
140
141struct bnep_proto_filter {
142 __u16 start;
143 __u16 end;
144};
145
146int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock);
147int bnep_del_connection(struct bnep_conndel_req *req);
148int bnep_get_connlist(struct bnep_connlist_req *req);
149int bnep_get_conninfo(struct bnep_conninfo *ci);
150
Szymon Janc3aad75a2011-03-21 14:19:58 +0100151/* BNEP sessions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152struct bnep_session {
153 struct list_head list;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 unsigned int role;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900156 unsigned long state;
157 unsigned long flags;
Peter Hurley751c10a2011-08-05 10:41:35 -0400158 atomic_t terminate;
Szymon Jancf4d7cd42011-03-21 14:20:00 +0100159 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 struct ethhdr eh;
162 struct msghdr msg;
163
164 struct bnep_proto_filter proto_filter[BNEP_MAX_PROTO_FILTERS];
Marcel Holtmanna418b892008-11-30 12:17:28 +0100165 unsigned long long mc_filter;
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +0900166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 struct socket *sock;
168 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169};
170
171void bnep_net_setup(struct net_device *dev);
172int bnep_sock_init(void);
Tobias Klausera4e2acf2008-03-05 18:47:40 -0800173void bnep_sock_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175static inline int bnep_mc_hash(__u8 *addr)
176{
Szymon Janc3aad75a2011-03-21 14:19:58 +0100177 return crc32_be(~0, addr, ETH_ALEN) >> 26;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
180#endif