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

Commit 1cc6760d authored by Yun-hao Chung's avatar Yun-hao Chung Committed by Automerger Merge Worker
Browse files

Merge "Floss: Implement pairing confirmation command" am: fd094c71

parents 5ab8c07c fd094c71
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ impl IBluetoothCallback for BtCallback {
        passkey: u32,
    ) {
        match variant {
            BtSspVariant::PasskeyNotification => {
            BtSspVariant::PasskeyNotification | BtSspVariant::PasskeyConfirmation => {
                print_info!(
                    "Device [{}: {}] would like to pair, enter passkey on remote device: {:06}",
                    &remote_device.address,
@@ -189,9 +189,6 @@ impl IBluetoothCallback for BtCallback {
            BtSspVariant::PasskeyEntry => {
                println!("Got PasskeyEntry but it is not supported...");
            }
            BtSspVariant::PasskeyConfirmation => {
                println!("Got PasskeyConfirmation but there's nothing to do...");
            }
        }
    }

+188 −116
Original line number Diff line number Diff line
@@ -112,7 +112,12 @@ fn build_commands() -> HashMap<String, CommandOption> {
    command_options.insert(
        String::from("device"),
        CommandOption {
            rules: vec![String::from("device <connect|disconnect|info|set-alias> <address>")],
            rules: vec![
                String::from("device <connect|disconnect|info|set-alias> <address>"),
                String::from("device <set-pairing-confirmation> <address> <accept|reject>"),
                String::from("device <set-pairing-pin> <address> <pin|reject>"),
                String::from("device <set-pairing-passkey> <address> <passkey|reject>"),
            ],
            description: String::from("Take action on a remote device. (i.e. info)"),
            function_pointer: CommandHandler::cmd_device,
        },
@@ -556,8 +561,7 @@ impl CommandHandler {
            return;
        }

        enforce_arg_len(args, 2, "device <connect|disconnect|info|set-alias> <address>", || {
            match &args[0][0..] {
        enforce_arg_len(args, 2, "device <commands>", || match &args[0][0..] {
            "connect" => {
                let device = BluetoothDevice {
                    address: String::from(&args[1]),
@@ -691,9 +695,77 @@ impl CommandHandler {
                    .unwrap()
                    .set_remote_alias(device.clone(), new_alias.clone());
            }
            "set-pairing-confirmation" => {
                if args.len() < 4 {
                    println!("usage: device set-pairing-confirmation <address> <accept|reject>");
                    return;
                }
                let device =
                    BluetoothDevice { address: String::from(&args[1]), name: String::from("") };
                let accept = match &args[2][0..] {
                    "accept" => true,
                    "reject" => false,
                    _ => {
                    println!("Invalid argument '{}'", args[0]);
                        println!("Failed to parse '{}'", args[2]);
                        return;
                    }
                };

                self.context
                    .lock()
                    .unwrap()
                    .adapter_dbus
                    .as_mut()
                    .unwrap()
                    .set_pairing_confirmation(device.clone(), accept);
            }
            "set-pairing-pin" => {
                if args.len() < 4 {
                    println!("usage: device set-pairing-pin <address> <pin|reject>");
                    return;
                }
                let device =
                    BluetoothDevice { address: String::from(&args[1]), name: String::from("") };
                let (accept, pin) = match (&args[2][0..], String::from(&args[2]).parse::<u32>()) {
                    (_, Ok(p)) => (true, Vec::from(p.to_ne_bytes())),
                    ("reject", _) => (false, vec![]),
                    _ => {
                        println!("Failed to parse '{}'", args[2]);
                        return;
                    }
                };

                self.context.lock().unwrap().adapter_dbus.as_mut().unwrap().set_pin(
                    device.clone(),
                    accept,
                    pin,
                );
            }
            "set-pairing-passkey" => {
                if args.len() < 4 {
                    println!("usage: device set-pairing-passkey <address> <passkey|reject>");
                    return;
                }
                let device =
                    BluetoothDevice { address: String::from(&args[1]), name: String::from("") };
                let (accept, passkey) = match (&args[2][0..], String::from(&args[2]).parse::<u32>())
                {
                    (_, Ok(p)) => (true, Vec::from(p.to_ne_bytes())),
                    ("reject", _) => (false, vec![]),
                    _ => {
                        println!("Failed to parse '{}'", args[2]);
                        return;
                    }
                };

                self.context.lock().unwrap().adapter_dbus.as_mut().unwrap().set_passkey(
                    device.clone(),
                    accept,
                    passkey,
                );
            }
            _ => {
                println!("Invalid argument '{}'", args[0]);
            }
        });
    }