Glimworm Beacons / nRF51822

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Mon Jul 06 10:21:00 2015 +0100
Revision:
372:758e9a3a346a
Parent:
nordic-sdk/components/softdevice/s130/include/ble_l2cap.h@371:8f7d2137727a
Synchronized with git rev 488e2462
Author: James Crosby
restructure to yotta module, with a few tweaks to get things building

Who changed what in which revision?

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