YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | 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 Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 13 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 18 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 19 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | SOFTWARE IS DISCLAIMED. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __HIDP_H |
| 24 | #define __HIDP_H |
| 25 | |
| 26 | #include <linux/types.h> |
David Herrmann | a4b1b58 | 2013-12-19 12:09:32 +0100 | [diff] [blame] | 27 | #include <linux/hid.h> |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 28 | #include <linux/kref.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <net/bluetooth/bluetooth.h> |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 30 | #include <net/bluetooth/l2cap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /* HIDP header masks */ |
| 33 | #define HIDP_HEADER_TRANS_MASK 0xf0 |
| 34 | #define HIDP_HEADER_PARAM_MASK 0x0f |
| 35 | |
| 36 | /* HIDP transaction types */ |
| 37 | #define HIDP_TRANS_HANDSHAKE 0x00 |
| 38 | #define HIDP_TRANS_HID_CONTROL 0x10 |
| 39 | #define HIDP_TRANS_GET_REPORT 0x40 |
| 40 | #define HIDP_TRANS_SET_REPORT 0x50 |
| 41 | #define HIDP_TRANS_GET_PROTOCOL 0x60 |
| 42 | #define HIDP_TRANS_SET_PROTOCOL 0x70 |
| 43 | #define HIDP_TRANS_GET_IDLE 0x80 |
| 44 | #define HIDP_TRANS_SET_IDLE 0x90 |
| 45 | #define HIDP_TRANS_DATA 0xa0 |
| 46 | #define HIDP_TRANS_DATC 0xb0 |
| 47 | |
| 48 | /* HIDP handshake results */ |
| 49 | #define HIDP_HSHK_SUCCESSFUL 0x00 |
| 50 | #define HIDP_HSHK_NOT_READY 0x01 |
| 51 | #define HIDP_HSHK_ERR_INVALID_REPORT_ID 0x02 |
| 52 | #define HIDP_HSHK_ERR_UNSUPPORTED_REQUEST 0x03 |
| 53 | #define HIDP_HSHK_ERR_INVALID_PARAMETER 0x04 |
| 54 | #define HIDP_HSHK_ERR_UNKNOWN 0x0e |
| 55 | #define HIDP_HSHK_ERR_FATAL 0x0f |
| 56 | |
| 57 | /* HIDP control operation parameters */ |
| 58 | #define HIDP_CTRL_NOP 0x00 |
| 59 | #define HIDP_CTRL_HARD_RESET 0x01 |
| 60 | #define HIDP_CTRL_SOFT_RESET 0x02 |
| 61 | #define HIDP_CTRL_SUSPEND 0x03 |
| 62 | #define HIDP_CTRL_EXIT_SUSPEND 0x04 |
| 63 | #define HIDP_CTRL_VIRTUAL_CABLE_UNPLUG 0x05 |
| 64 | |
| 65 | /* HIDP data transaction headers */ |
| 66 | #define HIDP_DATA_RTYPE_MASK 0x03 |
| 67 | #define HIDP_DATA_RSRVD_MASK 0x0c |
| 68 | #define HIDP_DATA_RTYPE_OTHER 0x00 |
| 69 | #define HIDP_DATA_RTYPE_INPUT 0x01 |
| 70 | #define HIDP_DATA_RTYPE_OUPUT 0x02 |
| 71 | #define HIDP_DATA_RTYPE_FEATURE 0x03 |
| 72 | |
| 73 | /* HIDP protocol header parameters */ |
| 74 | #define HIDP_PROTO_BOOT 0x00 |
| 75 | #define HIDP_PROTO_REPORT 0x01 |
| 76 | |
| 77 | /* HIDP ioctl defines */ |
| 78 | #define HIDPCONNADD _IOW('H', 200, int) |
| 79 | #define HIDPCONNDEL _IOW('H', 201, int) |
| 80 | #define HIDPGETCONNLIST _IOR('H', 210, int) |
| 81 | #define HIDPGETCONNINFO _IOR('H', 211, int) |
| 82 | |
| 83 | #define HIDP_VIRTUAL_CABLE_UNPLUG 0 |
| 84 | #define HIDP_BOOT_PROTOCOL_MODE 1 |
| 85 | #define HIDP_BLUETOOTH_VENDOR_ID 9 |
Antonio Ospite | 6d67c11 | 2011-04-06 10:43:23 +0200 | [diff] [blame] | 86 | #define HIDP_WAITING_FOR_RETURN 10 |
Alan Ott | 0825411 | 2011-01-18 03:04:38 -0500 | [diff] [blame] | 87 | #define HIDP_WAITING_FOR_SEND_ACK 11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | struct hidp_connadd_req { |
Szymon Janc | 17f09a7 | 2011-03-21 14:20:01 +0100 | [diff] [blame] | 90 | int ctrl_sock; /* Connected control socket */ |
| 91 | int intr_sock; /* Connected interrupt socket */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | __u16 parser; |
| 93 | __u16 rd_size; |
Al Viro | 55e7474 | 2007-02-09 16:38:00 +0000 | [diff] [blame] | 94 | __u8 __user *rd_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | __u8 country; |
| 96 | __u8 subclass; |
| 97 | __u16 vendor; |
| 98 | __u16 product; |
| 99 | __u16 version; |
| 100 | __u32 flags; |
| 101 | __u32 idle_to; |
| 102 | char name[128]; |
| 103 | }; |
| 104 | |
| 105 | struct hidp_conndel_req { |
| 106 | bdaddr_t bdaddr; |
| 107 | __u32 flags; |
| 108 | }; |
| 109 | |
| 110 | struct hidp_conninfo { |
| 111 | bdaddr_t bdaddr; |
| 112 | __u32 flags; |
| 113 | __u16 state; |
| 114 | __u16 vendor; |
| 115 | __u16 product; |
| 116 | __u16 version; |
| 117 | char name[128]; |
| 118 | }; |
| 119 | |
| 120 | struct hidp_connlist_req { |
| 121 | __u32 cnum; |
| 122 | struct hidp_conninfo __user *ci; |
| 123 | }; |
| 124 | |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 125 | int hidp_connection_add(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock); |
| 126 | int hidp_connection_del(struct hidp_conndel_req *req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int hidp_get_connlist(struct hidp_connlist_req *req); |
| 128 | int hidp_get_conninfo(struct hidp_conninfo *ci); |
| 129 | |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 130 | enum hidp_session_state { |
| 131 | HIDP_SESSION_IDLING, |
David Herrmann | 4e713cd | 2013-05-23 13:10:25 +0200 | [diff] [blame] | 132 | HIDP_SESSION_PREPARING, |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 133 | HIDP_SESSION_RUNNING, |
| 134 | }; |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* HIDP session defines */ |
| 137 | struct hidp_session { |
| 138 | struct list_head list; |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 139 | struct kref ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 141 | /* runtime management */ |
| 142 | atomic_t state; |
| 143 | wait_queue_head_t state_queue; |
Peter Hurley | 7bb59df | 2011-06-30 13:53:53 -0400 | [diff] [blame] | 144 | atomic_t terminate; |
Szymon Janc | aabf6f8 | 2011-04-05 15:37:45 +0200 | [diff] [blame] | 145 | struct task_struct *task; |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 146 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 148 | /* connection management */ |
| 149 | bdaddr_t bdaddr; |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 150 | struct l2cap_conn *conn; |
| 151 | struct l2cap_user user; |
| 152 | struct socket *ctrl_sock; |
| 153 | struct socket *intr_sock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | struct sk_buff_head ctrl_transmit; |
| 155 | struct sk_buff_head intr_transmit; |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 156 | uint ctrl_mtu; |
| 157 | uint intr_mtu; |
| 158 | unsigned long idle_to; |
| 159 | |
| 160 | /* device management */ |
David Herrmann | 4e713cd | 2013-05-23 13:10:25 +0200 | [diff] [blame] | 161 | struct work_struct dev_init; |
David Herrmann | b4f34d8 | 2013-04-06 20:28:46 +0200 | [diff] [blame] | 162 | struct input_dev *input; |
| 163 | struct hid_device *hid; |
| 164 | struct timer_list timer; |
| 165 | |
| 166 | /* Report descriptor */ |
| 167 | __u8 *rd_data; |
| 168 | uint rd_size; |
| 169 | |
| 170 | /* session data */ |
| 171 | unsigned char keys[8]; |
| 172 | unsigned char leds; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 173 | |
Alan Ott | 0ff1731 | 2011-01-18 03:04:40 -0500 | [diff] [blame] | 174 | /* Used in hidp_get_raw_report() */ |
| 175 | int waiting_report_type; /* HIDP_DATA_RTYPE_* */ |
| 176 | int waiting_report_number; /* -1 for not numbered */ |
| 177 | struct mutex report_mutex; |
| 178 | struct sk_buff *report_return; |
| 179 | wait_queue_head_t report_queue; |
| 180 | |
Alan Ott | 0825411 | 2011-01-18 03:04:38 -0500 | [diff] [blame] | 181 | /* Used in hidp_output_raw_report() */ |
| 182 | int output_report_success; /* boolean */ |
David Herrmann | a4b1b58 | 2013-12-19 12:09:32 +0100 | [diff] [blame] | 183 | |
| 184 | /* temporary input buffer */ |
| 185 | u8 input_buf[HID_MAX_BUFFER_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /* HIDP init defines */ |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 189 | int __init hidp_init_sockets(void); |
| 190 | void __exit hidp_cleanup_sockets(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | #endif /* __HIDP_H */ |