xref: /linux/net/bluetooth/hidp/hidp.h (revision bea06c7c1b83bcd0519b91141999369eae6925bd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3    HIDP implementation for Linux Bluetooth stack (BlueZ).
4    Copyright (C) 2003-2004 Marcel Holtmann <marcel@holtmann.org>
5 
6    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
7    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
9    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
10    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
11    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 
15    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
16    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
17    SOFTWARE IS DISCLAIMED.
18 */
19 
20 #ifndef __HIDP_H
21 #define __HIDP_H
22 
23 #include <linux/types.h>
24 #include <linux/hid.h>
25 #include <linux/kref.h>
26 #include <net/bluetooth/bluetooth.h>
27 #include <net/bluetooth/l2cap.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
83 #define HIDP_WAITING_FOR_RETURN		10
84 #define HIDP_WAITING_FOR_SEND_ACK	11
85 
86 struct hidp_connadd_req {
87 	int   ctrl_sock;	/* Connected control socket */
88 	int   intr_sock;	/* Connected interrupt socket */
89 	__u16 parser;
90 	__u16 rd_size;
91 	__u8 __user *rd_data;
92 	__u8  country;
93 	__u8  subclass;
94 	__u16 vendor;
95 	__u16 product;
96 	__u16 version;
97 	__u32 flags;
98 	__u32 idle_to;
99 	char  name[128];
100 };
101 
102 struct hidp_conndel_req {
103 	bdaddr_t bdaddr;
104 	__u32    flags;
105 };
106 
107 struct hidp_conninfo {
108 	bdaddr_t bdaddr;
109 	__u32    flags;
110 	__u16    state;
111 	__u16    vendor;
112 	__u16    product;
113 	__u16    version;
114 	char     name[128];
115 };
116 
117 struct hidp_connlist_req {
118 	__u32  cnum;
119 	struct hidp_conninfo __user *ci;
120 };
121 
122 int hidp_connection_add(const struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock);
123 int hidp_connection_del(struct hidp_conndel_req *req);
124 int hidp_get_connlist(struct hidp_connlist_req *req);
125 int hidp_get_conninfo(struct hidp_conninfo *ci);
126 
127 enum hidp_session_state {
128 	HIDP_SESSION_IDLING,
129 	HIDP_SESSION_PREPARING,
130 	HIDP_SESSION_RUNNING,
131 };
132 
133 /* HIDP session defines */
134 struct hidp_session {
135 	struct list_head list;
136 	struct kref ref;
137 
138 	/* runtime management */
139 	atomic_t state;
140 	wait_queue_head_t state_queue;
141 	atomic_t terminate;
142 	struct task_struct *task;
143 	unsigned long flags;
144 
145 	/* connection management */
146 	bdaddr_t bdaddr;
147 	struct l2cap_conn *conn;
148 	struct l2cap_user user;
149 	struct socket *ctrl_sock;
150 	struct socket *intr_sock;
151 	struct sk_buff_head ctrl_transmit;
152 	struct sk_buff_head intr_transmit;
153 	uint ctrl_mtu;
154 	uint intr_mtu;
155 	unsigned long idle_to;
156 
157 	/* device management */
158 	struct work_struct dev_init;
159 	struct input_dev *input;
160 	struct hid_device *hid;
161 	struct timer_list timer;
162 
163 	/* Report descriptor */
164 	__u8 *rd_data;
165 	uint rd_size;
166 
167 	/* session data */
168 	unsigned char keys[8];
169 	unsigned char leds;
170 
171 	/* Used in hidp_get_raw_report() */
172 	int waiting_report_type; /* HIDP_DATA_RTYPE_* */
173 	int waiting_report_number; /* -1 for not numbered */
174 	struct mutex report_mutex;
175 	struct sk_buff *report_return;
176 	wait_queue_head_t report_queue;
177 
178 	/* Used in hidp_output_raw_report() */
179 	int output_report_success; /* boolean */
180 
181 	/* temporary input buffer */
182 	u8 input_buf[HID_MAX_BUFFER_SIZE];
183 };
184 
185 /* HIDP init defines */
186 int __init hidp_init_sockets(void);
187 void __exit hidp_cleanup_sockets(void);
188 
189 #endif /* __HIDP_H */
190