-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fp set context #8
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 @@ | ||
use flake |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
.direnv |
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<()> { | ||
// 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / clippy
this function depends on never type fallback being () Warning