31class BluetoothGATTGetServicesResponse;
51static constexpr conn_err_t GATT_NOT_CONNECTED = ble_device_base::GATT_ERR_NOT_CONNECTED;
56static constexpr bool SUPPORTS_PAIRING =
true;
57static constexpr bool SUPPORTS_CACHE_CLEARING =
true;
58#elif defined(USE_RP2040_BLE) && defined(USE_BLE_GATT_CLIENT)
62static constexpr bool SUPPORTS_PAIRING =
true;
63static constexpr bool SUPPORTS_CACHE_CLEARING =
false;
65static constexpr bool SUPPORTS_PAIRING =
false;
66static constexpr bool SUPPORTS_CACHE_CLEARING =
false;
70#if (defined(USE_ESP32) || defined(USE_RP2040_BLE)) && defined(USE_BLE_GATT_CLIENT)
75#if defined(USE_ESP32) && defined(USE_BLE_GATT_CLIENT)
82static constexpr int DONE_SENDING_SERVICES = -2;
83static constexpr int INIT_SENDING_SERVICES = -3;
84static constexpr int SERVICES_DONE_PENDING = -4;
87static_assert(DONE_SENDING_SERVICES < 0 && INIT_SENDING_SERVICES < 0 && SERVICES_DONE_PENDING < 0);
88static_assert(DONE_SENDING_SERVICES != GATT_NOT_CONNECTED && INIT_SENDING_SERVICES != GATT_NOT_CONNECTED &&
89 SERVICES_DONE_PENDING != GATT_NOT_CONNECTED);
93static constexpr uint8_t SERVICES_DONE_RETRY_LIMIT = 30;
97static constexpr uint16_t PENDING_ACK_RETRY_LIMIT = 250;
102static constexpr size_t MAX_PACKET_SIZE = 1360;
105static constexpr uint8_t SERVICE_OVERHEAD_LEGACY = 25;
106static constexpr uint8_t SERVICE_OVERHEAD_EFFICIENT = 10;
107static constexpr uint8_t CHAR_SIZE_128BIT = 35;
108static constexpr uint8_t DESC_SIZE_128BIT = 25;
109static constexpr uint8_t DESC_PER_CHAR = 1;
115 size_t service_overhead = use_efficient_uuids ? SERVICE_OVERHEAD_EFFICIENT : SERVICE_OVERHEAD_LEGACY;
116 return service_overhead + (CHAR_SIZE_128BIT + DESC_SIZE_128BIT * DESC_PER_CHAR) * char_count;
126 if (uuid.
type() == ESPBTUUID::Type::UUID128) {
127 const uint8_t *u = uuid.
uuid128();
136 out[0] = ((uint64_t)
value << 32) | 0x00001000ULL;
137 out[1] = 0x800000805F9B34FBULL;
144 static constexpr uint8_t BASE_UUID_TAIL[12] = {0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
145 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
146 if (memcmp(uuid128 + 4, BASE_UUID_TAIL,
sizeof(BASE_UUID_TAIL)) != 0)
147 return ESPBTUUID::from_raw_reversed(uuid128);
149 return value <= UINT16_MAX ? ESPBTUUID::from_uint16(
value) : ESPBTUUID::from_uint32(
value);
158 if (!use_efficient_uuids || uuid.
type() == ESPBTUUID::Type::UUID128) {
160 }
else if (uuid.
type() == ESPBTUUID::Type::UUID16) {
161 short_uuid = uuid.
uuid16();
163 short_uuid = uuid.
uuid32();
167#ifdef USE_BLUETOOTH_PROXY_CONNECTIONS
178 uint8_t connection_index,
const char *address_str);
std::vector< uint8_t > & out
conn_err_t unpair_device(uint64_t address)
size_t estimate_service_size(uint16_t char_count, bool use_efficient_uuids)
Estimate the wire size of a service (service overhead + its characteristics, assuming 128-bit UUIDs a...
void fill_128bit_uuid_array(std::array< uint64_t, 2 > &out, const ble_device_base::ESPBTUUID &uuid)
BatchClose
Result of close_service_batch: keep filling the batch or send it now.
BatchClose close_service_batch(api::BluetoothGATTGetServicesResponse &resp, size_t ¤t_size, int16_t &send_service, uint8_t connection_index, const char *address_str)
Close out the service just packed into resp (account its actual wire size, advance the cursor) and de...
ble_device_base::ESPBTUUID uuid_from_be128(const uint8_t *uuid128)
A 128-bit UUID in big-endian (printable) order, as its 16 or 32-bit form when it is on the Bluetooth ...
void fill_gatt_uuid(std::array< uint64_t, 2 > &uuid_128, uint32_t &short_uuid, const ble_device_base::ESPBTUUID &uuid, bool use_efficient_uuids)
Fill the UUID in the appropriate wire format based on client support and UUID type (128-bit array for...
conn_err_t clear_gatt_cache(uint64_t address)
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.