Hi,
I'm trying to write a generic tool that lists the attribute table of a connected BLE Peripheral. For each discovered attribute I want to log to the console the attribute number, attribute type and its UUID.
I have a problem with primary service declarations. I can get the declaration UUID (2800) but I don't seem to be able to get the UUID of the service being declared. My understanding is that the service's own UUID is in the user_data field of the bt_gatt_attr.
My code in this area looks like this:
if (bt_uuid_cmp(attr->uuid, BT_UUID_GATT_PRIMARY) == 0) {
printk("Discovered Primary Service\n");
// The service's own UUID is in the user_data field of the bt_gatt_attr
// https://docs.zephyrproject.org/latest/doxygen/html/group__bt__gatt__client.html#:~:text=bt_gatt_discover_func_t,-typedef%20uint8_t(*&text=Discover%20attribute%20callback%20function.,-conn&text=Connection%20object.&text=Attribute%20found%2C%20or%20NULL%20if%20not%20found.&text=Discovery%20parameters%20given.,order%20to%20cache%20its%20information.&text=bt_gatt_attr%20is%20given%20as%20an,See%20below.
struct bt_gatt_service_val *svc = (struct bt_gatt_service_val *)attr->user_data;
uint16_t uuid_val = BT_UUID_16(svc->uuid)->val;
printk("Service UUID = %d\n",uuid_val);
}
But I'm always getting the same value from the user_data UUID field which as a uint16_t is 57926. Like this:
Creating connection with Coded PHY support Connected: D1:00:2D:79:94:DD (random) Discovered Primary Service Service UUID = 57926 Discovered attribute, handle: 01 uuid: 2800 Primary Service Discovered attribute, handle: 02 uuid: 2803 Characteristic Discovered attribute, handle: 03 uuid: 2a05 Service Changed Discovered attribute, handle: 04 uuid: 2902 Client Characteristic Configuration Discovered attribute, handle: 05 uuid: 2803 Characteristic Discovered attribute, handle: 06 uuid: 2b29 Client Supported Features Discovered attribute, handle: 07 uuid: 2803 Characteristic Discovered attribute, handle: 08 uuid: 2b2a Database Hash Discovered Primary Service Service UUID = 57926 Discovered attribute, handle: 09 uuid: 2800 Primary Service Discovered attribute, handle: 10 uuid: 2803 Characteristic Discovered attribute, handle: 11 uuid: 2a00 Device Name Discovered attribute, handle: 12 uuid: 2803 Characteristic Discovered attribute, handle: 13 uuid: 2a01 Appearance Discovered attribute, handle: 14 uuid: 2803 Characteristic Discovered attribute, handle: 15 uuid: 2a04 Peripheral Preferred Connection Parameters Discovered Primary Service Service UUID = 57926 Discovered attribute, handle: 16 uuid: 2800 Primary Service Discovered attribute, handle: 17 uuid: 2803 Characteristic Discovered attribute, handle: 18 uuid: 2a19 Battery Level Discovered attribute, handle: 19 uuid: 2902 Client Characteristic Configuration Discovered attribute, handle: 20 uuid: 2904 Characteristic Presentation Format Discovered Primary Service Service UUID = 57926 Discovered attribute, handle: 21 uuid: 2800 Primary Service Discovered attribute, handle: 22 uuid: 2803 Characteristic Discovered attribute, handle: 23 uuid: 2a24 Model Number String Discovered attribute, handle: 24 uuid: 2803 Characteristic Discovered attribute, handle: 25 uuid: 2a29 Manufacturer Name String Discovered Primary Service Service UUID = 57926 Discovered attribute, handle: 26 uuid: 2800 Primary Service Discovered attribute, handle: 27 uuid: 2803 Characteristic Discovered attribute, handle: 28 uuid: 2a37 Heart Rate Measurement Discovered attribute, handle: 29 uuid: 2902 Client Characteristic Configuration Discovered attribute, handle: 30 uuid: 2803 Characteristic Discovered attribute, handle: 31 uuid: 2a38 Body Sensor Location Discovered attribute, handle: 32 uuid: 2803 Characteristic Discovered attribute, handle: 33 uuid: 2a39 Heart Rate Control Point Discovery complete
What am I doing wrong?
Thanks in anticipation