ble_6lowpan.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * Copyright (c) 2014 - 2019, 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 ble_6lowpan.h
  41. *
  42. * @defgroup ble_6lowpan BLE 6LoWPAN library
  43. * @ingroup iot_sdk_6lowpan
  44. * @{
  45. * @brief 6LoWPAN techniques defined for BLE.
  46. *
  47. * @details This module implements 6LoWPAN techniques defined for BLE, including
  48. * IP and UDP header compression and decompression and conversion of EUI-48 BLE
  49. * addresses to EUI-64 and on to IPv6 addresses. This layer does not implement IP level
  50. * functionality of neighbor discovery etc.
  51. * @note Currently, only the 6LoWPAN node (host) role is supported.
  52. */
  53. #ifndef BLE_6LOWPAN_H__
  54. #define BLE_6LOWPAN_H__
  55. #include <stdint.h>
  56. #include "iot_defines.h"
  57. #include "iot_common.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /**@brief Maximum 6LoWPAN interface supported by module. */
  62. #define BLE_6LOWPAN_MAX_INTERFACE 1
  63. /**@brief Maximum transmit packets that are buffered per interface.
  64. *
  65. * @details FIFO size must be a power of 2.
  66. */
  67. #define BLE_6LOWPAN_TX_FIFO_SIZE 16
  68. /**@brief Asynchronous event identifiers type. */
  69. typedef enum
  70. {
  71. BLE_6LO_EVT_ERROR, /**< Notification of an error in the module. */
  72. BLE_6LO_EVT_INTERFACE_ADD, /**< Notification of a new 6LoWPAN interface added. */
  73. BLE_6LO_EVT_INTERFACE_DELETE, /**< Notification of a 6LoWPAN interface deleted. */
  74. BLE_6LO_EVT_INTERFACE_DATA_RX, /**< Notification of an IP packet received on the interface. */
  75. } ble_6lowpan_event_id_t;
  76. /**@brief Event parameters associated with the BLE_6LO_EVT_INTERFACE_DATA_RX event. */
  77. typedef struct
  78. {
  79. uint8_t * p_packet; /**< Uncompressed IPv6 packet received. This memory is available to the application until it is freed by the application using mem_free. */
  80. uint16_t packet_len; /**< Length of IPv6 packet. */
  81. iot_context_id_t rx_contexts; /**< RX contexts used in stateful decompression. IPV6_CONTEXT_IDENTIFIER_NONE if not used. */
  82. } ble_6lowpan_data_rx_t;
  83. /**@brief Asynchronous event parameter type. */
  84. typedef union
  85. {
  86. ble_6lowpan_data_rx_t rx_event_param; /**< Parameters notified with the received packet. */
  87. } ble_6lowpan_event_param_t;
  88. /**@brief Asynchronous event type. */
  89. typedef struct
  90. {
  91. ble_6lowpan_event_id_t event_id; /**< Event identifier. */
  92. ble_6lowpan_event_param_t event_param; /**< Event parameters. */
  93. uint32_t event_result; /**< Result of event being notified. */
  94. } ble_6lowpan_event_t;
  95. /**@brief Asynchronous event notification callback type. */
  96. typedef void (*ble_6lowpan_evt_handler_t)(iot_interface_t * p_interface,
  97. ble_6lowpan_event_t * p_event);
  98. /**@brief Initialization parameters type. */
  99. typedef struct
  100. {
  101. eui64_t * p_eui64; /**< EUI-64 address. */
  102. ble_6lowpan_evt_handler_t event_handler; /**< Asynchronous event notification callback registered to receive 6LoWPAN events. */
  103. } ble_6lowpan_init_t;
  104. /**@brief Initializes the module.
  105. *
  106. * @param[in] p_init Initialization parameters.
  107. *
  108. * @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
  109. */
  110. uint32_t ble_6lowpan_init(const ble_6lowpan_init_t * p_init);
  111. /**@brief Disconnects 6LoWPAN interface.
  112. *
  113. * @details This function is used to terminate connection on the L2CAP CoC layer. It calls
  114. * \ref ble_ipsp_disconnect to perform disconnection procedure. The registered callback
  115. * from 6LoWPAN module propagates \ref BLE_6LO_EVT_INTERFACE_DELETE event after
  116. * operation is finished.
  117. *
  118. * @param[in] p_interface Identifies the interface on which the disconnection has to be performed.
  119. *
  120. * @retval NRF_SUCCESS If disconnection was successful. Otherwise, an error code is returned.
  121. */
  122. uint32_t ble_6lowpan_interface_disconnect(const iot_interface_t * p_interface);
  123. /**@brief Sends IPv6 packet on the 6LoWPAN interface.
  124. *
  125. * @details This function is used to send an IPv6 packet on the interface. 6LoWPAN compression
  126. * techniques are applied on the packet before the packet is transmitted. The packet might
  127. * not be transferred to the peer immediately based on the flow control on the BLE Link.
  128. * In this case, the packet is queued to be transferred later.
  129. *
  130. * @param[in] p_interface Identifies the interface on which the packet is to be sent.
  131. * @param[in] p_packet IPv6 packet to be sent. Memory for the packet should be allocated
  132. * using mem_alloc and should not be freed. The module is responsible for
  133. * freeing the memory using mem_free. The module will free the packet once
  134. * the transmission is complete or the packet can no longer be transmitted
  135. * (in case of link disconnection.)
  136. * @param[in] packet_len Length of the IPv6 packet.
  137. *
  138. * @retval NRF_SUCCESS If the send request was successful.
  139. */
  140. uint32_t ble_6lowpan_interface_send(const iot_interface_t * p_interface,
  141. const uint8_t * p_packet,
  142. uint16_t packet_len);
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif //BLE_6LOWPAN_H__
  147. /** @} */