bt_l2cap.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /****************************************************************************
  2. * wireless/bluetooth/bt_l2cap.h
  3. * L2CAP handling
  4. *
  5. * Copyright (C) 2018 Gregory Nutt. All rights reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Ported from the Intel/Zephyr arduino101_firmware_source-v1.tar package
  9. * where the code was released with a compatible 3-clause BSD license:
  10. *
  11. * Copyright (c) 2016, Intel Corporation
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are
  16. * met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. *
  21. * 2. Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. *
  25. * 3. Neither the name of the copyright holder nor the names of its
  26. * contributors may be used to endorse or promote products derived from
  27. * this software without specific prior written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  31. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  32. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  33. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS
  36. * ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  37. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  38. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  39. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ****************************************************************************/
  42. #ifndef __WIRELESS_BLUETOOTH_BT_L2CAP_H
  43. #define __WIRELESS_BLUETOOTH_BT_L2CAP_H
  44. /****************************************************************************
  45. * Included Files
  46. ****************************************************************************/
  47. /****************************************************************************
  48. * Pre-processor Definitions
  49. ****************************************************************************/
  50. #define BT_L2CAP_CID_ATT 0x0004
  51. #define BT_L2CAP_CID_LE_SIG 0x0005
  52. #define BT_L2CAP_CID_SMP 0x0006
  53. #define BT_L2CAP_REJ_NOT_UNDERSTOOD 0x0000
  54. #define BT_L2CAP_REJ_MTU_EXCEEDED 0x0001
  55. #define BT_L2CAP_REJ_INVALID_CID 0x0002
  56. #define BT_L2CAP_CMD_REJECT 0x01
  57. #define BT_L2CAP_CONN_PARAM_REQ 0x12
  58. #define BT_L2CAP_CONN_PARAM_RSP 0x13
  59. /****************************************************************************
  60. * Public Types
  61. ****************************************************************************/
  62. begin_packed_struct struct bt_l2cap_hdr_s
  63. {
  64. uint16_t len;
  65. uint16_t cid;
  66. } end_packed_struct;
  67. begin_packed_struct struct bt_l2cap_sig_hdr_s
  68. {
  69. uint8_t code;
  70. uint8_t ident;
  71. uint16_t len;
  72. } end_packed_struct;
  73. begin_packed_struct struct bt_l2cap_cmd_reject_s
  74. {
  75. uint16_t reason;
  76. uint8_t data[0];
  77. } end_packed_struct;
  78. begin_packed_struct struct bt_l2cap_conn_param_req_s
  79. {
  80. uint16_t min_interval;
  81. uint16_t max_interval;
  82. uint16_t latency;
  83. uint16_t timeout;
  84. } end_packed_struct;
  85. begin_packed_struct struct bt_l2cap_conn_param_rsp_s
  86. {
  87. uint16_t result;
  88. } end_packed_struct;
  89. struct bt_l2cap_chan_s
  90. {
  91. FAR struct bt_l2cap_chan_s *flink;
  92. FAR void *context;
  93. uint16_t cid;
  94. CODE void (*connected)(FAR struct bt_conn_s *conn,
  95. FAR void *context, uint16_t cid);
  96. CODE void (*disconnected)(FAR struct bt_conn_s *conn, FAR void *context,
  97. uint16_t cid);
  98. CODE void (*encrypt_change)(FAR struct bt_conn_s *conn,
  99. FAR void *context, uint16_t cid);
  100. CODE void (*receive)(FAR struct bt_conn_s *conn, FAR struct bt_buf_s *buf,
  101. FAR void *context, uint16_t cid);
  102. };
  103. /****************************************************************************
  104. * Public Function Prototypes
  105. ****************************************************************************/
  106. /* Register a fixed L2CAP channel handler for L2CAP */
  107. void bt_l2cap_chan_register(FAR struct bt_l2cap_chan_s *chan);
  108. /* Register a default L2CAP channel handle for L2CAP */
  109. void bt_l2cap_chan_default(FAR struct bt_l2cap_chan_s *chan);
  110. /* Notify L2CAP channels of a new connection */
  111. void bt_l2cap_connected(FAR struct bt_conn_s *conn);
  112. /* Notify L2CAP channels of a disconnect event */
  113. void bt_l2cap_disconnected(FAR struct bt_conn_s *conn);
  114. /* Notify L2CAP channels of a change in encryption state */
  115. void bt_l2cap_encrypt_change(FAR struct bt_conn_s *conn);
  116. /* Prepare an L2CAP PDU to be sent over a connection */
  117. FAR struct bt_buf_s *bt_l2cap_create_pdu(FAR struct bt_conn_s *conn);
  118. /* Send L2CAP PDU over a connection */
  119. void bt_l2cap_send(FAR struct bt_conn_s *conn, uint16_t cid,
  120. FAR struct bt_buf_s *buf);
  121. /* Receive a new L2CAP PDU from a connection */
  122. void bt_l2cap_receive(FAR struct bt_conn_s *conn, FAR struct bt_buf_s *buf);
  123. /* Perform connection parameter update request */
  124. void bt_l2cap_update_conn_param(FAR struct bt_conn_s *conn);
  125. /* Initialize L2CAP and supported channels */
  126. int bt_l2cap_init(void);
  127. #endif /* __WIRELESS_BLUETOOTH_BT_L2CAP_H */