You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -11,6 +11,8 @@ This document describes how to customize Bluetooth LE services on your {IDF_TARG
11
11
12
12
The Bluetooth LE services are defined as a multivariate array of GATT structures, and the array contains at least one primary service whose attribute type is defined as 0x2800. Each service always consists of a service definition and several characteristics. Each characteristic always consists of a value and optional descriptors. Please refer to Part Generic Attribute Profile (GATT) of `Bluetooth Core Specification <https://www.bluetooth.com/specifications/specs/core-specification-4-2>`_ for more information.
13
13
14
+
ESP-AT uses the same ``gatts_data.csv`` format on all chips that support Bluetooth LE. The rules below describe which fields take effect on {IDF_TARGET_NAME}.
15
+
14
16
.. _factory-gatts-intro:
15
17
16
18
Bluetooth LE Service Source File
@@ -41,7 +43,7 @@ The ESP-AT project creates Bluetooth LE services based on its Bluetooth LE servi
41
43
- 0x01
42
44
- 1
43
45
- 1
44
-
- 2
46
+
- 02
45
47
* - 2
46
48
- 16
47
49
- 0xC300
@@ -66,7 +68,7 @@ The ESP-AT project creates Bluetooth LE services based on its Bluetooth LE servi
66
68
67
69
Below are descriptions of the table above.
68
70
69
-
- ``perm`` field describes the permission. Its definition in the ESP-AT project is as follows:
71
+
- ``perm`` describes attribute permissions. When a row's ``perm`` takes effect (see the rules below), its definition in the ESP-AT project is as follows:
70
72
71
73
.. code-block:: c
72
74
@@ -85,15 +87,23 @@ Below are descriptions of the table above.
- The first line of table is the service definition with a UUID of ``0xA002``.
89
-
- The second line is the declaration of a characteristic. UUID ``0x2803`` means the characteristic declaration. The value ``2`` sets the permission. The length of permission is 8 bits, and each bit represents permission for an operation. ``1`` indicates that the operation is supported, and ``0`` indicates not supported.
90
+
- The first line of the table is the service definition. Its attribute type is ``0x2800`` (primary service), and its ``value`` ``A002`` is the 16-bit service UUID ``0xA002``.
91
+
- The second line is the characteristic declaration. UUID ``0x2803`` identifies this row as a characteristic declaration.
92
+
93
+
- ``value``: characteristic properties of the **next** characteristic value attribute (the following row). It is one byte (8 bits). Each bit indicates whether a property is supported (``1``) or not (``0``).
94
+
95
+
.. only:: esp32c2 or esp32c5 or esp32c6 or esp32c61
96
+
97
+
On {IDF_TARGET_NAME}, ESP-AT translates this property value internally; you do not need to handle the difference.
98
+
99
+
For example, ``value`` ``02`` means the following characteristic has the READ property.
90
100
91
101
.. list-table::
92
102
:header-rows: 1
93
103
:widths: 20 100
94
104
95
105
* - Bit
96
-
- Permission
106
+
- Characteristic Property
97
107
* - 0
98
108
- BROADCAST
99
109
* - 1
@@ -110,8 +120,126 @@ Below are descriptions of the table above.
110
120
- AUTHENTICATION SIGNED WRITES
111
121
* - 7
112
122
- EXTENDED PROPERTIES
113
-
- The third line defines a characteristic of the service. UUID of this line is the characteristic's UUID, and value is the characteristic's value.
123
+
124
+
- The third line defines the characteristic value attribute of that characteristic. The ``uuid`` of this line is the characteristic UUID, and ``value`` is the characteristic's initial value.
114
125
- The fourth line defines a descriptor of the characteristic (optional).
126
+
- The ``value`` field is optional. If it is left empty, ESP-AT fills the attribute with all zeros during initialization. For example, in the default table, the characteristic ``0xC301`` row leaves ``value`` empty, so the characteristic is initialized to all zeros.
127
+
128
+
Field Rules
129
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130
+
131
+
.. only:: esp32 or esp32c3
132
+
133
+
- For the ``0x2803`` row, both ``perm`` and ``value`` take effect: ``perm`` is the permission of the declaration attribute itself (usually ``0x01``, readable), and ``value`` is the properties of the next characteristic.
134
+
- For the characteristic value row, ``perm`` takes effect. It must not conflict with the properties in the previous ``0x2803`` row. Properties advertise which operations the characteristic supports; ``perm`` controls whether the stack actually allows those operations. If properties claim READ-only but the value-row ``perm`` is WRITE-only, clients will fail when they try to read.
135
+
136
+
Typical mapping (encrypted or signed permission variants may be used when security is required):
137
+
138
+
.. list-table::
139
+
:header-rows: 1
140
+
:widths: 35 65
141
+
142
+
* - If properties include
143
+
- Characteristic value ``perm`` should include at least
144
+
* - READ
145
+
- READ (``0x01``), or a read-related encrypted/authorized variant
146
+
* - WRITE
147
+
- WRITE (``0x10``), or a write-related encrypted/authorized/signed variant
148
+
* - WRITE WITHOUT RESPONSE
149
+
- WRITE (``0x10``), or a write-related encrypted/authorized/signed variant
150
+
* - NOTIFY or INDICATE
151
+
- Usually READ on the characteristic value; you must add the CCCD (``0x2902``) yourself. Its ``perm`` is typically READ | WRITE (``0x11``).
152
+
153
+
You can combine properties. For example, ``0A`` (READ | WRITE) should be paired with characteristic value ``perm`` ``0x11`` (READ | WRITE).
154
+
155
+
- If the characteristic supports NOTIFY or INDICATE, add a ``0x2902`` row in the table. Other descriptors (such as ``0x2901``) are also added as defined, and each descriptor row's ``perm`` takes effect.
156
+
157
+
.. only:: esp32c2 or esp32c5 or esp32c6 or esp32c61
158
+
159
+
- For the ``0x2803`` row, only ``value`` (properties of the next characteristic) takes effect. The ``perm`` of this row is **ignored and does not take effect**.
160
+
- For the characteristic value row, ``perm`` is **ignored and does not take effect**. If the optional 8th field described below is not provided, the characteristic capabilities come only from the ``value`` (properties) of the previous ``0x2803`` row.
161
+
- If the characteristic properties include NOTIFY or INDICATE, the CCCD (``0x2902``) is **added automatically**. Any ``0x2902`` row in ``gatts_data.csv`` is **skipped and not processed** (you may keep such rows for CSV compatibility; they simply do not take effect on {IDF_TARGET_NAME}).
162
+
- Other descriptors (such as ``0x2901``) are still added. If the optional 8th field described below is not provided, ``perm`` of **that descriptor row** takes effect.
163
+
164
+
**Optional 8th field**
165
+
166
+
On {IDF_TARGET_NAME}, **characteristic value rows** and **descriptor rows** may append an optional field after ``value``. The ``0x`` / ``0X`` prefix is optional. If you add this field on other rows (such as the service definition ``0x2800`` or the characteristic declaration ``0x2803``), it **does not take effect**.
167
+
168
+
1. **Characteristic value row**: the 8th field is a **32-bit** hexadecimal string that sets the full characteristic flag. If this field is present, the ``value`` (properties) of the **previous** ``0x2803`` row is **ignored and does not take effect**; this field takes precedence.
169
+
170
+
For example, the original row:
171
+
172
+
.. code-block:: none
173
+
174
+
2,16,0xC300,0x01,1,1,30
175
+
176
+
can also be written as:
177
+
178
+
.. code-block:: none
179
+
180
+
2,16,0xC300,0x01,1,1,30,0x00020000
181
+
182
+
or:
183
+
184
+
.. code-block:: none
185
+
186
+
2,16,0xC300,0x01,1,1,30,00020000
187
+
188
+
The field is defined as follows (bits can be combined with OR):
2. **Descriptor row**: the 8th field is an **8-bit** hexadecimal string that sets the descriptor permission. If this field is present, ``perm`` of **this row** is **ignored and does not take effect**; this field takes precedence.
212
+
213
+
For example, the original row:
214
+
215
+
.. code-block:: none
216
+
217
+
3,16,0x2901,0x11,1,1,30
218
+
219
+
can also be written as:
220
+
221
+
.. code-block:: none
222
+
223
+
3,16,0x2901,0x11,1,1,30,0x80
224
+
225
+
or:
226
+
227
+
.. code-block:: none
228
+
229
+
3,16,0x2901,0x11,1,1,30,80
230
+
231
+
The field is defined as follows (bits can be combined with OR):
232
+
233
+
.. code-block:: c
234
+
235
+
#define BLE_ATT_F_READ 0x01
236
+
#define BLE_ATT_F_WRITE 0x02
237
+
#define BLE_ATT_F_READ_ENC 0x04
238
+
#define BLE_ATT_F_READ_AUTHEN 0x08
239
+
#define BLE_ATT_F_READ_AUTHOR 0x10
240
+
#define BLE_ATT_F_WRITE_ENC 0x20
241
+
#define BLE_ATT_F_WRITE_AUTHEN 0x40
242
+
#define BLE_ATT_F_WRITE_AUTHOR 0x80
115
243
116
244
For more information about UUID, please refer to `Bluetooth Special Interest Group (SIG) Assigned Numbers <https://www.bluetooth.com/specifications/assigned-numbers/>`_.
117
245
@@ -162,6 +290,14 @@ You can define more than one service. For example, if you want to define three s
162
290
163
291
In this example, we define a readable and writable characteristic with UUID 0xC300, and set its value to 0x30.
164
292
293
+
.. only:: esp32 or esp32c3
294
+
295
+
The declaration-row ``perm`` is ``0x01``. The characteristic-value-row ``perm`` is ``0x11`` (required to match READ | WRITE properties).
296
+
297
+
.. only:: esp32c2 or esp32c5 or esp32c6 or esp32c61
298
+
299
+
The declaration-row ``perm`` and the characteristic-value-row ``perm`` are ignored and do not take effect.
300
+
165
301
.. list-table::
166
302
:header-rows: 1
167
303
@@ -175,7 +311,7 @@ You can define more than one service. For example, if you want to define three s
175
311
* - 32
176
312
- 16
177
313
- 0x2803
178
-
- 0x11
314
+
- 0x01
179
315
- 1
180
316
- 1
181
317
- 0A
@@ -189,66 +325,110 @@ You can define more than one service. For example, if you want to define three s
189
325
190
326
3. Add the characteristic descriptor (optional).
191
327
192
-
In this example, we add client characteristic configuration. Its value 0x0000 represents notifications and indications are disabled.
193
-
194
-
.. list-table::
195
-
:header-rows: 1
196
-
197
-
* - index
198
-
- uuid_len
199
-
- uuid
200
-
- perm
201
-
- val_max_len
202
-
- val_cur_len
203
-
- value
204
-
* - 34
205
-
- 16
206
-
- 0x2902
207
-
- 0x11
208
-
- 2
209
-
- 2
210
-
- 0000
211
-
212
-
After the above steps, the customized Bluetooth LE service has been defined as follows.
213
-
214
-
.. list-table::
215
-
:header-rows: 1
216
-
217
-
* - index
218
-
- uuid_len
219
-
- uuid
220
-
- perm
221
-
- val_max_len
222
-
- val_cur_len
223
-
- value
224
-
* - 31
225
-
- 16
226
-
- 0x2800
227
-
- 0x01
228
-
- 2
229
-
- 2
230
-
- FF01
231
-
* - 32
232
-
- 16
233
-
- 0x2803
234
-
- 0x11
235
-
- 1
236
-
- 1
237
-
- 0A
238
-
* - 33
239
-
- 16
240
-
- 0xC300
241
-
- 0x11
242
-
- 1
243
-
- 1
244
-
- 30
245
-
* - 34
246
-
- 16
247
-
- 0x2902
248
-
- 0x11
249
-
- 2
250
-
- 2
251
-
- 0000
328
+
The characteristic in step 2 uses properties ``0A`` (READ | WRITE) and does **not** require a CCCD. The content below is a **separate optional illustration** for characteristics that support NOTIFY or INDICATE; it is not tied to the ``0A`` example above. If you need NOTIFY, set the ``0x2803`` properties accordingly (for example ``1A`` for READ | WRITE | NOTIFY).
329
+
330
+
.. only:: esp32 or esp32c3
331
+
332
+
If the characteristic supports NOTIFY or INDICATE, add client characteristic configuration (``0x2902``) yourself. The example below sets ``value`` to ``0000`` (notifications and indications disabled).
333
+
334
+
Example of a CCCD row:
335
+
336
+
.. list-table::
337
+
:header-rows: 1
338
+
339
+
* - index
340
+
- uuid_len
341
+
- uuid
342
+
- perm
343
+
- val_max_len
344
+
- val_cur_len
345
+
- value
346
+
* - 34
347
+
- 16
348
+
- 0x2902
349
+
- 0x11
350
+
- 2
351
+
- 2
352
+
- 0000
353
+
354
+
After the above steps, the customized Bluetooth LE service can be defined as follows. The table combines the service and characteristic from steps 1–2 with the optional CCCD illustration from step 3. For the ``0A`` (READ | WRITE) characteristic alone, omit the ``0x2902`` row.
355
+
356
+
.. list-table::
357
+
:header-rows: 1
358
+
359
+
* - index
360
+
- uuid_len
361
+
- uuid
362
+
- perm
363
+
- val_max_len
364
+
- val_cur_len
365
+
- value
366
+
* - 31
367
+
- 16
368
+
- 0x2800
369
+
- 0x01
370
+
- 2
371
+
- 2
372
+
- FF01
373
+
* - 32
374
+
- 16
375
+
- 0x2803
376
+
- 0x01
377
+
- 1
378
+
- 1
379
+
- 0A
380
+
* - 33
381
+
- 16
382
+
- 0xC300
383
+
- 0x11
384
+
- 1
385
+
- 1
386
+
- 30
387
+
* - 34
388
+
- 16
389
+
- 0x2902
390
+
- 0x11
391
+
- 2
392
+
- 2
393
+
- 0000
394
+
395
+
.. only:: esp32c2 or esp32c5 or esp32c6 or esp32c61
396
+
397
+
If properties include NOTIFY or INDICATE, CCCD is added automatically. You do not need to add a ``0x2902`` row; if the row exists in the CSV, it is skipped and does not take effect. Other descriptors (not ``0x2902``) are still added, and that row's ``perm`` takes effect.
398
+
399
+
After the above steps, the customized Bluetooth LE service can be defined as follows (the ``0A`` READ | WRITE example; no ``0x2902`` row is needed):
400
+
401
+
.. list-table::
402
+
:header-rows: 1
403
+
404
+
* - index
405
+
- uuid_len
406
+
- uuid
407
+
- perm
408
+
- val_max_len
409
+
- val_cur_len
410
+
- value
411
+
* - 31
412
+
- 16
413
+
- 0x2800
414
+
- 0x01
415
+
- 2
416
+
- 2
417
+
- FF01
418
+
* - 32
419
+
- 16
420
+
- 0x2803
421
+
- 0x01
422
+
- 1
423
+
- 1
424
+
- 0A
425
+
* - 33
426
+
- 16
427
+
- 0xC300
428
+
- 0x11
429
+
- 1
430
+
- 1
431
+
- 30
252
432
253
433
Please modify the GATTS configurations according to your own needs and generate ``mfg_nvs.bin`` file.
0 commit comments