l2cap.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. BlueZ - Bluetooth protocol stack for Linux
  3. Copyright (c) 2000-2001, 2010-2012 The Linux Foundation. All rights reserved.
  4. Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org>
  5. Copyright (C) 2010 Google Inc.
  6. Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License version 2 as
  9. published by the Free Software Foundation;
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  13. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  14. CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  15. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
  19. COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
  20. SOFTWARE IS DISCLAIMED.
  21. */
  22. #ifndef __L2CAP_H
  23. #define __L2CAP_H
  24. /* L2CAP defaults */
  25. #define L2CAP_DEFAULT_MTU 672
  26. #define L2CAP_DEFAULT_MIN_MTU 48
  27. #define L2CAP_DEFAULT_MAX_SDU_SIZE 0xffff
  28. #define L2CAP_DEFAULT_FLUSH_TO 0xffff
  29. #define L2CAP_MAX_FLUSH_TO 0x7ff
  30. #define L2CAP_DEFAULT_TX_WINDOW 63
  31. #define L2CAP_DEFAULT_MAX_TX 3
  32. #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */
  33. #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */
  34. #define L2CAP_DEFAULT_MAX_PDU_SIZE 1482 /* Sized for AMP or BR/EDR */
  35. #define L2CAP_DEFAULT_ACK_TO 200
  36. #define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */
  37. #define L2CAP_MAX_ERTM_QUEUED 5
  38. #define L2CAP_MIN_ERTM_QUEUED 2
  39. #define L2CAP_A2MP_DEFAULT_MTU 670
  40. #define L2CAP_TX_WIN_MAX_ENHANCED 0x3f
  41. #define L2CAP_TX_WIN_MAX_EXTENDED 0x3fff
  42. #define L2CAP_LE_DEFAULT_MTU 23
  43. #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */
  44. #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */
  45. #define L2CAP_MOVE_TIMEOUT (4*HZ) /* 4 seconds */
  46. #define L2CAP_MOVE_ERTX_TIMEOUT (60*HZ) /* 60 seconds */
  47. /* L2CAP socket address */
  48. struct sockaddr_l2 {
  49. sa_family_t l2_family;
  50. __le16 l2_psm;
  51. bdaddr_t l2_bdaddr;
  52. __le16 l2_cid;
  53. };
  54. /* L2CAP socket options */
  55. #define L2CAP_OPTIONS 0x01
  56. struct l2cap_options {
  57. __u16 omtu;
  58. __u16 imtu;
  59. __u16 flush_to;
  60. __u8 mode;
  61. __u8 fcs;
  62. __u8 max_tx;
  63. __u16 txwin_size;
  64. };
  65. #define L2CAP_CONNINFO 0x02
  66. struct l2cap_conninfo {
  67. __u16 hci_handle;
  68. __u8 dev_class[3];
  69. };
  70. #define L2CAP_LM 0x03
  71. #define L2CAP_LM_MASTER 0x0001
  72. #define L2CAP_LM_AUTH 0x0002
  73. #define L2CAP_LM_ENCRYPT 0x0004
  74. #define L2CAP_LM_TRUSTED 0x0008
  75. #define L2CAP_LM_RELIABLE 0x0010
  76. #define L2CAP_LM_SECURE 0x0020
  77. #define L2CAP_LM_FLUSHABLE 0x0040
  78. /* L2CAP command codes */
  79. #define L2CAP_COMMAND_REJ 0x01
  80. #define L2CAP_CONN_REQ 0x02
  81. #define L2CAP_CONN_RSP 0x03
  82. #define L2CAP_CONF_REQ 0x04
  83. #define L2CAP_CONF_RSP 0x05
  84. #define L2CAP_DISCONN_REQ 0x06
  85. #define L2CAP_DISCONN_RSP 0x07
  86. #define L2CAP_ECHO_REQ 0x08
  87. #define L2CAP_ECHO_RSP 0x09
  88. #define L2CAP_INFO_REQ 0x0a
  89. #define L2CAP_INFO_RSP 0x0b
  90. #define L2CAP_CREATE_CHAN_REQ 0x0c
  91. #define L2CAP_CREATE_CHAN_RSP 0x0d
  92. #define L2CAP_MOVE_CHAN_REQ 0x0e
  93. #define L2CAP_MOVE_CHAN_RSP 0x0f
  94. #define L2CAP_MOVE_CHAN_CFM 0x10
  95. #define L2CAP_MOVE_CHAN_CFM_RSP 0x11
  96. #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12
  97. #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13
  98. /* L2CAP feature mask */
  99. #define L2CAP_FEAT_FLOWCTL 0x00000001
  100. #define L2CAP_FEAT_RETRANS 0x00000002
  101. #define L2CAP_FEAT_ERTM 0x00000008
  102. #define L2CAP_FEAT_STREAMING 0x00000010
  103. #define L2CAP_FEAT_FCS 0x00000020
  104. #define L2CAP_FEAT_FIXED_CHAN 0x00000080
  105. #define L2CAP_FEAT_EXT_WINDOW 0x00000100
  106. #define L2CAP_FEAT_UCD 0x00000200
  107. /* L2CAP checksum option */
  108. #define L2CAP_FCS_NONE 0x00
  109. #define L2CAP_FCS_CRC16 0x01
  110. /* L2CAP fixed channels */
  111. #define L2CAP_FC_L2CAP 0x02
  112. #define L2CAP_FC_A2MP 0x08
  113. /* L2CAP Control Field */
  114. #define L2CAP_CTRL_SAR 0xC000
  115. #define L2CAP_CTRL_REQSEQ 0x3F00
  116. #define L2CAP_CTRL_TXSEQ 0x007E
  117. #define L2CAP_CTRL_FINAL 0x0080
  118. #define L2CAP_CTRL_POLL 0x0010
  119. #define L2CAP_CTRL_SUPERVISE 0x000C
  120. #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */
  121. #define L2CAP_CTRL_TXSEQ_SHIFT 1
  122. #define L2CAP_CTRL_SUPERVISE_SHIFT 2
  123. #define L2CAP_CTRL_POLL_SHIFT 4
  124. #define L2CAP_CTRL_FINAL_SHIFT 7
  125. #define L2CAP_CTRL_REQSEQ_SHIFT 8
  126. #define L2CAP_CTRL_SAR_SHIFT 14
  127. #define L2CAP_EXT_CTRL_SAR 0x00030000
  128. #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC
  129. #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000
  130. #define L2CAP_EXT_CTRL_FINAL 0x00000002
  131. #define L2CAP_EXT_CTRL_POLL 0x00040000
  132. #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000
  133. #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */
  134. #define L2CAP_EXT_CTRL_FINAL_SHIFT 1
  135. #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2
  136. #define L2CAP_EXT_CTRL_SAR_SHIFT 16
  137. #define L2CAP_EXT_CTRL_SUPERVISE_SHIFT 16
  138. #define L2CAP_EXT_CTRL_POLL_SHIFT 18
  139. #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18
  140. /* L2CAP Supervisory Frame Types */
  141. #define L2CAP_SFRAME_RR 0x00
  142. #define L2CAP_SFRAME_REJ 0x01
  143. #define L2CAP_SFRAME_RNR 0x02
  144. #define L2CAP_SFRAME_SREJ 0x03
  145. /* L2CAP Segmentation and Reassembly */
  146. #define L2CAP_SAR_UNSEGMENTED 0x00
  147. #define L2CAP_SAR_START 0x01
  148. #define L2CAP_SAR_END 0x02
  149. #define L2CAP_SAR_CONTINUE 0x03
  150. /* L2CAP ERTM / Streaming extra field lengths */
  151. #define L2CAP_SDULEN_SIZE 2
  152. #define L2CAP_FCS_SIZE 2
  153. /* L2CAP structures */
  154. struct l2cap_hdr {
  155. __le16 len;
  156. __le16 cid;
  157. } __packed;
  158. #define L2CAP_HDR_SIZE 4
  159. #define L2CAP_ENHANCED_HDR_SIZE 6
  160. #define L2CAP_EXTENDED_HDR_SIZE 8
  161. struct l2cap_cmd_hdr {
  162. __u8 code;
  163. __u8 ident;
  164. __le16 len;
  165. } __packed;
  166. #define L2CAP_CMD_HDR_SIZE 4
  167. struct l2cap_cmd_rej {
  168. __le16 reason;
  169. } __packed;
  170. struct l2cap_conn_req {
  171. __le16 psm;
  172. __le16 scid;
  173. } __packed;
  174. struct l2cap_conn_rsp {
  175. __le16 dcid;
  176. __le16 scid;
  177. __le16 result;
  178. __le16 status;
  179. } __packed;
  180. /* channel indentifier */
  181. #define L2CAP_CID_SIGNALING 0x0001
  182. #define L2CAP_CID_CONN_LESS 0x0002
  183. #define L2CAP_CID_A2MP 0x0003
  184. #define L2CAP_CID_LE_DATA 0x0004
  185. #define L2CAP_CID_LE_SIGNALING 0x0005
  186. #define L2CAP_CID_SMP 0x0006
  187. #define L2CAP_CID_DYN_START 0x0040
  188. #define L2CAP_CID_DYN_END 0xffff
  189. /* connect result */
  190. #define L2CAP_CR_SUCCESS 0x0000
  191. #define L2CAP_CR_PEND 0x0001
  192. #define L2CAP_CR_BAD_PSM 0x0002
  193. #define L2CAP_CR_SEC_BLOCK 0x0003
  194. #define L2CAP_CR_NO_MEM 0x0004
  195. /* connect status */
  196. #define L2CAP_CS_NO_INFO 0x0000
  197. #define L2CAP_CS_AUTHEN_PEND 0x0001
  198. #define L2CAP_CS_AUTHOR_PEND 0x0002
  199. struct l2cap_conf_req {
  200. __le16 dcid;
  201. __le16 flags;
  202. __u8 data[0];
  203. } __packed;
  204. struct l2cap_conf_rsp {
  205. __le16 scid;
  206. __le16 flags;
  207. __le16 result;
  208. __u8 data[0];
  209. } __packed;
  210. #define L2CAP_CONF_SUCCESS 0x0000
  211. #define L2CAP_CONF_UNACCEPT 0x0001
  212. #define L2CAP_CONF_REJECT 0x0002
  213. #define L2CAP_CONF_UNKNOWN 0x0003
  214. #define L2CAP_CONF_PENDING 0x0004
  215. #define L2CAP_CONF_FLOW_SPEC_REJECT 0x0005
  216. struct l2cap_conf_opt {
  217. __u8 type;
  218. __u8 len;
  219. __u8 val[0];
  220. } __packed;
  221. #define L2CAP_CONF_OPT_SIZE 2
  222. #define L2CAP_CONF_HINT 0x80
  223. #define L2CAP_CONF_MASK 0x7f
  224. #define L2CAP_CONF_MTU 0x01
  225. #define L2CAP_CONF_FLUSH_TO 0x02
  226. #define L2CAP_CONF_QOS 0x03
  227. #define L2CAP_CONF_RFC 0x04
  228. #define L2CAP_CONF_FCS 0x05
  229. #define L2CAP_CONF_EXT_FS 0x06
  230. #define L2CAP_CONF_EXT_WINDOW 0x07
  231. /* QOS Service type */
  232. #define L2CAP_SERVICE_NO_TRAFFIC 0x00
  233. #define L2CAP_SERVICE_BEST_EFFORT 0x01
  234. #define L2CAP_SERVICE_GUARANTEED 0x02
  235. #define L2CAP_CONF_MAX_SIZE 22
  236. struct l2cap_conf_rfc {
  237. __u8 mode;
  238. __u8 txwin_size;
  239. __u8 max_transmit;
  240. __le16 retrans_timeout;
  241. __le16 monitor_timeout;
  242. __le16 max_pdu_size;
  243. } __packed;
  244. struct l2cap_conf_ext_fs {
  245. __u8 id;
  246. __u8 type;
  247. __le16 max_sdu;
  248. __le32 sdu_arr_time;
  249. __le32 acc_latency;
  250. __le32 flush_to;
  251. } __packed;
  252. struct l2cap_conf_prm {
  253. __u8 fcs;
  254. __le32 flush_to;
  255. };
  256. #define L2CAP_MODE_BASIC 0x00
  257. #define L2CAP_MODE_RETRANS 0x01
  258. #define L2CAP_MODE_FLOWCTL 0x02
  259. #define L2CAP_MODE_ERTM 0x03
  260. #define L2CAP_MODE_STREAMING 0x04
  261. struct l2cap_disconn_req {
  262. __le16 dcid;
  263. __le16 scid;
  264. } __packed;
  265. struct l2cap_disconn_rsp {
  266. __le16 dcid;
  267. __le16 scid;
  268. } __packed;
  269. struct l2cap_info_req {
  270. __le16 type;
  271. } __packed;
  272. struct l2cap_info_rsp {
  273. __le16 type;
  274. __le16 result;
  275. __u8 data[0];
  276. } __packed;
  277. struct l2cap_create_chan_req {
  278. __le16 psm;
  279. __le16 scid;
  280. __u8 amp_id;
  281. } __attribute__ ((packed));
  282. struct l2cap_create_chan_rsp {
  283. __le16 dcid;
  284. __le16 scid;
  285. __le16 result;
  286. __le16 status;
  287. } __attribute__ ((packed));
  288. #define L2CAP_CREATE_CHAN_SUCCESS (0x0000)
  289. #define L2CAP_CREATE_CHAN_PENDING (0x0001)
  290. #define L2CAP_CREATE_CHAN_REFUSED_PSM (0x0002)
  291. #define L2CAP_CREATE_CHAN_REFUSED_SECURITY (0x0003)
  292. #define L2CAP_CREATE_CHAN_REFUSED_RESOURCES (0x0004)
  293. #define L2CAP_CREATE_CHAN_REFUSED_CONTROLLER (0x0005)
  294. #define L2CAP_CREATE_CHAN_STATUS_NONE (0x0000)
  295. #define L2CAP_CREATE_CHAN_STATUS_AUTHENTICATION (0x0001)
  296. #define L2CAP_CREATE_CHAN_STATUS_AUTHORIZATION (0x0002)
  297. struct l2cap_move_chan_req {
  298. __le16 icid;
  299. __u8 dest_amp_id;
  300. } __attribute__ ((packed));
  301. struct l2cap_move_chan_rsp {
  302. __le16 icid;
  303. __le16 result;
  304. } __attribute__ ((packed));
  305. #define L2CAP_MOVE_CHAN_SUCCESS (0x0000)
  306. #define L2CAP_MOVE_CHAN_PENDING (0x0001)
  307. #define L2CAP_MOVE_CHAN_REFUSED_CONTROLLER (0x0002)
  308. #define L2CAP_MOVE_CHAN_REFUSED_SAME_ID (0x0003)
  309. #define L2CAP_MOVE_CHAN_REFUSED_CONFIG (0x0004)
  310. #define L2CAP_MOVE_CHAN_REFUSED_COLLISION (0x0005)
  311. #define L2CAP_MOVE_CHAN_REFUSED_NOT_ALLOWED (0x0006)
  312. struct l2cap_move_chan_cfm {
  313. __le16 icid;
  314. __le16 result;
  315. } __attribute__ ((packed));
  316. #define L2CAP_MOVE_CHAN_CONFIRMED (0x0000)
  317. #define L2CAP_MOVE_CHAN_UNCONFIRMED (0x0001)
  318. struct l2cap_move_chan_cfm_rsp {
  319. __le16 icid;
  320. } __attribute__ ((packed));
  321. struct l2cap_amp_signal_work {
  322. struct work_struct work;
  323. struct l2cap_cmd_hdr cmd;
  324. struct l2cap_conn *conn;
  325. struct sk_buff *skb;
  326. u8 *data;
  327. };
  328. struct l2cap_resegment_work {
  329. struct work_struct work;
  330. struct sock *sk;
  331. };
  332. struct l2cap_logical_link_work {
  333. struct work_struct work;
  334. struct hci_chan *chan;
  335. u8 status;
  336. };
  337. /* info type */
  338. #define L2CAP_IT_CL_MTU 0x0001
  339. #define L2CAP_IT_FEAT_MASK 0x0002
  340. #define L2CAP_IT_FIXED_CHAN 0x0003
  341. /* info result */
  342. #define L2CAP_IR_SUCCESS 0x0000
  343. #define L2CAP_IR_NOTSUPP 0x0001
  344. struct l2cap_conn_param_update_req {
  345. __le16 min;
  346. __le16 max;
  347. __le16 latency;
  348. __le16 to_multiplier;
  349. } __packed;
  350. struct l2cap_conn_param_update_rsp {
  351. __le16 result;
  352. } __packed;
  353. /* Connection Parameters result */
  354. #define L2CAP_CONN_PARAM_ACCEPTED 0x0000
  355. #define L2CAP_CONN_PARAM_REJECTED 0x0001
  356. /* ----- L2CAP connections ----- */
  357. struct l2cap_chan_list {
  358. struct sock *head;
  359. rwlock_t lock;
  360. };
  361. struct l2cap_conn {
  362. struct hci_conn *hcon;
  363. bdaddr_t *dst;
  364. bdaddr_t *src;
  365. unsigned int mtu;
  366. __u32 feat_mask;
  367. __u8 fc_mask;
  368. struct amp_mgr *mgr;
  369. __u8 info_state;
  370. __u8 info_ident;
  371. struct timer_list info_timer;
  372. spinlock_t lock;
  373. struct sk_buff *rx_skb;
  374. __u32 rx_len;
  375. __u8 tx_ident;
  376. __u8 disc_reason;
  377. struct l2cap_chan_list chan_list;
  378. };
  379. struct sock_del_list {
  380. struct sock *sk;
  381. struct list_head list;
  382. };
  383. #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
  384. #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04
  385. #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08
  386. /* ----- L2CAP channel and socket info ----- */
  387. #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
  388. #define TX_QUEUE(sk) (&l2cap_pi(sk)->tx_queue)
  389. #define SREJ_QUEUE(sk) (&l2cap_pi(sk)->srej_queue)
  390. struct l2cap_seq_list {
  391. __u16 head;
  392. __u16 tail;
  393. __u16 size;
  394. __u16 mask;
  395. __u16 *list;
  396. };
  397. struct l2cap_pinfo {
  398. struct bt_sock bt;
  399. __le16 psm;
  400. __u16 dcid;
  401. __u16 scid;
  402. __u16 imtu;
  403. __u16 omtu;
  404. __u16 flush_to;
  405. __u8 mode;
  406. __u8 fixed_channel;
  407. __u8 num_conf_req;
  408. __u8 num_conf_rsp;
  409. __u8 incoming;
  410. __u8 fcs;
  411. __u8 sec_level;
  412. __u8 role_switch;
  413. __u8 force_reliable;
  414. __u8 flushable;
  415. __u8 force_active;
  416. __u8 conf_req[64];
  417. __u8 conf_len;
  418. __u8 conf_ident;
  419. __u16 conf_state;
  420. __u8 conn_state;
  421. __u8 tx_state;
  422. __u8 rx_state;
  423. __u8 reconf_state;
  424. __u8 amp_id;
  425. __u8 amp_move_id;
  426. __u8 amp_move_state;
  427. __u8 amp_move_role;
  428. __u8 amp_move_cmd_ident;
  429. __u16 amp_move_reqseq;
  430. __u16 amp_move_event;
  431. __u16 next_tx_seq;
  432. __u16 expected_ack_seq;
  433. __u16 expected_tx_seq;
  434. __u16 buffer_seq;
  435. __u16 srej_save_reqseq;
  436. __u16 last_acked_seq;
  437. __u32 frames_sent;
  438. __u16 unacked_frames;
  439. __u8 retry_count;
  440. __u16 srej_queue_next;
  441. __u16 sdu_len;
  442. struct sk_buff *sdu;
  443. struct sk_buff *sdu_last_frag;
  444. atomic_t ertm_queued;
  445. __u8 ident;
  446. __u16 tx_win;
  447. __u16 tx_win_max;
  448. __u16 ack_win;
  449. __u8 max_tx;
  450. __u8 amp_pref;
  451. __u16 remote_tx_win;
  452. __u8 remote_max_tx;
  453. __u8 extended_control;
  454. __u16 retrans_timeout;
  455. __u16 monitor_timeout;
  456. __u16 remote_mps;
  457. __u16 mps;
  458. __le16 sport;
  459. struct delayed_work retrans_work;
  460. struct delayed_work monitor_work;
  461. struct delayed_work ack_work;
  462. struct work_struct tx_work;
  463. struct sk_buff_head tx_queue;
  464. struct sk_buff_head srej_queue;
  465. struct l2cap_seq_list srej_list;
  466. struct l2cap_seq_list retrans_list;
  467. struct hci_conn *ampcon;
  468. struct hci_chan *ampchan;
  469. struct l2cap_conn *conn;
  470. struct l2cap_conf_prm local_conf;
  471. struct l2cap_conf_prm remote_conf;
  472. struct l2cap_conf_ext_fs local_fs;
  473. struct l2cap_conf_ext_fs remote_fs;
  474. struct sock *next_c;
  475. struct sock *prev_c;
  476. };
  477. #define L2CAP_CONF_REQ_SENT 0x0001
  478. #define L2CAP_CONF_INPUT_DONE 0x0002
  479. #define L2CAP_CONF_OUTPUT_DONE 0x0004
  480. #define L2CAP_CONF_MTU_DONE 0x0008
  481. #define L2CAP_CONF_MODE_DONE 0x0010
  482. #define L2CAP_CONF_CONNECT_PEND 0x0020
  483. #define L2CAP_CONF_NO_FCS_RECV 0x0040
  484. #define L2CAP_CONF_STATE2_DEVICE 0x0080
  485. #define L2CAP_CONF_EXT_WIN_RECV 0x0100
  486. #define L2CAP_CONF_LOCKSTEP 0x0200
  487. #define L2CAP_CONF_LOCKSTEP_PEND 0x0400
  488. #define L2CAP_CONF_PEND_SENT 0x0800
  489. #define L2CAP_CONF_EFS_RECV 0x1000
  490. #define L2CAP_CONF_MAX_CONF_REQ 2
  491. #define L2CAP_CONF_MAX_CONF_RSP 2
  492. #define L2CAP_RECONF_NONE 0x00
  493. #define L2CAP_RECONF_INT 0x01
  494. #define L2CAP_RECONF_ACC 0x02
  495. #define L2CAP_CONN_SREJ_ACT 0x01
  496. #define L2CAP_CONN_REJ_ACT 0x02
  497. #define L2CAP_CONN_REMOTE_BUSY 0x04
  498. #define L2CAP_CONN_LOCAL_BUSY 0x08
  499. #define L2CAP_CONN_SEND_FBIT 0x10
  500. #define L2CAP_CONN_SENT_RNR 0x20
  501. #define L2CAP_SEQ_LIST_CLEAR 0xFFFF
  502. #define L2CAP_SEQ_LIST_TAIL 0x8000
  503. #define L2CAP_ERTM_TX_STATE_XMIT 0x01
  504. #define L2CAP_ERTM_TX_STATE_WAIT_F 0x02
  505. #define L2CAP_ERTM_RX_STATE_RECV 0x01
  506. #define L2CAP_ERTM_RX_STATE_SREJ_SENT 0x02
  507. #define L2CAP_ERTM_RX_STATE_AMP_MOVE 0x03
  508. #define L2CAP_ERTM_RX_STATE_WAIT_P_FLAG 0x04
  509. #define L2CAP_ERTM_RX_STATE_WAIT_P_FLAG_RECONFIGURE 0x05
  510. #define L2CAP_ERTM_RX_STATE_WAIT_F_FLAG 0x06
  511. #define L2CAP_ERTM_TXSEQ_EXPECTED 0x00
  512. #define L2CAP_ERTM_TXSEQ_EXPECTED_SREJ 0x01
  513. #define L2CAP_ERTM_TXSEQ_UNEXPECTED 0x02
  514. #define L2CAP_ERTM_TXSEQ_UNEXPECTED_SREJ 0x03
  515. #define L2CAP_ERTM_TXSEQ_DUPLICATE 0x04
  516. #define L2CAP_ERTM_TXSEQ_DUPLICATE_SREJ 0x05
  517. #define L2CAP_ERTM_TXSEQ_INVALID 0x06
  518. #define L2CAP_ERTM_TXSEQ_INVALID_IGNORE 0x07
  519. #define L2CAP_ERTM_EVENT_DATA_REQUEST 0x01
  520. #define L2CAP_ERTM_EVENT_LOCAL_BUSY_DETECTED 0x02
  521. #define L2CAP_ERTM_EVENT_LOCAL_BUSY_CLEAR 0x03
  522. #define L2CAP_ERTM_EVENT_RECV_REQSEQ_AND_FBIT 0x04
  523. #define L2CAP_ERTM_EVENT_RECV_FBIT 0x05
  524. #define L2CAP_ERTM_EVENT_RETRANS_TIMER_EXPIRES 0x06
  525. #define L2CAP_ERTM_EVENT_MONITOR_TIMER_EXPIRES 0x07
  526. #define L2CAP_ERTM_EVENT_EXPLICIT_POLL 0x08
  527. #define L2CAP_ERTM_EVENT_RECV_IFRAME 0x09
  528. #define L2CAP_ERTM_EVENT_RECV_RR 0x0a
  529. #define L2CAP_ERTM_EVENT_RECV_REJ 0x0b
  530. #define L2CAP_ERTM_EVENT_RECV_RNR 0x0c
  531. #define L2CAP_ERTM_EVENT_RECV_SREJ 0x0d
  532. #define L2CAP_ERTM_EVENT_RECV_FRAME 0x0e
  533. #define L2CAP_AMP_MOVE_NONE 0
  534. #define L2CAP_AMP_MOVE_INITIATOR 1
  535. #define L2CAP_AMP_MOVE_RESPONDER 2
  536. #define L2CAP_AMP_STATE_STABLE 0
  537. #define L2CAP_AMP_STATE_WAIT_CREATE 1
  538. #define L2CAP_AMP_STATE_WAIT_CREATE_RSP 2
  539. #define L2CAP_AMP_STATE_WAIT_MOVE 3
  540. #define L2CAP_AMP_STATE_WAIT_MOVE_RSP 4
  541. #define L2CAP_AMP_STATE_WAIT_MOVE_RSP_SUCCESS 5
  542. #define L2CAP_AMP_STATE_WAIT_MOVE_CONFIRM 6
  543. #define L2CAP_AMP_STATE_WAIT_MOVE_CONFIRM_RSP 7
  544. #define L2CAP_AMP_STATE_WAIT_LOGICAL_COMPLETE 8
  545. #define L2CAP_AMP_STATE_WAIT_LOGICAL_CONFIRM 9
  546. #define L2CAP_AMP_STATE_WAIT_LOCAL_BUSY 10
  547. #define L2CAP_AMP_STATE_WAIT_PREPARE 11
  548. #define L2CAP_AMP_STATE_RESEGMENT 12
  549. #define L2CAP_ATT_ERROR 0x01
  550. #define L2CAP_ATT_MTU_REQ 0x02
  551. #define L2CAP_ATT_MTU_RSP 0x03
  552. #define L2CAP_ATT_RESPONSE_BIT 0x01
  553. #define L2CAP_ATT_INDICATE 0x1D
  554. #define L2CAP_ATT_CONFIRM 0x1E
  555. #define L2CAP_ATT_NOT_SUPPORTED 0x06
  556. #define __delta_seq(x, y, pi) ((x) >= (y) ? (x) - (y) : \
  557. (pi)->tx_win_max + 1 - (y) + (x))
  558. #define __next_seq(x, pi) ((x + 1) & ((pi)->tx_win_max))
  559. extern bool disable_ertm;
  560. extern const struct proto_ops l2cap_sock_ops;
  561. extern struct bt_sock_list l2cap_sk_list;
  562. int l2cap_init_sockets(void);
  563. void l2cap_cleanup_sockets(void);
  564. bool l2cap_is_socket(struct socket *sock);
  565. u8 l2cap_get_ident(struct l2cap_conn *conn);
  566. void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data);
  567. int l2cap_build_conf_req(struct sock *sk, void *data, size_t data_size);
  568. int __l2cap_wait_ack(struct sock *sk);
  569. struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len);
  570. struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len);
  571. struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg,
  572. size_t len, u16 sdulen, int reseg);
  573. int l2cap_segment_sdu(struct sock *sk, struct sk_buff_head* seg_queue,
  574. struct msghdr *msg, size_t len, int reseg);
  575. int l2cap_resegment_queue(struct sock *sk, struct sk_buff_head *queue);
  576. void l2cap_do_send(struct sock *sk, struct sk_buff *skb);
  577. void l2cap_streaming_send(struct sock *sk);
  578. int l2cap_ertm_send(struct sock *sk);
  579. int l2cap_strm_tx(struct sock *sk, struct sk_buff_head *skbs);
  580. int l2cap_ertm_tx(struct sock *sk, struct bt_l2cap_control *control,
  581. struct sk_buff_head *skbs, u8 event);
  582. int l2cap_sock_le_params_valid(struct bt_le_params *le_params);
  583. void l2cap_sock_set_timer(struct sock *sk, long timeout);
  584. void l2cap_sock_clear_timer(struct sock *sk);
  585. void __l2cap_sock_close(struct sock *sk, int reason);
  586. void l2cap_sock_kill(struct sock *sk);
  587. void l2cap_sock_init(struct sock *sk, struct sock *parent);
  588. struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
  589. int proto, gfp_t prio);
  590. struct sock *l2cap_find_sock_by_fixed_cid_and_dir(__le16 cid, bdaddr_t *src,
  591. bdaddr_t *dst, int server);
  592. void l2cap_send_disconn_req(struct l2cap_conn *conn, struct sock *sk, int err);
  593. void l2cap_chan_del(struct sock *sk, int err);
  594. int l2cap_do_connect(struct sock *sk);
  595. int l2cap_data_channel(struct sock *sk, struct sk_buff *skb);
  596. void l2cap_amp_move_init(struct sock *sk);
  597. void l2cap_ertm_destruct(struct sock *sk);
  598. void l2cap_ertm_shutdown(struct sock *sk);
  599. void l2cap_ertm_recv_done(struct sock *sk);
  600. void l2cap_fixed_channel_config(struct sock *sk, struct l2cap_options *opt);
  601. void l2cap_recv_deferred_frame(struct sock *sk, struct sk_buff *skb);
  602. void l2cap_amp_physical_complete(int result, u8 remote_id, u8 local_id,
  603. struct sock *sk);
  604. void l2cap_amp_logical_complete(int result, struct hci_conn *ampcon,
  605. struct hci_chan *ampchan, struct sock *sk);
  606. void l2cap_amp_logical_destroyed(struct hci_conn *ampcon);
  607. #endif /* __L2CAP_H */