blob: 92e093e61f2707daecdb2aa80f2acf4406a76bcc [file] [log] [blame]
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +09001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 HIDP implementation for Linux Bluetooth stack (BlueZ).
3 Copyright (C) 2003-2004 Marcel Holtmann <marcel@holtmann.org>
4
5 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 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
10 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
12 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +090013 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +090018 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
19 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 SOFTWARE IS DISCLAIMED.
21*/
22
23#ifndef __HIDP_H
24#define __HIDP_H
25
26#include <linux/types.h>
27#include <net/bluetooth/bluetooth.h>
28
29/* HIDP header masks */
30#define HIDP_HEADER_TRANS_MASK 0xf0
31#define HIDP_HEADER_PARAM_MASK 0x0f
32
33/* HIDP transaction types */
34#define HIDP_TRANS_HANDSHAKE 0x00
35#define HIDP_TRANS_HID_CONTROL 0x10
36#define HIDP_TRANS_GET_REPORT 0x40
37#define HIDP_TRANS_SET_REPORT 0x50
38#define HIDP_TRANS_GET_PROTOCOL 0x60
39#define HIDP_TRANS_SET_PROTOCOL 0x70
40#define HIDP_TRANS_GET_IDLE 0x80
41#define HIDP_TRANS_SET_IDLE 0x90
42#define HIDP_TRANS_DATA 0xa0
43#define HIDP_TRANS_DATC 0xb0
44
45/* HIDP handshake results */
46#define HIDP_HSHK_SUCCESSFUL 0x00
47#define HIDP_HSHK_NOT_READY 0x01
48#define HIDP_HSHK_ERR_INVALID_REPORT_ID 0x02
49#define HIDP_HSHK_ERR_UNSUPPORTED_REQUEST 0x03
50#define HIDP_HSHK_ERR_INVALID_PARAMETER 0x04
51#define HIDP_HSHK_ERR_UNKNOWN 0x0e
52#define HIDP_HSHK_ERR_FATAL 0x0f
53
54/* HIDP control operation parameters */
55#define HIDP_CTRL_NOP 0x00
56#define HIDP_CTRL_HARD_RESET 0x01
57#define HIDP_CTRL_SOFT_RESET 0x02
58#define HIDP_CTRL_SUSPEND 0x03
59#define HIDP_CTRL_EXIT_SUSPEND 0x04
60#define HIDP_CTRL_VIRTUAL_CABLE_UNPLUG 0x05
61
62/* HIDP data transaction headers */
63#define HIDP_DATA_RTYPE_MASK 0x03
64#define HIDP_DATA_RSRVD_MASK 0x0c
65#define HIDP_DATA_RTYPE_OTHER 0x00
66#define HIDP_DATA_RTYPE_INPUT 0x01
67#define HIDP_DATA_RTYPE_OUPUT 0x02
68#define HIDP_DATA_RTYPE_FEATURE 0x03
69
70/* HIDP protocol header parameters */
71#define HIDP_PROTO_BOOT 0x00
72#define HIDP_PROTO_REPORT 0x01
73
74/* HIDP ioctl defines */
75#define HIDPCONNADD _IOW('H', 200, int)
76#define HIDPCONNDEL _IOW('H', 201, int)
77#define HIDPGETCONNLIST _IOR('H', 210, int)
78#define HIDPGETCONNINFO _IOR('H', 211, int)
79
80#define HIDP_VIRTUAL_CABLE_UNPLUG 0
81#define HIDP_BOOT_PROTOCOL_MODE 1
82#define HIDP_BLUETOOTH_VENDOR_ID 9
Alan Ott08254112011-01-18 03:04:38 -050083#define HIDP_WAITING_FOR_SEND_ACK 11
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85struct hidp_connadd_req {
86 int ctrl_sock; // Connected control socket
87 int intr_sock; // Connteted interrupt socket
88 __u16 parser;
89 __u16 rd_size;
Al Viro55e74742007-02-09 16:38:00 +000090 __u8 __user *rd_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 __u8 country;
92 __u8 subclass;
93 __u16 vendor;
94 __u16 product;
95 __u16 version;
96 __u32 flags;
97 __u32 idle_to;
98 char name[128];
99};
100
101struct hidp_conndel_req {
102 bdaddr_t bdaddr;
103 __u32 flags;
104};
105
106struct hidp_conninfo {
107 bdaddr_t bdaddr;
108 __u32 flags;
109 __u16 state;
110 __u16 vendor;
111 __u16 product;
112 __u16 version;
113 char name[128];
114};
115
116struct hidp_connlist_req {
117 __u32 cnum;
118 struct hidp_conninfo __user *ci;
119};
120
121int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock);
122int hidp_del_connection(struct hidp_conndel_req *req);
123int hidp_get_connlist(struct hidp_connlist_req *req);
124int hidp_get_conninfo(struct hidp_conninfo *ci);
125
126/* HIDP session defines */
127struct hidp_session {
128 struct list_head list;
129
Marcel Holtmannedad6382009-08-22 14:22:15 -0700130 struct hci_conn *conn;
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 struct socket *ctrl_sock;
133 struct socket *intr_sock;
134
135 bdaddr_t bdaddr;
136
137 unsigned long state;
138 unsigned long flags;
139 unsigned long idle_to;
140
141 uint ctrl_mtu;
142 uint intr_mtu;
143
144 atomic_t terminate;
145
146 unsigned char keys[8];
147 unsigned char leds;
148
149 struct input_dev *input;
150
Marcel Holtmanne1aaadd2007-02-17 23:58:49 +0100151 struct hid_device *hid;
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct timer_list timer;
154
155 struct sk_buff_head ctrl_transmit;
156 struct sk_buff_head intr_transmit;
Jiri Slabyc500c972008-05-16 11:49:16 +0200157
Alan Ott08254112011-01-18 03:04:38 -0500158 /* Used in hidp_output_raw_report() */
159 int output_report_success; /* boolean */
160
Michael Poole15c697c2010-02-05 12:23:43 -0500161 /* Report descriptor */
162 __u8 *rd_data;
163 uint rd_size;
Alan Ott0f69dca2011-01-18 03:04:37 -0500164
165 wait_queue_head_t startup_queue;
166 int waiting_for_startup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167};
168
169static inline void hidp_schedule(struct hidp_session *session)
170{
171 struct sock *ctrl_sk = session->ctrl_sock->sk;
172 struct sock *intr_sk = session->intr_sock->sk;
173
Eric Dumazetaa395142010-04-20 13:03:51 +0000174 wake_up_interruptible(sk_sleep(ctrl_sk));
175 wake_up_interruptible(sk_sleep(intr_sk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
178/* HIDP init defines */
179extern int __init hidp_init_sockets(void);
180extern void __exit hidp_cleanup_sockets(void);
181
182#endif /* __HIDP_H */