-
Notifications
You must be signed in to change notification settings - Fork 673
Description
Overview
I was debugging some code which was using the att_db_util to generate the ATT DB at runtime and comparing it to the output of compile_gatt.py to verify the results. They did not match for the simple Battery Service and characteristic.
When using compile_gatt.py on a characteristic w/NOTIFY or INDICATE, the flags entry of the ATTDB entry includes WRITE_WITHOUT_RESPONSE.
PRIMARY_SERVICE, ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE
CHARACTERISTIC, ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL, DYNAMIC | READ | NOTIFY,
generates
// 0x0004 PRIMARY_SERVICE-ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE
0x0a, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x28, 0x0f, 0x18,
// 0x0005 CHARACTERISTIC-ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL - DYNAMIC | READ | NOTIFY
0x0d, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x28, 0x12, 0x06, 0x00, 0x19, 0x2a,
// 0x0006 VALUE CHARACTERISTIC-ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL - DYNAMIC | READ | NOTIFY
// READ_ANYBODY
0x08, 0x00, 0x02, 0x01, 0x06, 0x00, 0x19, 0x2a,
// 0x0007 CLIENT_CHARACTERISTIC_CONFIGURATION
// READ_ANYBODY, WRITE_ANYBODY
0x0a, 0x00, 0x0e, 0x01, 0x07, 0x00, 0x02, 0x29, 0x00, 0x00,
which has flags=0x010e on the last line.
When using att_db_util to programatically generate the same characteristic entries it does not include the WRITE_WITHOUT_RESPONSE bit set
0a 00 02 00 04 00 00 28 0f 18
0d 00 02 00 05 00 03 28 12 06 00 19 2a
08 00 02 01 06 00 19 2a
0a 00 0a 01 07 00 02 29 00 00
Here, the flags on the CCC line are 0x0107.
Steps to reproduce
The Python sets the WRITE_WO_RESP flag bit:
Lines 622 to 629 in af0dac0
| if add_client_characteristic_configuration(properties): | |
| # use write permissions and encryption key size from attribute value and set READ_ANYBODY | READ | WRITE | DYNAMIC | |
| flags = write_permissions_and_key_size_flags_from_properties(properties) | |
| flags |= property_flags['READ'] | |
| flags |= property_flags['WRITE'] | |
| flags |= property_flags['WRITE_WITHOUT_RESPONSE'] | |
| flags |= property_flags['DYNAMIC'] |
The C code does not:
Lines 245 to 248 in af0dac0
| static void att_db_util_add_client_characteristic_configuration(uint16_t flags){ | |
| uint8_t buffer[2]; | |
| // drop permission for read (0xc00), keep write permissions (0x0091) | |
| uint16_t flags_to_store = (flags & 0x1f391u) | ATT_PROPERTY_READ | ATT_PROPERTY_WRITE | ATT_PROPERTY_DYNAMIC; |
Expected behavior
They should both set the same flags on the CCC. Either set the WRITE_WO_RESPONSE flag on both, or on neither.