mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
setup time setting from QR code scan
this is a stub based off the password scanning QR code still need to add actual password setting, will do that tomorrow
This commit is contained in:
parent
e8edb3f4b2
commit
18dd921cb8
2 changed files with 70 additions and 2 deletions
|
|
@ -6,11 +6,14 @@ use std::sync::{
|
||||||
Arc, Mutex,
|
Arc, Mutex,
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
};
|
};
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
#[cfg(feature = "hosted-baosec")]
|
#[cfg(feature = "hosted-baosec")]
|
||||||
use bao1x_emu::trng::Trng;
|
use bao1x_emu::trng::Trng;
|
||||||
|
use bao1x_hal_service::api::TimeOp;
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
use bao1x_hal_service::trng::Trng;
|
use bao1x_hal_service::trng::Trng;
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use keystore::Keystore;
|
use keystore::Keystore;
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use num_traits::*;
|
use num_traits::*;
|
||||||
|
|
@ -74,6 +77,8 @@ pub struct ActionManager {
|
||||||
keystore: Keystore,
|
keystore: Keystore,
|
||||||
|
|
||||||
gfx: ux_api::service::gfx::Gfx,
|
gfx: ux_api::service::gfx::Gfx,
|
||||||
|
// used to set time when QR codes are scanned
|
||||||
|
rtc_conn: xous::CID,
|
||||||
}
|
}
|
||||||
impl ActionManager {
|
impl ActionManager {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
|
@ -86,6 +91,9 @@ impl ActionManager {
|
||||||
let storage_manager = storage::Manager::new(&xns);
|
let storage_manager = storage::Manager::new(&xns);
|
||||||
|
|
||||||
let mc = (*mode.lock().unwrap()).clone();
|
let mc = (*mode.lock().unwrap()).clone();
|
||||||
|
let rtc_conn =
|
||||||
|
xous::connect(xous::SID::from_bytes(bao1x_hal_service::api::TIME_SERVER_PUBLIC).unwrap())
|
||||||
|
.unwrap();
|
||||||
ActionManager {
|
ActionManager {
|
||||||
modals: modals::Modals::new(&xns).unwrap(),
|
modals: modals::Modals::new(&xns).unwrap(),
|
||||||
storage: RefCell::new(storage_manager),
|
storage: RefCell::new(storage_manager),
|
||||||
|
|
@ -102,6 +110,7 @@ impl ActionManager {
|
||||||
main_conn,
|
main_conn,
|
||||||
keystore: Keystore::new(&xns),
|
keystore: Keystore::new(&xns),
|
||||||
gfx: ux_api::service::gfx::Gfx::new(&xns).unwrap(),
|
gfx: ux_api::service::gfx::Gfx::new(&xns).unwrap(),
|
||||||
|
rtc_conn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1076,7 +1085,31 @@ impl ActionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"pwauth" => {
|
"pwauth" => {
|
||||||
// todo
|
if let Some((op_type, rest)) = data.split_once('/') {
|
||||||
|
match op_type {
|
||||||
|
"pass" => {
|
||||||
|
if let Some(time_pos) = rest.rfind("?time=") {
|
||||||
|
let url = &rest[..time_pos];
|
||||||
|
let time_str = &rest[time_pos + 6..];
|
||||||
|
self.set_time(time_str);
|
||||||
|
log::info!("URL: {}", url);
|
||||||
|
// now try to lookup the password; if it does not exist, offer
|
||||||
|
// to create a password
|
||||||
|
|
||||||
|
// TODO: left off here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"new" => {
|
||||||
|
if let Some(pass_pos) = rest.find("?pass=") {
|
||||||
|
let url = &rest[..pass_pos];
|
||||||
|
let password = &rest[pass_pos + 6..];
|
||||||
|
log::info!("URL: {}", url);
|
||||||
|
log::info!("Password: {}", password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => log::error!("Unknown pwauth operation: {}", op_type),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"time" => {
|
"time" => {
|
||||||
// todo
|
// todo
|
||||||
|
|
@ -1100,6 +1133,41 @@ impl ActionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_time(&self, time_str: &str) {
|
||||||
|
match DateTime::parse_from_rfc3339(time_str) {
|
||||||
|
Ok(datetime) => {
|
||||||
|
let utc_time = datetime.with_timezone(&Utc);
|
||||||
|
log::info!("Time (UTC): {}", utc_time);
|
||||||
|
let since_epoch_ms = utc_time.timestamp_millis();
|
||||||
|
xous::send_message(
|
||||||
|
self.rtc_conn,
|
||||||
|
xous::Message::new_scalar(
|
||||||
|
TimeOp::SetUtcTimeMs.to_usize().unwrap(),
|
||||||
|
((since_epoch_ms >> 32) & 0xFFFF_FFFF) as usize,
|
||||||
|
(since_epoch_ms & 0xFFFF_FFFF) as usize,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
let offset = datetime.offset();
|
||||||
|
let offset_ms = (offset.local_minus_utc() as i64) * 1000;
|
||||||
|
xous::send_message(
|
||||||
|
self.rtc_conn,
|
||||||
|
xous::Message::new_scalar(
|
||||||
|
TimeOp::SetTzOffsetMs.to_usize().unwrap(),
|
||||||
|
(((offset_ms as u64) >> 32) & 0xFFFF_FFFF) as usize,
|
||||||
|
(offset_ms & 0xFFFF_FFFF) as usize,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
Err(e) => log::error!("Failed to parse time: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This is just a placeholder function - needs to be upgraded to consider prompting the user for
|
/// This is just a placeholder function - needs to be upgraded to consider prompting the user for
|
||||||
/// a PIN value, etc.
|
/// a PIN value, etc.
|
||||||
pub(crate) fn get_pin_key(&self) -> [u8; 32] {
|
pub(crate) fn get_pin_key(&self) -> [u8; 32] {
|
||||||
|
|
|
||||||
|
|
@ -411,7 +411,7 @@ fn main() -> ! {
|
||||||
}
|
}
|
||||||
Some(VaultOp::KeyPress) => xous::msg_scalar_unpack!(msg, k1, _k2, _k3, _k4, {
|
Some(VaultOp::KeyPress) => xous::msg_scalar_unpack!(msg, k1, _k2, _k3, _k4, {
|
||||||
let k = char::from_u32(k1 as u32).unwrap_or('\u{0000}');
|
let k = char::from_u32(k1 as u32).unwrap_or('\u{0000}');
|
||||||
log::info!("key {}", k);
|
log::debug!("key {}", k);
|
||||||
if menu_active {
|
if menu_active {
|
||||||
menu_mgr.key_press(k);
|
menu_mgr.key_press(k);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue