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

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

Merge "Floss: Add GATT client command for setting advertising data"

parents 00a8d653 5f7539c1
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -196,6 +196,7 @@ fn build_commands() -> HashMap<String, CommandOption> {
                String::from("advertise <on|off|ext>"),
                String::from("advertise set-interval <ms>"),
                String::from("advertise set-scan-rsp <enable|disable>"),
                String::from("advertise set-raw-data <raw-adv-data> <adv-id>"),
            ],
            description: String::from("Advertising utilities."),
            function_pointer: CommandHandler::cmd_advertise,
@@ -1256,6 +1257,26 @@ impl CommandHandler {
                    context.gatt_dbus.as_mut().unwrap().set_advertising_parameters(adv_id, params);
                }
            }
            "set-raw-data" => {
                let data = hex::decode(get_arg(args, 1)?).or(Err("Failed parsing data"))?;

                let adv_id = String::from(get_arg(args, 2)?)
                    .parse::<i32>()
                    .or(Err("Failed parsing adv_id"))?;

                let mut context = self.context.lock().unwrap();
                if context
                    .adv_sets
                    .iter()
                    .find(|(_, s)| s.adv_id.map_or(false, |id| id == adv_id))
                    .is_none()
                {
                    return Err("Failed to find advertising set".into());
                }

                print_info!("Setting advertising data for {}", adv_id);
                context.gatt_dbus.as_mut().unwrap().set_raw_adv_data(adv_id, data);
            }
            _ => return Err(CommandError::InvalidArgs),
        }

+5 −0
Original line number Diff line number Diff line
@@ -1071,6 +1071,11 @@ impl IBluetoothGatt for BluetoothGattDBus {
        dbus_generated!()
    }

    #[dbus_method("SetRawAdvertisingData")]
    fn set_raw_adv_data(&mut self, advertiser_id: i32, data: Vec<u8>) {
        dbus_generated!()
    }

    #[dbus_method("SetScanResponseData")]
    fn set_scan_response_data(&mut self, advertiser_id: i32, data: AdvertiseData) {
        dbus_generated!()
+5 −0
Original line number Diff line number Diff line
@@ -565,6 +565,11 @@ impl IBluetoothGatt for IBluetoothGattDBus {
        dbus_generated!()
    }

    #[dbus_method("SetRawAdvertisingData")]
    fn set_raw_adv_data(&mut self, advertiser_id: i32, data: Vec<u8>) {
        dbus_generated!()
    }

    #[dbus_method("SetScanResponseData")]
    fn set_scan_response_data(&mut self, advertiser_id: i32, data: AdvertiseData) {
        dbus_generated!()
+17 −0
Original line number Diff line number Diff line
@@ -352,6 +352,9 @@ pub trait IBluetoothGatt {
    /// Updates advertisement data of the advertising set.
    fn set_advertising_data(&mut self, advertiser_id: i32, data: AdvertiseData);

    /// Set the advertisement data of the advertising set.
    fn set_raw_adv_data(&mut self, advertiser_id: i32, data: Vec<u8>);

    /// Updates scan response of the advertising set.
    fn set_scan_response_data(&mut self, advertiser_id: i32, data: AdvertiseData);

@@ -1504,6 +1507,20 @@ impl IBluetoothGatt for BluetoothGatt {
        }
    }

    fn set_raw_adv_data(&mut self, advertiser_id: i32, data: Vec<u8>) {
        if self.advertisers.suspend_mode() != SuspendMode::Normal {
            return;
        }

        if let Some(s) = self.advertisers.get_by_advertiser_id(advertiser_id) {
            self.gatt.as_ref().unwrap().lock().unwrap().advertiser.set_data(
                s.adv_id(),
                false,
                data,
            );
        }
    }

    fn set_scan_response_data(&mut self, advertiser_id: i32, data: AdvertiseData) {
        if self.advertisers.suspend_mode() != SuspendMode::Normal {
            return;