Nordic stack and drivers for the mbed BLE API

Dependents:   idd_hw5_bleFanProto

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ble_l2cap.h Source File

ble_l2cap.h

00001 /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic Semiconductor. The use,
00004  * copying, transfer or disclosure of such information is prohibited except by express written
00005  * agreement with Nordic Semiconductor.
00006  *
00007  */
00008 /**
00009   @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
00010   @{
00011   @brief Definitions and prototypes for the L2CAP interface.
00012  */
00013 
00014 #ifndef BLE_L2CAP_H__
00015 #define BLE_L2CAP_H__ 
00016 
00017 #include "ble_types.h"
00018 #include "ble_ranges.h"
00019 #include "ble_err.h"
00020 #include "nrf_svc.h"
00021 
00022 /**@addtogroup BLE_L2CAP_ENUMERATIONS Enumerations
00023  * @{ */
00024 
00025 /**@brief L2CAP API SVC numbers. */
00026 enum BLE_L2CAP_SVCS 
00027 {
00028   SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE,  /**< Register a CID. */
00029   SD_BLE_L2CAP_CID_UNREGISTER,                     /**< Unregister a CID. */
00030   SD_BLE_L2CAP_TX                                  /**< Transmit a packet. */
00031 };
00032 
00033 /** @} */
00034 
00035 /**@addtogroup BLE_L2CAP_DEFINES Defines
00036  * @{ */
00037 
00038 /**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP
00039  * @{ */
00040 #define BLE_ERROR_L2CAP_CID_IN_USE            (NRF_L2CAP_ERR_BASE + 0x000)  /**< CID already in use. */
00041 /** @} */
00042 
00043 /**@brief Default L2CAP MTU. */
00044 #define BLE_L2CAP_MTU_DEF           (23)    
00045 
00046 /**@brief Invalid Channel Identifier. */
00047 #define BLE_L2CAP_CID_INVALID       (0x0000) 
00048 
00049 /**@brief Dynamic Channel Identifier base. */
00050 #define BLE_L2CAP_CID_DYN_BASE      (0x0040) 
00051 
00052 /**@brief Maximum amount of dynamic CIDs. */
00053 #define BLE_L2CAP_CID_DYN_MAX       (8) 
00054 
00055 /** @} */
00056 
00057 /**@addtogroup BLE_L2CAP_STRUCTURES Structures
00058  * @{ */
00059 
00060 /**@brief Packet header format for L2CAP transmission. */
00061 typedef struct
00062 {
00063   uint16_t   len;                                 /**< Length of valid info in data member. */
00064   uint16_t   cid;                                 /**< Channel ID on which packet is transmitted. */
00065 } ble_l2cap_header_t;
00066 
00067 /**@brief L2CAP Event IDs. */
00068 enum BLE_L2CAP_EVTS 
00069 {
00070   BLE_L2CAP_EVT_RX  = BLE_L2CAP_EVT_BASE          /**< L2CAP packet received. */
00071 };
00072 
00073 
00074 /**@brief L2CAP Received packet event report. */
00075 typedef struct
00076 {
00077   ble_l2cap_header_t header;                      /** L2CAP packet header. */
00078   uint8_t    data[1];                             /**< Packet data, variable length. */
00079 } ble_l2cap_evt_rx_t;
00080 
00081 
00082 /**@brief L2CAP event callback event structure. */
00083 typedef struct
00084 {
00085   uint16_t conn_handle;                           /**< Connection Handle on which event occured. */
00086   union
00087   {
00088     ble_l2cap_evt_rx_t rx;                        /**< RX Event parameters. */
00089   } params;
00090 } ble_l2cap_evt_t;
00091 
00092 
00093 /**@brief Register a CID with L2CAP.
00094  *
00095  * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID.
00096  *          
00097  * @param[in] cid L2CAP CID.
00098  *
00099  * @return @ref NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
00100  * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
00101  * @return @ref BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
00102  * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
00103  */
00104 SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid));
00105 
00106 /**@brief Unregister a CID with L2CAP.
00107  *
00108  * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer.
00109  *          
00110  * @param[in] cid L2CAP CID.
00111  *
00112  * @return @ref NRF_SUCCESS Successfully unregistered the CID.
00113  * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
00114  * @return @ref NRF_ERROR_NOT_FOUND CID not previously registered.
00115  */
00116 SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid));
00117 
00118 /**@brief Transmit an L2CAP packet.
00119  *
00120  * @note    It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore 
00121  *          generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. 
00122  *          Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
00123  *
00124  * @param[in] conn_handle Connection Handle.
00125  * @param[in] p_header    Pointer to a packet header containing length and CID.
00126  * @param[in] p_data      Pointer to the data to be transmitted.
00127  *
00128  * @return @ref NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
00129  * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
00130  * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
00131  * @return @ref NRF_ERROR_NOT_FOUND CID not found.
00132  * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
00133  * @return @ref BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available.
00134  * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
00135  */
00136 SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const * const p_header, uint8_t const * const p_data));
00137 
00138 /** @} */
00139 
00140 #endif // BLE_L2CAP_H__
00141 
00142 /**
00143   @}
00144 */