^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) HIDP implementation for Linux Bluetooth stack (BlueZ).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) Copyright (C) 2003-2004 Marcel Holtmann <marcel@holtmann.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) published by the Free Software Foundation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) SOFTWARE IS DISCLAIMED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #ifndef __HIDP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define __HIDP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <net/bluetooth/l2cap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* HIDP header masks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define HIDP_HEADER_TRANS_MASK 0xf0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define HIDP_HEADER_PARAM_MASK 0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* HIDP transaction types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define HIDP_TRANS_HANDSHAKE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define HIDP_TRANS_HID_CONTROL 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define HIDP_TRANS_GET_REPORT 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define HIDP_TRANS_SET_REPORT 0x50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define HIDP_TRANS_GET_PROTOCOL 0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define HIDP_TRANS_SET_PROTOCOL 0x70
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define HIDP_TRANS_GET_IDLE 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define HIDP_TRANS_SET_IDLE 0x90
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define HIDP_TRANS_DATA 0xa0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define HIDP_TRANS_DATC 0xb0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* HIDP handshake results */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define HIDP_HSHK_SUCCESSFUL 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define HIDP_HSHK_NOT_READY 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define HIDP_HSHK_ERR_INVALID_REPORT_ID 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define HIDP_HSHK_ERR_UNSUPPORTED_REQUEST 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define HIDP_HSHK_ERR_INVALID_PARAMETER 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define HIDP_HSHK_ERR_UNKNOWN 0x0e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define HIDP_HSHK_ERR_FATAL 0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* HIDP control operation parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define HIDP_CTRL_NOP 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define HIDP_CTRL_HARD_RESET 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define HIDP_CTRL_SOFT_RESET 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define HIDP_CTRL_SUSPEND 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define HIDP_CTRL_EXIT_SUSPEND 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define HIDP_CTRL_VIRTUAL_CABLE_UNPLUG 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* HIDP data transaction headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define HIDP_DATA_RTYPE_MASK 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define HIDP_DATA_RSRVD_MASK 0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define HIDP_DATA_RTYPE_OTHER 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define HIDP_DATA_RTYPE_INPUT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define HIDP_DATA_RTYPE_OUPUT 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define HIDP_DATA_RTYPE_FEATURE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* HIDP protocol header parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define HIDP_PROTO_BOOT 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define HIDP_PROTO_REPORT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* HIDP ioctl defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define HIDPCONNADD _IOW('H', 200, int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define HIDPCONNDEL _IOW('H', 201, int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define HIDPGETCONNLIST _IOR('H', 210, int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define HIDPGETCONNINFO _IOR('H', 211, int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define HIDP_VIRTUAL_CABLE_UNPLUG 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define HIDP_BOOT_PROTOCOL_MODE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define HIDP_BLUETOOTH_VENDOR_ID 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define HIDP_WAITING_FOR_RETURN 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define HIDP_WAITING_FOR_SEND_ACK 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct hidp_connadd_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int ctrl_sock; /* Connected control socket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int intr_sock; /* Connected interrupt socket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) __u16 parser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) __u16 rd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __u8 __user *rd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) __u8 country;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) __u8 subclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) __u16 vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) __u16 product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) __u16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) __u32 idle_to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) char name[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct hidp_conndel_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) bdaddr_t bdaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) __u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct hidp_conninfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) bdaddr_t bdaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) __u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) __u16 state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) __u16 vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) __u16 product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) __u16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) char name[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct hidp_connlist_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) __u32 cnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct hidp_conninfo __user *ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int hidp_connection_add(const struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int hidp_connection_del(struct hidp_conndel_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int hidp_get_connlist(struct hidp_connlist_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int hidp_get_conninfo(struct hidp_conninfo *ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) enum hidp_session_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) HIDP_SESSION_IDLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) HIDP_SESSION_PREPARING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) HIDP_SESSION_RUNNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* HIDP session defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct hidp_session {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct kref ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* runtime management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) atomic_t state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) wait_queue_head_t state_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) atomic_t terminate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct task_struct *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* connection management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) bdaddr_t bdaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct l2cap_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct l2cap_user user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct socket *ctrl_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct socket *intr_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct sk_buff_head ctrl_transmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct sk_buff_head intr_transmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) uint ctrl_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) uint intr_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) unsigned long idle_to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* device management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct work_struct dev_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct hid_device *hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* Report descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) __u8 *rd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) uint rd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* session data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) unsigned char keys[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) unsigned char leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* Used in hidp_get_raw_report() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int waiting_report_type; /* HIDP_DATA_RTYPE_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int waiting_report_number; /* -1 for not numbered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct mutex report_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct sk_buff *report_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) wait_queue_head_t report_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Used in hidp_output_raw_report() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int output_report_success; /* boolean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* temporary input buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u8 input_buf[HID_MAX_BUFFER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* HIDP init defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int __init hidp_init_sockets(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) void __exit hidp_cleanup_sockets(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #endif /* __HIDP_H */