テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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