hidp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. HIDP implementation for Linux Bluetooth stack (BlueZ).
  3. Copyright (C) 2003-2004 Marcel Holtmann <marcel@holtmann.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License version 2 as
  6. published by the Free Software Foundation;
  7. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  9. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  10. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  11. CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  12. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  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. #ifndef __HIDP_H
  20. #define __HIDP_H
  21. #include <linux/types.h>
  22. #include <linux/hid.h>
  23. #include <net/bluetooth/bluetooth.h>
  24. /* HIDP header masks */
  25. #define HIDP_HEADER_TRANS_MASK 0xf0
  26. #define HIDP_HEADER_PARAM_MASK 0x0f
  27. /* HIDP transaction types */
  28. #define HIDP_TRANS_HANDSHAKE 0x00
  29. #define HIDP_TRANS_HID_CONTROL 0x10
  30. #define HIDP_TRANS_GET_REPORT 0x40
  31. #define HIDP_TRANS_SET_REPORT 0x50
  32. #define HIDP_TRANS_GET_PROTOCOL 0x60
  33. #define HIDP_TRANS_SET_PROTOCOL 0x70
  34. #define HIDP_TRANS_GET_IDLE 0x80
  35. #define HIDP_TRANS_SET_IDLE 0x90
  36. #define HIDP_TRANS_DATA 0xa0
  37. #define HIDP_TRANS_DATC 0xb0
  38. /* HIDP handshake results */
  39. #define HIDP_HSHK_SUCCESSFUL 0x00
  40. #define HIDP_HSHK_NOT_READY 0x01
  41. #define HIDP_HSHK_ERR_INVALID_REPORT_ID 0x02
  42. #define HIDP_HSHK_ERR_UNSUPPORTED_REQUEST 0x03
  43. #define HIDP_HSHK_ERR_INVALID_PARAMETER 0x04
  44. #define HIDP_HSHK_ERR_UNKNOWN 0x0e
  45. #define HIDP_HSHK_ERR_FATAL 0x0f
  46. /* HIDP control operation parameters */
  47. #define HIDP_CTRL_NOP 0x00
  48. #define HIDP_CTRL_HARD_RESET 0x01
  49. #define HIDP_CTRL_SOFT_RESET 0x02
  50. #define HIDP_CTRL_SUSPEND 0x03
  51. #define HIDP_CTRL_EXIT_SUSPEND 0x04
  52. #define HIDP_CTRL_VIRTUAL_CABLE_UNPLUG 0x05
  53. /* HIDP data transaction headers */
  54. #define HIDP_DATA_RTYPE_MASK 0x03
  55. #define HIDP_DATA_RSRVD_MASK 0x0c
  56. #define HIDP_DATA_RTYPE_OTHER 0x00
  57. #define HIDP_DATA_RTYPE_INPUT 0x01
  58. #define HIDP_DATA_RTYPE_OUPUT 0x02
  59. #define HIDP_DATA_RTYPE_FEATURE 0x03
  60. /* HIDP protocol header parameters */
  61. #define HIDP_PROTO_BOOT 0x00
  62. #define HIDP_PROTO_REPORT 0x01
  63. /* HIDP ioctl defines */
  64. #define HIDPCONNADD _IOW('H', 200, int)
  65. #define HIDPCONNDEL _IOW('H', 201, int)
  66. #define HIDPGETCONNLIST _IOR('H', 210, int)
  67. #define HIDPGETCONNINFO _IOR('H', 211, int)
  68. #define HIDP_VIRTUAL_CABLE_UNPLUG 0
  69. #define HIDP_BOOT_PROTOCOL_MODE 1
  70. #define HIDP_BLUETOOTH_VENDOR_ID 9
  71. struct hidp_connadd_req {
  72. int ctrl_sock; /* Connected control socket */
  73. int intr_sock; /* Connected interrupt socket */
  74. __u16 parser;
  75. __u16 rd_size;
  76. __u8 __user *rd_data;
  77. __u8 country;
  78. __u8 subclass;
  79. __u16 vendor;
  80. __u16 product;
  81. __u16 version;
  82. __u32 flags;
  83. __u32 idle_to;
  84. char name[128];
  85. };
  86. struct hidp_conndel_req {
  87. bdaddr_t bdaddr;
  88. __u32 flags;
  89. };
  90. struct hidp_conninfo {
  91. bdaddr_t bdaddr;
  92. __u32 flags;
  93. __u16 state;
  94. __u16 vendor;
  95. __u16 product;
  96. __u16 version;
  97. char name[128];
  98. };
  99. struct hidp_connlist_req {
  100. __u32 cnum;
  101. struct hidp_conninfo __user *ci;
  102. };
  103. int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock);
  104. int hidp_del_connection(struct hidp_conndel_req *req);
  105. int hidp_get_connlist(struct hidp_connlist_req *req);
  106. int hidp_get_conninfo(struct hidp_conninfo *ci);
  107. /* HIDP session defines */
  108. struct hidp_session {
  109. struct list_head list;
  110. struct hci_conn *conn;
  111. struct socket *ctrl_sock;
  112. struct socket *intr_sock;
  113. bdaddr_t bdaddr;
  114. unsigned long state;
  115. unsigned long flags;
  116. unsigned long idle_to;
  117. uint ctrl_mtu;
  118. uint intr_mtu;
  119. atomic_t terminate;
  120. unsigned char keys[8];
  121. unsigned char leds;
  122. struct input_dev *input;
  123. struct hid_device *hid;
  124. struct timer_list timer;
  125. struct sk_buff_head ctrl_transmit;
  126. struct sk_buff_head intr_transmit;
  127. /* Report descriptor */
  128. __u8 *rd_data;
  129. uint rd_size;
  130. };
  131. static inline void hidp_schedule(struct hidp_session *session)
  132. {
  133. struct sock *ctrl_sk = session->ctrl_sock->sk;
  134. struct sock *intr_sk = session->intr_sock->sk;
  135. wake_up_interruptible(sk_sleep(ctrl_sk));
  136. wake_up_interruptible(sk_sleep(intr_sk));
  137. }
  138. /* temporary input buffer */
  139. u8 input_buf[HID_MAX_BUFFER_SIZE];
  140. /* HIDP init defines */
  141. extern int __init hidp_init_sockets(void);
  142. extern void __exit hidp_cleanup_sockets(void);
  143. #endif /* __HIDP_H */