From a2d5504d867ec1a3ac41f75ec298feaca3fc9ed9 Mon Sep 17 00:00:00 2001 From: Rajas Paranjpe <52586855+ChocolateLoverRaj@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:01:38 -0700 Subject: [PATCH] Some improvements Added an async wait_event function, added get encryption status function, made some more functions use generic trait for file. --- Cargo.lock | 591 +++++++++++++++++- crosec/Cargo.toml | 1 + crosec/src/commands/fp_download.rs | 8 +- .../src/commands/fp_get_encryption_status.rs | 21 + crosec/src/commands/fp_info.rs | 6 +- crosec/src/commands/fp_mode.rs | 2 +- crosec/src/commands/fp_set_seed.rs | 4 +- crosec/src/commands/fp_upload_template.rs | 8 +- crosec/src/commands/get_cmd_versions.rs | 3 +- crosec/src/commands/get_protocol_info.rs | 4 +- crosec/src/commands/mod.rs | 2 + crosec/src/wait_event/event.rs | 28 +- crosec/src/wait_event/mod.rs | 27 +- .../src/fp_get_encryption_status_command.rs | 11 + ectool/src/main.rs | 8 +- 15 files changed, 680 insertions(+), 44 deletions(-) create mode 100644 crosec/src/commands/fp_get_encryption_status.rs create mode 100644 ectool/src/fp_get_encryption_status_command.rs diff --git a/Cargo.lock b/Cargo.lock index a342345..59d8e73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,7 +59,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -69,7 +69,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -101,6 +101,154 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8828ec6e544c02b0d6691d21ed9f9218d0384a82542855073c2a3f58304aaf0" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand 2.1.0", + "futures-lite 2.3.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.3.1", + "async-executor", + "async-io 2.3.3", + "async-lock 3.4.0", + "blocking", + "futures-lite 2.3.0", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2", + "waker-fn", +] + +[[package]] +name = "async-io" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6baa8f0178795da0e71bc42c9e5d13261aac7ee549853162e66a241ba17964" +dependencies = [ + "async-lock 3.4.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.3.0", + "parking", + "polling 3.7.2", + "rustix 0.38.34", + "slab", + "tracing", + "windows-sys 0.52.0", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +dependencies = [ + "event-listener 5.3.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.2.0" @@ -169,6 +317,19 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c12d1856e42f0d817a835fe55853957c85c8c8a470114029143d3f12671446e" +[[package]] +name = "blocking" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" +dependencies = [ + "async-channel 2.3.1", + "async-task", + "futures-io", + "futures-lite 2.3.0", + "piper", +] + [[package]] name = "built" version = "0.7.3" @@ -319,6 +480,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -332,6 +502,7 @@ dependencies = [ name = "crosec" version = "0.1.0" dependencies = [ + "async-std", "bytemuck", "clap", "nix", @@ -398,6 +569,43 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.1", + "pin-project-lite", +] + [[package]] name = "exr" version = "1.72.0" @@ -424,6 +632,21 @@ dependencies = [ "once_cell", ] +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + [[package]] name = "fdeflate" version = "0.3.4" @@ -452,6 +675,55 @@ dependencies = [ "spin", ] +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand 2.1.0", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "getrandom" version = "0.2.14" @@ -479,6 +751,18 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "half" version = "2.4.1" @@ -501,6 +785,18 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + [[package]] name = "image" version = "0.25.1" @@ -556,6 +852,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + [[package]] name = "interpolate_name" version = "0.2.4" @@ -567,6 +872,17 @@ dependencies = [ "syn", ] +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -597,6 +913,24 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -626,6 +960,18 @@ dependencies = [ "once_cell", ] +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "lock_api" version = "0.4.12" @@ -641,6 +987,9 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "value-bag", +] [[package]] name = "loop9" @@ -821,6 +1170,12 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + [[package]] name = "paste" version = "1.0.15" @@ -833,6 +1188,23 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "piper" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1d5c74c9876f070d3e8fd503d748c7d974c3e48da8f41350fa5222ef9b4391" +dependencies = [ + "atomic-waker", + "fastrand 2.1.0", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.30" @@ -852,6 +1224,37 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "polling" +version = "3.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ed00ed3fbf728b5816498ecd316d1716eecaced9c0c8d2c5a6740ca214985b" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi 0.4.0", + "pin-project-lite", + "rustix 0.38.34", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1025,6 +1428,33 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys 0.4.14", + "windows-sys 0.52.0", +] + [[package]] name = "rustversion" version = "1.0.17" @@ -1090,12 +1520,31 @@ dependencies = [ "quote", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "spin" version = "0.9.8" @@ -1305,12 +1754,24 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + [[package]] name = "version-compare" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" +[[package]] +name = "waker-fn" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1342,6 +1803,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.92" @@ -1371,19 +1844,75 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "weezl" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -1392,28 +1921,46 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -1426,24 +1973,48 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.5" diff --git a/crosec/Cargo.toml b/crosec/Cargo.toml index a832b8e..7942f73 100644 --- a/crosec/Cargo.toml +++ b/crosec/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +async-std = "1.12.0" bytemuck = { version = "1.16.0", features = ["derive"] } clap = { version = "4.5.6", optional = true } nix = { version = "0.27.1", features = ["ioctl"] } diff --git a/crosec/src/commands/fp_download.rs b/crosec/src/commands/fp_download.rs index 8790d8b..bdd47d3 100644 --- a/crosec/src/commands/fp_download.rs +++ b/crosec/src/commands/fp_download.rs @@ -1,10 +1,10 @@ -use std::{fs::File, os::fd::AsRawFd, thread::sleep, time::Duration}; +use std::{os::fd::AsRawFd, thread::sleep, time::Duration}; use bytemuck::{bytes_of, Pod, Zeroable}; use crate::ec_command::ec_command_with_dynamic_output_size; -use super::{fp_info::EcResponseFpInfo, get_protocol_info::EcResponseGetProtocolInfo, CrosEcCmd}; +use super::{CrosEcCmd, fp_info::EcResponseFpInfo, get_protocol_info::EcResponseGetProtocolInfo}; #[repr(C)] #[derive(Pod, Zeroable, Clone, Copy)] @@ -31,7 +31,7 @@ pub enum DownloadType { /// Downloads a frame buffer from the FPMCU. /// The downloaded data might be either the finger image or a finger template. -pub fn fp_download( +pub fn fp_download( file: &mut File, fp_info: &EcResponseFpInfo, protocol_info: &EcResponseGetProtocolInfo, @@ -101,7 +101,7 @@ impl FpTemplate { } } -pub fn fp_download_template( +pub fn fp_download_template( file: &mut File, fp_info: &EcResponseFpInfo, protocol_info: &EcResponseGetProtocolInfo, diff --git a/crosec/src/commands/fp_get_encryption_status.rs b/crosec/src/commands/fp_get_encryption_status.rs new file mode 100644 index 0000000..47ac684 --- /dev/null +++ b/crosec/src/commands/fp_get_encryption_status.rs @@ -0,0 +1,21 @@ +use std::os::fd::AsRawFd; +use bytemuck::{Pod, Zeroable}; +use crate::commands::CrosEcCmd; +use crate::ec_command::ec_command_bytemuck; +use crate::EcCmdResult; + +#[repr(u32)] +pub enum FpEncryptionStatus { + SeedSet = 0b1 +} + +#[derive(Pod, Zeroable, Copy, Clone)] +#[repr(C)] +pub struct EcResponseFpGetEncryptionStatus { + pub valid_flags: u32, + pub status: u32, +} + +pub fn fp_get_encryption_status(file: &mut File) -> EcCmdResult { + ec_command_bytemuck(CrosEcCmd::FpGetEncryptionStatus, 0, &(), file.as_raw_fd()) +} \ No newline at end of file diff --git a/crosec/src/commands/fp_info.rs b/crosec/src/commands/fp_info.rs index 89a2cad..4a49c44 100644 --- a/crosec/src/commands/fp_info.rs +++ b/crosec/src/commands/fp_info.rs @@ -1,12 +1,12 @@ -use std::{fs::File, os::fd::AsRawFd}; +use std::os::fd::AsRawFd; use bytemuck::{Pod, Zeroable}; use crate::{ec_command::ec_command_bytemuck, EcCmdResult}; use super::{ - get_cmd_versions::{ec_cmd_get_cmd_versions, V1}, CrosEcCmd, + get_cmd_versions::{ec_cmd_get_cmd_versions, V1}, }; #[repr(C, align(4))] @@ -41,7 +41,7 @@ impl EcResponseFpInfo { } } -pub fn fp_info(file: &mut File) -> EcCmdResult { +pub fn fp_info(file: &mut File) -> EcCmdResult { let fd = file.as_raw_fd(); let versions = ec_cmd_get_cmd_versions(file, CrosEcCmd::FpInfo)?; if versions & V1 == 0 { diff --git a/crosec/src/commands/fp_mode.rs b/crosec/src/commands/fp_mode.rs index 8a632ca..cafecff 100644 --- a/crosec/src/commands/fp_mode.rs +++ b/crosec/src/commands/fp_mode.rs @@ -9,7 +9,7 @@ use crate::{ec_command::ec_command_bytemuck, EcCmdResult}; use super::CrosEcCmd; /// Note that with the ChromiumOS ectool, to start enrolling, as well as continue the next step in enrolling, you do `ectool --name=cros_fp fpmode enroll`. The equivalent of this is to do `ectool fp-mode EnrollImage EnrollSession`. -#[derive(EnumString, EnumIter, IntoStaticStr, Clone, Copy)] +#[derive(EnumString, EnumIter, IntoStaticStr, Clone, Copy, Debug)] #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] #[repr(u32)] pub enum FpMode { diff --git a/crosec/src/commands/fp_set_seed.rs b/crosec/src/commands/fp_set_seed.rs index 0bff0e2..fc35009 100644 --- a/crosec/src/commands/fp_set_seed.rs +++ b/crosec/src/commands/fp_set_seed.rs @@ -1,4 +1,4 @@ -use std::{fs::File, os::fd::AsRawFd}; +use std::os::fd::AsRawFd; use bytemuck::{Pod, Zeroable}; @@ -17,7 +17,7 @@ struct EcParamsFpSeed { pub seed: [u8; FP_CONTEXT_TPM_BYTES], } -pub fn fp_set_seed(file: &mut File, seed: [u8; FP_CONTEXT_TPM_BYTES]) -> EcCmdResult<()> { +pub fn fp_set_seed(file: &mut File, seed: [u8; FP_CONTEXT_TPM_BYTES]) -> EcCmdResult<()> { ec_command_bytemuck( CrosEcCmd::FpSetSeed, 0, diff --git a/crosec/src/commands/fp_upload_template.rs b/crosec/src/commands/fp_upload_template.rs index 0f293d2..2c6a90c 100644 --- a/crosec/src/commands/fp_upload_template.rs +++ b/crosec/src/commands/fp_upload_template.rs @@ -1,12 +1,12 @@ -use std::{fs::File, mem::offset_of, os::fd::AsRawFd}; +use std::{mem::offset_of, os::fd::AsRawFd}; use bytemuck::{bytes_of, Pod, Zeroable}; use crate::{ec_command::ec_command_with_dynamic_output_size, EcCmdResult}; use super::{ - fp_download::FpTemplate, fp_info::EcResponseFpInfo, - get_protocol_info::EcResponseGetProtocolInfo, CrosEcCmd, + CrosEcCmd, fp_download::FpTemplate, + fp_info::EcResponseFpInfo, get_protocol_info::EcResponseGetProtocolInfo, }; #[derive(Pod, Zeroable, Clone, Copy)] @@ -20,7 +20,7 @@ struct EcParamsFpTemplateWithoutData { /// Flag in the 'size' field indicating that the full template has been sent const FP_TEMPLATE_COMMIT: u32 = 0x80000000; -pub fn fp_upload_template( +pub fn fp_upload_template( file: &mut File, protocol_info: &EcResponseGetProtocolInfo, fp_info: &EcResponseFpInfo, diff --git a/crosec/src/commands/get_cmd_versions.rs b/crosec/src/commands/get_cmd_versions.rs index ab0d84d..cca1cc4 100644 --- a/crosec/src/commands/get_cmd_versions.rs +++ b/crosec/src/commands/get_cmd_versions.rs @@ -1,4 +1,3 @@ -use std::fs::File; use std::os::fd::AsRawFd; use bytemuck::{Pod, Zeroable}; @@ -29,7 +28,7 @@ pub const V0: u32 = 0b001; pub const V1: u32 = 0b010; pub const V2: u32 = 0b100; -pub fn ec_cmd_get_cmd_versions(file: &mut File, cmd: CrosEcCmd) -> EcCmdResult { +pub fn ec_cmd_get_cmd_versions(file: &mut File, cmd: CrosEcCmd) -> EcCmdResult { let fd = file.as_raw_fd(); let response: EcResponseGetCmdVersion = match ec_command_bytemuck( CrosEcCmd::GetCmdVersions, diff --git a/crosec/src/commands/get_protocol_info.rs b/crosec/src/commands/get_protocol_info.rs index 69b0b25..66c6228 100644 --- a/crosec/src/commands/get_protocol_info.rs +++ b/crosec/src/commands/get_protocol_info.rs @@ -1,4 +1,4 @@ -use std::{fs::File, mem::size_of, os::fd::AsRawFd}; +use std::{mem::size_of, os::fd::AsRawFd}; use bytemuck::{Pod, Zeroable}; @@ -42,6 +42,6 @@ struct EcHostResponse { reserved: u16, } -pub fn get_protocol_info(file: &mut File) -> EcCmdResult { +pub fn get_protocol_info(file: &mut File) -> EcCmdResult { ec_command_bytemuck(CrosEcCmd::GetProtocolInfo, 0, &(), file.as_raw_fd()) } diff --git a/crosec/src/commands/mod.rs b/crosec/src/commands/mod.rs index e2b87f5..1a86ca6 100644 --- a/crosec/src/commands/mod.rs +++ b/crosec/src/commands/mod.rs @@ -22,6 +22,7 @@ pub enum CrosEcCmd { FpTemplate = 0x0405, FpStats = 0x0407, FpSetSeed = 0x0408, + FpGetEncryptionStatus = 0x0409, BatteryGetStatic = 0x0600, } @@ -29,6 +30,7 @@ pub mod board_version; pub mod charge_control; pub mod fp_download; pub mod fp_info; +pub mod fp_get_encryption_status; pub mod fp_mode; pub mod fp_set_seed; pub mod fp_stats; diff --git a/crosec/src/wait_event/event.rs b/crosec/src/wait_event/event.rs index ad61e21..7d197ed 100644 --- a/crosec/src/wait_event/event.rs +++ b/crosec/src/wait_event/event.rs @@ -1,7 +1,6 @@ -use std::{ - io::{self, Read}, - mem::size_of, -}; +use std::io; +use std::mem::size_of; +use async_std::io::ReadExt; use bytemuck::{from_bytes, Pod, Zeroable}; use num_derive::FromPrimitive; @@ -50,6 +49,7 @@ pub enum EcMkbpEventType { OnlineCalibration, Pchg, } + impl EcMkbpEventType { fn data_size(&self) -> usize { match self { @@ -66,17 +66,27 @@ impl EcMkbpEventType { } } - pub(crate) fn read(&self, stream: &mut T) -> io::Result { - let mut event = vec![Default::default(); size_of::() + self.data_size()]; - stream.read_exact(&mut event)?; + fn parse_event(&self, event: &mut Vec) -> EcMkbpEvent { debug_assert_eq!(event[0], *self as u8); event.remove(0); let data = event; - Ok(match self { + match self { EcMkbpEventType::Fingerprint => { EcMkbpEvent::Fingerprint(from_bytes::(&data).to_owned()) } event_type => panic!("{event_type:#?} from_bytes not implemented yet"), - }) + } + } + + pub(crate) fn read_sync(&self, stream: &mut T) -> io::Result { + let mut event = vec![Default::default(); size_of::() + self.data_size()]; + stream.read_exact(&mut event)?; + Ok(self.parse_event(&mut event)) + } + + pub(crate) async fn read_async(&self, stream: &mut T) -> io::Result { + let mut event = vec![Default::default(); size_of::() + self.data_size()]; + stream.read_exact(&mut event).await?; + Ok(self.parse_event(&mut event)) } } diff --git a/crosec/src/wait_event/mod.rs b/crosec/src/wait_event/mod.rs index a195220..faca0f9 100644 --- a/crosec/src/wait_event/mod.rs +++ b/crosec/src/wait_event/mod.rs @@ -1,11 +1,13 @@ -use std::{fs::File, os::fd::AsRawFd}; +use std::io; +use std::os::fd::AsRawFd; -use event::{EcMkbpEvent, EcMkbpEventType}; use nix::{ libc::{ioctl, poll, pollfd}, request_code_none, }; +use event::{EcMkbpEvent, EcMkbpEventType}; + use crate::CROS_EC_IOC_MAGIC; pub mod event; @@ -21,7 +23,7 @@ pub enum PollData { } /// If no timeout is specified, this function will wait for an unlimited amount of time -pub fn wait_event( +pub fn wait_event_sync( file: &mut File, event_type: EcMkbpEventType, timeout: Option, @@ -45,12 +47,27 @@ pub fn wait_event( match result { 0 => Ok(PollData::Timeout), 1 => match fds.revents { - POLL_IN => Ok(PollData::EventHappened(event_type.read(file).unwrap())), + POLL_IN => Ok(PollData::EventHappened(event_type.read_sync(file).unwrap())), events => Ok(PollData::SomethingElseHappened(events)), }, result => Err(result), } } - None => Ok(PollData::EventHappened(event_type.read(file).unwrap())), + None => Ok(PollData::EventHappened(event_type.read_sync(file).unwrap())), } } + +pub async fn wait_event_async( + file: &mut File, + event_type: EcMkbpEventType, +) -> io::Result { + let mask = 1 << event_type as u8; + unsafe { + ioctl( + file.as_raw_fd(), + request_code_none!(CROS_EC_IOC_MAGIC, 2), + mask, + ) + }; + event_type.read_async(file).await +} \ No newline at end of file diff --git a/ectool/src/fp_get_encryption_status_command.rs b/ectool/src/fp_get_encryption_status_command.rs new file mode 100644 index 0000000..295f5ed --- /dev/null +++ b/ectool/src/fp_get_encryption_status_command.rs @@ -0,0 +1,11 @@ +use std::fs::File; +use crosec::commands::fp_get_encryption_status::{EcResponseFpGetEncryptionStatus, fp_get_encryption_status}; +use crosec::CROS_FP_PATH; + +pub fn fp_get_encryption_status_command() -> color_eyre::Result<()> { + let mut file = File::open(CROS_FP_PATH)?; + let EcResponseFpGetEncryptionStatus { status, valid_flags } = fp_get_encryption_status(&mut file)?; + println!("FPMCU encryption status: {status:#b}"); + println!("Valid flags: {valid_flags:#b}"); + Ok(()) +} diff --git a/ectool/src/main.rs b/ectool/src/main.rs index 8393bd0..b123a8d 100644 --- a/ectool/src/main.rs +++ b/ectool/src/main.rs @@ -9,7 +9,7 @@ use crosec::commands::fp_mode::{fp_mode, FpMode}; use crosec::commands::fp_set_seed::{fp_set_seed, FP_CONTEXT_TPM_BYTES}; use crosec::commands::fp_stats::fp_stats; use crosec::commands::get_protocol_info::get_protocol_info; -use crosec::wait_event::{event::EcMkbpEventType, wait_event}; +use crosec::wait_event::{event::EcMkbpEventType, wait_event_sync}; use fp_download_subcommand::{fp_download_subcommand, FpDownloadSubcommand}; use fp_upload_template_command::fp_upload_template_command; use num_traits::cast::FromPrimitive; @@ -29,11 +29,13 @@ use crosec::{ CROS_EC_PATH, CROS_FP_PATH, EC_FAN_SPEED_ENTRIES, EC_FAN_SPEED_NOT_PRESENT, EC_FAN_SPEED_STALLED, EC_MEM_MAP_FAN, }; +use crate::fp_get_encryption_status_command::fp_get_encryption_status_command; mod charge_control_subcommand; mod check_seed; mod fp_download_subcommand; mod fp_upload_template_command; +mod fp_get_encryption_status_command; #[derive(Parser)] #[command(version, about)] @@ -120,6 +122,7 @@ enum Commands { }, /// Uploads template from stdin FpUploadTemplate, + FpGetEncryptionStatus, } fn main() -> Result<()> { @@ -263,11 +266,12 @@ fn main() -> Result<()> { timeout, } => { let mut file = File::open(device.unwrap_or_default().get_path())?; - let result = wait_event(&mut file, event_type, timeout).unwrap(); + let result = wait_event_sync(&mut file, event_type, timeout).unwrap(); println!("{result:#?}"); } Commands::FpDownload { command } => fp_download_subcommand(command)?, Commands::FpUploadTemplate => fp_upload_template_command()?, + Commands::FpGetEncryptionStatus => fp_get_encryption_status_command()?, } Ok(())