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

Commit 977de034 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang Committed by Gerrit Code Review
Browse files

Merge changes Ic4c909a2,Id177abdb into main

* changes:
  floss: topshim: gatt: Remove unnecessary type convert
  floss: topshim: Add utility for easier sharing types with cxx bridge
parents 3609373c 89f48ed3
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -6,8 +6,8 @@ use bt_topshim::btif::{
    BluetoothInterface, BtStatus, BtTransport, DisplayAddress, RawAddress, Uuid,
    BluetoothInterface, BtStatus, BtTransport, DisplayAddress, RawAddress, Uuid,
};
};
use bt_topshim::profiles::gatt::{
use bt_topshim::profiles::gatt::{
    ffi::RustAdvertisingTrackInfo, AdvertisingStatus, BtGattDbElement, BtGattNotifyParams,
    AdvertisingStatus, AdvertisingTrackInfo, BtGattDbElement, BtGattNotifyParams, BtGattReadParams,
    BtGattReadParams, BtGattResponse, BtGattValue, Gatt, GattAdvCallbacksDispatcher,
    BtGattResponse, BtGattValue, Gatt, GattAdvCallbacksDispatcher,
    GattAdvInbandCallbacksDispatcher, GattClientCallbacks, GattClientCallbacksDispatcher,
    GattAdvInbandCallbacksDispatcher, GattClientCallbacks, GattClientCallbacksDispatcher,
    GattScannerCallbacks, GattScannerCallbacksDispatcher, GattScannerInbandCallbacks,
    GattScannerCallbacks, GattScannerCallbacksDispatcher, GattScannerInbandCallbacks,
    GattScannerInbandCallbacksDispatcher, GattServerCallbacks, GattServerCallbacksDispatcher,
    GattScannerInbandCallbacksDispatcher, GattServerCallbacks, GattServerCallbacksDispatcher,
@@ -3742,7 +3742,7 @@ pub(crate) trait BtifGattScannerCallbacks {
    );
    );


    #[btif_callback(OnTrackAdvFoundLost)]
    #[btif_callback(OnTrackAdvFoundLost)]
    fn on_track_adv_found_lost(&mut self, adv_track_info: RustAdvertisingTrackInfo);
    fn on_track_adv_found_lost(&mut self, adv_track_info: AdvertisingTrackInfo);
}
}


#[btif_callbacks_dispatcher(dispatch_le_scanner_inband_callbacks, GattScannerInbandCallbacks)]
#[btif_callbacks_dispatcher(dispatch_le_scanner_inband_callbacks, GattScannerInbandCallbacks)]
@@ -4019,7 +4019,7 @@ impl BtifGattScannerCallbacks for BluetoothGatt {
        });
        });
    }
    }


    fn on_track_adv_found_lost(&mut self, track_adv_info: RustAdvertisingTrackInfo) {
    fn on_track_adv_found_lost(&mut self, track_adv_info: AdvertisingTrackInfo) {
        let addr = track_adv_info.advertiser_address;
        let addr = track_adv_info.advertiser_address;
        let display_addr = DisplayAddress(&addr);
        let display_addr = DisplayAddress(&addr);
        let mut binding = self.scanners.lock().unwrap();
        let mut binding = self.scanners.lock().unwrap();
+0 −42
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef GD_RUST_TOPSHIM_COMMON_TYPE_ALIAS_H
#define GD_RUST_TOPSHIM_COMMON_TYPE_ALIAS_H

/*
 * Declare type aliases in the topshim namespace in this file.
 *
 * The type declarations in cxx bridge blocks are bound to the namespace of the
 * block. Since in topshim we always put the bridge codes in namespace
 * `bluetooth::topshim::rust`, to reuse the existing types in GD it's necessary
 * to define the aliases in the topshim namespace.
 */

#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

namespace bluetooth {
namespace topshim {
namespace rust {

using RawAddress = ::RawAddress;
using Uuid = ::bluetooth::Uuid;

}  // namespace rust
}  // namespace topshim
}  // namespace bluetooth

#endif  // GD_RUST_TOPSHIM_COMMON_TYPE_ALIAS_H
+2 −2
Original line number Original line Diff line number Diff line
@@ -124,10 +124,10 @@ impl GattServiceImpl {
            filt_logic_type: 0,
            filt_logic_type: 0,
            rssi_high_thres: 0,
            rssi_high_thres: 0,
            rssi_low_thres: 0,
            rssi_low_thres: 0,
            delay_mode: 0,
            dely_mode: 0,
            found_timeout: 0,
            found_timeout: 0,
            lost_timeout: 0,
            lost_timeout: 0,
            found_timeout_count: 0,
            found_timeout_cnt: 0,
            num_of_tracking_entries: 0,
            num_of_tracking_entries: 0,
        }
        }
    }
    }
