amp.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. Copyright (c) 2010-2012 The Linux Foundation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License version 2 and
  5. only version 2 as published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. */
  11. #ifndef __AMP_H
  12. #define __AMP_H
  13. /* AMP defaults */
  14. #define A2MP_RSP_TIMEOUT (8000) /* 8 seconds */
  15. /* A2MP Protocol */
  16. /* A2MP command codes */
  17. #define A2MP_COMMAND_REJ 0x01
  18. #define A2MP_DISCOVER_REQ 0x02
  19. #define A2MP_DISCOVER_RSP 0x03
  20. #define A2MP_CHANGE_NOTIFY 0x04
  21. #define A2MP_CHANGE_RSP 0x05
  22. #define A2MP_GETINFO_REQ 0x06
  23. #define A2MP_GETINFO_RSP 0x07
  24. #define A2MP_GETAMPASSOC_REQ 0x08
  25. #define A2MP_GETAMPASSOC_RSP 0x09
  26. #define A2MP_CREATEPHYSLINK_REQ 0x0A
  27. #define A2MP_CREATEPHYSLINK_RSP 0x0B
  28. #define A2MP_DISCONNPHYSLINK_REQ 0x0C
  29. #define A2MP_DISCONNPHYSLINK_RSP 0x0D
  30. struct a2mp_cmd_hdr {
  31. __u8 code;
  32. __u8 ident;
  33. __le16 len;
  34. } __packed;
  35. struct a2mp_cmd_rej {
  36. __le16 reason;
  37. } __packed;
  38. struct a2mp_discover_req {
  39. __le16 mtu;
  40. __le16 ext_feat;
  41. } __packed;
  42. struct a2mp_cl {
  43. __u8 id;
  44. __u8 type;
  45. __u8 status;
  46. } __packed;
  47. struct a2mp_discover_rsp {
  48. __le16 mtu;
  49. __le16 ext_feat;
  50. struct a2mp_cl cl[0];
  51. } __packed;
  52. struct a2mp_getinfo_req {
  53. __u8 id;
  54. } __packed;
  55. struct a2mp_getinfo_rsp {
  56. __u8 id;
  57. __u8 status;
  58. __le32 total_bw;
  59. __le32 max_bw;
  60. __le32 min_latency;
  61. __le16 pal_cap;
  62. __le16 assoc_size;
  63. } __packed;
  64. struct a2mp_getampassoc_req {
  65. __u8 id;
  66. } __packed;
  67. struct a2mp_getampassoc_rsp {
  68. __u8 id;
  69. __u8 status;
  70. __u8 amp_assoc[0];
  71. } __packed;
  72. struct a2mp_createphyslink_req {
  73. __u8 local_id;
  74. __u8 remote_id;
  75. __u8 amp_assoc[0];
  76. } __packed;
  77. struct a2mp_createphyslink_rsp {
  78. __u8 local_id;
  79. __u8 remote_id;
  80. __u8 status;
  81. } __packed;
  82. struct a2mp_disconnphyslink_req {
  83. __u8 local_id;
  84. __u8 remote_id;
  85. } __packed;
  86. struct a2mp_disconnphyslink_rsp {
  87. __u8 local_id;
  88. __u8 remote_id;
  89. __u8 status;
  90. } __packed;
  91. /* L2CAP-AMP module interface */
  92. int amp_init(void);
  93. void amp_exit(void);
  94. /* L2CAP-AMP fixed channel interface */
  95. void amp_conn_ind(struct hci_conn *hcon, struct sk_buff *skb);
  96. /* L2CAP-AMP link interface */
  97. void amp_create_physical(struct l2cap_conn *conn, struct sock *sk);
  98. void amp_accept_physical(struct l2cap_conn *conn, u8 id, struct sock *sk);
  99. /* AMP manager internals */
  100. struct amp_ctrl {
  101. struct amp_mgr *mgr;
  102. __u8 id;
  103. __u8 type;
  104. __u8 status;
  105. __u32 total_bw;
  106. __u32 max_bw;
  107. __u32 min_latency;
  108. __u16 pal_cap;
  109. __u16 max_assoc_size;
  110. };
  111. struct amp_mgr {
  112. struct list_head list;
  113. __u8 discovered;
  114. __u8 next_ident;
  115. struct l2cap_conn *l2cap_conn;
  116. struct socket *a2mp_sock;
  117. struct list_head ctx_list;
  118. rwlock_t ctx_list_lock;
  119. struct amp_ctrl *ctrls; /* @@ TODO s.b. list of controllers */
  120. struct sk_buff *skb;
  121. __u8 connected;
  122. };
  123. /* AMP Manager signalling contexts */
  124. #define AMP_GETAMPASSOC 1
  125. #define AMP_CREATEPHYSLINK 2
  126. #define AMP_ACCEPTPHYSLINK 3
  127. #define AMP_CREATELOGLINK 4
  128. #define AMP_ACCEPTLOGLINK 5
  129. /* Get AMP Assoc sequence */
  130. #define AMP_GAA_INIT 0
  131. #define AMP_GAA_RLAA_COMPLETE 1
  132. struct amp_gaa_state {
  133. __u8 req_ident;
  134. __u16 len_so_far;
  135. __u8 *assoc;
  136. };
  137. /* Create Physical Link sequence */
  138. #define AMP_CPL_INIT 0
  139. #define AMP_CPL_DISC_RSP 1
  140. #define AMP_CPL_GETINFO_RSP 2
  141. #define AMP_CPL_GAA_RSP 3
  142. #define AMP_CPL_CPL_STATUS 4
  143. #define AMP_CPL_WRA_COMPLETE 5
  144. #define AMP_CPL_CHANNEL_SELECT 6
  145. #define AMP_CPL_RLA_COMPLETE 7
  146. #define AMP_CPL_PL_COMPLETE 8
  147. #define AMP_CPL_PL_CANCEL 9
  148. struct amp_cpl_state {
  149. __u8 remote_id;
  150. __u16 max_len;
  151. __u8 *remote_assoc;
  152. __u8 *local_assoc;
  153. __u16 len_so_far;
  154. __u16 rem_len;
  155. __u8 phy_handle;
  156. };
  157. /* Accept Physical Link sequence */
  158. #define AMP_APL_INIT 0
  159. #define AMP_APL_APL_STATUS 1
  160. #define AMP_APL_WRA_COMPLETE 2
  161. #define AMP_APL_PL_COMPLETE 3
  162. struct amp_apl_state {
  163. __u8 remote_id;
  164. __u8 req_ident;
  165. __u8 *remote_assoc;
  166. __u16 len_so_far;
  167. __u16 rem_len;
  168. __u8 phy_handle;
  169. };
  170. /* Create/Accept Logical Link sequence */
  171. #define AMP_LOG_INIT 0
  172. #define AMP_LOG_LL_STATUS 1
  173. #define AMP_LOG_LL_COMPLETE 2
  174. struct amp_log_state {
  175. __u8 remote_id;
  176. };
  177. /* Possible event types a context may wait for */
  178. #define AMP_INIT 0x01
  179. #define AMP_HCI_EVENT 0x02
  180. #define AMP_HCI_CMD_CMPLT 0x04
  181. #define AMP_HCI_CMD_STATUS 0x08
  182. #define AMP_A2MP_RSP 0x10
  183. #define AMP_KILLED 0x20
  184. #define AMP_CANCEL 0x40
  185. struct amp_ctx {
  186. struct list_head list;
  187. struct amp_mgr *mgr;
  188. struct hci_dev *hdev;
  189. __u8 type;
  190. __u8 state;
  191. union {
  192. struct amp_gaa_state gaa;
  193. struct amp_cpl_state cpl;
  194. struct amp_apl_state apl;
  195. } d;
  196. __u8 evt_type;
  197. __u8 evt_code;
  198. __u16 opcode;
  199. __u8 id;
  200. __u8 rsp_ident;
  201. struct sock *sk;
  202. struct amp_ctx *deferred;
  203. struct timer_list timer;
  204. };
  205. /* AMP work */
  206. struct amp_work_pl_timeout {
  207. struct work_struct work;
  208. struct amp_ctrl *ctrl;
  209. };
  210. struct amp_work_ctx_timeout {
  211. struct work_struct work;
  212. struct amp_ctx *ctx;
  213. };
  214. struct amp_work_data_ready {
  215. struct work_struct work;
  216. struct sock *sk;
  217. int bytes;
  218. };
  219. struct amp_work_state_change {
  220. struct work_struct work;
  221. struct sock *sk;
  222. };
  223. struct amp_work_conn_ind {
  224. struct work_struct work;
  225. struct hci_conn *hcon;
  226. struct sk_buff *skb;
  227. };
  228. struct amp_work_create_physical {
  229. struct work_struct work;
  230. struct l2cap_conn *conn;
  231. u8 id;
  232. struct sock *sk;
  233. };
  234. struct amp_work_accept_physical {
  235. struct work_struct work;
  236. struct l2cap_conn *conn;
  237. u8 id;
  238. struct sock *sk;
  239. };
  240. struct amp_work_cmd_cmplt {
  241. struct work_struct work;
  242. struct hci_dev *hdev;
  243. u16 opcode;
  244. struct sk_buff *skb;
  245. };
  246. struct amp_work_cmd_status {
  247. struct work_struct work;
  248. struct hci_dev *hdev;
  249. u16 opcode;
  250. u8 status;
  251. };
  252. struct amp_work_event {
  253. struct work_struct work;
  254. struct hci_dev *hdev;
  255. u8 event;
  256. struct sk_buff *skb;
  257. };
  258. #endif /* __AMP_H */