Michael Galis / nRF51822

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:29:13 2016 +0000
Revision:
607:e98331f1d6b5
Import nordic sdk from https://github.com/ARMmbed/nrf51-sdk.git#a0faa63aae1f6351ac36cd70f28ce037d6f4ae11

Who changed what in which revision?

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