+15 −45
Original line number Original line Diff line number Diff line
@@ -37,35 +37,6 @@ namespace rust {


namespace rusty = ::bluetooth::topshim::rust;
namespace rusty = ::bluetooth::topshim::rust;


namespace internal {
AdvertiseParameters ConvertRustAdvParams(const RustAdvertiseParameters& params) {
  AdvertiseParameters converted = {
      .advertising_event_properties = params.advertising_event_properties,
      .min_interval = params.min_interval,
      .max_interval = params.max_interval,
      .channel_map = params.channel_map,
      .tx_power = params.tx_power,
      .primary_advertising_phy = params.primary_advertising_phy,
      .secondary_advertising_phy = params.secondary_advertising_phy,
      .scan_request_notification_enable = params.scan_request_notification_enable,
      .own_address_type = params.own_address_type,
  };

  return converted;
}
PeriodicAdvertisingParameters ConvertRustPeriodicAdvParams(const RustPeriodicAdvertisingParameters& params) {
  PeriodicAdvertisingParameters converted = {
      .enable = params.enable,
      .include_adi = params.include_adi,
      .min_interval = params.min_interval,
      .max_interval = params.max_interval,
      .periodic_advertising_properties = params.periodic_advertising_properties,
  };

  return converted;
}
}  // namespace internal

// AdvertisingCallbacks implementations
// AdvertisingCallbacks implementations


void BleAdvertiserIntf::OnAdvertisingSetStarted(int reg_id, uint8_t advertiser_id, int8_t tx_power, uint8_t status) {
void BleAdvertiserIntf::OnAdvertisingSetStarted(int reg_id, uint8_t advertiser_id, int8_t tx_power, uint8_t status) {
@@ -111,10 +82,11 @@ void BleAdvertiserIntf::GetOwnAddress(uint8_t adv_id) {
      adv_id, base::Bind(&BleAdvertiserIntf::OnGetAddressCallback, base::Unretained(this), adv_id));
      adv_id, base::Bind(&BleAdvertiserIntf::OnGetAddressCallback, base::Unretained(this), adv_id));
}
}


void BleAdvertiserIntf::SetParameters(uint8_t adv_id, RustAdvertiseParameters params) {
void BleAdvertiserIntf::SetParameters(uint8_t adv_id, AdvertiseParameters params) {
  AdvertiseParameters converted = internal::ConvertRustAdvParams(params);
  adv_intf_->SetParameters(
  adv_intf_->SetParameters(
      adv_id, converted, base::Bind(&BleAdvertiserIntf::OnParametersCallback, base::Unretained(this), adv_id));
      adv_id,
      params,
      base::Bind(&BleAdvertiserIntf::OnParametersCallback, base::Unretained(this), adv_id));
}
}


