Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nrf51-sdk by
ble_l2cap.h
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 /** 00034 @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP) 00035 @{ 00036 @brief Definitions and prototypes for the L2CAP interface. 00037 */ 00038 00039 #ifndef BLE_L2CAP_H__ 00040 #define BLE_L2CAP_H__ 00041 00042 #include "ble_types.h" 00043 #include "ble_ranges.h" 00044 #include "ble_err.h" 00045 #include "nrf_svc.h" 00046 00047 /**@addtogroup BLE_L2CAP_ENUMERATIONS Enumerations 00048 * @{ */ 00049 00050 /**@brief L2CAP API SVC numbers. */ 00051 enum BLE_L2CAP_SVCS 00052 { 00053 SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE, /**< Register a CID. */ 00054 SD_BLE_L2CAP_CID_UNREGISTER, /**< Unregister a CID. */ 00055 SD_BLE_L2CAP_TX /**< Transmit a packet. */ 00056 }; 00057 00058 /**@brief L2CAP Event IDs. */ 00059 enum BLE_L2CAP_EVTS 00060 { 00061 BLE_L2CAP_EVT_RX = BLE_L2CAP_EVT_BASE /**< L2CAP packet received. */ 00062 }; 00063 00064 /** @} */ 00065 00066 /**@addtogroup BLE_L2CAP_DEFINES Defines 00067 * @{ */ 00068 00069 /**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP 00070 * @{ */ 00071 #define BLE_ERROR_L2CAP_CID_IN_USE (NRF_L2CAP_ERR_BASE + 0x000) /**< CID already in use. */ 00072 /** @} */ 00073 00074 /**@brief Default L2CAP MTU. */ 00075 #define BLE_L2CAP_MTU_DEF (23) 00076 00077 /**@brief Invalid Channel Identifier. */ 00078 #define BLE_L2CAP_CID_INVALID (0x0000) 00079 00080 /**@brief Dynamic Channel Identifier base. */ 00081 #define BLE_L2CAP_CID_DYN_BASE (0x0040) 00082 00083 /**@brief Maximum amount of dynamic CIDs. */ 00084 #define BLE_L2CAP_CID_DYN_MAX (8) 00085 00086 /** @} */ 00087 00088 /**@addtogroup BLE_L2CAP_STRUCTURES Structures 00089 * @{ */ 00090 00091 /**@brief Packet header format for L2CAP transmission. */ 00092 typedef struct 00093 { 00094 uint16_t len; /**< Length of valid info in data member. */ 00095 uint16_t cid; /**< Channel ID on which packet is transmitted. */ 00096 } ble_l2cap_header_t; 00097 00098 00099 /**@brief L2CAP Received packet event report. */ 00100 typedef struct 00101 { 00102 ble_l2cap_header_t header; /**< L2CAP packet header. */ 00103 uint8_t data[1]; /**< Packet data, variable length. */ 00104 } ble_l2cap_evt_rx_t; 00105 00106 00107 /**@brief L2CAP event callback event structure. */ 00108 typedef struct 00109 { 00110 uint16_t conn_handle; /**< Connection Handle on which event occured. */ 00111 union 00112 { 00113 ble_l2cap_evt_rx_t rx; /**< RX Event parameters. */ 00114 } params; /**< Event Parameters. */ 00115 } ble_l2cap_evt_t; 00116 00117 /** @} */ 00118 00119 /**@addtogroup BLE_L2CAP_FUNCTIONS Functions 00120 * @{ */ 00121 00122 /**@brief Register a CID with L2CAP. 00123 * 00124 * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID. 00125 * 00126 * @param[in] cid L2CAP CID. 00127 * 00128 * @retval ::NRF_SUCCESS Successfully registered a CID with the L2CAP layer. 00129 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE. 00130 * @retval ::BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use. 00131 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. 00132 */ 00133 SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid)); 00134 00135 /**@brief Unregister a CID with L2CAP. 00136 * 00137 * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer. 00138 * 00139 * @param[in] cid L2CAP CID. 00140 * 00141 * @retval ::NRF_SUCCESS Successfully unregistered the CID. 00142 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. 00143 * @retval ::NRF_ERROR_NOT_FOUND CID not previously registered. 00144 */ 00145 SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid)); 00146 00147 /**@brief Transmit an L2CAP packet. 00148 * 00149 * @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore 00150 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. 00151 * Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details. 00152 * 00153 * @param[in] conn_handle Connection Handle. 00154 * @param[in] p_header Pointer to a packet header containing length and CID. 00155 * @param[in] p_data Pointer to the data to be transmitted. 00156 * 00157 * @retval ::NRF_SUCCESS Successfully queued an L2CAP packet for transmission. 00158 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00159 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register. 00160 * @retval ::NRF_ERROR_NOT_FOUND CID not found. 00161 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. 00162 * @retval ::BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available. 00163 * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF. 00164 */ 00165 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)); 00166 00167 /** @} */ 00168 00169 #endif // BLE_L2CAP_H__ 00170 00171 /** 00172 @} 00173 */
Generated on Tue Jul 12 2022 14:11:18 by
