project for nrf51822 qfab

Dependencies:   eddystone_URL mbed

Fork of eddystone_URL by vo dung

Committer:
jksoft
Date:
Wed Nov 12 02:40:34 2014 +0000
Revision:
0:76dfa9657d9d
????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:76dfa9657d9d 1 /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
jksoft 0:76dfa9657d9d 2 *
jksoft 0:76dfa9657d9d 3 * The information contained herein is confidential property of Nordic Semiconductor. The use,
jksoft 0:76dfa9657d9d 4 * copying, transfer or disclosure of such information is prohibited except by express written
jksoft 0:76dfa9657d9d 5 * agreement with Nordic Semiconductor.
jksoft 0:76dfa9657d9d 6 *
jksoft 0:76dfa9657d9d 7 */
jksoft 0:76dfa9657d9d 8 /**
jksoft 0:76dfa9657d9d 9 @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
jksoft 0:76dfa9657d9d 10 @{
jksoft 0:76dfa9657d9d 11 @brief Definitions and prototypes for the L2CAP interface.
jksoft 0:76dfa9657d9d 12 */
jksoft 0:76dfa9657d9d 13
jksoft 0:76dfa9657d9d 14 #ifndef BLE_L2CAP_H__
jksoft 0:76dfa9657d9d 15 #define BLE_L2CAP_H__
jksoft 0:76dfa9657d9d 16
jksoft 0:76dfa9657d9d 17 #include "ble_types.h"
jksoft 0:76dfa9657d9d 18 #include "ble_ranges.h"
jksoft 0:76dfa9657d9d 19 #include "ble_err.h"
jksoft 0:76dfa9657d9d 20 #include "nrf_svc.h"
jksoft 0:76dfa9657d9d 21
jksoft 0:76dfa9657d9d 22 /**@addtogroup BLE_L2CAP_ENUMERATIONS Enumerations
jksoft 0:76dfa9657d9d 23 * @{ */
jksoft 0:76dfa9657d9d 24
jksoft 0:76dfa9657d9d 25 /**@brief L2CAP API SVC numbers. */
jksoft 0:76dfa9657d9d 26 enum BLE_L2CAP_SVCS
jksoft 0:76dfa9657d9d 27 {
jksoft 0:76dfa9657d9d 28 SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE, /**< Register a CID. */
jksoft 0:76dfa9657d9d 29 SD_BLE_L2CAP_CID_UNREGISTER, /**< Unregister a CID. */
jksoft 0:76dfa9657d9d 30 SD_BLE_L2CAP_TX /**< Transmit a packet. */
jksoft 0:76dfa9657d9d 31 };
jksoft 0:76dfa9657d9d 32
jksoft 0:76dfa9657d9d 33 /** @} */
jksoft 0:76dfa9657d9d 34
jksoft 0:76dfa9657d9d 35 /**@addtogroup BLE_L2CAP_DEFINES Defines
jksoft 0:76dfa9657d9d 36 * @{ */
jksoft 0:76dfa9657d9d 37
jksoft 0:76dfa9657d9d 38 /**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP
jksoft 0:76dfa9657d9d 39 * @{ */
jksoft 0:76dfa9657d9d 40 #define BLE_ERROR_L2CAP_CID_IN_USE (NRF_L2CAP_ERR_BASE + 0x000) /**< CID already in use. */
jksoft 0:76dfa9657d9d 41 /** @} */
jksoft 0:76dfa9657d9d 42
jksoft 0:76dfa9657d9d 43 /**@brief Default L2CAP MTU. */
jksoft 0:76dfa9657d9d 44 #define BLE_L2CAP_MTU_DEF (23)
jksoft 0:76dfa9657d9d 45
jksoft 0:76dfa9657d9d 46 /**@brief Invalid Channel Identifier. */
jksoft 0:76dfa9657d9d 47 #define BLE_L2CAP_CID_INVALID (0x0000)
jksoft 0:76dfa9657d9d 48
jksoft 0:76dfa9657d9d 49 /**@brief Dynamic Channel Identifier base. */
jksoft 0:76dfa9657d9d 50 #define BLE_L2CAP_CID_DYN_BASE (0x0040)
jksoft 0:76dfa9657d9d 51
jksoft 0:76dfa9657d9d 52 /**@brief Maximum amount of dynamic CIDs. */
jksoft 0:76dfa9657d9d 53 #define BLE_L2CAP_CID_DYN_MAX (8)
jksoft 0:76dfa9657d9d 54
jksoft 0:76dfa9657d9d 55 /** @} */
jksoft 0:76dfa9657d9d 56
jksoft 0:76dfa9657d9d 57 /**@addtogroup BLE_L2CAP_STRUCTURES Structures
jksoft 0:76dfa9657d9d 58 * @{ */
jksoft 0:76dfa9657d9d 59
jksoft 0:76dfa9657d9d 60 /**@brief Packet header format for L2CAP transmission. */
jksoft 0:76dfa9657d9d 61 typedef struct
jksoft 0:76dfa9657d9d 62 {
jksoft 0:76dfa9657d9d 63 uint16_t len; /**< Length of valid info in data member. */
jksoft 0:76dfa9657d9d 64 uint16_t cid; /**< Channel ID on which packet is transmitted. */
jksoft 0:76dfa9657d9d 65 } ble_l2cap_header_t;
jksoft 0:76dfa9657d9d 66
jksoft 0:76dfa9657d9d 67 /**@brief L2CAP Event IDs. */
jksoft 0:76dfa9657d9d 68 enum BLE_L2CAP_EVTS
jksoft 0:76dfa9657d9d 69 {
jksoft 0:76dfa9657d9d 70 BLE_L2CAP_EVT_RX = BLE_L2CAP_EVT_BASE /**< L2CAP packet received. */
jksoft 0:76dfa9657d9d 71 };
jksoft 0:76dfa9657d9d 72
jksoft 0:76dfa9657d9d 73
jksoft 0:76dfa9657d9d 74 /**@brief L2CAP Received packet event report. */
jksoft 0:76dfa9657d9d 75 typedef struct
jksoft 0:76dfa9657d9d 76 {
jksoft 0:76dfa9657d9d 77 ble_l2cap_header_t header; /** L2CAP packet header. */
jksoft 0:76dfa9657d9d 78 uint8_t data[1]; /**< Packet data, variable length. */
jksoft 0:76dfa9657d9d 79 } ble_l2cap_evt_rx_t;
jksoft 0:76dfa9657d9d 80
jksoft 0:76dfa9657d9d 81
jksoft 0:76dfa9657d9d 82 /**@brief L2CAP event callback event structure. */
jksoft 0:76dfa9657d9d 83 typedef struct
jksoft 0:76dfa9657d9d 84 {
jksoft 0:76dfa9657d9d 85 uint16_t conn_handle; /**< Connection Handle on which event occured. */
jksoft 0:76dfa9657d9d 86 union
jksoft 0:76dfa9657d9d 87 {
jksoft 0:76dfa9657d9d 88 ble_l2cap_evt_rx_t rx; /**< RX Event parameters. */
jksoft 0:76dfa9657d9d 89 } params;
jksoft 0:76dfa9657d9d 90 } ble_l2cap_evt_t;
jksoft 0:76dfa9657d9d 91
jksoft 0:76dfa9657d9d 92
jksoft 0:76dfa9657d9d 93 /**@brief Register a CID with L2CAP.
jksoft 0:76dfa9657d9d 94 *
jksoft 0:76dfa9657d9d 95 * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID.
jksoft 0:76dfa9657d9d 96 *
jksoft 0:76dfa9657d9d 97 * @param[in] cid L2CAP CID.
jksoft 0:76dfa9657d9d 98 *
jksoft 0:76dfa9657d9d 99 * @return @ref NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
jksoft 0:76dfa9657d9d 100 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
jksoft 0:76dfa9657d9d 101 * @return @ref BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
jksoft 0:76dfa9657d9d 102 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
jksoft 0:76dfa9657d9d 103 */
jksoft 0:76dfa9657d9d 104 SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid));
jksoft 0:76dfa9657d9d 105
jksoft 0:76dfa9657d9d 106 /**@brief Unregister a CID with L2CAP.
jksoft 0:76dfa9657d9d 107 *
jksoft 0:76dfa9657d9d 108 * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer.
jksoft 0:76dfa9657d9d 109 *
jksoft 0:76dfa9657d9d 110 * @param[in] cid L2CAP CID.
jksoft 0:76dfa9657d9d 111 *
jksoft 0:76dfa9657d9d 112 * @return @ref NRF_SUCCESS Successfully unregistered the CID.
jksoft 0:76dfa9657d9d 113 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
jksoft 0:76dfa9657d9d 114 * @return @ref NRF_ERROR_NOT_FOUND CID not previously registered.
jksoft 0:76dfa9657d9d 115 */
jksoft 0:76dfa9657d9d 116 SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid));
jksoft 0:76dfa9657d9d 117
jksoft 0:76dfa9657d9d 118 /**@brief Transmit an L2CAP packet.
jksoft 0:76dfa9657d9d 119 *
jksoft 0:76dfa9657d9d 120 * @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore
jksoft 0:76dfa9657d9d 121 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
jksoft 0:76dfa9657d9d 122 * Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
jksoft 0:76dfa9657d9d 123 *
jksoft 0:76dfa9657d9d 124 * @param[in] conn_handle Connection Handle.
jksoft 0:76dfa9657d9d 125 * @param[in] p_header Pointer to a packet header containing length and CID.
jksoft 0:76dfa9657d9d 126 * @param[in] p_data Pointer to the data to be transmitted.
jksoft 0:76dfa9657d9d 127 *
jksoft 0:76dfa9657d9d 128 * @return @ref NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
jksoft 0:76dfa9657d9d 129 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
jksoft 0:76dfa9657d9d 130 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
jksoft 0:76dfa9657d9d 131 * @return @ref NRF_ERROR_NOT_FOUND CID not found.
jksoft 0:76dfa9657d9d 132 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
jksoft 0:76dfa9657d9d 133 * @return @ref BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available.
jksoft 0:76dfa9657d9d 134 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
jksoft 0:76dfa9657d9d 135 */
jksoft 0:76dfa9657d9d 136 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));
jksoft 0:76dfa9657d9d 137
jksoft 0:76dfa9657d9d 138 /** @} */
jksoft 0:76dfa9657d9d 139
jksoft 0:76dfa9657d9d 140 #endif // BLE_L2CAP_H__
jksoft 0:76dfa9657d9d 141
jksoft 0:76dfa9657d9d 142 /**
jksoft 0:76dfa9657d9d 143 @}
jksoft 0:76dfa9657d9d 144 */