-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathble_gatt.erpc
More file actions
330 lines (274 loc) · 14.2 KB
/
ble_gatt.erpc
File metadata and controls
330 lines (274 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*! Bluetooth UUID type - values chosen to correspond with the ATT UUID format */
enum bleUuidType_t {
gBleUuidType16_c = 0x01, /*!< 16-bit standard UUID */
gBleUuidType128_c = 0x02, /*!< 128-bit UUID */
gBleUuidType32_c = 0x03 /*!< 32-bit UUID - not available as ATT UUID format */
}
//union bleUuid_t {
// uint16_t uuid16; /*!< For gBleUuidType16_c. */
// uint32_t uuid32; /*!< For gBleUuidType32_c. */
// uint8_t uuid128[16]; /*!< For gBleUuidType128_c. */
//}
struct bleUuid_t {
uint8[16] uuid128
}
enum gattCharacteristicPropertiesBitFields_t {
gGattCharPropNone_c = 0, /*!< No Properties selected. */
gGattCharPropBroadcast_c = BIT0, /*!< Characteristic can be broadcast. */
gGattCharPropRead_c = BIT1, /*!< Characteristic can be read. */
gGattCharPropWriteWithoutRsp_c = BIT2, /*!< Characteristic can be written without response. */
gGattCharPropWrite_c = BIT3, /*!< Characteristic can be written with response. */
gGattCharPropNotify_c = BIT4, /*!< Characteristic can be notified. */
gGattCharPropIndicate_c = BIT5, /*!< Characteristic can be indicated. */
gGattCharPropAuthSignedWrites_c = BIT6, /*!< Characteristic can be written with signed data. */
gGattCharPropExtendedProperties_c = BIT7 /*!< Extended Characteristic properties. */
}
enum gattAttributePermissionsBitFields_t {
gPermissionNone_c = 0, /*!< No permissions selected. */
/* Reading Permissions */
gPermissionFlagReadable_c = BIT0, /*!< Attribute can be read. */
/* if gPermissionFlagReadable_c == 1 */
gPermissionFlagReadWithEncryption_c = BIT1, /*!< Attribute may be read only if link is encrypted. */
gPermissionFlagReadWithAuthentication_c = BIT2, /*!< Attribute may be read only by authenticated peers. */
gPermissionFlagReadWithAuthorization_c = BIT3, /*!< Attribute may be read only by authorized peers. */
/* endif */
/* Writing Permissions */
gPermissionFlagWritable_c = BIT4, /*!< Attribute can be written. */
/* if gPermissionFlagWritable_c == 1 */
gPermissionFlagWriteWithEncryption_c = BIT5, /*!< Attribute may be written only if link is encrypted. */
gPermissionFlagWriteWithAuthentication_c = BIT6, /*!< Attribute may be written only by authenticated peers. */
gPermissionFlagWriteWithAuthorization_c = BIT7, /*!< Attribute may be written only by authorized peers. */
/* endif */
}
/*! GATT Server Event type enumeration */
//enum gattServerEventType_t {
// gEvtMtuChanged_c, /*!< ATT_MTU was changed after the MTU exchange. */
// gEvtHandleValueConfirmation_c, /*!< Received a Handle Value Confirmation from the Client. */
// gEvtAttributeWritten_c, /*!< An attribute registered with GattServer_RegisterHandlesForWriteNotifications was written.
// After receiving this event, application must call GattServer_SendAttributeWrittenStatus.
// Application must write the Attribute in the Database if it considers necessary. */
// gEvtCharacteristicCccdWritten_c, /*!< A CCCD was written. Application should save the CCCD value with Gap_SaveCccd. */
// gEvtAttributeWrittenWithoutResponse_c, /*!< An attribute registered with GattServer_RegisterHandlesForWriteNotifications was written without response (with ATT Write Command).
// Application must write the Attribute Value in the Database if it considers necessary. */
// gEvtError_c, /*!< An error appeared during a Server-initiated procedure. */
// gEvtLongCharacteristicWritten_c, /*!< A long characteristic was written. */
// gEvtAttributeRead_c, /*!< An attribute registered with GattServer_RegisterHandlesForReadNotifications is being read.
// After receiving this event, application must call GattServer_SendAttributeReadStatus. */
//}
enum gattServerEventType_t {
gEvtMtuChanged_c,
gEvtHandleValueConfirmation_c,
gEvtAttributeWritten_c,
gEvtCharacteristicCccdWritten_c,
gEvtAttributeWrittenWithoutResponse_c,
gEvtError_c,
gEvtLongCharacteristicWritten_c,
gEvtAttributeRead_c,
}
/*! GATT Server MTU Changed Event structure */
struct gattServerMtuChangedEvent_t {
uint16 newMtu; /*!< Value of the agreed ATT_MTU for this connection. */
}
/*! GATT Server Attribute Written Event structure */
struct gattServerAttributeWrittenEvent_t {
uint16 handle; /*!< Handle of the attribute. */
uint16 cValueLength; /*!< Length of the attribute value array. */
// uint8_t* aValue; /*!< Attribute value array attempted to be written. */
list<uint8> aValue @length(cValueLength); /*!< Attribute value array attempted to be written. */
}
/*! GATT Server Long Characteristic Written Event structure */
struct gattServerLongCharacteristicWrittenEvent_t {
uint16 handle; /*!< Handle of the Characteristic Value. */
uint16 cValueLength; /*!< Length of the value written. */
// uint8_t* aValue; /*!< Pointer to the attribute value in the database. */
list<uint8> aValue @length(cValueLength); /*!< Pointer to the attribute value in the database. */
}
/*! Flags for the value of the Client Characteristic Configuration Descriptor. */
enum gattCccdFlags_t {
gCccdEmpty_c = 0x0000, /*!< Nothing is enabled. */
gCccdNotification_c = BIT0, /*!< Enables notifications. */
gCccdIndication_c = BIT1 /*!< Enabled indications. */
}
/*! GATT Server CCCD Written Event structure */
struct gattServerCccdWrittenEvent_t {
uint16 handle; /*!< Handle of the CCCD attribute. */
gattCccdFlags_t newCccd; /*!< New value of the CCCD. */
}
/*! GATT Server Attribute Read Event structure */
struct gattServerAttributeReadEvent_t {
uint16 handle; /*!< Handle of the attribute. */
}
/*! Server-initiated procedure type enumeration */
enum gattServerProcedureType_t {
gSendAttributeWrittenStatus_c, /*!< Procedure initiated by GattServer_SendAttributeWrittenStatus. */
gSendAttributeReadStatus_c, /*!< Procedure initiated by GattServer_SendAttributeReadStatus. */
gSendNotification_c, /*!< Procedure initiated by GattServer_SendNotification. */
gSendIndication_c /*!< Procedure initiated by GattServer_SendIndication. */
}
/*! Server-initiated procedure error structure */
struct gattServerProcedureError_t {
gattServerProcedureType_t procedureType; /*!< Procedure that generated error. */
bleResult_t error; /*!< Error generated. */
}
/*! GATT Server Event structure: type + data. */
struct gattServerEvent_t {
gattServerEventType_t eventType; /*!< Event type. */
union (eventType) {
case gEvtMtuChanged_c:
gattServerMtuChangedEvent_t mtuChangedEvent; /*!< For event type gEvtMtuChanged_c: the new value of the ATT_MTU. */
case gEvtAttributeWritten_c, gEvtAttributeWrittenWithoutResponse_c:
gattServerAttributeWrittenEvent_t attributeWrittenEvent; /*!< For event types gEvtAttributeWritten_c, gEvtAttributeWrittenWithoutResponse_c: handle and value of the attempted write. */
case gEvtCharacteristicCccdWritten_c:
gattServerCccdWrittenEvent_t charCccdWrittenEvent; /*!< For event type gEvtCharacteristicCccdWritten_c: handle and value of the CCCD. */
case gEvtError_c:
gattServerProcedureError_t procedureError; /*!< For event type gEvtError_c: error that terminated a Server-initiated procedure. */
case gEvtLongCharacteristicWritten_c:
gattServerLongCharacteristicWrittenEvent_t longCharWrittenEvent; /*!< For event type gEvtLongCharacteristicWritten_c: handle and value. */
case gEvtAttributeRead_c:
gattServerAttributeReadEvent_t attributeReadEvent; /*!< For event types gEvtAttributeRead_c: handle of the attempted read. */
} eventData; /*!< Event data : selected according to event type. */
}
type gattServerCallback_t = uint32
@group("ble_api")
interface gatt_server {
_GattServer_RegisterCallback(
// gattServerCallback_t callback
) -> bleResult_t
_GattServer_RegisterHandlesForWriteNotifications(
uint8 handleCount,
/*uint16_t ptr*/ list<uint16> aAttributeHandles @length(handleCount)
) -> bleResult_t
GattServer_SendAttributeWrittenStatus(
deviceId_t deviceId,
uint16 attributeHandle,
uint8 status
) -> bleResult_t
_GattServer_RegisterHandlesForReadNotifications(
uint8 handleCount,
/*uint16 ptr*/ list<uint16> aAttributeHandles @length(handleCount)
) -> bleResult_t
GattServer_SendAttributeReadStatus(
deviceId_t deviceId,
uint16 attributeHandle,
uint8 status
) -> bleResult_t
GattServer_SendNotification(
deviceId_t deviceId,
uint16 handle
) -> bleResult_t
GattServer_SendIndication(
deviceId_t deviceId,
uint16 handle
) -> bleResult_t
GattServer_SendInstantValueNotification(
deviceId_t deviceId,
uint16 handle,
uint16 valueLength,
/*uint8_t ptr*/ list<uint8> aValue @length(valueLength)
) -> bleResult_t
GattServer_SendInstantValueIndication(
deviceId_t deviceId,
uint16 handle,
uint16 valueLength,
/*uint8_t ptr*/ list<uint8> aValue @length(valueLength)
) -> bleResult_t
}
@group("ble_api")
@py_interface_name_strip_prefix("_GattDb_")
interface gatt_db {
_GattDb_WriteAttribute(
uint16 handle,
uint16 valueLength,
list<uint8> aValue @length(valueLength)
) -> bleResult_t
_GattDb_ReadAttribute(
uint16 handle,
uint16 maxBytes,
// @out list<uint8> /*uint8 ptr*/ aOutValue @length(pOutValueLength),
out uint16 pOutValueLength
) -> bleResult_t
_GattDb_FindServiceHandle(
uint16 startHandle,
bleUuidType_t serviceUuidType,
bleUuid_t pServiceUuid,
out uint16 pOutServiceHandle
) -> bleResult_t
_GattDb_FindCharValueHandleInService(
uint16 serviceHandle,
bleUuidType_t characteristicUuidType,
bleUuid_t pCharacteristicUuid,
out uint16 pOutCharValueHandle
) -> bleResult_t
GattDb_FindCccdHandleForCharValueHandle(
uint16 charValueHandle,
out uint16 pOutCccdHandle
) -> bleResult_t
_GattDb_FindDescriptorHandleForCharValueHandle(
uint16 charValueHandle,
bleUuidType_t descriptorUuidType,
bleUuid_t pDescriptorUuid,
out uint16 pOutDescriptorHandle
) -> bleResult_t
}
@group("ble_api")
interface gatt_dynamic_db {
GattDbDynamic_AllocateAttributes(
uint16 cNumAttributes
) -> bleResult_t
GattDbDynamic_AllocateAttributeValues(
uint32 cNumBytes
) -> bleResult_t
GattDbDynamic_ReleaseDatabase() -> bleResult_t
GattDbDynamic_AddPrimaryServiceDeclaration(
bleUuidType_t serviceUuidType,
bleUuid_t pServiceUuid
) -> bleResult_t
GattDbDynamic_AddSecondaryServiceDeclaration(
bleUuidType_t serviceUuidType,
bleUuid_t pServiceUuid
) -> bleResult_t
GattDbDynamic_AddIncludeDeclaration(
uint16 includedServiceHandle,
uint16 endGroupHandle,
bleUuidType_t serviceUuidType,
bleUuid_t pServiceUuid
) -> bleResult_t
_GattDbDynamic_AddCharacteristicDeclarationAndValue(
bleUuidType_t characteristicUuidType,
bleUuid_t pCharacteristicUuid,
gattCharacteristicPropertiesBitFields_t characteristicProperties,
uint16 maxValueLength,
uint16 initialValueLength,
list<uint8> aInitialValue @length(initialValueLength),
gattAttributePermissionsBitFields_t valueAccessPermissions
) -> bleResult_t
_GattDbDynamic_AddCharacteristicDescriptor(
bleUuidType_t descriptorUuidType,
bleUuid_t pDescriptorUuid,
uint16 descriptorValueLength,
// list<uint8> aInitialValue @length(initialValueLength),
gattAttributePermissionsBitFields_t descriptorAccessPermissions
) -> bleResult_t
GattDbDynamic_AddCccd() -> bleResult_t
GattDbDynamic_AddCharacteristicDeclarationWithUniqueValue(
bleUuidType_t characteristicUuidType,
bleUuid_t pCharacteristicUuid,
gattCharacteristicPropertiesBitFields_t characteristicProperties,
gattAttributePermissionsBitFields_t valueAccessPermissions
) -> bleResult_t
}
@group("ble_callbacks")
interface gatt_server_cb {
oneway gattServerCallback(
deviceId_t deviceId,
gattServerEvent_t pServerEvent
)
}