ble_ipsp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**
  2. * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /** @file
  41. *
  42. * @defgroup ble_ipsp Internet Protocol Support Profile
  43. * @{
  44. * @ingroup ble_sdk_srv
  45. * @brief Internet Protocol Support Profile.
  46. *
  47. * @details This module implements the Internet Protocol Support Profile creating and managing
  48. * transport for 6lowpan.
  49. * GATT is used to discover if IPSP is supported or not, but no IP data is exchanged
  50. * over GATT. To exchange data, LE L2CAP Credit Mode is used. The PSM used for the channel
  51. * is BLE_IPSP_PSM and is defined by the specification. The MTU mandated by the
  52. * specification is 1280 bytes.
  53. *
  54. * @note Attention!
  55. * To maintain compliance with Nordic Semiconductor ASA's Bluetooth profile
  56. * qualification listings, this section of source code must not be modified.
  57. */
  58. #ifndef BLE_IPSP_H__
  59. #define BLE_IPSP_H__
  60. #include <stdint.h>
  61. #include "ble.h"
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. /**@brief Maximum IPSP channels required to be supported. */
  66. #define BLE_IPSP_MAX_CHANNELS 1
  67. /**@brief Maximum Transmit Unit on IPSP channel. */
  68. #define BLE_IPSP_MTU 1280
  69. /**@brief Receive MPS used by IPSP. */
  70. #define BLE_IPSP_RX_MPS 50
  71. /**@brief Transmission MPS used by IPSP.
  72. *
  73. * @note The actual MPS used is minimum of this value and the one requested by
  74. * the peer during the channel setup. Here, the value used is
  75. * (23 + 27 * 7).
  76. */
  77. #define BLE_IPSP_TX_MPS 212
  78. /**@brief Maximum data size that can be received.
  79. *
  80. * @details Maximum data size that can be received on the IPSP channel.
  81. * Modify this values to intentionally set a receive size less
  82. * than the MTU set on the channel.
  83. */
  84. #define BLE_IPSP_RX_BUFFER_SIZE 1280
  85. /**@brief Maximum number of receive buffers.
  86. *
  87. * @details Maximum number of receive buffers to be used per IPSP channel.
  88. * Each receive buffer is of size @ref BLE_IPSP_RX_BUFFER_SIZE.
  89. * This configuration has implications on the number of SDUs that can
  90. * be received while an SDU is being consumed by the application
  91. * (6LoWPAN/IP Stack).
  92. */
  93. #define BLE_IPSP_RX_BUFFER_COUNT 4
  94. /**@brief L2CAP Protocol Service Multiplexers number. */
  95. #define BLE_IPSP_PSM 0x0023
  96. /**@brief IPSP event identifier type. */
  97. typedef enum
  98. {
  99. BLE_IPSP_EVT_CHANNEL_CONNECTED, /**< Channel connection event. */
  100. BLE_IPSP_EVT_CHANNEL_DISCONNECTED, /**< Channel disconnection event. */
  101. BLE_IPSP_EVT_CHANNEL_DATA_RX, /**< Data received on channel event. */
  102. BLE_IPSP_EVT_CHANNEL_DATA_TX_COMPLETE /**< Requested data transmission complete on channel event. */
  103. } ble_ipsp_evt_type_t;
  104. /**@brief IPSP event parameter. */
  105. typedef struct
  106. {
  107. ble_l2cap_evt_t const * p_l2cap_evt; /**< L2CAP event parameters. */
  108. ble_gap_addr_t const * p_peer; /**< Peer device address. */
  109. } ble_ipsp_event_param_t;
  110. /**@brief IPSP event and associated parameter type. */
  111. typedef struct
  112. {
  113. ble_ipsp_evt_type_t evt_id; /**< Identifier event type. */
  114. ble_ipsp_event_param_t * p_evt_param; /**< Parameters associated with the event. */
  115. uint32_t evt_result; /**< Result of the event.
  116. \n The event result is SDK_ERR_RX_PKT_TRUNCATED for @ref BLE_IPSP_EVT_CHANNEL_DATA_RX,
  117. \n implies that an incomplete SDU was received due to insufficient RX buffer size.
  118. \n The size determined by @ref BLE_IPSP_RX_BUFFER_SIZE. */
  119. } ble_ipsp_evt_t;
  120. /**@brief IPSP handle. */
  121. typedef struct
  122. {
  123. uint16_t conn_handle; /**< Identifies the link on which the IPSP channel is established. */
  124. uint16_t cid; /**< Identifies the IPSP logical channel. */
  125. } ble_ipsp_handle_t;
  126. /**@brief Profile event handler type.
  127. *
  128. * @param[in] p_handle Identifies the connection and channel on which the event occurred.
  129. * @param[in] p_evt Event and related parameters (if any).
  130. *
  131. * @returns Provision for the application to indicate if the event was successfully processed or
  132. * not. Currently not used.
  133. */
  134. typedef uint32_t (*ble_ipsp_evt_handler_t) (ble_ipsp_handle_t const * p_handle,
  135. ble_ipsp_evt_t const * p_evt);
  136. /**@brief IPSP initialization structure.
  137. *
  138. * @details IPSP initialization structure containing all options and data needed to
  139. * initialize the profile.
  140. */
  141. typedef struct
  142. {
  143. ble_ipsp_evt_handler_t evt_handler; /**< Event notification callback registered with the module to receive asynchronous events. */
  144. } ble_ipsp_init_t;
  145. /**@brief Function for initializing the Internet Protocol Support Profile.
  146. *
  147. * @param[in] p_init Information needed to initialize the service.
  148. *
  149. * @retval NRF_SUCCESS If initialization of the service was successful, else,
  150. * an error code indicating reason for failure.
  151. */
  152. uint32_t ble_ipsp_init(ble_ipsp_init_t const * p_init);
  153. /**@brief Function for requesting a channel creation for the Internet Protocol Support Profile.
  154. *
  155. * @details Channel creation for Internet Protocol Support Profile (IPSP) is requested using this
  156. * API. Connection handle provided in p_handle parameter identifies the peer with which
  157. * the IPSP channel is being requested.
  158. * NRF_SUCCESS return value by the API is only indicative of request procedure having
  159. * succeeded. Result of channel establishment is known when the
  160. * @ref BLE_IPSP_EVT_CHANNEL_CONNECTED event is notified.
  161. * Therefore, the application must wait for @ref BLE_IPSP_EVT_CHANNEL_CONNECTED event on
  162. * successful return of this API.
  163. *
  164. * @param[in] p_handle Indicates the connection handle on which IPSP channel is to be created.
  165. *
  166. * @retval NRF_SUCCESS If initialization of the service was successful, else,
  167. * an error code indicating reason for failure.
  168. */
  169. uint32_t ble_ipsp_connect(ble_ipsp_handle_t const * p_handle);
  170. /**@brief Function for sending IP data to peer.
  171. *
  172. * @param[in] p_handle Instance of the logical channel and peer for which the data is intended.
  173. * @param[in] p_data Pointer to memory containing the data to be transmitted.
  174. * @note This memory must be resident and should not be freed unless
  175. * @ref BLE_IPSP_EVT_CHANNEL_DATA_TX_COMPLETE event is notified.
  176. * @param[in] data_len Length/size of data to be transferred.
  177. *
  178. * @retval NRF_SUCCESS If initialization of the service was successful, else,
  179. * an error code indicating reason for failure.
  180. */
  181. uint32_t ble_ipsp_send(ble_ipsp_handle_t const * p_handle,
  182. uint8_t const * p_data,
  183. uint16_t data_len);
  184. /**@brief Function for disconnecting IP transport.
  185. *
  186. * @param[in] p_handle Identifies IPSP transport.
  187. *
  188. * @retval NRF_SUCCESS If initialization of the service was successful, else,
  189. * an error code indicating reason for failure.
  190. */
  191. uint32_t ble_ipsp_disconnect(ble_ipsp_handle_t const * p_handle);
  192. /**@brief Function to accept incoming connections from a peer.
  193. *
  194. * @param[in] conn_handle Identifies the link with the peer.
  195. */
  196. void ble_ipsp_incoming_channel_accept(uint16_t conn_handle);
  197. /**@brief Function to reject incoming connections from a peer.
  198. *
  199. * @param[in] conn_handle Identifies the link with the peer.
  200. */
  201. void ble_ipsp_incoming_channel_reject(uint16_t conn_handle);
  202. /**@brief BLE event handler of the module.
  203. *
  204. * @param[in] p_evt BLE event to be handled.
  205. *
  206. * @retval NRF_SUCCESS If initialization of the service was successful, else,
  207. * an error code indicating reason for failure.
  208. */
  209. void ble_ipsp_evt_handler(ble_evt_t const * p_evt);
  210. #ifdef __cplusplus
  211. }
  212. #endif
  213. #endif // BLE_IPSP_H__
  214. /** @} */