Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
TARGET_MCU_NRF51822/sdk/source/softdevice/s130/headers/ble_l2cap.h@640:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 640:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
640:c90ae1400bf2 | 1 | /* |
Vincent Coubard |
640:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
640:c90ae1400bf2 | 3 | * All rights reserved. |
Vincent Coubard |
640:c90ae1400bf2 | 4 | * |
Vincent Coubard |
640:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
640:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
640:c90ae1400bf2 | 7 | * |
Vincent Coubard |
640:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
640:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
640:c90ae1400bf2 | 10 | * |
Vincent Coubard |
640:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
640:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
640:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
640:c90ae1400bf2 | 14 | * |
Vincent Coubard |
640:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
640:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
640:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
640:c90ae1400bf2 | 18 | * |
Vincent Coubard |
640:c90ae1400bf2 | 19 | * |
Vincent Coubard |
640:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
640:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
640:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
640:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
640:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
640:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
640:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
640:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
640:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
640:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
640:c90ae1400bf2 | 30 | * |
Vincent Coubard |
640:c90ae1400bf2 | 31 | */ |
Vincent Coubard |
640:c90ae1400bf2 | 32 | |
Vincent Coubard |
640:c90ae1400bf2 | 33 | /** |
Vincent Coubard |
640:c90ae1400bf2 | 34 | @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP) |
Vincent Coubard |
640:c90ae1400bf2 | 35 | @{ |
Vincent Coubard |
640:c90ae1400bf2 | 36 | @brief Definitions and prototypes for the L2CAP interface. |
Vincent Coubard |
640:c90ae1400bf2 | 37 | */ |
Vincent Coubard |
640:c90ae1400bf2 | 38 | |
Vincent Coubard |
640:c90ae1400bf2 | 39 | #ifndef BLE_L2CAP_H__ |
Vincent Coubard |
640:c90ae1400bf2 | 40 | #define BLE_L2CAP_H__ |
Vincent Coubard |
640:c90ae1400bf2 | 41 | |
Vincent Coubard |
640:c90ae1400bf2 | 42 | #include "ble_types.h" |
Vincent Coubard |
640:c90ae1400bf2 | 43 | #include "ble_ranges.h" |
Vincent Coubard |
640:c90ae1400bf2 | 44 | #include "ble_err.h" |
Vincent Coubard |
640:c90ae1400bf2 | 45 | #include "nrf_svc.h" |
Vincent Coubard |
640:c90ae1400bf2 | 46 | |
Vincent Coubard |
640:c90ae1400bf2 | 47 | /**@addtogroup BLE_L2CAP_ENUMERATIONS Enumerations |
Vincent Coubard |
640:c90ae1400bf2 | 48 | * @{ */ |
Vincent Coubard |
640:c90ae1400bf2 | 49 | |
Vincent Coubard |
640:c90ae1400bf2 | 50 | /**@brief L2CAP API SVC numbers. */ |
Vincent Coubard |
640:c90ae1400bf2 | 51 | enum BLE_L2CAP_SVCS |
Vincent Coubard |
640:c90ae1400bf2 | 52 | { |
Vincent Coubard |
640:c90ae1400bf2 | 53 | SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE, /**< Register a CID. */ |
Vincent Coubard |
640:c90ae1400bf2 | 54 | SD_BLE_L2CAP_CID_UNREGISTER, /**< Unregister a CID. */ |
Vincent Coubard |
640:c90ae1400bf2 | 55 | SD_BLE_L2CAP_TX /**< Transmit a packet. */ |
Vincent Coubard |
640:c90ae1400bf2 | 56 | }; |
Vincent Coubard |
640:c90ae1400bf2 | 57 | |
Vincent Coubard |
640:c90ae1400bf2 | 58 | /**@brief L2CAP Event IDs. */ |
Vincent Coubard |
640:c90ae1400bf2 | 59 | enum BLE_L2CAP_EVTS |
Vincent Coubard |
640:c90ae1400bf2 | 60 | { |
Vincent Coubard |
640:c90ae1400bf2 | 61 | BLE_L2CAP_EVT_RX = BLE_L2CAP_EVT_BASE /**< L2CAP packet received. */ |
Vincent Coubard |
640:c90ae1400bf2 | 62 | }; |
Vincent Coubard |
640:c90ae1400bf2 | 63 | |
Vincent Coubard |
640:c90ae1400bf2 | 64 | /** @} */ |
Vincent Coubard |
640:c90ae1400bf2 | 65 | |
Vincent Coubard |
640:c90ae1400bf2 | 66 | /**@addtogroup BLE_L2CAP_DEFINES Defines |
Vincent Coubard |
640:c90ae1400bf2 | 67 | * @{ */ |
Vincent Coubard |
640:c90ae1400bf2 | 68 | |
Vincent Coubard |
640:c90ae1400bf2 | 69 | /**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP |
Vincent Coubard |
640:c90ae1400bf2 | 70 | * @{ */ |
Vincent Coubard |
640:c90ae1400bf2 | 71 | #define BLE_ERROR_L2CAP_CID_IN_USE (NRF_L2CAP_ERR_BASE + 0x000) /**< CID already in use. */ |
Vincent Coubard |
640:c90ae1400bf2 | 72 | /** @} */ |
Vincent Coubard |
640:c90ae1400bf2 | 73 | |
Vincent Coubard |
640:c90ae1400bf2 | 74 | /**@brief Default L2CAP MTU. */ |
Vincent Coubard |
640:c90ae1400bf2 | 75 | #define BLE_L2CAP_MTU_DEF (23) |
Vincent Coubard |
640:c90ae1400bf2 | 76 | |
Vincent Coubard |
640:c90ae1400bf2 | 77 | /**@brief Invalid Channel Identifier. */ |
Vincent Coubard |
640:c90ae1400bf2 | 78 | #define BLE_L2CAP_CID_INVALID (0x0000) |
Vincent Coubard |
640:c90ae1400bf2 | 79 | |
Vincent Coubard |
640:c90ae1400bf2 | 80 | /**@brief Dynamic Channel Identifier base. */ |
Vincent Coubard |
640:c90ae1400bf2 | 81 | #define BLE_L2CAP_CID_DYN_BASE (0x0040) |
Vincent Coubard |
640:c90ae1400bf2 | 82 | |
Vincent Coubard |
640:c90ae1400bf2 | 83 | /**@brief Maximum amount of dynamic CIDs. */ |
Vincent Coubard |
640:c90ae1400bf2 | 84 | #define BLE_L2CAP_CID_DYN_MAX (8) |
Vincent Coubard |
640:c90ae1400bf2 | 85 | |
Vincent Coubard |
640:c90ae1400bf2 | 86 | /** @} */ |
Vincent Coubard |
640:c90ae1400bf2 | 87 | |
Vincent Coubard |
640:c90ae1400bf2 | 88 | /**@addtogroup BLE_L2CAP_STRUCTURES Structures |
Vincent Coubard |
640:c90ae1400bf2 | 89 | * @{ */ |
Vincent Coubard |
640:c90ae1400bf2 | 90 | |
Vincent Coubard |
640:c90ae1400bf2 | 91 | /**@brief Packet header format for L2CAP transmission. */ |
Vincent Coubard |
640:c90ae1400bf2 | 92 | typedef struct |
Vincent Coubard |
640:c90ae1400bf2 | 93 | { |
Vincent Coubard |
640:c90ae1400bf2 | 94 | uint16_t len; /**< Length of valid info in data member. */ |
Vincent Coubard |
640:c90ae1400bf2 | 95 | uint16_t cid; /**< Channel ID on which packet is transmitted. */ |
Vincent Coubard |
640:c90ae1400bf2 | 96 | } ble_l2cap_header_t; |
Vincent Coubard |
640:c90ae1400bf2 | 97 | |
Vincent Coubard |
640:c90ae1400bf2 | 98 | |
Vincent Coubard |
640:c90ae1400bf2 | 99 | /**@brief L2CAP Received packet event report. */ |
Vincent Coubard |
640:c90ae1400bf2 | 100 | typedef struct |
Vincent Coubard |
640:c90ae1400bf2 | 101 | { |
Vincent Coubard |
640:c90ae1400bf2 | 102 | ble_l2cap_header_t header; /**< L2CAP packet header. */ |
Vincent Coubard |
640:c90ae1400bf2 | 103 | uint8_t data[1]; /**< Packet data, variable length. */ |
Vincent Coubard |
640:c90ae1400bf2 | 104 | } ble_l2cap_evt_rx_t; |
Vincent Coubard |
640:c90ae1400bf2 | 105 | |
Vincent Coubard |
640:c90ae1400bf2 | 106 | |
Vincent Coubard |
640:c90ae1400bf2 | 107 | /**@brief L2CAP event callback event structure. */ |
Vincent Coubard |
640:c90ae1400bf2 | 108 | typedef struct |
Vincent Coubard |
640:c90ae1400bf2 | 109 | { |
Vincent Coubard |
640:c90ae1400bf2 | 110 | uint16_t conn_handle; /**< Connection Handle on which event occured. */ |
Vincent Coubard |
640:c90ae1400bf2 | 111 | union |
Vincent Coubard |
640:c90ae1400bf2 | 112 | { |
Vincent Coubard |
640:c90ae1400bf2 | 113 | ble_l2cap_evt_rx_t rx; /**< RX Event parameters. */ |
Vincent Coubard |
640:c90ae1400bf2 | 114 | } params; /**< Event Parameters. */ |
Vincent Coubard |
640:c90ae1400bf2 | 115 | } ble_l2cap_evt_t; |
Vincent Coubard |
640:c90ae1400bf2 | 116 | |
Vincent Coubard |
640:c90ae1400bf2 | 117 | /** @} */ |
Vincent Coubard |
640:c90ae1400bf2 | 118 | |
Vincent Coubard |
640:c90ae1400bf2 | 119 | /**@addtogroup BLE_L2CAP_FUNCTIONS Functions |
Vincent Coubard |
640:c90ae1400bf2 | 120 | * @{ */ |
Vincent Coubard |
640:c90ae1400bf2 | 121 | |
Vincent Coubard |
640:c90ae1400bf2 | 122 | /**@brief Register a CID with L2CAP. |
Vincent Coubard |
640:c90ae1400bf2 | 123 | * |
Vincent Coubard |
640:c90ae1400bf2 | 124 | * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID. |
Vincent Coubard |
640:c90ae1400bf2 | 125 | * |
Vincent Coubard |
640:c90ae1400bf2 | 126 | * @param[in] cid L2CAP CID. |
Vincent Coubard |
640:c90ae1400bf2 | 127 | * |
Vincent Coubard |
640:c90ae1400bf2 | 128 | * @retval ::NRF_SUCCESS Successfully registered a CID with the L2CAP layer. |
Vincent Coubard |
640:c90ae1400bf2 | 129 | * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE. |
Vincent Coubard |
640:c90ae1400bf2 | 130 | * @retval ::BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use. |
Vincent Coubard |
640:c90ae1400bf2 | 131 | * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. |
Vincent Coubard |
640:c90ae1400bf2 | 132 | */ |
Vincent Coubard |
640:c90ae1400bf2 | 133 | SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid)); |
Vincent Coubard |
640:c90ae1400bf2 | 134 | |
Vincent Coubard |
640:c90ae1400bf2 | 135 | /**@brief Unregister a CID with L2CAP. |
Vincent Coubard |
640:c90ae1400bf2 | 136 | * |
Vincent Coubard |
640:c90ae1400bf2 | 137 | * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer. |
Vincent Coubard |
640:c90ae1400bf2 | 138 | * |
Vincent Coubard |
640:c90ae1400bf2 | 139 | * @param[in] cid L2CAP CID. |
Vincent Coubard |
640:c90ae1400bf2 | 140 | * |
Vincent Coubard |
640:c90ae1400bf2 | 141 | * @retval ::NRF_SUCCESS Successfully unregistered the CID. |
Vincent Coubard |
640:c90ae1400bf2 | 142 | * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. |
Vincent Coubard |
640:c90ae1400bf2 | 143 | * @retval ::NRF_ERROR_NOT_FOUND CID not previously registered. |
Vincent Coubard |
640:c90ae1400bf2 | 144 | */ |
Vincent Coubard |
640:c90ae1400bf2 | 145 | SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid)); |
Vincent Coubard |
640:c90ae1400bf2 | 146 | |
Vincent Coubard |
640:c90ae1400bf2 | 147 | /**@brief Transmit an L2CAP packet. |
Vincent Coubard |
640:c90ae1400bf2 | 148 | * |
Vincent Coubard |
640:c90ae1400bf2 | 149 | * @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore |
Vincent Coubard |
640:c90ae1400bf2 | 150 | * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. |
Vincent Coubard |
640:c90ae1400bf2 | 151 | * Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details. |
Vincent Coubard |
640:c90ae1400bf2 | 152 | * |
Vincent Coubard |
640:c90ae1400bf2 | 153 | * @param[in] conn_handle Connection Handle. |
Vincent Coubard |
640:c90ae1400bf2 | 154 | * @param[in] p_header Pointer to a packet header containing length and CID. |
Vincent Coubard |
640:c90ae1400bf2 | 155 | * @param[in] p_data Pointer to the data to be transmitted. |
Vincent Coubard |
640:c90ae1400bf2 | 156 | * |
Vincent Coubard |
640:c90ae1400bf2 | 157 | * @retval ::NRF_SUCCESS Successfully queued an L2CAP packet for transmission. |
Vincent Coubard |
640:c90ae1400bf2 | 158 | * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
Vincent Coubard |
640:c90ae1400bf2 | 159 | * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register. |
Vincent Coubard |
640:c90ae1400bf2 | 160 | * @retval ::NRF_ERROR_NOT_FOUND CID not found. |
Vincent Coubard |
640:c90ae1400bf2 | 161 | * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. |
Vincent Coubard |
640:c90ae1400bf2 | 162 | * @retval ::BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available. |
Vincent Coubard |
640:c90ae1400bf2 | 163 | * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF. |
Vincent Coubard |
640:c90ae1400bf2 | 164 | */ |
Vincent Coubard |
640:c90ae1400bf2 | 165 | SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const *p_header, uint8_t const *p_data)); |
Vincent Coubard |
640:c90ae1400bf2 | 166 | |
Vincent Coubard |
640:c90ae1400bf2 | 167 | /** @} */ |
Vincent Coubard |
640:c90ae1400bf2 | 168 | |
Vincent Coubard |
640:c90ae1400bf2 | 169 | #endif // BLE_L2CAP_H__ |
Vincent Coubard |
640:c90ae1400bf2 | 170 | |
Vincent Coubard |
640:c90ae1400bf2 | 171 | /** |
Vincent Coubard |
640:c90ae1400bf2 | 172 | @} |
Vincent Coubard |
640:c90ae1400bf2 | 173 | */ |