ble_gatt.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file ble_gatt.h
5 *
6 * @brief BLE GATT
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 *****************************************************************************************
36 */
37
38 /**
39 * @addtogroup BLE
40 * @{
41 */
42
43 /**
44 * @addtogroup BLE_GATT Generic Attribute Profile (GATT)
45 * @{
46 * @brief Definitions and prototypes for the GATT interface.
47 */
48
49 /**
50 @addtogroup BLE_GATTS Generic Attribute Profile (GATT) Common
51 @{
52 @brief Definitions and prototypes for the GATT Common interface.
53 */
54 #ifndef __BLE_GATT_H__
55 #define __BLE_GATT_H__
56
57 #include "ble_error.h"
58 #include <stdint.h>
59
60 /** @addtogroup BLE_GATT_COMMON Enumerations
61 * @{ */
62
63 /**
64 * @brief GATT common events.
65 */
66 typedef enum
67 {
68 BLE_GATT_NOTIFICATION = 0x00, /**< Handle Value Notification. */
69 BLE_GATT_INDICATION, /**< Handle Value Indication. */
70 } ble_gatt_evt_type_t;
71
72 /** @} */
73
74 /** @addtogroup BLE_GATT_COMMON_STRUCTURES Structures
75 * @{ */
76
77 /**
78 * @brief GATT UUID structure.
79 */
80 typedef struct
81 {
82 uint8_t uuid_len; /**< UUID length. */
83 uint8_t *uuid; /**< UUID value. */
84 } ble_uuid_t;
85
86 /**
87 * @brief GATT MTU Exchange event for @ref BLE_GATT_COMMON_EVT_MTU_EXCHANGE.
88 */
89 typedef struct
90 {
91 uint16_t mtu; /**< MTU Exchanged value. */
92 } ble_gatt_common_evt_mtu_exchange_t;
93
94 /**
95 * @brief GATT Server Profile Register event for @ref BLE_GATT_COMMON_EVT_PRF_REGISTER.
96 */
97 typedef struct
98 {
99 uint8_t prf_index; /**< Profile Index. */
100 } ble_gatt_common_evt_prf_reg_t;
101
102 /**@brief GATT Common structure. */
103 typedef struct
104 {
105 uint8_t index; /**< Index of connection. */
106 union
107 {
108 ble_gatt_common_evt_mtu_exchange_t mtu_exchange; /**< MTU exchanged event. */
109 ble_gatt_common_evt_prf_reg_t prf_reg; /**< Server Profile Register event. */
110 } params; /**< Event Parameters. */
111 } ble_gatt_common_evt_t;
112 /** @} */
113
114 /** @addtogroup BLE_GATT_FUNCTIONS Functions
115 * @{ */
116
117 /**
118 ****************************************************************************************
119 * @brief Set ATT_MTU size.
120 *
121 * @param[in] mtu: ATT_MTU size.
122 *
123 * @note This function should be called before exchange MTU operation. This MTU size is used to all connections.
124 * If not set these parameters, the stack will config the default value as (max_mtu = 512).
125 *
126 * @retval ::SDK_SUCCESS: Successfully get ATT_MTU.
127 * @retval ::SDK_ERR_DISALLOWED: Operation is disallowed.
128 ****************************************************************************************
129 */
130 uint16_t ble_gatt_mtu_set(uint16_t mtu);
131
132 /**
133 ****************************************************************************************
134 * @brief Get the current ATT_MTU size for a given connection.
135 *
136 * @param[in] conn_idx: Current connection index.
137 * @param[out] p_mtu: ATT_MTU size for the given connection.
138 *
139 * @retval ::SDK_SUCCESS: Successfully get ATT_MTU.
140 * @retval ::SDK_ERR_INVALID_PARAM: Invalid parameter(s) supplied.
141 ****************************************************************************************
142 */
143 uint16_t ble_gatt_mtu_get(uint8_t conn_idx, uint16_t *p_mtu);
144
145 /** @} */
146
147 #endif
148 /** @} */
149 /** @} */
150 /** @} */
151
ble_gatt_common_evt_t::index
uint8_t index
Definition: ble_gatt.h:105
ble_uuid_t::uuid
uint8_t * uuid
Definition: ble_gatt.h:83
ble_gatt_mtu_get
uint16_t ble_gatt_mtu_get(uint8_t conn_idx, uint16_t *p_mtu)
Get the current ATT_MTU size for a given connection.
ble_gatt_common_evt_mtu_exchange_t::mtu
uint16_t mtu
Definition: ble_gatt.h:91
ble_uuid_t::uuid_len
uint8_t uuid_len
Definition: ble_gatt.h:82
ble_error.h
File that contains error codes.
ble_gatt_common_evt_mtu_exchange_t
GATT MTU Exchange event for BLE_GATT_COMMON_EVT_MTU_EXCHANGE.
Definition: ble_gatt.h:90
ble_gatt_evt_type_t
ble_gatt_evt_type_t
GATT common events.
Definition: ble_gatt.h:67
ble_gatt_common_evt_t::mtu_exchange
ble_gatt_common_evt_mtu_exchange_t mtu_exchange
Definition: ble_gatt.h:108
BLE_GATT_INDICATION
@ BLE_GATT_INDICATION
Definition: ble_gatt.h:69
BLE_GATT_NOTIFICATION
@ BLE_GATT_NOTIFICATION
Definition: ble_gatt.h:68
ble_gatt_common_evt_prf_reg_t::prf_index
uint8_t prf_index
Definition: ble_gatt.h:99
ble_gatt_common_evt_t
GATT Common structure.
Definition: ble_gatt.h:104
ble_gatt_common_evt_prf_reg_t
GATT Server Profile Register event for BLE_GATT_COMMON_EVT_PRF_REGISTER.
Definition: ble_gatt.h:98
ble_gatt_common_evt_t::prf_reg
ble_gatt_common_evt_prf_reg_t prf_reg
Definition: ble_gatt.h:109
ble_uuid_t
GATT UUID structure.
Definition: ble_gatt.h:81
ble_gatt_mtu_set
uint16_t ble_gatt_mtu_set(uint16_t mtu)
Set ATT_MTU size.