void BleAdvertiserIntf::SetData(uint8_t adv_id, bool set_scan_rsp, ::rust::Vec<uint8_t> data) {
void BleAdvertiserIntf::SetData(uint8_t adv_id, bool set_scan_rsp, ::rust::Vec<uint8_t> data) {
@@ -140,11 +112,10 @@ void BleAdvertiserIntf::Enable(uint8_t adv_id, bool enable, uint16_t duration, u


void BleAdvertiserIntf::StartAdvertising(
void BleAdvertiserIntf::StartAdvertising(
    uint8_t adv_id,
    uint8_t adv_id,
    RustAdvertiseParameters params,
    AdvertiseParameters params,
    ::rust::Vec<uint8_t> advertise_data,
    ::rust::Vec<uint8_t> advertise_data,
    ::rust::Vec<uint8_t> scan_response_data,
    ::rust::Vec<uint8_t> scan_response_data,
    int32_t timeout_in_sec) {
    int32_t timeout_in_sec) {
  AdvertiseParameters converted_params = internal::ConvertRustAdvParams(params);
  std::vector<uint8_t> converted_adv_data, converted_scan_rsp_data;
  std::vector<uint8_t> converted_adv_data, converted_scan_rsp_data;
  std::copy(advertise_data.begin(), advertise_data.end(), std::back_inserter(converted_adv_data));
  std::copy(advertise_data.begin(), advertise_data.end(), std::back_inserter(converted_adv_data));
  std::copy(scan_response_data.begin(), scan_response_data.end(), std::back_inserter(converted_scan_rsp_data));
  std::copy(scan_response_data.begin(), scan_response_data.end(), std::back_inserter(converted_scan_rsp_data));
@@ -152,7 +123,7 @@ void BleAdvertiserIntf::StartAdvertising(
  adv_intf_->StartAdvertising(
  adv_intf_->StartAdvertising(
      adv_id,
      adv_id,
      base::Bind(&BleAdvertiserIntf::OnIdStatusCallback, base::Unretained(this), adv_id),
      base::Bind(&BleAdvertiserIntf::OnIdStatusCallback, base::Unretained(this), adv_id),
      converted_params,
      params,
      converted_adv_data,
      converted_adv_data,
      converted_scan_rsp_data,
      converted_scan_rsp_data,
      timeout_in_sec,
      timeout_in_sec,
@@ -161,15 +132,13 @@ void BleAdvertiserIntf::StartAdvertising(


void BleAdvertiserIntf::StartAdvertisingSet(
void BleAdvertiserIntf::StartAdvertisingSet(
    int32_t reg_id,
    int32_t reg_id,
    RustAdvertiseParameters params,
    AdvertiseParameters params,
    ::rust::Vec<uint8_t> advertise_data,
    ::rust::Vec<uint8_t> advertise_data,
    ::rust::Vec<uint8_t> scan_response_data,
    ::rust::Vec<uint8_t> scan_response_data,
    RustPeriodicAdvertisingParameters periodic_params,
    PeriodicAdvertisingParameters periodic_params,
    ::rust::Vec<uint8_t> periodic_data,
    ::rust::Vec<uint8_t> periodic_data,
    uint16_t duration,
    uint16_t duration,
    uint8_t max_ext_adv_events) {
    uint8_t max_ext_adv_events) {
  AdvertiseParameters converted_params = internal::ConvertRustAdvParams(params);
  PeriodicAdvertisingParameters converted_periodic_params = internal::ConvertRustPeriodicAdvParams(periodic_params);
  std::vector<uint8_t> converted_adv_data, converted_scan_rsp_data, converted_periodic_data;
  std::vector<uint8_t> converted_adv_data, converted_scan_rsp_data, converted_periodic_data;
  std::copy(advertise_data.begin(), advertise_data.end(), std::back_inserter(converted_adv_data));
  std::copy(advertise_data.begin(), advertise_data.end(), std::back_inserter(converted_adv_data));
  std::copy(scan_response_data.begin(), scan_response_data.end(), std::back_inserter(converted_scan_rsp_data));
  std::copy(scan_response_data.begin(), scan_response_data.end(), std::back_inserter(converted_scan_rsp_data));
@@ -179,21 +148,22 @@ void BleAdvertiserIntf::StartAdvertisingSet(
      kAdvertiserClientIdJni,
      kAdvertiserClientIdJni,
      reg_id,
      reg_id,
      base::Bind(&BleAdvertiserIntf::OnIdTxPowerStatusCallback, base::Unretained(this)),
      base::Bind(&BleAdvertiserIntf::OnIdTxPowerStatusCallback, base::Unretained(this)),
      converted_params,
      params,
      converted_adv_data,
      converted_adv_data,
      converted_scan_rsp_data,
      converted_scan_rsp_data,
      converted_periodic_params,
      periodic_params,
      converted_periodic_data,
      converted_periodic_data,
      duration,
      duration,
      max_ext_adv_events,
      max_ext_adv_events,
      base::Bind(&BleAdvertiserIntf::OnIdStatusCallback, base::Unretained(this)));
      base::Bind(&BleAdvertiserIntf::OnIdStatusCallback, base::Unretained(this)));
}
}


void BleAdvertiserIntf::SetPeriodicAdvertisingParameters(uint8_t adv_id, RustPeriodicAdvertisingParameters params) {
void BleAdvertiserIntf::SetPeriodicAdvertisingParameters(
  PeriodicAdvertisingParameters converted = internal::ConvertRustPeriodicAdvParams(params);
    uint8_t adv_id, PeriodicAdvertisingParameters params) {

  adv_intf_->SetPeriodicAdvertisingParameters(
  adv_intf_->SetPeriodicAdvertisingParameters(
      adv_id, converted, base::Bind(&BleAdvertiserIntf::OnIdStatusCallback, base::Unretained(this), adv_id));
      adv_id,
      params,
      base::Bind(&BleAdvertiserIntf::OnIdStatusCallback, base::Unretained(this), adv_id));
}
}


void BleAdvertiserIntf::SetPeriodicAdvertisingData(uint8_t adv_id, ::rust::Vec<uint8_t> data) {
void BleAdvertiserIntf::SetPeriodicAdvertisingData(uint8_t adv_id, ::rust::Vec<uint8_t> data) {
+5 −10
Original line number Original line Diff line number Diff line
@@ -19,17 +19,12 @@
#include <memory>
#include <memory>


#include "include/hardware/ble_advertiser.h"
#include "include/hardware/ble_advertiser.h"
#include "include/hardware/bt_gatt.h"
#include "rust/cxx.h"
#include "rust/cxx.h"


namespace bluetooth {
namespace bluetooth {
namespace topshim {
namespace topshim {
namespace rust {
namespace rust {


struct RustAdvertiseParameters;
struct RustPeriodicAdvertisingParameters;
struct RustUuid;

// See include/hardware/ble_advertiser.h for more documentation.
// See include/hardware/ble_advertiser.h for more documentation.
//
//
// This shim implementation just calls the underlying interface and binds the
// This shim implementation just calls the underlying interface and binds the
@@ -56,25 +51,25 @@ class BleAdvertiserIntf : public AdvertisingCallbacks {
  void Unregister(uint8_t adv_id);
  void Unregister(uint8_t adv_id);


  void GetOwnAddress(uint8_t adv_id);
  void GetOwnAddress(uint8_t adv_id);
  void SetParameters(uint8_t adv_id, RustAdvertiseParameters params);
  void SetParameters(uint8_t adv_id, AdvertiseParameters params);
  void SetData(uint8_t adv_id, bool set_scan_rsp, ::rust::Vec<uint8_t> data);
  void SetData(uint8_t adv_id, bool set_scan_rsp, ::rust::Vec<uint8_t> data);
  void Enable(uint8_t adv_id, bool enable, uint16_t duration, uint8_t max_ext_adv_events);
  void Enable(uint8_t adv_id, bool enable, uint16_t duration, uint8_t max_ext_adv_events);
  void StartAdvertising(
  void StartAdvertising(
      uint8_t adv_id,
      uint8_t adv_id,
      RustAdvertiseParameters params,
      AdvertiseParameters params,
      ::rust::Vec<uint8_t> advertise_data,
      ::rust::Vec<uint8_t> advertise_data,
      ::rust::Vec<uint8_t> scan_response_data,
      ::rust::Vec<uint8_t> scan_response_data,
      int32_t timeout_in_sec);
      int32_t timeout_in_sec);
  void StartAdvertisingSet(
  void StartAdvertisingSet(
      int32_t reg_id,
      int32_t reg_id,
      RustAdvertiseParameters params,
      AdvertiseParameters params,
      ::rust::Vec<uint8_t> advertise_data,
      ::rust::Vec<uint8_t> advertise_data,
      ::rust::Vec<uint8_t> scan_response_data,
      ::rust::Vec<uint8_t> scan_response_data,
      RustPeriodicAdvertisingParameters periodic_params,
      PeriodicAdvertisingParameters periodic_params,
      ::rust::Vec<uint8_t> periodic_data,
      ::rust::Vec<uint8_t> periodic_data,
      uint16_t duration,
      uint16_t duration,
      uint8_t max_ext_adv_events);
      uint8_t max_ext_adv_events);
  void SetPeriodicAdvertisingParameters(uint8_t adv_id, RustPeriodicAdvertisingParameters params);
  void SetPeriodicAdvertisingParameters(uint8_t adv_id, PeriodicAdvertisingParameters params);
  void SetPeriodicAdvertisingData(uint8_t adv_id, ::rust::Vec<uint8_t> data);
  void SetPeriodicAdvertisingData(uint8_t adv_id, ::rust::Vec<uint8_t> data);
  void SetPeriodicAdvertisingEnable(uint8_t adv_id, bool enable, bool include_adi);
  void SetPeriodicAdvertisingEnable(uint8_t adv_id, bool enable, bool include_adi);


Loading