hci_transport.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /**@file
  13. *
  14. * @defgroup hci_transport HCI Transport
  15. * @{
  16. * @ingroup app_common
  17. *
  18. * @brief HCI transport module implementation.
  19. *
  20. * This module implements certain specific features from the three-wire UART transport layer,
  21. * defined by the Bluetooth specification version 4.0 [Vol 4] part D.
  22. *
  23. * \par Features supported
  24. * - Transmission and reception of Vendor Specific HCI packet type application packets.
  25. * - Transmission and reception of reliable packets: defined by chapter 6 of the specification.
  26. *
  27. * \par Features not supported
  28. * - Link establishment procedure: defined by chapter 8 of the specification.
  29. * - Low power: defined by chapter 9 of the specification.
  30. *
  31. * \par Implementation specific behaviour
  32. * - As Link establishment procedure is not supported following static link configuration parameters
  33. * are used:
  34. * + TX window size is 1.
  35. * + 16 bit CCITT-CRC must be used.
  36. * + Out of frame software flow control not supported.
  37. * + Parameters specific for resending reliable packets are compile time configurable (clarifed
  38. * later in this document).
  39. * + Acknowledgement packet transmissions are not timeout driven , meaning they are delivered for
  40. * transmission within same context which the corresponding application packet was received.
  41. *
  42. * \par Implementation specific limitations
  43. * Current implementation has the following limitations which will have impact to system wide
  44. * behaviour:
  45. * - Delayed acknowledgement scheduling not implemented:
  46. * There exists a possibility that acknowledgement TX packet and application TX packet will collide
  47. * in the TX pipeline having the end result that acknowledgement packet will be excluded from the TX
  48. * pipeline which will trigger the retransmission algorithm within the peer protocol entity.
  49. * - Delayed retransmission scheduling not implemented:
  50. * There exists a possibility that retransmitted application TX packet and acknowledgement TX packet
  51. * will collide in the TX pipeline having the end result that retransmitted application TX packet
  52. * will be excluded from the TX pipeline.
  53. * - Processing of the acknowledgement number from RX application packets:
  54. * Acknowledgement number is not processed from the RX application packets having the end result
  55. * that unnecessary application packet retransmissions can occur.
  56. *
  57. * The application TX packet processing flow is illustrated by the statemachine below.
  58. *
  59. * @image html hci_transport_tx_sm.png "TX - application packet statemachine"
  60. *
  61. * \par Component specific configuration options
  62. *
  63. * The following compile time configuration options are available, and used to configure the
  64. * application TX packet retransmission interval, in order to suite various application specific
  65. * implementations:
  66. * - MAC_PACKET_SIZE_IN_BITS Maximum size of a single application packet in bits.
  67. * - USED_BAUD_RATE Used uart baudrate.
  68. *
  69. * The following compile time configuration option is available to configure module specific
  70. * behaviour:
  71. * - MAX_RETRY_COUNT Max retransmission retry count for applicaton packets.
  72. */
  73. #ifndef HCI_TRANSPORT_H__
  74. #define HCI_TRANSPORT_H__
  75. #include <stdint.h>
  76. #include "nrf_error.h"
  77. /**@brief Generic event callback function events. */
  78. typedef enum
  79. {
  80. HCI_TRANSPORT_RX_RDY, /**< An event indicating that RX packet is ready for read. */
  81. HCI_TRANSPORT_EVT_TYPE_MAX /**< Enumeration upper bound. */
  82. } hci_transport_evt_type_t;
  83. /**@brief Struct containing events from the Transport layer.
  84. */
  85. typedef struct
  86. {
  87. hci_transport_evt_type_t evt_type; /**< Type of event. */
  88. } hci_transport_evt_t;
  89. /**@brief Transport layer generic event callback function type.
  90. *
  91. * @param[in] event Transport layer event.
  92. */
  93. typedef void (*hci_transport_event_handler_t)(hci_transport_evt_t event);
  94. /**@brief TX done event callback function result codes. */
  95. typedef enum
  96. {
  97. HCI_TRANSPORT_TX_DONE_SUCCESS, /**< Transmission success, peer transport entity has acknowledged the transmission. */
  98. HCI_TRANSPORT_TX_DONE_FAILURE /**< Transmission failure. */
  99. } hci_transport_tx_done_result_t;
  100. /**@brief Transport layer TX done event callback function type.
  101. *
  102. * @param[in] result TX done event result code.
  103. */
  104. typedef void (*hci_transport_tx_done_handler_t)(hci_transport_tx_done_result_t result);
  105. /**@brief Function for registering a generic event handler.
  106. *
  107. * @note Multiple registration requests will overwrite any possible existing registration.
  108. *
  109. * @param[in] event_handler The function to be called by the transport layer upon an event.
  110. *
  111. * @retval NRF_SUCCESS Operation success.
  112. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
  113. */
  114. uint32_t hci_transport_evt_handler_reg(hci_transport_event_handler_t event_handler);
  115. /**@brief Function for registering a handler for TX done event.
  116. *
  117. * @note Multiple registration requests will overwrite any possible existing registration.
  118. *
  119. * @param[in] event_handler The function to be called by the transport layer upon TX done
  120. * event.
  121. *
  122. * @retval NRF_SUCCESS Operation success.
  123. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
  124. */
  125. uint32_t hci_transport_tx_done_register(hci_transport_tx_done_handler_t event_handler);
  126. /**@brief Function for opening the transport channel and initializing the transport layer.
  127. *
  128. * @warning Must not be called for a channel which has been allready opened.
  129. *
  130. * @retval NRF_SUCCESS Operation success.
  131. * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred.
  132. */
  133. uint32_t hci_transport_open(void);
  134. /**@brief Function for closing the transport channel.
  135. *
  136. * @note Can be called multiple times and also for not opened channel.
  137. *
  138. * @retval NRF_SUCCESS Operation success.
  139. */
  140. uint32_t hci_transport_close(void);
  141. /**@brief Function for allocating tx packet memory.
  142. *
  143. * @param[out] pp_memory Pointer to the packet data.
  144. *
  145. * @retval NRF_SUCCESS Operation success. Memory was allocated.
  146. * @retval NRF_ERROR_NO_MEM Operation failure. No memory available.
  147. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
  148. */
  149. uint32_t hci_transport_tx_alloc(uint8_t ** pp_memory);
  150. /**@brief Function for freeing tx packet memory.
  151. *
  152. * @note Memory management works in FIFO principle meaning that free order must match the alloc
  153. * order.
  154. *
  155. * @retval NRF_SUCCESS Operation success. Memory was freed.
  156. */
  157. uint32_t hci_transport_tx_free(void);
  158. /**@brief Function for writing a packet.
  159. *
  160. * @note Completion of this method does not guarantee that actual peripheral transmission would
  161. * have completed.
  162. *
  163. * @note In case of 0 byte packet length write request, message will consist of only transport
  164. * module specific headers.
  165. *
  166. * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue
  167. * and an event will be send upon transmission completion.
  168. * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
  169. * added to the transmission queue. User should wait for
  170. * a appropriate event prior issuing this operation again.
  171. * @retval NRF_ERROR_DATA_SIZE Operation failure. Packet size exceeds limit.
  172. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
  173. * @retval NRF_ERROR_INVALID_STATE Operation failure. Channel is not open.
  174. */
  175. uint32_t hci_transport_pkt_write(const uint8_t * p_buffer, uint16_t length);
  176. /**@brief Function for extracting received packet.
  177. *
  178. * @note Extracted memory can't be reused by the underlying transport layer untill freed by call to
  179. * hci_transport_rx_pkt_consume().
  180. *
  181. * @param[out] pp_buffer Pointer to the packet data.
  182. * @param[out] p_length Length of packet data in bytes.
  183. *
  184. * @retval NRF_SUCCESS Operation success. Packet was extracted.
  185. * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to extract.
  186. * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
  187. */
  188. uint32_t hci_transport_rx_pkt_extract(uint8_t ** pp_buffer, uint16_t * p_length);
  189. /**@brief Function for consuming extracted packet described by p_buffer.
  190. *
  191. * RX memory pointed to by p_buffer is freed and can be reused by the underlying transport layer.
  192. *
  193. * @param[in] p_buffer Pointer to the buffer that has been consumed.
  194. *
  195. * @retval NRF_SUCCESS Operation success.
  196. * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to consume.
  197. * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer.
  198. */
  199. uint32_t hci_transport_rx_pkt_consume(uint8_t * p_buffer);
  200. #endif // HCI_TRANSPORT_H__
  201. /** @} */