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