Back to home page

OSCL-LXR

 
 

    


0001 /*
0002    HIDP implementation for Linux Bluetooth stack (BlueZ).
0003    Copyright (C) 2003-2004 Marcel Holtmann <marcel@holtmann.org>
0004 
0005    This program is free software; you can redistribute it and/or modify
0006    it under the terms of the GNU General Public License version 2 as
0007    published by the Free Software Foundation;
0008 
0009    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0010    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0011    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
0012    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
0013    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
0014    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0015    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0016    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0017 
0018    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
0019    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
0020    SOFTWARE IS DISCLAIMED.
0021 */
0022 
0023 #ifndef __HIDP_H
0024 #define __HIDP_H
0025 
0026 #include <linux/types.h>
0027 #include <linux/hid.h>
0028 #include <linux/kref.h>
0029 #include <net/bluetooth/bluetooth.h>
0030 #include <net/bluetooth/l2cap.h>
0031 
0032 /* HIDP header masks */
0033 #define HIDP_HEADER_TRANS_MASK          0xf0
0034 #define HIDP_HEADER_PARAM_MASK          0x0f
0035 
0036 /* HIDP transaction types */
0037 #define HIDP_TRANS_HANDSHAKE            0x00
0038 #define HIDP_TRANS_HID_CONTROL          0x10
0039 #define HIDP_TRANS_GET_REPORT           0x40
0040 #define HIDP_TRANS_SET_REPORT           0x50
0041 #define HIDP_TRANS_GET_PROTOCOL         0x60
0042 #define HIDP_TRANS_SET_PROTOCOL         0x70
0043 #define HIDP_TRANS_GET_IDLE         0x80
0044 #define HIDP_TRANS_SET_IDLE         0x90
0045 #define HIDP_TRANS_DATA             0xa0
0046 #define HIDP_TRANS_DATC             0xb0
0047 
0048 /* HIDP handshake results */
0049 #define HIDP_HSHK_SUCCESSFUL            0x00
0050 #define HIDP_HSHK_NOT_READY         0x01
0051 #define HIDP_HSHK_ERR_INVALID_REPORT_ID     0x02
0052 #define HIDP_HSHK_ERR_UNSUPPORTED_REQUEST   0x03
0053 #define HIDP_HSHK_ERR_INVALID_PARAMETER     0x04
0054 #define HIDP_HSHK_ERR_UNKNOWN           0x0e
0055 #define HIDP_HSHK_ERR_FATAL         0x0f
0056 
0057 /* HIDP control operation parameters */
0058 #define HIDP_CTRL_NOP               0x00
0059 #define HIDP_CTRL_HARD_RESET            0x01
0060 #define HIDP_CTRL_SOFT_RESET            0x02
0061 #define HIDP_CTRL_SUSPEND           0x03
0062 #define HIDP_CTRL_EXIT_SUSPEND          0x04
0063 #define HIDP_CTRL_VIRTUAL_CABLE_UNPLUG      0x05
0064 
0065 /* HIDP data transaction headers */
0066 #define HIDP_DATA_RTYPE_MASK            0x03
0067 #define HIDP_DATA_RSRVD_MASK            0x0c
0068 #define HIDP_DATA_RTYPE_OTHER           0x00
0069 #define HIDP_DATA_RTYPE_INPUT           0x01
0070 #define HIDP_DATA_RTYPE_OUPUT           0x02
0071 #define HIDP_DATA_RTYPE_FEATURE         0x03
0072 
0073 /* HIDP protocol header parameters */
0074 #define HIDP_PROTO_BOOT             0x00
0075 #define HIDP_PROTO_REPORT           0x01
0076 
0077 /* HIDP ioctl defines */
0078 #define HIDPCONNADD _IOW('H', 200, int)
0079 #define HIDPCONNDEL _IOW('H', 201, int)
0080 #define HIDPGETCONNLIST _IOR('H', 210, int)
0081 #define HIDPGETCONNINFO _IOR('H', 211, int)
0082 
0083 #define HIDP_VIRTUAL_CABLE_UNPLUG   0
0084 #define HIDP_BOOT_PROTOCOL_MODE     1
0085 #define HIDP_BLUETOOTH_VENDOR_ID    9
0086 #define HIDP_WAITING_FOR_RETURN     10
0087 #define HIDP_WAITING_FOR_SEND_ACK   11
0088 
0089 struct hidp_connadd_req {
0090     int   ctrl_sock;    /* Connected control socket */
0091     int   intr_sock;    /* Connected interrupt socket */
0092     __u16 parser;
0093     __u16 rd_size;
0094     __u8 __user *rd_data;
0095     __u8  country;
0096     __u8  subclass;
0097     __u16 vendor;
0098     __u16 product;
0099     __u16 version;
0100     __u32 flags;
0101     __u32 idle_to;
0102     char  name[128];
0103 };
0104 
0105 struct hidp_conndel_req {
0106     bdaddr_t bdaddr;
0107     __u32    flags;
0108 };
0109 
0110 struct hidp_conninfo {
0111     bdaddr_t bdaddr;
0112     __u32    flags;
0113     __u16    state;
0114     __u16    vendor;
0115     __u16    product;
0116     __u16    version;
0117     char     name[128];
0118 };
0119 
0120 struct hidp_connlist_req {
0121     __u32  cnum;
0122     struct hidp_conninfo __user *ci;
0123 };
0124 
0125 int hidp_connection_add(const struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock);
0126 int hidp_connection_del(struct hidp_conndel_req *req);
0127 int hidp_get_connlist(struct hidp_connlist_req *req);
0128 int hidp_get_conninfo(struct hidp_conninfo *ci);
0129 
0130 enum hidp_session_state {
0131     HIDP_SESSION_IDLING,
0132     HIDP_SESSION_PREPARING,
0133     HIDP_SESSION_RUNNING,
0134 };
0135 
0136 /* HIDP session defines */
0137 struct hidp_session {
0138     struct list_head list;
0139     struct kref ref;
0140 
0141     /* runtime management */
0142     atomic_t state;
0143     wait_queue_head_t state_queue;
0144     atomic_t terminate;
0145     struct task_struct *task;
0146     unsigned long flags;
0147 
0148     /* connection management */
0149     bdaddr_t bdaddr;
0150     struct l2cap_conn *conn;
0151     struct l2cap_user user;
0152     struct socket *ctrl_sock;
0153     struct socket *intr_sock;
0154     struct sk_buff_head ctrl_transmit;
0155     struct sk_buff_head intr_transmit;
0156     uint ctrl_mtu;
0157     uint intr_mtu;
0158     unsigned long idle_to;
0159 
0160     /* device management */
0161     struct work_struct dev_init;
0162     struct input_dev *input;
0163     struct hid_device *hid;
0164     struct timer_list timer;
0165 
0166     /* Report descriptor */
0167     __u8 *rd_data;
0168     uint rd_size;
0169 
0170     /* session data */
0171     unsigned char keys[8];
0172     unsigned char leds;
0173 
0174     /* Used in hidp_get_raw_report() */
0175     int waiting_report_type; /* HIDP_DATA_RTYPE_* */
0176     int waiting_report_number; /* -1 for not numbered */
0177     struct mutex report_mutex;
0178     struct sk_buff *report_return;
0179     wait_queue_head_t report_queue;
0180 
0181     /* Used in hidp_output_raw_report() */
0182     int output_report_success; /* boolean */
0183 
0184     /* temporary input buffer */
0185     u8 input_buf[HID_MAX_BUFFER_SIZE];
0186 };
0187 
0188 /* HIDP init defines */
0189 int __init hidp_init_sockets(void);
0190 void __exit hidp_cleanup_sockets(void);
0191 
0192 #endif /* __HIDP_H */