esphome/esphome/components/bluetooth_proxy/bluetooth_connection.h
Fredrik Gustafsson 29571a1acd
implement pairing for bluetooth proxy (#4475)
* default to just-works encryption

This patch will turn on encryption when making active connections in order to comply with just-works BLE encryption.

* Revert "default to just-works encryption"

This reverts commit 05bc9e9f1c.

* implement pair method

* adhere to clang formatter

* fix oopsie

* bump bluetooth_proxy_version

* add auth callback

* generate new protos

* fix another oopsie

* add pairing status to connection

* clear paired on connect()

* lint

* add unpair ("forget") ble method

* compile protos

* fix oopsie

* add missing unpairing method

* add unpairing

* fix get_paired return type

* remove unused memcpy

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* change to is_paired

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update bluetooth_proxy.cpp

* actually add missing method

* send auth cb on set_encryption failure

* cleanup from havin the worst test setup

* lint

* match auth events to bd_addr

* add second addr check to auth cb

* add addr check to third auth cb

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-03-06 18:04:35 +00:00

36 lines
1 KiB
C++

#pragma once
#ifdef USE_ESP32
#include "esphome/components/esp32_ble_client/ble_client_base.h"
namespace esphome {
namespace bluetooth_proxy {
class BluetoothProxy;
class BluetoothConnection : public esp32_ble_client::BLEClientBase {
public:
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) override;
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
esp_err_t read_characteristic(uint16_t handle);
esp_err_t write_characteristic(uint16_t handle, const std::string &data, bool response);
esp_err_t read_descriptor(uint16_t handle);
esp_err_t write_descriptor(uint16_t handle, const std::string &data, bool response);
esp_err_t notify_characteristic(uint16_t handle, bool enable);
protected:
friend class BluetoothProxy;
bool seen_mtu_or_services_{false};
int16_t send_service_{-2};
BluetoothProxy *proxy_;
};
} // namespace bluetooth_proxy
} // namespace esphome
#endif // USE_ESP32