-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Needed for successful fingerprint template uploading on many Chromebooks
- Loading branch information
1 parent
4b5329c
commit 48726d6
Showing
7 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::{os::fd::AsRawFd, thread::sleep, time::Duration}; | ||
|
||
use bytemuck::{Pod, Zeroable}; | ||
use num::ToPrimitive; | ||
use num_derive::ToPrimitive; | ||
|
||
use crate::{ec_command::ec_command_bytemuck, EcCmdResult}; | ||
|
||
use super::CrosEcCmd; | ||
|
||
pub type UserId = [u8; 32]; | ||
|
||
/* Version 1 of the command is "asynchronous". */ | ||
#[repr(C, align(4))] | ||
#[derive(Pod, Zeroable, Clone, Copy, Debug)] | ||
struct EcParamsFpContextV1 { | ||
/**< enum fp_context_action */ | ||
action: u8, | ||
reserved: [u8; 3], | ||
user_id: UserId, | ||
} | ||
|
||
#[repr(u8)] | ||
#[derive(ToPrimitive)] | ||
enum FpContextAction { | ||
Async = 0, | ||
GetResult = 1, | ||
} | ||
|
||
/// Make sure that the fp mode is Reset before setting the context | ||
/// Related: https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/biod/cros_fp_device.cc#660 | ||
pub fn fp_set_context<File: AsRawFd>(file: &mut File, user_id: UserId) -> EcCmdResult<()> { | ||
Check warning Code scanning / clippy this function depends on never type fallback being () Warning
this function depends on never type fallback being ()
|
||
// From testing, it seems that this can be anything besides all zeroes, but we're going to use these numbers in honor of CoolStar - https://github.com/coolstar/crosfingerprint/blob/5e77307d7542218e173f24eb657b426565ed361a/fingerprint_adapter/eccmd.cpp#L140 | ||
ec_command_bytemuck( | ||
CrosEcCmd::FpContext, | ||
1, | ||
&EcParamsFpContextV1 { | ||
action: FpContextAction::Async.to_u8().unwrap(), | ||
reserved: Default::default(), | ||
user_id, | ||
}, | ||
file.as_raw_fd(), | ||
)?; | ||
let mut tries = 20; | ||
let delay = Duration::from_millis(100); | ||
loop { | ||
sleep(delay); | ||
let result = ec_command_bytemuck( | ||
CrosEcCmd::FpContext, | ||
1, | ||
&EcParamsFpContextV1 { | ||
action: FpContextAction::GetResult.to_u8().unwrap(), | ||
reserved: Default::default(), | ||
user_id, | ||
}, | ||
file.as_raw_fd(), | ||
); | ||
if result.is_ok() { | ||
break result; | ||
} else { | ||
tries -= 1; | ||
if tries == 0 { | ||
break result; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ num-traits = "0.2.19" | |
image = "0.25.1" | ||
strum = "0.26.3" | ||
uom = "0.36.0" | ||
hex = "0.4.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crosec::commands::fp_set_context::UserId; | ||
|
||
pub fn check_user_id(user_id_str: &str) -> Result<UserId, String> { | ||
let mut user_id = UserId::default(); | ||
hex::decode_to_slice(user_id_str.as_bytes(), &mut user_id).map_err(|e| e.to_string())?; | ||
Ok(user_id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use crosec::commands::fp_set_context::{fp_set_context, UserId}; | ||
use crosec::CROS_FP_PATH; | ||
use std::fs::File; | ||
|
||
pub fn fp_context_command(user_id: UserId) -> color_eyre::Result<()> { | ||
let mut file = File::open(CROS_FP_PATH)?; | ||
fp_set_context(&mut file, user_id)?; | ||
let user_id_str = hex::encode(user_id); | ||
println!("Set FP context to user id: 0x{user_id_str}"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters