Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7aa9fc3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "floss: GATT: Make sure OnConnectionUpdated is sent when ConnectionParameterUpdate" into main

parents a7391758 ee26c37d
Loading
Loading
Loading
Loading
+45 −8
Original line number Diff line number Diff line
@@ -1306,6 +1306,10 @@ pub struct ScanFilter {
}

pub enum GattActions {
    /// Used when we need to invoke an update in this layer e.g. when there's no active connection,
    /// where LibBluetooth accepts the conn_parameter_update call but won't send out a callback.
    /// Params: client_id, address, interval, latency, timeout, status
    InvokeConnectionUpdated(i32, RawAddress, i32, i32, i32, GattStatus),
    /// This disconnects all server and client connections to the device.
    /// Params: remote_device
    Disconnect(BluetoothDevice),
@@ -1335,6 +1339,7 @@ enum ControllerScanType {
/// Implementation of the GATT API (IBluetoothGatt).
pub struct BluetoothGatt {
    gatt: Arc<Mutex<Gatt>>,
    tx: Sender<Message>,

    context_map: ContextMap,
    server_context_map: ServerContextMap,
@@ -1370,6 +1375,7 @@ impl BluetoothGatt {
    pub fn new(intf: Arc<Mutex<BluetoothInterface>>, tx: Sender<Message>) -> BluetoothGatt {
        BluetoothGatt {
            gatt: Arc::new(Mutex::new(Gatt::new(&intf.lock().unwrap()))),
            tx: tx.clone(),
            context_map: ContextMap::new(tx.clone()),
            server_context_map: ServerContextMap::new(tx.clone()),
            reliable_queue: HashSet::new(),
@@ -1387,24 +1393,24 @@ impl BluetoothGatt {
        }
    }

    pub fn init_profiles(&mut self, tx: Sender<Message>, api_tx: Sender<APIMessage>) {
    pub fn init_profiles(&mut self, api_tx: Sender<APIMessage>) {
        let gatt_client_callbacks_dispatcher = GattClientCallbacksDispatcher {
            dispatch: make_message_dispatcher(tx.clone(), Message::GattClient),
            dispatch: make_message_dispatcher(self.tx.clone(), Message::GattClient),
        };
        let gatt_server_callbacks_dispatcher = GattServerCallbacksDispatcher {
            dispatch: make_message_dispatcher(tx.clone(), Message::GattServer),
            dispatch: make_message_dispatcher(self.tx.clone(), Message::GattServer),
        };
        let gatt_scanner_callbacks_dispatcher = GattScannerCallbacksDispatcher {
            dispatch: make_message_dispatcher(tx.clone(), Message::LeScanner),
            dispatch: make_message_dispatcher(self.tx.clone(), Message::LeScanner),
        };
        let gatt_scanner_inband_callbacks_dispatcher = GattScannerInbandCallbacksDispatcher {
            dispatch: make_message_dispatcher(tx.clone(), Message::LeScannerInband),
            dispatch: make_message_dispatcher(self.tx.clone(), Message::LeScannerInband),
        };
        let gatt_adv_inband_callbacks_dispatcher = GattAdvInbandCallbacksDispatcher {
            dispatch: make_message_dispatcher(tx.clone(), Message::LeAdvInband),
            dispatch: make_message_dispatcher(self.tx.clone(), Message::LeAdvInband),
        };
        let gatt_adv_callbacks_dispatcher = GattAdvCallbacksDispatcher {
            dispatch: make_message_dispatcher(tx.clone(), Message::LeAdv),
            dispatch: make_message_dispatcher(self.tx.clone(), Message::LeAdv),
        };

        self.gatt.lock().unwrap().initialize(
@@ -1820,6 +1826,20 @@ impl BluetoothGatt {

    pub fn handle_action(&mut self, action: GattActions) {
        match action {
            GattActions::InvokeConnectionUpdated(
                client_id,
                addr,
                interval,
                latency,
                timeout,
                status,
            ) => {
                if let Some(client) = self.context_map.get_by_client_id(client_id) {
                    if let Some(cb) = self.context_map.get_callback_from_callback_id(client.cbid) {
                        cb.on_connection_updated(addr, interval, latency, timeout, status);
                    }
                }
            }
            GattActions::Disconnect(device) => {
                for client_id in self.context_map.get_client_ids_from_address(&device.address) {
                    if let Some(conn_id) =
@@ -2474,7 +2494,7 @@ impl IBluetoothGatt for BluetoothGatt {

    fn connection_parameter_update(
        &self,
        _client_id: i32,
        client_id: i32,
        addr: RawAddress,
        min_interval: i32,
        max_interval: i32,
@@ -2492,6 +2512,23 @@ impl IBluetoothGatt for BluetoothGatt {
            min_ce_len,
            max_ce_len,
        );
        // If there's no connection for this client, LibBluetooth would not propagate a callback.
        // Thus make up a success callback here.
        if self.context_map.get_conn_id_from_address(client_id, &addr).is_none() {
            let tx = self.tx.clone();
            tokio::spawn(async move {
                let _ = tx
                    .send(Message::GattActions(GattActions::InvokeConnectionUpdated(
                        client_id,
                        addr,
                        max_interval,
                        latency,
                        timeout,
                        GattStatus::Success,
                    )))
                    .await;
            });
        }
    }

    fn client_set_preferred_phy(
+1 −1
Original line number Diff line number Diff line
@@ -303,7 +303,7 @@ impl Stack {
                    bluetooth_media.lock().unwrap().initialize();
                    bluetooth.lock().unwrap().set_media(bluetooth_media.clone());
                    // Init Gatt and pass it to Bluetooth.
                    bluetooth_gatt.lock().unwrap().init_profiles(tx.clone(), api_tx.clone());
                    bluetooth_gatt.lock().unwrap().init_profiles(api_tx.clone());
                    bluetooth_gatt.lock().unwrap().enable(true);
                    bluetooth.lock().unwrap().set_gatt_and_init_scanner(bluetooth_gatt.clone());
                    // Init AdvertiseManager. It selects the stack per is_le_ext_adv_supported