6
6
7
7
/** @file
8
8
*
9
- * @defgroup nrf_ble_qwr Queued Writes module
9
+ * @defgroup ble_qwr Queued Writes module
10
10
* @{
11
11
* @ingroup ble_sdk_lib
12
12
* @brief Module for handling Queued Write operations.
15
15
* commands. It also manages memory requests related to these operations.
16
16
*
17
17
* @note The application must propagate BLE stack events to this module by calling
18
- * @ref nrf_ble_qwr_on_ble_evt ().
18
+ * @ref ble_qwr_on_ble_evt ().
19
19
*/
20
20
21
21
#ifndef NRF_BLE_QUEUED_WRITES_H__
@@ -31,94 +31,103 @@ extern "C" {
31
31
#include <ble_gatts.h>
32
32
33
33
/**
34
- * @brief Macro for defining a nrf_ble_qwr instance.
34
+ * @brief Macro for defining a ble_qwr instance.
35
35
*
36
36
* @param _name Name of the instance.
37
37
* @hideinitializer
38
38
*/
39
- #define NRF_BLE_QWR_DEF (_name ) \
40
- static struct nrf_ble_qwr _name; \
39
+ #define BLE_QWR_DEF (_name ) \
40
+ static struct ble_qwr _name; \
41
41
NRF_SDH_BLE_OBSERVER(_name ## _obs, \
42
- nrf_ble_qwr_on_ble_evt, \
42
+ ble_qwr_on_ble_evt, \
43
43
&_name, \
44
- CONFIG_NRF_BLE_QWR_BLE_OBSERVER_PRIO )
44
+ CONFIG_BLE_QWR_BLE_OBSERVER_PRIO )
45
45
46
46
/* Error code used by the module to reject prepare write requests on non-registered attributes. */
47
- #define NRF_BLE_QWR_REJ_REQUEST_ERR_CODE BLE_GATT_STATUS_ATTERR_APP_BEGIN + 0
47
+ #define BLE_QWR_REJ_REQUEST_ERR_CODE BLE_GATT_STATUS_ATTERR_APP_BEGIN + 0
48
48
49
49
/** @brief Queued Writes module event types. */
50
- enum nrf_ble_qwr_evt_type {
50
+ enum ble_qwr_evt_type {
51
+ /** Error event */
52
+ BLE_QWR_EVT_ERROR ,
51
53
/** Event that indicates that an execute write command was received for a registered handle
52
54
* and that the received data was actually written and is now ready.
53
55
*/
54
- NRF_BLE_QWR_EVT_EXECUTE_WRITE ,
56
+ BLE_QWR_EVT_EXECUTE_WRITE ,
55
57
/** Event that indicates that an execute write command was received for a registered handle
56
58
* and that the write request must now be accepted or rejected.
57
59
*/
58
- NRF_BLE_QWR_EVT_AUTH_REQUEST ,
60
+ BLE_QWR_EVT_AUTH_REQUEST ,
59
61
};
60
62
61
63
/** @brief Queued Writes module events. */
62
- struct nrf_ble_qwr_evt {
64
+ struct ble_qwr_evt {
63
65
/** Type of the event. */
64
- enum nrf_ble_qwr_evt_type evt_type ;
65
- /** Handle of the attribute to which the event relates. */
66
- uint16_t attr_handle ;
66
+ enum ble_qwr_evt_type evt_type ;
67
+ union {
68
+ /** @ref BLE_QWR_EVT_ERROR event data. */
69
+ struct {
70
+ int reason ;
71
+ } error ;
72
+ /** @ref BLE_QWR_EVT_EXECUTE_WRITE event data. */
73
+ struct {
74
+ /** Handle of the attribute to which the event relates. */
75
+ uint16_t attr_handle ;
76
+ } exec_write ;
77
+ /** @ref BLE_QWR_EVT_AUTH_REQUEST event data. */
78
+ struct {
79
+ /** Handle of the attribute to which the event relates. */
80
+ uint16_t attr_handle ;
81
+ } auth_req ;
82
+ };
67
83
};
68
84
69
- /* Forward declaration of the struct nrf_ble_qwr . */
70
- struct nrf_ble_qwr ;
85
+ /* Forward declaration of the struct ble_qwr . */
86
+ struct ble_qwr ;
71
87
72
88
/**
73
89
* @brief Queued Writes module event handler type.
74
90
*
75
- * If the provided event is of type @ref NRF_BLE_QWR_EVT_AUTH_REQUEST ,
91
+ * If the provided event is of type @ref BLE_QWR_EVT_AUTH_REQUEST ,
76
92
* this function must accept or reject the execute write request by returning
77
93
* one of the @ref BLE_GATT_STATUS_CODES.
78
94
*/
79
- typedef uint16_t (* nrf_ble_qwr_evt_handler_t )(struct nrf_ble_qwr * qwr , struct nrf_ble_qwr_evt * evt );
80
-
81
- /**
82
- * @brief Type definition for error handler function that will be called in case of an error.
83
- */
84
- typedef void (* nrf_ble_qwr_error_handler_t )(int err );
95
+ typedef uint16_t (* ble_qwr_evt_handler_t )(struct ble_qwr * qwr , const struct ble_qwr_evt * evt );
85
96
86
97
/**
87
98
* @brief Queued Writes structure.
88
99
* @details This structure contains status information for the Queued Writes module.
89
100
*/
90
- struct nrf_ble_qwr {
101
+ struct ble_qwr {
91
102
/** Flag that indicates whether the module has been initialized. */
92
103
uint32_t initialized ;
104
+ /** Event handler function that is called for events concerning the handles of all
105
+ * registered attributes.
106
+ */
107
+ ble_qwr_evt_handler_t evt_handler ;
93
108
/** Connection handle. */
94
109
uint16_t conn_handle ;
95
- /** Error handler. */
96
- nrf_ble_qwr_error_handler_t error_handler ;
97
110
/** Flag that indicates whether a mem_reply is pending
98
111
* (because a previous attempt returned busy).
99
112
*/
100
113
bool is_user_mem_reply_pending ;
101
- #if (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0 )
114
+ #if (CONFIG_BLE_QWR_MAX_ATTR > 0 )
102
115
/** List of handles for registered attributes, for which the module accepts and handles
103
116
* prepare write operations.
104
117
*/
105
- uint16_t attr_handles [CONFIG_NRF_BLE_QWR_MAX_ATTR ];
118
+ uint16_t attr_handles [CONFIG_BLE_QWR_MAX_ATTR ];
106
119
/** Number of registered attributes. */
107
120
uint8_t nb_registered_attr ;
108
121
/** List of attribute handles that have been written to during the current prepare write or
109
122
* execute write operation.
110
123
*/
111
- uint16_t written_attr_handles [CONFIG_NRF_BLE_QWR_MAX_ATTR ];
124
+ uint16_t written_attr_handles [CONFIG_BLE_QWR_MAX_ATTR ];
112
125
/** Number of attributes that have been written to during the current prepare write or
113
126
* execute write operation.
114
127
*/
115
128
uint8_t nb_written_handles ;
116
129
/** Memory buffer that is provided to the SoftDevice on an ON_USER_MEM_REQUEST event. */
117
130
ble_user_mem_block_t mem_buffer ;
118
- /** Event handler function that is called for events concerning the handles of all
119
- * registered attributes.
120
- */
121
- nrf_ble_qwr_evt_handler_t callback ;
122
131
#endif
123
132
};
124
133
@@ -127,16 +136,14 @@ struct nrf_ble_qwr {
127
136
*
128
137
* @details This structure contains all information needed to initialize the Queued Writes module.
129
138
*/
130
- struct nrf_ble_qwr_init {
131
- /** Error handler. */
132
- nrf_ble_qwr_error_handler_t error_handler ;
133
- #if (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0 )
134
- /** Memory buffer that is provided to the SoftDevice on an ON_USER_MEM_REQUEST event. */
135
- ble_user_mem_block_t mem_buffer ;
139
+ struct ble_qwr_config {
136
140
/** Event handler function that is called for events concerning the handles of all
137
141
* registered attributes.
138
142
*/
139
- nrf_ble_qwr_evt_handler_t callback ;
143
+ ble_qwr_evt_handler_t evt_handler ;
144
+ #if (CONFIG_BLE_QWR_MAX_ATTR > 0 )
145
+ /** Memory buffer that is provided to the SoftDevice on an ON_USER_MEM_REQUEST event. */
146
+ ble_user_mem_block_t mem_buffer ;
140
147
#endif
141
148
};
142
149
@@ -156,7 +163,7 @@ struct nrf_ble_qwr_init {
156
163
* @retval -EFAULT If @p qwr or @p qwr_init is @c NULL.
157
164
* @retval -EPERM If the given @p qwr instance has already been initialized.
158
165
*/
159
- int nrf_ble_qwr_init (struct nrf_ble_qwr * qwr , struct nrf_ble_qwr_init const * qwr_init );
166
+ int ble_qwr_init (struct ble_qwr * qwr , struct ble_qwr_config const * qwr_config );
160
167
161
168
162
169
/**
@@ -173,7 +180,7 @@ int nrf_ble_qwr_init(struct nrf_ble_qwr *qwr, struct nrf_ble_qwr_init const *qwr
173
180
* @retval -EFAULT If @p qwr is @c NULL.
174
181
* @retval -EPERM If the given @p qwr instance has not been initialized.
175
182
*/
176
- int nrf_ble_qwr_conn_handle_assign (struct nrf_ble_qwr * qwr , uint16_t conn_handle );
183
+ int ble_qwr_conn_handle_assign (struct ble_qwr * qwr , uint16_t conn_handle );
177
184
178
185
/**
179
186
* @brief Function for handling BLE stack events.
@@ -183,9 +190,9 @@ int nrf_ble_qwr_conn_handle_assign(struct nrf_ble_qwr *qwr, uint16_t conn_handle
183
190
* @param[in] ble_evt Event received from the BLE stack.
184
191
* @param[in] context Queued Writes structure.
185
192
*/
186
- void nrf_ble_qwr_on_ble_evt (ble_evt_t const * ble_evt , void * context );
193
+ void ble_qwr_on_ble_evt (ble_evt_t const * ble_evt , void * context );
187
194
188
- #if (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0 )
195
+ #if (CONFIG_BLE_QWR_MAX_ATTR > 0 )
189
196
/**
190
197
* @brief Function for registering an attribute with the Queued Writes module.
191
198
*
@@ -200,13 +207,13 @@ void nrf_ble_qwr_on_ble_evt(ble_evt_t const *ble_evt, void *context);
200
207
* @retval -EFAULT If @p qwr is @c NULL.
201
208
* @retval -EPERM If the given @p qwr instance has not been initialized.
202
209
*/
203
- int nrf_ble_qwr_attr_register (struct nrf_ble_qwr * qwr , uint16_t attr_handle );
210
+ int ble_qwr_attr_register (struct ble_qwr * qwr , uint16_t attr_handle );
204
211
205
212
206
213
/**
207
214
* @brief Function for retrieving the received data for a given attribute.
208
215
*
209
- * @details Call this function after receiving an @ref NRF_BLE_QWR_EVT_AUTH_REQUEST
216
+ * @details Call this function after receiving an @ref BLE_QWR_EVT_AUTH_REQUEST
210
217
* event to retrieve a linear copy of the data that was received for the given attribute.
211
218
*
212
219
* @param[in] qwr Queued Writes structure.
@@ -219,9 +226,9 @@ int nrf_ble_qwr_attr_register(struct nrf_ble_qwr *qwr, uint16_t attr_handle);
219
226
* @retval -EFAULT If @p qwr, @p mem or @p len is @c NULL.
220
227
* @retval -EPERM If the given @p qwr instance has not been initialized.
221
228
*/
222
- int nrf_ble_qwr_value_get (
223
- struct nrf_ble_qwr * qwr , uint16_t attr_handle , uint8_t * mem , uint16_t * len );
224
- #endif /* (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0) */
229
+ int ble_qwr_value_get (
230
+ struct ble_qwr * qwr , uint16_t attr_handle , uint8_t * mem , uint16_t * len );
231
+ #endif /* (CONFIG_BLE_QWR_MAX_ATTR > 0) */
225
232
226
233
#ifdef __cplusplus
227
234
}
0 commit comments